Answer: You can add an MCP server in code by passing it in the `mcpServers` option when calling `query()`, or from a config file by creating a `.mcp.json` file at your project root that is loaded via `settingSources`. Status: Confirmed Entry: tool/claude-code/integrations/add-mcp-server Revision: 1 Digest: sha256:7ff73aff2d05d143 (changes whenever the content changes) Timeline: Created: 2026-11-13T03:02:46Z Last changed: 2026-11-13T03:02:46Z Last verified: 2026-11-20T12:16:44Z Next check: 2026-11-21T12:16:44Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of In-code option | mcpServers | [1] | 2026-11-20 Config file name | .mcp.json | [1] | 2026-11-20 Setting source for config file | project | [1] | 2026-11-20 Example server command | npx | [1] | 2026-11-20 Example server package | @modelcontextprotocol/server-filesystem | [1] | 2026-11-20 Example allowed tools | mcp__filesystem__* | [1] | 2026-11-20 Sources: [1] Anthropic. "Connect to external tools with MCP". https://code.claude.com/docs/en/agent-sdk/mcp.md Role: primary. Accessed: 2026-11-20T12:16:44Z Quote: "Pass MCP servers directly in the `mcpServers` option." (Supports: In-code option) Quote: "Create a `.mcp.json` file at your project root." (Supports: Config file name) Quote: "The file is picked up when the `project` setting source is enabled" (Supports: Setting source for config file) Quote: ""command": "npx"," (Supports: Example server command) Quote: ""args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]" (Supports: Example server package) Quote: "allowedTools: ["mcp__filesystem__*"]" (Supports: Example allowed tools) Published: 2026-11-20T04:04:07Z Snapshot SHA-256: 0163d83baa2a5802847161b80dd85386cb604bdb25edb89412152ff37b79b546 (captured 2026-11-13T03:02:46Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-13T03:02:46Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:16:44Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:16:44Z Last attempt: 2026-11-20T12:16:44Z Notes and limitations: Extracted automatically from a single official source (section "Add an MCP server"). Related: https://latestn.com/tool/claude-code/integrations/add-mcp-server-to-plugin How do I add an MCP server to a Claude Code plugin? https://latestn.com/tool/claude-code/integrations/add-remote-http-mcp-server How do I add a remote HTTP MCP server to Claude Code? https://latestn.com/tool/claude-code/integrations/add-verify-mcp-server How do I add and verify an MCP server in Claude Code? https://latestn.com/tool/claude-code/install-and-setup/vs-code-extension-prerequisites What are the prerequisites for installing the Claude Code extension in VS Code? https://latestn.com/tool/claude-code/install-and-setup/wsl-session-requirements What are the requirements to run a Claude Code Desktop session in WSL? https://latestn.com/tool/claude-code/integrations/add-language-without-plugin How do I add code intelligence for a language that has no official Claude Code plugin? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T03:02:46Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/integrations/add-mcp-server/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/integrations/add-mcp-server POST: https://latestn.com/dispute/tool/claude-code/integrations/add-mcp-server with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/integrations/add-mcp-server?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I add an MCP server to Claude Code Agent SDK in code or from a config file? Revision 1, last verified 2026-11-20T12:16:44Z. https://latestn.com/tool/claude-code/integrations/add-mcp-server (accessed 2026-11-21T09:54:10Z). @misc{LatestN_tool_claude_code_integrations_add_mcp_server_r1, title = {How do I add an MCP server to Claude Code Agent SDK in code or from a config file?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/integrations/add-mcp-server}}, note = {Revision 1; digest sha256:7ff73aff2d05d143; last verified 2026-11-20T12:16:44Z; accessed 2026-11-21T09:54:10Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/integrations/add-mcp-server