Omniscio

OmniscioGuidesClaude Agent SDK and MCP

Claude Agent SDK: connecting MCP servers to your agent

MCP is how an SDK agent reaches tools you did not write: a database, an issue tracker, an internal API. The SDK runs the same servers Claude Code does, but you configure them in code or a project file, and you decide which ones the agent may call.

This page owns the server connection. The SDK guide owns the agent itself, the custom tools guide owns in-process tools you write in your own code, and adding an MCP server to Claude Code owns the CLI's install scopes. This page links all three.

Sources read November 26, 2026. By the Omniscio team. Updated .

Add a server

There are two places to configure one. Pass servers in the mcpServers option when you call query(), or keep them in a .mcp.json at the project root. The file is picked up when the project setting source is enabled, which it is for default query() options; if you set settingSources yourself, include "project" or the file never loads.

The key you give a server matters later: it becomes part of every tool name. This is a filesystem server passed in code.

query({
  prompt: "List files in my project",
  options: {
    mcpServers: {
      filesystem: {
        command: "npx",
        args: ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]
      }
    },
    allowedTools: ["mcp__filesystem__*"]
  }
})

Check the server's documentation for its transport. A command to run means stdio; a URL means HTTP or SSE; tools you define in your own code mean an in-process SDK server, which the custom tools guide covers.

The three transports

TransportWhen to use itWhat you pass
stdioA local process that talks over stdin and stdout, such as an npx packagecommand and args
httpA cloud-hosted server or remote API, using streamable HTTPtype, url, and headers for credentials
sseA remote server that serves server-sent eventstype: "sse", url, and headers

In JSON config files "streamable-http" is accepted as an alias for "http", but the TypeScript and Python SDK types declare only "http", so servers you pass in code should use "http".

Allowing the tools

MCP tools need explicit permission. Without it Claude sees that the tools exist and cannot call them, which is why an agent can have a server connected and never use it.

Names follow mcp__<server-name>__<tool-name>, where the server name is the key you registered with dots and spaces replaced by underscores. A list_issues tool on a server keyed github is mcp__github__list_issues; on a server keyed my.server it is mcp__my_server__list_issues.

allowedTools: [
  "mcp__github__*",        // every tool from the github server
  "mcp__db__query",        // only the query tool from db
  "mcp__slack__send_message"
]

Prefer allowedTools over a permission mode for this. acceptEdits does not auto-approve MCP tools at all; bypassPermissions does, but it also disables most other safety prompts. A wildcard grants exactly the server you want and nothing more.

To see what a server offers, read the tools array in the init message: MCP tool names start with mcp__, and the array lists the servers that connected inside the first-turn wait plus those with a cached tool list. Servers still connecting are absent from it.

When the first turn waits

A stdio server, or an HTTP/SSE server with no cached tool list, delays the first turn until it connects or until MCP_TIMEOUT expires — 30 seconds by default, after which the connection fails. A remote server with a cached tool list does not delay the first turn: it connects on its first tool call.

Servers from a settings file such as .mcp.json, or from plugins, often still show pending in the init message. When options.mcpServers holds no stdio, HTTP or SSE server, the first turn waits up to 2 seconds for them — the default with tool search on — and only for pending servers that set alwaysLoad: true or that you named in allowedTools; the rest keep connecting in the background. A stdio, HTTP or SSE server in options.mcpServers makes the first turn wait for the pending settings-file and plugin servers too, up to MCP_TIMEOUT.

To set the wait yourself, pass CLAUDE_CODE_MCP_STARTUP_WAIT_MS in the SDK's env option; it needs Claude Code v2.1.274 or later. Three waits survive any value you set, including 0: a permission-prompt tool's server and an in-process SDK server each wait up to MCP_TIMEOUT, and a named server that is still connecting waits at least 2 seconds.

To make startup itself wait, set MCP_CONNECTION_NONBLOCKING to 0 and cap the wait with MCP_CONNECT_TIMEOUT_MS, or mark a server alwaysLoad: true so its tools are there at full schema from the first turn.

Credentials

A server that needs a credential takes it in one of three places. For a stdio server, pass it in the env field of the server's configuration. For a remote server, send it as an HTTP header such as Authorization. For a server that speaks OAuth2, complete the flow in your app and supply the access token it returns.

mcpServers: {
  "api-server": {
    command: "npx",
    args: ["-y", "@your-org/api-mcp-server"],
    env: { API_KEY: process.env.API_KEY }
  }
}

Reading a server's status

Claude Code emits a system message with subtype init at the start of each query, and it carries a status for every server: pending, connected, failed, needs-auth or disabled.

Do not treat pending as a failure. It can mean the server has not connected yet, that its tool list came from the cache and it will connect on first use, or that the first-turn wait ended before it connected. Check for failed and needs-auth to find servers that will not be usable, and ask for updated status later in the session with mcpServerStatus() in TypeScript or get_mcp_status() in Python.

The usual causes behind failed are a missing variable, or an env field that does not match what the server expects; an npx package that is not installed, or a Node.js that is not on PATH; a malformed database connection string; or a remote URL a firewall blocks.

Two limits matter. A server that takes longer than 30 seconds to start fails unless MCP_TIMEOUT is raised, and MCP_TOOL_TIMEOUT caps a running tool call. A tool result larger than 25,000 tokens with no image content is written to a file and replaced by a message naming that file, so the agent can read it back in pieces; MAX_MCP_OUTPUT_TOKENS changes that token limit, and unless the tool declares anthropic/maxResultSizeChars, a text result over 50,000 characters is saved to a file regardless of it.

Sources

Every line on this page rests on these. The date beside each one is the day we read it.

  • Connect to external tools with MCP, for the quickstart, the two configuration routes, transports, tool naming, allowedTools, connection timing, tool search, authentication, status handling and the output limit. Read November 26, 2026.
  • Give Claude custom tools, for the boundary between an in-process SDK server and an external one. Read November 26, 2026.

No SDK agent was run for this page. Every name, default and message is transcribed from those pages.

Common questions

How do I add an MCP server to a Claude Agent SDK agent?

Pass it in the mcpServers option of query(), or put it in a .mcp.json at the project root, which loads when the project setting source is on. Give each server a key, because the key becomes part of every tool name.

What are the MCP tool names in the Agent SDK?

They are mcp__<server-name>__<tool-name>, where the server name is the key you registered, with characters such as dots and spaces replaced by underscores. A tool called list_issues on a server keyed github is mcp__github__list_issues.

Why is my MCP server still pending in the init message?

Pending is not a failure. It can mean the server has not connected yet, that its tool list came from the cache and it will connect on first use, or that the first-turn wait ended before it connected. Check for failed or needs-auth to find servers that will not work.

Does the Agent SDK use tool search for MCP tools?

Yes, it is on by default. Tool definitions are withheld from context and loaded when a turn needs them, which keeps a large MCP setup from consuming the window. A server marked alwaysLoad is exempt; one named in allowedTools gets the first-turn wait, but its tools are still deferred.

How do I authenticate an MCP server in the Agent SDK?

For stdio servers pass credentials in the env field. For remote servers send them as HTTP headers, or complete an OAuth2 flow and supply the resulting access token. Most servers take one of these three.

Every session, one window

Omniscio runs several agent sessions side by side in one window, each with its own context and its own diff view. Any model, any harness: Claude Code, Codex, OpenCode, Devin, Pi, and Hermes all supported.