MCP gateway
Model Context Protocol servers give models tools, such as searching Jira or reading a database. Without a gateway every developer configures each server in their own client with their own credential, and nobody knows which tools are in use. With the Spanway MCP gateway you register a server once. The upstream credential stays on the gateway, every MCP client connects to one address with a virtual key, every tool call is checked against the key and team, screened by guardrails, costed and written to the logs, and the Admin UI shows health, sessions and usage per server. Models get the same tools inside chat and Responses API requests.
This page covers registering a server and connecting a client. The rest of the section goes deeper.
| Topic | Page |
|---|---|
| OAuth servers, dynamic client registration and the gateway's own authorization server | OAuth and dynamic client registration |
| Per-user credentials, bring your own key and per-user environment variables | Per-user credentials |
| Well-known connectors that start read-only | Connector catalogue |
| Running beneath an existing enterprise search or knowledge assistant | Enterprise search |
| Turning an OpenAPI specification into MCP tools | OpenAPI specs as MCP tools |
| Toolsets and pinned tool catalogues | Toolsets |
| Semantic tool filtering and tool search | Tool filtering and search |
The mcp_security and mcp_jwt_signer guardrails | MCP guardrails |
| Access control by key, team and client application, sessions and submissions | Access control |
| Calling tools with plain HTTP | MCP tools over REST |
| Relaying elicitation requests to the client | Elicitation |
| The admin MCP server that manages the gateway itself | Admin MCP server |
| Servers behind AWS IAM | MCP with AWS SigV4 |
A real-world scenario
A support team wants its assistant to look up Jira issues. The platform admin registers the Jira MCP server on the gateway with the team's service token and allows only search_issues and get_issue. Developers add one entry to their MCP client that points at the gateway with their own virtual key. The assistant can search Jira, the Jira token never reaches a laptop, and the admin sees every search on the Logs page with its cost. When the team needs more, the admin changes the allowed tools once and every client picks it up.
Register a server
Only proxy admins can add, import, edit or delete servers. Servers come from mcp_servers in config.yaml, from the MCP Servers page or from POST /v1/mcp/server. Servers created in the Admin UI or the API are stored in the database and loaded by every instance.
-
In the Admin UI, open MCP Servers and click + Add New MCP Server. Pick a connector from the catalogue or click + Custom Server.
-
Fill in MCP Server Name, choose Transport Type (Streamable HTTP for most servers), enter the MCP Server URL and choose an Authentication type with its Authentication Value. The Connection Status card connects to the server and lists its tools, and Tool Configuration lets you untick the tools users must not call. Click Add MCP Server. The toast reads "MCP Server created successfully".
-
Or register the same server with the API:
curl -X POST http://localhost:4000/v1/mcp/server \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"server_name": "jira","url": "https://mcp.jira.internal.example.com/mcp","transport": "http","auth_type": "bearer_token","credentials": {"auth_value": "os.environ/JIRA_MCP_TOKEN"},"allowed_tools": ["search_issues", "get_issue"],"description": "Read access to Jira issues"}'Expected result, with status 201:
{"server_id": "8f1c2d3e-4b5a-4c6d-9e7f-0a1b2c3d4e5f","server_name": "jira","alias": "jira","url": "https://mcp.jira.internal.example.com/mcp","transport": "http","auth_type": "bearer_token","allowed_tools": ["search_issues", "get_issue"],"created_by": "admin"} -
The server appears as a card on MCP Servers with a Healthy badge once the first health check passes.
GET /v1/mcp/server/healthruns the check on one or every server you may see.
The same server in config.yaml:
mcp_servers:
jira:
url: https://mcp.jira.internal.example.com/mcp
transport: http
auth_type: bearer_token
authentication_token: os.environ/JIRA_MCP_TOKEN
allowed_tools: ["search_issues", "get_issue"]
mcp_info:
description: Read access to Jira issues
| Field | Meaning |
|---|---|
url | Server URL. For stdio servers use command, args and env instead. |
transport | http, sse or stdio. The 2026-07-28 protocol revision needs http or stdio. |
auth_type | none, api_key, bearer_token, basic, authorization, token, oauth2, oauth2_token_exchange, oauth2_id_jag, aws_sigv4, true_passthrough or oauth_delegate. |
authentication_token | Credential for the chosen auth type. In the API the same value is credentials.auth_value. |
allowed_tools | Only these tools are exposed. Per-key and per-team tool grants narrow the list further, see access control. |
tool_name_to_display_name, tool_name_to_description | Rename or re-describe tools for your users. |
static_headers, extra_headers | Headers always sent to the server, and client headers forwarded unchanged. |
allowed_params | Restrict which tool parameters callers may set. |
spec_path | An OpenAPI document to turn into tools, see OpenAPI specs. |
mcp_info.protocol_version | MCP revision to speak upstream, auto by default. |
timeout, max_concurrent_requests, rpm | Per-server upstream timeout, concurrency cap and request rate. |
allow_all_keys | Let every key reach the server without an explicit grant. |
available_on_public_internet | Set to false for servers only reachable from internal networks, which pairs with mcp_internal_ip_ranges. |
mcp_access_groups | Group names that keys and teams can be granted instead of individual servers. |
catalog_entry | The connector this server belongs to, which turns on the read-only default of the connector catalogue. |
enabled_write_tools | Write tools of a catalogue connector that agents may use, by exact name. Defaults to an empty list, so a catalogue server serves only its read tools. Adding a tool lets agents change data with it, for example create a work item, which is also what a prompt injection would try, so add only the tools a team needs. Only proxy admins should change it, in the Admin UI under Tool access or with PUT /v1/mcp/server/{server_id}/tool-policy, and each change is audited. |
instructions | Server instructions returned to clients at initialisation. |
Stored credentials never follow a server to a new destination on their own. An update that changes url or another destination field, such as token_url or authorization_url, while it leaves the stored secret out or sends it back masked, is refused with 400 and a message that names the changed field and asks you to enter the secret again. Per-user values are cleared as described in per-user credentials.
POST /v1/mcp/server/import takes a Claude Desktop or Claude Code mcpServers mapping, or an Anthropic Messages API mcp_servers array, and creates one server per entry, reporting the outcome of each. The Import from JSON button on MCP Servers does the same. GET /v1/mcp/discover returns the connector catalogue the Add MCP Server dialog shows. POST /mcp-rest/test/connection and POST /mcp-rest/test/tools/list try a definition before you save it, see MCP tools over REST.
Connect a client
-
Create or pick a virtual key that may reach the server. On Virtual Keys, edit the key and select the server in the MCP server picker, or grant it as shown in access control. An admin key reaches every server.
-
Open MCP Servers, then the Connect tab, and copy the snippet for your client. Each client has its own file format and its own way to read a secret from the environment, so MCP clients has a working configuration per client. In Cursor's
mcp.jsonthe entry looks like this, and${env:SPANWAY_API_KEY}reads the key from the environment Cursor was started in:{"mcpServers": {"spanway": {"url": "http://localhost:4000/mcp","headers": {"Authorization": "Bearer ${env:SPANWAY_API_KEY}", "x-mcp-servers": "jira"}}}}A JSON configuration file is not run through a shell, so a bare
$SPANWAY_API_KEYis sent as those literal characters and the gateway answers 401. Use the client's own variable syntax or paste the key itself. The gateway reads the key fromAuthorization: Bearer <key>or fromx-spanway-api-key, and when a client sends both, for example because its OAuth sign-in fillsAuthorization,x-spanway-api-keywins. -
Restart the client. Its tool list shows
jira-search_issuesandjira-get_issue. Tools are namespaced as{server_name}-{tool_name}so two servers can expose a tool with the same name. -
On MCP Servers, the Live Connections tab lists the client's session with its name, version, user and key alias.
Without further headers a session sees every server the key may use. The x-mcp-servers header narrows it to named servers and x-mcp-access-groups to access groups. One server is reachable at /mcp/{server_name}, the form to use for new setups, and the older /{server_name}/mcp still works because the gateway rewrites it to the new form. A toolset is reachable at /toolset/{toolset_name}/mcp. Clients that only speak OAuth, such as desktop assistants and MCP inspectors, can discover the gateway as their authorization server and sign in through the gateway's own login, see OAuth.
general_settings.mcp_advertised_versions lists the protocol revisions the gateway offers to clients. The default is every completed legacy revision (2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25) and the 2026-07-28 revision has to be listed explicitly.
Tools in model requests
A chat completion or Responses API request lists registered servers in tools, and the gateway runs the tool calls the model makes against them within the limits of the calling key.
curl -X POST http://localhost:4000/v1/responses \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"input": "Which Jira issues are assigned to me?",
"tools": [{"type": "mcp", "server_label": "jira", "server_url": "spanway_proxy/mcp/jira", "require_approval": "never"}]
}'
The response carries the model's answer and an mcp_call output item per tool call, and the call is logged against the key with the server's cost. The MCP security guardrail rejects requests that name a server the gateway does not know, and the semantic tool filter keeps the tool list a model sees short.
Cost tracking
Each server can carry mcp_info.mcp_server_cost_info with default_cost_per_query and tool_name_to_cost_per_query. In the Admin UI these are the Cost Configuration card of the server form. Every tool call is written to the spend logs with that cost against the calling key, team and user, the same way model calls are, and GET /v1/tool/spend adds it up per tool, see the tool registry.
Management routes
{{ops:^/v1/mcp/(server|access_groups|discover|make_public|registry.json|tools)$|^/v1/mcp/server/(import|health|register|submissions)$|^/v1/mcp/server/{server_id}$|^/v1/mcp/server/{server_id}/(approve|reject|pin)$}}
GET /v1/mcp/registry.json serves the registered servers in the MCP registry format so registry aware clients can browse them. It is off by default and answers 404 "MCP registry is not enabled" until you set general_settings.enable_mcp_registry: true. POST /v1/mcp/make_public publishes servers to the AI hub, where GET /public/mcp_hub lists them without authentication. Publishing only lists a server on the hub. A server marked internal network only (available_on_public_internet: false) stays unreachable from public addresses even when it is listed. Publishing is audited with the list before and after.
Local command servers
A stdio server runs a program on the gateway's own host, so it is off by default. Set SPANWAY_ENABLE_MCP_STDIO=true on the gateway and restart to allow it. Even then the command must be one of npx, uvx, python, python3, node, docker or deno, and any other command is refused with 403 "MCP stdio command '...' is not in the allowlist (...). Add it to SPANWAY_MCP_STDIO_EXTRA_COMMANDS to allow this command.". To allow another program, list it in SPANWAY_MCP_STDIO_EXTRA_COMMANDS, comma separated. The settings reference lists the other MCP environment variables, such as the timeouts.
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
| 400, message naming a changed destination field | PUT /v1/mcp/server | The URL or an OAuth endpoint changed while the stored secret was left out or sent masked. | Enter the credential again in the same save. |
400 An MCP server with this name/alias already exists. | Create and edit in the Admin UI | Names and aliases are unique, ignoring case and treating spaces as underscores. | Pick another name. Names cannot contain hyphens or spaces. |
400 An MCP server with <field> '<value>' already exists (server_id=<id>). MCP server names and aliases must be unique, case-insensitive. | POST, PUT /v1/mcp/server, register and import | The same check through the API, naming the field and the server that holds it. | Pick another name or alias. |
403 MCP stdio command '<command>' is not in the allowlist (...) | Create, test and start of a stdio server | The command is not one the gateway allows. | Use an allowed command, or add it to SPANWAY_MCP_STDIO_EXTRA_COMMANDS. |
404 MCP registry is not enabled | GET /v1/mcp/registry.json | The public registry is off. | Set general_settings.enable_mcp_registry: true. |
403 You can only create mcp servers if you are a PROXY_ADMIN. | POST /v1/mcp/server | The key is not a proxy admin key. | Use an admin key, or submit the server for review with POST /v1/mcp/server/register, see access control. |
404 on /mcp | Any client | The MCP dependency is missing from the gateway, or the client calls a server name that is not registered. | Use the Spanway image, which bundles it, and check the name on MCP Servers. |
404 mcp-session-id was terminated by an administrator. Send initialize to start a new session. | Any client | An admin closed the session on Live Connections or with DELETE /v1/mcp/sessions, and the client kept sending the old session id. | Restart the client or reconnect the server so it sends initialize again. A session id that simply expired or landed on another gateway worker is replaced without an error. |
401 with the literal text $SPANWAY_API_KEY in the client log | Any client with a JSON config | The client sent the variable name, because JSON files are not expanded by a shell. | Use the client's variable syntax from MCP clients or paste the key. |
| Card badge Unhealthy | MCP Servers | The last health check failed. The tooltip shows the upstream error. | Check the URL, the credential and whether the server is reachable from the gateway. |
| Card badge stdio disabled | MCP Servers | A stdio server on a gateway where stdio is off. | Set SPANWAY_ENABLE_MCP_STDIO=true and restart. |
500 Could not save the MCP server. The gateway log has the cause. | POST /v1/mcp/server, POST /v1/mcp/server/register, and per entry in the errors list of POST /v1/mcp/server/import | Saving the server failed, usually because the database is down. The database's own message stays in the log, because it can name stored values. | Read the Error creating mcp server, Error registering mcp server or Error importing mcp server log line, then retry. |
500 Could not stage the MCP server. The gateway log has the cause. | POST /v1/mcp/server/oauth/session | The server form's OAuth test could not stage the server. | Read the Error caching temporary mcp server log line, usually Redis or the database. |
200 with "error": true and Failed to load the OpenAPI spec. The gateway log has the cause. | POST /mcp-rest/test/tools/list for an OpenAPI backed server | The spec_path could not be fetched or parsed. The reason stays in the log, because it can carry a URL with credentials. | Read the Error previewing OpenAPI tools log line, then check that the gateway can reach spec_path and that it holds valid OpenAPI JSON or YAML. |
| Client sees no tools | Any client | The key has no grant for the server and allow_all_keys is off, or allowed_tools leaves nothing. | Grant the server, see access control. GET /v1/mcp/tools shows what a key ends up with. |
Logs
| Level | Line | What it means | Action |
|---|---|---|---|
| ERROR | Error creating mcp server: <error>, Error registering mcp server: <error>, Error importing mcp server <name>: <error> or Error caching temporary mcp server: <error> | A save behind one of the 500 answers above failed. The caller only saw the fixed text, the cause is here. | Fix what the error names, usually the database. |
| ERROR | Error previewing OpenAPI tools: <error> | The OpenAPI preview behind POST /mcp-rest/test/tools/list could not load spec_path. The caller only saw the fixed text. | Fix what the error names, usually an unreachable URL or a spec that is not valid OpenAPI. |
| ERROR | MCP server <id> created but in-memory registry refresh failed: <error> | The server was saved, but this gateway has not loaded it yet. The next reload picks it up. | None unless it repeats. Then check the server definition. |
| WARNING | Rejected MCP request from a disallowed client application: <details> | A client not listed in mcp_allowed_clients was refused with 403. | None if the client should not connect. Otherwise add it to the list. |
| WARNING | MCP server '<name>' will not start: stdio MCP servers are disabled ... | A stdio server is configured but SPANWAY_ENABLE_MCP_STDIO is off. | Turn stdio on, or remove the server. |
| INFO | Loading OpenAPI spec from <path> for server <name> | An OpenAPI server is building its tools from the spec. | None. |
The log reference lists every MCP line.
Related
- MCP clients for a working configuration per client.
- MCP access control for grants, client allow lists, networks and sessions.
- The MCP Servers page for every control of the Admin UI.
- MCP tools over REST for scripts that are not MCP clients.
- Tool registry and tool policies for trust policies on the tools models call.
- Logs for finding tool calls by server and key.