---
title: How to use MCP servers with the Claude Agent SDK
description: Pass remote servers in mcpServers with type http, a URL and auth headers, then allow their tools with allowedTools. TypeScript and Python examples.
canonical: https://mcp1.com/blog/mcp-servers-claude-agent-sdk
last-updated: 2026-11-25
---

# How to use MCP servers with the Claude Agent SDK

Pass remote servers in mcpServers with type http, a URL and auth headers, then allow their tools with allowedTools. TypeScript and Python examples.

![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite

 agent.ts

mcpServers: {
  linear: { type: "http", url, headers }
},
allowedTools: ["mcp__linear__*"]

linearconnected

 agent.ts

mcpServers: {
  linear: { type: "http", url, headers }
},
allowedTools: ["mcp__linear__*"]

linearconnected

To use a remote MCP server with the Claude Agent SDK, pass it in the `mcpServers` option of `query()` with `type: "http"`, its URL and any auth headers, and list its tools in `allowedTools`. The SDK doesn’t run OAuth for you, so send a token in the headers. Without `allowedTools`, the agent sees the tools but can’t call them.

## How do I connect a remote MCP server to the Agent SDK?

Add an entry to `mcpServers`. The key becomes the server’s name in tool names. This agent reads Linear through its read-only endpoint, authenticated with a Linear API key:

agent.ts

```
import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Summarize the open issues in the Checkout project by priority",
  options: {
    mcpServers: {
      linear: {
        type: "http",
        url: "https://mcp.linear.app/mcp/readonly",
        headers: { Authorization: `Bearer ${process.env.LINEAR_API_KEY}` },
      },
    },
    allowedTools: ["mcp__linear__*"],
  },
})) {
  if (message.type === "result" && message.subtype === "success") {
    console.log(message.result);
  }
}
```

The Python SDK takes the same config as a dict:

agent.py

```
import asyncio, os
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage

options = ClaudeAgentOptions(
    mcp_servers={
        "linear": {
            "type": "http",
            "url": "https://mcp.linear.app/mcp/readonly",
            "headers": {"Authorization": f"Bearer {os.environ['LINEAR_API_KEY']}"},
        }
    },
    allowed_tools=["mcp__linear__*"],
)

async def main():
    async for message in query(
        prompt="Summarize the open issues in the Checkout project by priority",
        options=options,
    ):
        if isinstance(message, ResultMessage) and message.subtype == "success":
            print(message.result)

asyncio.run(main())
```

Use `"http"` for Streamable HTTP servers, which is what most hosted servers speak now, and `"sse"` only for older ones. In code the SDK accepts only `"http"`, not the `"streamable-http"` alias that `.mcp.json` files allow.

## Why can’t my agent call the MCP tools?

Because MCP tools need explicit permission. Tools are named `mcp__<server>__<tool>`, and a tool not covered by `allowedTools` shows up in the agent’s list but every call to it is refused. Your options:

SettingEffect on MCP tools

`mcp__linear__*`

Allows every tool on one server. Fine when the credential is already read-only.

`mcp__github__get_file_contents`

Allows one tool. Use this for servers that can also write.

`acceptEdits`

Doesn’t help. It approves file edits and filesystem commands, not MCP tools.

`bypassPermissions`

Approves MCP tools, and turns off most other safety prompts with them. Avoid it for this.

Allow by name rather than by mode. An agent in production reads untrusted text (issues, emails, web pages), and the tool list is the boundary that text can’t talk its way past. For what to keep out of that list, see [how to stop agents from running destructive MCP tools](https://mcp1.com/blog/stop-destructive-mcp-tools).

## How does the Agent SDK authenticate to MCP servers?

With whatever you put in `headers`. The SDK doesn’t open a browser or run an OAuth flow, so you have two routes:

- A service token, like a Linear API key or a GitHub fine-grained token, read from an environment variable. Right for internal agents and jobs that act as one account.
- A user’s OAuth access token, when your product’s agent acts for each of its users. Run the OAuth flow in your own app, store and refresh the token there, and pass the current one in the header for that user’s run.

Either way, scope the credential to what the agent needs. A read-only token or endpoint, like Linear’s `/mcp/readonly` above, means the server refuses writes even if a prompt talks the agent into trying. See [how to make an MCP server read-only](https://mcp1.com/blog/read-only-mcp-server).

## How do I know an MCP server connected?

Check the first message. A server that fails to connect doesn’t throw: the run continues without its tools, and the agent answers with less than you expect. The `system` message with subtype `init` lists each server with a `status` of `connected`, `pending`, `failed`, `needs-auth` or `disabled`. Fail loudly on the bad ones:

agent.ts, inside the loop

```
if (message.type === "system" && message.subtype === "init") {
  const broken = message.mcp_servers.filter(
    (s) => s.status === "failed" || s.status === "needs-auth",
  );
  if (broken.length) throw new Error(`MCP down: ${broken.map((s) => s.name).join(", ")}`);
}
```

`needs-auth` means no usable credential, usually a missing or expired token in `headers`. `pending` alone isn’t a failure; the server may still be connecting.

## What changes when an agent has several MCP servers?

Three defaults start to matter:

- Tool search is on by default, so the SDK holds back tool definitions and loads the ones a turn needs. Set `alwaysLoad: true` on a server whose tools the agent uses every turn.
- Connections time out after 30 seconds. Raise it with the `MCP_TIMEOUT` environment variable, in milliseconds, for slow servers.
- Tool results are capped at 25,000 tokens by default (`MAX_MCP_OUTPUT_TOKENS`). Ask for narrow results in the prompt before raising it.

You can also keep servers in a `.mcp.json` at the project root instead of code. `query()` loads it by default; if you set `settingSources` yourself, include `"project"`.

Name collisions

Two servers can both have a tool called `search`. The `mcp__<server>__` prefix keeps them apart, so give servers short, distinct keys. More in [MCP tool name collisions](https://mcp1.com/blog/mcp-tool-name-collisions).

## One URL and one key for every server

Each server above means its own token in your secrets, its own scoping rules and its own logs, and nothing records which agent run called what. MCP1 puts the servers behind one gateway. The agent holds one MCP1 API key, scoped to that gateway and optionally to some of its servers, with an expiry:

agent.ts, options

```
mcpServers: {
  mcp1: {
    type: "http",
    url: "https://mcp1.com/mcp/<workspace>/<gateway>",
    headers: { Authorization: `Bearer ${process.env.MCP1_API_KEY}` },
  },
},
allowedTools: ["mcp__mcp1__*"],
```

A small gateway lists its servers’ tools directly, as `mcp__mcp1__linear__list_issues` and so on. A larger one lists MCP1’s own tools, and the agent finds the rest with `mcp1__search_tools` and runs them with `mcp1__call_tool`, which keeps tool definitions small. The key acts as the person who made it, so their groups, read-only grants and tool rules apply, and every call lands in the audit log as `API key · <name>`. Revoking the key under Keys stops the agent at once. The [docs](https://mcp1.com/docs#keys) cover keys, and the Individual plan is free to [start with](https://mcp1.com/signup).

## Common questions

### Does the Claude Agent SDK support MCP OAuth?

Not interactively. The SDK doesn’t open a browser, so run the OAuth flow in your own app and pass the access token in the server’s headers.

### Can I use local stdio MCP servers with the Agent SDK?

Yes. Give the entry a command and args instead of a type and URL, and the SDK starts the process. Remote servers are easier to run in production because nothing has to be installed next to the agent.

### How do I block one MCP tool but allow the rest?

Allow the server with a wildcard like mcp\_\_github\_\_\* and list the tool you don’t want in disallowedTools.

### Is the Claude Agent SDK the same as Claude Code?

It runs the same agent loop and tools as Claude Code, packaged as a library for TypeScript and Python, so MCP config and tool names work the same way.

Give your team one URL

Create a workspace, install your servers and share a gateway with a group. Free for individuals.

[Start with MCP1](https://mcp1.com/signup)[Read the docs](https://mcp1.com/docs)

## More from the blog

[ ProductLinearRead onlyProductboardRead onlyFigmaRead onlyPostHogRead onlyMCP servers for product teams: what to connect firstConnect Linear, a feedback tool (Productboard, Dovetail), analytics (PostHog, Amplitude) and Figma, read-only. Their tools, setup and which writes to hold back.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/mcp-servers-for-product-teams)[ Terminal$ gemini mcp add --transport http github https://api.githubcopilot.com/mcp/\-H 'Authorization: Bearer $GITHUB\_MCP\_PAT'githubConnectedHow to connect GitHub MCP to Gemini CLIInstall GitHub’s Gemini CLI extension or add https://api.githubcopilot.com/mcp/ with a token header. Read-only mode, policy rules, headless runs and fixes.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/github-mcp-gemini-cli)

---

This is the markdown copy of https://mcp1.com/blog/mcp-servers-claude-agent-sdk. Site index for agents: https://mcp1.com/llms.txt
