# ApiWall > ApiWall turns selected HTTP API operations into one MCP endpoint. An external agent can write a contract and give the user a preview link to review and save it. ## Create and share a contract 1. Check the service's documentation for the exact routes, authentication, encoding, response fields, and operation scope. Describe only the operations the user wants. 2. Write one `schemaVersion: 4` contract using the [MCP JSON Schema](/mcp.schema.json) and the runtime rules below. Save it as `mcp.json`. 3. Send the raw JSON to [POST /api/validate](/api/validate) with `Content-Type: application/json`. Fix the reported `issues` until the response has `valid: true`. Validation checks the contract and makes no request to the upstream API. 4. Send the same JSON to [POST /api/contracts](/api/contracts). The service stores the contract. Anyone with its non-expiring link can view the preview and save their own copy. 5. In your reply, include the exact `url` from HTTP 201 as the contract preview link and give the user each of these steps. 1. Open the preview, review the tools and choose **Сохранить** (Save) to create a draft. 2. In the [workspace](/app/), set up any required connection and settings on the **MCP** tab. 3. Publish the MCP and grant your MCP client access. Both POSTs use the origin where you fetched this guide and need no ApiWall login or key. Send the contract itself, without a wrapper or real values for private hosts, credentials or other private settings. If you cannot send POST requests, give the user the JSON and these commands. Replace `https://HOST` with this installation's scheme, hostname and port. ```sh curl --fail-with-body --request POST 'https://HOST/api/validate' --header 'Content-Type: application/json' --data-binary '@mcp.json' curl --fail-with-body --request POST 'https://HOST/api/contracts' --header 'Content-Type: application/json' --data-binary '@mcp.json' ``` Run the second command only after `valid: true`. ## Contract rules - Use `adapter: {"id":"http","version":1,"baseUrl":"https://api.example.com/"}`. Use `${connection.serverUrl}` if the owner supplies the HTTPS address. Preserve any API path prefix in `baseUrl` or `request.path`. Optional `adapter.iconUrl` is a literal public HTTPS URL. - Use closed JSON Schema 2020-12 objects with `properties` and `additionalProperties: false` for `connectionSchema`, `settingsSchema` and `inputSchema`. Only local `$ref` references are supported. - Put reusable fields in `connectionSchema`, with empty `properties` for an anonymous API with a fixed host. Connections match by resolved HTTPS origin and schema. Use consistent lowerCamelCase field names, types, required fields, constraints and secret flags for the same authentication profile. For Telegram Bot API, require a secret string `botToken`. For Carrot Quest, require a secret string `apiKey` with `minLength: 1` and an integer `appId` with `minimum: 1`. - Use optional `settingsSchema` for owner-set values scoped to this MCP, such as a fixed room. Reserve `inputSchema` for bounded arguments the caller may change. Put fixed restrictions directly in the request or in owner-controlled settings. Mark credential fields with `secret: true` in `connectionSchema` or `settingsSchema`. The owner enters their values in the workspace. - Give every field in `connectionSchema` and `settingsSchema` a short `title` and helpful `description` in the owner's language. Use the description to explain what to enter and where to find it. Keep the technical keys stable in schemas and templates. - Each tool has one `request`, with a static method and relative path without a leading slash or query string. Use `request.query` for scalars or arrays of scalars and `request.headers` for strings. A body defaults to JSON. Use `request.contentType: "application/x-www-form-urlencoded"` for a flat form if the API requires it. - Use `outputs` to select and validate JSON response fields by JSON Pointer. An empty pointer selects the whole body, and an empty body is treated as `null`. Select only the fields needed or project them in `result`. A schema validates data. Selecting an object can still include fields beyond those listed in its schema. If the result must be an array, add an explicit branch returning `[]` for empty input because `$map` on an empty array returns `null`. ## JSON-e templates Use [JSON-e](https://json-e.js.org/) at these boundaries: | Field | What is evaluated | Context | | --- | --- | --- | | `adapter.baseUrl` | Whole value | `connection` | | `adapter.headers` | Each header value | `connection`, `settings` | | `request.headers`, `request.query` | Each header or parameter value | `args`, `connection`, `settings` | | `request.body` | Whole body | `args`, `connection`, `settings` | | `result` | Whole result | `args`, validated `outputs`, non-secret `connection` and `settings` fields | Use `{"$eval":"args.limit"}` to preserve the JSON type and `"${args.limit}"` for a string. To omit an optional value when absent, use `{"$if":"'limit' in args","then":{"$eval":"args.limit"}}` as the parameter value. This preserves valid values such as `0` and `false`. Query and form values cannot be `null`. `request.path` accepts only direct scalar placeholders such as `users/${args.userId}`. ApiWall escapes their values. ### ApiWall functions Call these functions inside JSON-e expressions such as `$eval`. Inputs, keys and return values are strings. When provided, `options` is an object with the keys listed for that function. | Signature | Options and defaults | | --- | --- | | `crypto.hash(algorithm, input, options?)` | `inputEncoding: 'utf8'`, `outputEncoding: 'hex'` | | `crypto.hmac(algorithm, key, input, options?)` | `keyEncoding: 'utf8'`, `inputEncoding: 'utf8'`, `outputEncoding: 'hex'` | | `base.encode16(input, options?)` | `inputEncoding: 'utf8'` | | `base.decode16(input, options?)` | `outputEncoding: 'utf8'` | | `base.encode64(input, options?)` | `inputEncoding: 'utf8'` | | `base.decode64(input, options?)` | `outputEncoding: 'utf8'` | | `base.encode64url(input, options?)` | `inputEncoding: 'utf8'` | | `base.decode64url(input, options?)` | `outputEncoding: 'utf8'` | - Algorithms are `sha256`, `sha384` and `sha512`. Hash and HMAC output accepts `hex`, `base64` and `base64url`. Other encoding options also accept `utf8`. Names are case-sensitive. - Suffixes `16`, `64` and `64url` mean `hex`, `base64` and `base64url` respectively. They specify the output of `base.encode*` and the input of `base.decode*`. Hex uses two digits per byte, Base64 requires `=` padding when needed, and Base64url omits padding. Encoded inputs require the expected alphabet and padding, without whitespace. Use `outputEncoding: 'hex'` to decode arbitrary bytes, as in `base.decode64('/w==', {outputEncoding: 'hex'})`, which returns `ff`. - Choose the hash or HMAC `outputEncoding` directly to encode the digest bytes. Build the signing string in the exact order and encoding required by the API. Set `keyEncoding` when the key is supplied as encoded bytes. Keep credentials and their transformations in the request. For an API that expects a Base64 HMAC-SHA256 of a UTF-8 message, use this fragment in `request.headers`. Declare `connection.signingKey` as a secret string and `args.message` as a bounded string. ```json {"X-Signature":{"$eval":"crypto.hmac('sha256', connection.signingKey, args.message, {outputEncoding: 'base64'})"}} ``` ## Example: Rocket.Chat channel history The owner chooses the server and credentials in `connection` and fixes the room for this MCP in `settings`. The caller controls only `count`. [Rocket.Chat channel history](https://developer.rocket.chat/apidocs/get-channel-history). ```json { "schemaVersion": 4, "title": "Support room messages", "description": "Read messages only from the owner's fixed support room.", "adapter": { "id": "http", "version": 1, "baseUrl": "${connection.serverUrl}", "iconUrl": "https://www.rocket.chat/favicon.ico", "headers": {"X-User-Id": "${connection.userId}", "X-Auth-Token": "${connection.authToken}"} }, "connectionSchema": { "type": "object", "properties": { "serverUrl": { "type": "string", "pattern": "^https://[^/?#]+/$", "title": "Адрес сервера", "description": "Корневой HTTPS-адрес сервера Rocket.Chat с косой чертой в конце." }, "userId": { "type": "string", "minLength": 1, "title": "Идентификатор пользователя", "description": "ID пользователя Rocket.Chat, от имени которого выполняются запросы." }, "authToken": { "type": "string", "minLength": 1, "secret": true, "title": "Токен авторизации", "description": "Токен для доступа к API Rocket.Chat от имени этого пользователя." } }, "required": ["serverUrl", "userId", "authToken"], "additionalProperties": false }, "settingsSchema": { "type": "object", "properties": { "roomId": { "type": "string", "minLength": 1, "title": "Идентификатор комнаты", "description": "ID комнаты Rocket.Chat, из которой этот MCP читает сообщения." } }, "required": ["roomId"], "additionalProperties": false }, "tools": [ { "name": "read_support_messages", "description": "Read up to 100 messages only from the configured support room.", "inputSchema": { "type": "object", "properties": {"count": {"type": "integer", "minimum": 1, "maximum": 100}}, "additionalProperties": false }, "request": { "method": "GET", "path": "api/v1/channels.history", "query": { "roomId": "${settings.roomId}", "count": {"$if": "'count' in args", "then": {"$eval": "args.count"}, "else": 20} } }, "outputs": { "success": {"pointer": "/success", "schema": {"const": true}}, "messages": { "pointer": "/messages", "schema": { "type": "array", "items": { "type": "object", "properties": {"_id": {"type": "string"}, "msg": {"type": "string"}}, "required": ["_id", "msg"] } } } }, "result": { "$if": "len(outputs.messages) == 0", "then": [], "else": { "$map": {"$eval": "outputs.messages"}, "each(message)": {"id": {"$eval": "message._id"}, "text": {"$eval": "message.msg"}} } } } ] } ```