An MCP server for every mock
Every deployed mock is also an MCP server for the same API, at
/mock/<name>/_rustybin/mcp: one tool per operation, answered by the mock. Upload
the customer's OpenAPI description and you have an MCP upstream that speaks their
domain, for MCP gateway demos (per-tool authorization and rate limits, guardrails
on tool arguments and results, audit, tool filtering), for comparing a gateway's
REST-to-MCP conversion with a native MCP server over identical data, and for
giving an agent a realistic tool set before the real API exists.
claude mcp add --transport http petstore http://localhost:8080/mock/petstore/_rustybin/mcp
With RUSTYBIN_MOCKS_HOST, the same server answers at
<name>.<domain>/_rustybin/mcp. Self-service mocks have one too, on the mocks
domain only. The console's MCP server tab on a mock shows the URL, the
claude mcp add command and mcpServers JSON, and which operations are tools.
The server
The endpoint speaks Streamable HTTP with the same protocol versions as the
mock MCP server: 2026-07-28 (stateless, server/discover) and the
2025 handshake versions (initialize, Mcp-Session-Id). It offers tools, one
resource (the OpenAPI document the mock serves, rustybin://mock/<name>/openapi.json)
and logging. Legacy HTTP+SSE is not offered.
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: server/discover
{"jsonrpc": "2.0", "id": 1, "method": "server/discover", "params": {"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.capabilities.tools" exists
jsonpath "$.result.capabilities.resources" exists
jsonpath "$.result._meta['io.modelcontextprotocol/serverInfo'].name" == "rustybin-mock-petstore"
jsonpath "$.result.instructions" contains "Petstore"
It is a data-plane route like the rest of /mock/*: never behind control-plane
authentication, subject to plan limits, API keys and quotas like any other request,
captured by the request inspector, and open to fault injection. A mock that does not
exist, is not deployed or is switched off, or whose MCP server is disabled, answers
404 with a JSON-RPC error (for self-service mocks always the same message, so other
visitors' names cannot be probed).
Operations as tools
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.tools" count == 6
jsonpath "$.result.tools[*].name" contains "getPetById"
jsonpath "$.result.tools[2].inputSchema.required[0]" == "petId"
jsonpath "$.result.tools[2].annotations.readOnlyHint" == true
jsonpath "$.result.tools[4].annotations.destructiveHint" == true
jsonpath "$.result.tools[2]._meta['rustybin.dev/operation'].path" == "/pets/{petId}"
| Part of the tool | Comes from |
|---|---|
name | The operationId (or the generated id, such as get_pets_petId), limited to A-Z a-z 0-9 _ . - and 64 characters; a name taken twice gets _2, _3 in spec order |
title, description | The summary; the summary, description and METHOD /path, at most 1,000 characters. Deprecated operations start with "Deprecated." |
inputSchema | One flat object: path parameters (always required), query, header and cookie parameters under their names, and the request body under body |
outputSchema | {status, body} with the schema of the default 2xx JSON response, when the operation documents one |
annotations | From the method: GET, HEAD and OPTIONS are read only, DELETE is destructive, GET, HEAD, OPTIONS, PUT and DELETE are idempotent; openWorldHint is false |
_meta["rustybin.dev/operation"] | The operationId, method and path behind the tool |
Schemas are self-contained: $refs are inlined (to a depth of 8; a recursive
reference becomes an empty schema with a description), OpenAPI 3.0 nullable
becomes a null type, boolean exclusiveMinimum and exclusiveMaximum become
numeric, readOnly properties are left out of arguments and writeOnly properties
out of results. When two parameters share a name (id in the path and the query),
the later one is called <location>_<name> (query_id) and its description says
where it goes.
Some things are never arguments: Authorization, Content-Type, Accept,
Cookie and the API key parameters of the spec's security schemes. Credentials come
from the MCP request instead (see Security). Operations whose request
body is not JSON (forms, multipart, XML, binary) are not tools in this version; the
mock's detail lists them under mcp.skipped with the reason.
Calling a tool
A call becomes a request to the operation (path parameters substituted and percent-encoded, the query string, header and cookie arguments (a cookie argument is percent-encoded where RFC 6265 does not allow the byte, so it cannot add another cookie), the JSON body) and runs through the mock exactly like a request over HTTP. Rules, overrides, examples, generated data, stateful mode, request validation, mocked security, delays and the restrictions on self-service responses all apply, so a tool returns what the REST call returns:
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: getPetById
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {
"name": "getPetById", "arguments": {"petId": 42}, "_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.isError" == false
jsonpath "$.result.structuredContent.status" == 200
jsonpath "$.result.structuredContent.body.id" == 42
jsonpath "$.result.content[0].type" == "text"
structuredContentis{status, body}for JSON and empty bodies; the text content carries the same JSON. Other bodies are returned as text.- A status outside 2xx is a tool error (
isError: true) with the problem body, so a model sees the 404 or 422 it would have got over REST:
# The sample's rule answers 404 for pet 0: a tool error with the problem body.
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: getPetById
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {
"name": "getPetById", "arguments": {"petId": 0}, "_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.isError" == true
jsonpath "$.result.structuredContent.status" == 404
jsonpath "$.result.structuredContent.body.message" == "pet not found"
- When the tool declares an output schema and a 2xx body does not match it (a rule or override that returns something else), the call is a tool error that names the mismatch instead of structured content a client would reject.
- Arguments that are unknown, missing (required path parameters and bodies) or of
the wrong kind are a tool error before anything is sent. Everything else is the
mock's request validation (
responses.validate_requests): withenforcethe call answers the400and its errors. - A slow answer (a configured delay) reports progress every second to a client that asked for it; cancelling the request stops the call.
Every call is captured in the mock's traffic, marked with channel: "mcp" and the
tool name (the console shows an MCP badge):
# The call is in the mock's traffic, marked as an MCP tool call.
GET {{base_url}}/_rustybin/mocks/petstore/requests?limit=1
HTTP 200
[Asserts]
jsonpath "$.requests[0].channel" == "mcp"
jsonpath "$.requests[0].tool" == "getPetById"
jsonpath "$.requests[0].path" == "/v1/pets/0"
jsonpath "$.requests[0].status" == 404
Security
By default the MCP endpoint itself is open, like the mock's REST endpoints. Mocked security
applies per tool: the MCP request's Authorization and Cookie headers, the header
of the api_key mode and the headers and query parameters of the spec's apiKey
schemes are passed into every call. Without a valid credential the call answers the
401 or 403 the REST call would have:
PATCH {{base_url}}/_rustybin/mocks/petstore
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{"security": {"enabled": true}, "deploy": true}
HTTP 200
# Without credentials the call is the 401 the REST call gets.
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: createPet
{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {
"name": "createPet", "arguments": {"body": {"name": "Rex"}}, "_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.isError" == true
jsonpath "$.result.structuredContent.status" == 401
# The MCP request's API key header is passed to the call.
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: createPet
X-API-Key: demo-key
{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {
"name": "createPet", "arguments": {"body": {"name": "Rex"}}, "_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.isError" == false
jsonpath "$.result.structuredContent.status" == 201
jsonpath "$.result.structuredContent.body.name" == "Rex"
So a gateway in front of the MCP server can inject the credential (an API key, a token exchange) and the demo shows the tool failing without it and working through the gateway. The console's snippets include the mock's API key header when security is on.
To try a client's sign-in against a mock, set mcp.oauth: true (the MCP tab's Ask for an
OAuth token, or settings on any surface). The endpoint then answers 401 with protected
resource metadata, as a real protected server does, at
/.well-known/oauth-protected-resource/mock/<name>/_rustybin/mcp, and takes tokens from the
built-in identity provider issued for that mock's own URL (resource=<the MCP URL>): a token for
another mock or for /mcp/protected is refused. Use the instance's address, not a
<name>.<domain> one, and it is not available on a visitor's mock, because the issuer is the
instance's.
# A mock that asks for a token answers as a protected server does.
POST {{base_url}}/_rustybin/mocks
X-Rustybin-Admin-Token: {{admin_token}}
{"name": "docs-mcp-oauth", "mcp": {"oauth": true}, "spec": "{\"openapi\":\"3.0.3\",\"info\":{\"title\":\"G\",\"version\":\"1\"},\"paths\":{\"/a\":{\"get\":{\"operationId\":\"a\",\"responses\":{\"200\":{\"description\":\"ok\"}}}}}}"}
HTTP 201
POST {{base_url}}/mock/docs-mcp-oauth/_rustybin/mcp
Accept: application/json, text/event-stream
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "docs", "version": "1"}}}
HTTP 401
[Asserts]
header "WWW-Authenticate" contains "resource_metadata"
GET {{base_url}}/.well-known/oauth-protected-resource/mock/docs-mcp-oauth/_rustybin/mcp
HTTP 200
[Asserts]
jsonpath "$.resource" contains "/mock/docs-mcp-oauth/_rustybin/mcp"
DELETE {{base_url}}/_rustybin/mocks/docs-mcp-oauth
X-Rustybin-Admin-Token: {{admin_token}}
HTTP 200
Settings
The MCP server is on for every mock. The mcp block of the
settings switches it off or hides operations, in the control
API, rustybin.yaml, exports, the console and the management MCP server's
create_mock and update_mock. Like every setting it goes into the draft and is
served after a deploy.
mcp:
enabled: true # the default
exclude: [deletePet] # operationIds that are not tools
PATCH {{base_url}}/_rustybin/mocks/petstore
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{"mcp": {"exclude": ["deletePet"]}, "deploy": true}
HTTP 200
[Asserts]
jsonpath "$.mcp.tools" count == 5
jsonpath "$.mcp.skipped[0].operation" == "deletePet"
jsonpath "$.mcp.skipped[0].reason" contains "mcp.exclude"
PATCH {{base_url}}/_rustybin/mocks/petstore
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{"mcp": {"enabled": false}, "deploy": true}
HTTP 200
POST {{base_url}}/mock/petstore/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
{"jsonrpc": "2.0", "id": 7, "method": "tools/list", "params": {"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 404
[Asserts]
jsonpath "$.error.message" contains "mcp.enabled"
GET /_rustybin/mocks/<name> describes the server under mcp: url, host_url
(with a mocks domain), enabled, serving (deployed, switched on and enabled), the
tools and the skipped operations with their reasons. The served
openapi.json names the server in an x-rustybin-mcp extension. Deploying a mock
from the management MCP server returns the URL, so an agent can
build a mock and then connect to its tools.
GET {{base_url}}/_rustybin/mocks/petstore
HTTP 200
[Asserts]
jsonpath "$.mcp.url" == "{{base_url}}/mock/petstore/_rustybin/mcp"
jsonpath "$.mcp.serving" == true
jsonpath "$.mcp.tools" count == 6
jsonpath "$.mcp.skipped" count == 0
Limits
- Tools per mock are bounded by the operations a mock may have (500, 200 in public
mode);
tools/listis paginated like on/mcp(?page_size=). - The tool list is computed once per deployed revision and dropped with it; sessions
of the handshake versions use the bounded session store of
/mcpand belong to one mock. - A result carries at most the MCP server's large-output cap (1 MB, 256 KB in public mode); the text copy of a structured result is cut at 32 KB.
- Tool names, descriptions and results of a self-service mock are visitor-written text, served on the mocks domain only. Descriptions are capped and stripped of control characters, and results go through the same response restrictions as the mock's REST answers.