MCP With the Claude Agent SDK
Connect MCP servers to Claude Agent SDK applications: stdio, HTTP, SSE configs, OAuth, managed policy parity, and tool-search interaction.
Open the source and read safety notes before installing.
Safety notes
- Remote MCP introduces network trust boundaries—review servers before production attach.
- Stdio servers inherit environment variables including session ids—avoid leaking secrets into subprocess env.
- HTTP 403 on connect should surface as needs-auth, not silent failure—verify UX for operators.
Privacy notes
- MCP tool arguments and results flow to both the model provider and MCP server operator.
- OAuth refresh tokens persist locally; plan revocation on employee offboarding.
- Plugin `.mcp.json` servers reload after `/clear`—confirm which integrations return automatically.
Prerequisites
- Claude Agent SDK service with configurable `mcpServers` and `allowedTools`.
- MCP server packages or remote URLs reviewed for tool scope and data handling.
- OAuth client ids for remote servers or local stdio launch commands documented.
- Enterprise managed MCP policy if deploying inside regulated orgs.
Schema details
- Install type
- copy
- Reading time
- 8 min
- Difficulty score
- 60
- Troubleshooting
- Yes
- Breaking changes
- No
- Scope
- Source repo
Full copyable content
Use this guide to register stdio, HTTP, and SSE MCP servers in Agent SDK query options with OAuth and allowlists.About this resource
TL;DR
Agent SDK apps connect MCP servers through the same mcpServers configuration as Claude Code—stdio for local tools, HTTP/SSE for remote services. Pair connections with allowedTools, respect managed MCP policy, and use tool search when catalogs grow large.
Prerequisites & Requirements
- {"task": "Claude Code installed", "description": "Latest approved build is available on the target machine"}
- {"task": "Credentials ready", "description": "Login, API key, or provider credentials match the workflow"}
- {"task": "Test environment prepared", "description": "A disposable project or sandbox can validate the setup"}
- {"task": "Team policy reviewed", "description": "Managed settings and MCP policy align with org requirements"}
- {"task": "Rollback documented", "description": "Steps to disable or revert the integration are written down"}
Core Concepts Explained
Transport selection
Stdio suits colocated binaries; HTTP/SSE suit shared remote services with OAuth and load balancing.
Session env injection
Stdio MCP subprocesses receive CLAUDE_CODE_SESSION_ID, CLAUDECODE=1, and CLAUDE_PROJECT_DIR for hook parity.
OAuth and proxies
MCP OAuth flows should respect HTTP(S)_PROXY, mTLS, and NO_PROXY for discovery, DCR, and refresh.
Tool search deferral
Large MCP catalogs defer descriptions until MCPSearch unless alwaysLoad: true on a server.
Step-by-Step Implementation Guide
Inventory servers. List each MCP integration with transport, owner, and required OAuth scopes.
Add config. Declare servers in SDK
mcpServers,.mcp.json, or--mcp-configfiles per environment.Authenticate remotes. Complete OAuth consent for HTTP/SSE servers; verify 403 paths show needs-auth prompts.
Allow tools. Map discovered tools to
allowedToolsusingmcp__name__toolconventions.Tune timeouts. Set
MCP_TOOL_TIMEOUTwhen remote tool calls exceed default fetch limits.Test reconnect. Restart SDK host and confirm servers return after
/clearwithout silent drops.Apply enterprise policy. Validate
allowedMcpServerspredicates if managed settings apply to SDK hosts.Monitor discovery. Log tool list drift after server upgrades and block unknown write tools.
SDK MCP Connection Checklist
- {"task": "Transports documented", "description": "Each server labeled stdio HTTP or SSE"}
- {"task": "OAuth complete", "description": "Remote servers authenticated in staging"}
- {"task": "Tools allowed", "description": "allowedTools matches approved inventory"}
- {"task": "Timeouts set", "description": "Long calls use MCP_TOOL_TIMEOUT"}
- {"task": "Policy enforced", "description": "Managed MCP rules verified on SDK host"}
Operational Guardrails
- Pin Claude Code or Agent SDK versions in team docs and CI images before rolling out
integration-specific flags such as
--remote-control,--chrome, or provider env vars. - Run a five-minute smoke test on a disposable profile after managed settings or MCP policy changes—do not wait for user reports to discover blocked servers.
- Capture
/statusoutput and relevant env sources when escalating provider or transport issues; recent builds expose more provider and region diagnostics. - Revisit allowlists and OAuth scopes after major
CHANGELOG.mdMCP or auth fixes; enforcement timing changes often require client upgrades, not just policy edits. - Document rollback: which env vars to unset, which MCP entries to remove, and who can publish emergency managed-settings overrides.
Troubleshooting
Servers vanish after clear
Upgrade to builds that restore .mcp.json, plugin, and connector servers after /clear in SDK hosts.
60s tool cap
Raise MCP_TOOL_TIMEOUT—per-request fetch timeout now respects the configured value.
OAuth refresh lost
Concurrent refresh fixes reduce daily re-auth for multiple remote servers.
SSE reconnect loop
Stateful servers without GET SSE streams should not reconnect-loop on tools/list—update CLI/SDK.
Source Verification Notes
Verified against the public anthropics/claude-code repository README,
plugins/README.md, and CHANGELOG.md on 2026-06-14:
plugins/README.mdoptional.mcp.jsonper plugin documents external MCP configuration patterns.CHANGELOG.mdpassesCLAUDE_CODE_SESSION_IDandCLAUDECODE=1to stdio MCP subprocesses.CHANGELOG.mdfixedMCP_TOOL_TIMEOUTnot raising per-request fetch timeout for HTTP/SSE servers.CHANGELOG.mdfixed MCP HTTP/SSE 403 responses showing as failed instead of needs-auth.CHANGELOG.mdfixed MCP servers disappearing after/clearin Agent SDK hosts.
Duplicate Check
This guide covers MCP connectivity for Agent SDK hosts. See fix-mcp-connection-errors.mdx for client troubleshooting and building-in-process-mcp-tools-with-the-claude-agent-sdk.mdx for in-process alternatives.
References
- Agent SDK MCP - https://code.claude.com/docs/en/agent-sdk/mcp
- Fix MCP connection errors - fix-mcp-connection-errors
- Choosing MCP transport - choosing-mcp-transport-stdio-http-sse-and-websocket
Source citations
Add this badge to your README
Show that MCP With the Claude Agent SDK is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.
[](https://heyclau.de/entry/guides/mcp-with-the-claude-agent-sdk)Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.