MagicTools
claudeApril 13, 2026461 views2 min read

Claude Code MCP: Connect External Tools and Data Sources

What Is MCP

Model Context Protocol (MCP) is an open protocol by Anthropic that defines a standard communication layer between AI models and external tools. Through MCP, Claude Code can connect to databases, call APIs, and interact with third-party services, extending its capabilities far beyond code editing.

MCP uses a client-server architecture: Claude Code acts as the MCP client, communicating with MCP servers via the standard protocol. Each MCP server exposes a set of tools that Claude can invoke on demand.

Configuring MCP Servers

Add MCP server configurations to .claude/settings.json:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
    },
    "sqlite": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sqlite", "--db-path", "./data.db"]
    }
  }
}

Restart Claude Code after adding configurations, and the external tools become available in your conversations.

Server Capabilities Package
GitHub Manage issues, PRs, repos @modelcontextprotocol/server-github
Filesystem Secure file system access @modelcontextprotocol/server-filesystem
SQLite Query SQLite databases @modelcontextprotocol/server-sqlite
PostgreSQL Query PostgreSQL databases @modelcontextprotocol/server-postgres
Slack Send messages, manage channels @modelcontextprotocol/server-slack
Memory Persistent cross-session memory @modelcontextprotocol/server-memory

Find more community-built MCP servers in the MCP Servers repository.

Writing a Simple MCP Server

Build a custom MCP server in TypeScript:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({ name: "my-server", version: "1.0.0" });

server.tool(
  "get_weather",
  "Get weather information for a city",
  { city: z.string().describe("City name") },
  async ({ city }) => {
    const data = await fetch(`https://api.weather.com/${city}`);
    return { content: [{ type: "text", text: JSON.stringify(await data.json()) }] };
  }
);

const transport = new StdioServerTransport();
await server.connect(transport);

Security Considerations

  • Principle of least privilege: Only grant MCP servers the permissions they actually need
  • Protect secrets: Pass API keys via the env field; never hardcode them in configuration
  • Network isolation: For MCP servers accessing internal services, ensure proper network access controls
  • Audit third-party servers: Review source code of community MCP servers before using them

FAQ

Do MCP servers need to run continuously?

No. Claude Code automatically starts configured MCP server processes on launch and shuts them down when the session ends. You don't need to manage server lifecycles manually.

Can I use multiple MCP servers in one project?

Yes. Configure as many servers as needed in mcpServers. Claude automatically selects the appropriate tool for each task. Tools from all servers are merged into Claude's available tool list.

What programming languages can I use to write MCP servers?

The official MCP SDK is available in TypeScript and Python. Community implementations exist for Rust, Go, Java, and more. Any language can be used as long as it follows the MCP protocol specification.

Related Articles

Claude Code 踩坑实录:两个 AI 幻觉真实案例与 hook 日志交叉验证法

Claude Code (Opus 4.8) 一天内两次真实翻车:rg -rn flag 误用被 AI 判定为提示注入、凭空忏悔一次从未发生的文件删除——问题由 Fable 5 排查定案,Opus 4.8 多次测试未能自主发现。本文还原排查过程,并给出用 PostToolUse hook 建立真相基线日志的模型无关防御方案。

debuggingclaude-code+4
ai-tutorialsJul 20, 20265 min
79

10 Advanced Claude Code Techniques: Session Recovery, Checkpoint Rewind, and Headless CI

From named sessions and the /rewind time machine to context slimming, path-scoped rules, auto memory, and wiring Claude Code into CI with headless mode — 10 advanced techniques straight from the official docs that most users never open, each with the exact commands and when to use them.

claude-codeheadless+4
claudeJul 20, 20265 min
65

What's New in Claude Code in 2026: Agent Teams, Nested Subagents, and Background Sessions

The first half of 2026 pushed Claude Code well beyond the single-session workflow: multi-agent teams, subagents that recurse up to 5 levels deep, background sessions with Agent View, and an Opus-class Fast Mode. Based on the official docs and changelog, here is what each feature does, how to turn it on, and when it's actually worth using.

claude-codeagent-teams+4
claudeJul 20, 20265 min
93

Claude Code 2026 新功能盘点:Agent Teams、嵌套子代理与后台会话

2026 年上半年 Claude Code 的能力边界被大幅推宽:多智能体团队协作、可递归 5 层的嵌套子代理、后台会话与 Agent View、Opus 级 Fast Mode。本文基于官方文档与 changelog,逐一讲清每个新功能是什么、怎么开、什么场景值得用。

claude-codeai编程+4
claudeJul 20, 20265 min
96

Published by MagicTools