---
title: Model Context Protocol (MCP)
---
# Model Context Protocol (MCP)
The Model Context Protocol (MCP) gives models access to external tools such as search, databases, and internal APIs through a standard interface. SMG acts as the MCP client: it connects to MCP servers, offers their tools to the model as function tools, runs the calls the model makes, and feeds the results back until the model answers. The model never connects to an MCP server and never sees its credentials.
---
## Overview
### :material-tools: Gateway-Side Tool Loop
SMG runs each MCP call and calls the model again, so the client gets the final answer plus a record of every call.
### :material-shield-check: Credential Isolation
Server tokens and headers stay in the config file or the request. The model only sees tool names, descriptions, schemas, and results.
### :material-timer-sand: Bounded Execution
Every call has a deadline, an interrupted call is never silently re-run, and each request has a tool-call budget.
### :material-server-network: Static and Dynamic Servers
Connect servers from a config file at startup, or per request by URL over a pooled connection.
---
## Where MCP Runs
SMG runs the MCP tool loop on these paths:
| API | Backend | How a request opts in |
|-----|---------|------------------------|
| Responses (`POST /v1/responses`) | gRPC or ZMQ workers (not with `--epd-disaggregation`), including gpt-oss (Harmony) models | An `mcp` tool, or a built-in tool that is routed to MCP |
| Responses (`POST /v1/responses`) | OpenAI-compatible provider (`--backend openai`, or an external worker in IGW mode, which SMG routes by model name) | Same as above |
| Messages (`POST /v1/messages`) | Anthropic provider (`--backend anthropic`, or an external worker in IGW mode whose discovered models are named `claude-*`) | The `X-SMG-MCP: enabled` header plus `mcp_servers` and `mcp_toolset` tools (see [MCP in the Messages API](#mcp-in-the-messages-api)) |
No other path runs MCP tools. Chat Completions has no MCP loop, SMG forwards `/v1/responses` requests to HTTP workers with their `mcp` tools left in place, and on gRPC workers the Messages API ignores `mcp_toolset` tools.
---
## How It Works
1. **Resolve servers.** An `mcp` tool with only a `server_label` refers to a static server from the config file. An `mcp` tool with a `server_url` opens (or reuses) a pooled connection to a dynamic server. A built-in tool such as `web_search_preview` adds the static server configured for it.
2. **Expose tools.** SMG adds each server's tools to the model request as function tools, after `allowed_tools` filtering, aliases, and name de-duplication.
3. **Generate.** The model runs, and SMG parses its tool calls.
4. **Execute.** Calls to MCP tools pass the [approval](#approval) check and run on their server under the [per-call timeout](#per-call-timeout). On gRPC workers, calls to the client's own function tools go back to the client.
5. **Loop.** SMG appends the calls and their results to the conversation and calls the model again, until the model answers without tool calls or a [limit](#tool-loop-limits) stops the loop.
6. **Respond.** In the Responses API, `mcp_list_tools` and `mcp_call` items (or hosted-tool items such as `web_search_call`) come before the model's answer in `output`. In the Messages API, executed calls appear as `mcp_tool_use` and `mcp_tool_result` blocks.
---
## Servers and Transports
### Transports
| `protocol` | Servers | Connection |
|------------|---------|------------|
| `stdio` | Static only | SMG starts `command` with `args` as a child process and speaks MCP over its stdin and stdout. The process inherits SMG's environment plus `envs`, and its stderr goes to SMG's stderr. |
| `streamable` | Static and dynamic | Streamable HTTP to `url`. `token` is sent as `Authorization: Bearer