# Anthropic MCP Specification — Protocol Reference > Official Model Context Protocol specification reference. Understand MCP architecture, message format, tool definitions, resource types, and transport protocols for building servers. ## Install Merge the JSON below into your `.mcp.json`: ## Quick Use ```bash # Start building an MCP server npm init -y && npm install @modelcontextprotocol/sdk ``` ```typescript import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const server = new McpServer({ name: "my-server", version: "1.0.0" }); server.tool("hello", { name: { type: "string" } }, async ({ name }) => ({ content: [{ type: "text", text: `Hello, ${name}!` }], })); const transport = new StdioServerTransport(); await server.connect(transport); ``` ## What is MCP? The Model Context Protocol (MCP) is an open standard by Anthropic that defines how AI applications (clients) connect to external data sources and tools (servers). It standardizes the interface between LLMs and the outside world — similar to how HTTP standardized web communication. MCP enables AI agents to use tools, access resources, and receive prompts from any compliant server. **Answer-Ready**: MCP (Model Context Protocol) is Anthropic's open standard for connecting AI to external tools and data. Defines tools (actions), resources (data), and prompts (templates). JSON-RPC over stdio or HTTP. Used by Claude Code, Cursor, and 200+ servers. The USB-C of AI integrations. **Best for**: Developers building MCP servers or understanding the protocol. **Works with**: Claude Code, Cursor, Claude Desktop, any MCP client. ## Protocol Architecture ### Client-Server Model ``` AI Application (Client) MCP Server ┌─────────────────┐ ┌─────────────────┐ │ Claude Code │ ←JSON→ │ GitHub MCP │ │ Cursor │ RPC │ Database MCP │ │ Claude Desktop │ │ Custom Server │ └─────────────────┘ └─────────────────┘ ``` ### Three Primitives | Primitive | Direction | Purpose | |-----------|-----------|---------| | **Tools** | Client → Server | Actions the AI can perform (search, create, delete) | | **Resources** | Client ← Server | Data the AI can read (files, DB records, API responses) | | **Prompts** | Client ← Server | Reusable prompt templates with parameters | ## Tool Definition ```typescript server.tool( "search_issues", { query: { type: "string", description: "Search query" }, state: { type: "string", enum: ["open", "closed", "all"], default: "open" }, limit: { type: "number", default: 10 }, }, async ({ query, state, limit }) => { const results = await github.searchIssues(query, state, limit); return { content: [{ type: "text", text: JSON.stringify(results) }], }; } ); ``` ## Resource Definition ```typescript server.resource( "file://{path}", async ({ path }) => ({ contents: [{ uri: `file://${path}`, text: await readFile(path, "utf-8") }], }) ); ``` ## Transport Protocols | Transport | Use Case | How | |-----------|----------|-----| | stdio | Local servers | Spawn as child process, communicate via stdin/stdout | | HTTP+SSE | Remote servers | HTTP POST for requests, SSE for notifications | | Streamable HTTP | Modern remote | Full-duplex over HTTP | ### stdio Configuration ```json { "mcpServers": { "my-server": { "command": "node", "args": ["server.js"], "env": { "API_KEY": "..." } } } } ``` ### HTTP Configuration ```json { "mcpServers": { "remote-server": { "transport": "http", "url": "https://api.example.com/mcp" } } } ``` ## Message Format (JSON-RPC 2.0) ```json // Request {"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "search_issues", "arguments": {"query": "bug"}}} // Response {"jsonrpc": "2.0", "id": 1, "result": {"content": [{"type": "text", "text": "..."}]}} ``` ## SDK Languages | Language | Package | |----------|---------| | TypeScript | `@modelcontextprotocol/sdk` | | Python | `mcp` | | Kotlin | `io.modelcontextprotocol:kotlin-sdk` | | C# | `ModelContextProtocol` | ## FAQ **Q: Is MCP only for Anthropic/Claude?** A: No, MCP is an open standard. Cursor, Codex, and other tools support it. **Q: How many MCP servers exist?** A: 200+ and growing. Browse at smithery.ai or the official MCP servers repo. **Q: Can I build a server in Python?** A: Yes, use the `mcp` Python package. Same capabilities as TypeScript SDK. ## Source & Thanks > Created by [Anthropic](https://github.com/modelcontextprotocol). Licensed under MIT. > > [modelcontextprotocol/specification](https://github.com/modelcontextprotocol/specification) — Official MCP spec > [spec.modelcontextprotocol.io](https://spec.modelcontextprotocol.io) — Full specification ## 快速使用 ```bash npm install @modelcontextprotocol/sdk ``` 几行代码创建 MCP 服务器。 ## 什么是 MCP? Anthropic 的开放标准,定义 AI 应用与外部工具/数据的连接方式。类似 HTTP 之于 Web,MCP 是 AI 集成的标准协议。 **一句话总结**:Anthropic 开放标准,AI 连接外部工具和数据的协议,定义 Tools/Resources/Prompts 三原语,JSON-RPC 通信,200+ 服务器,AI 集成的 USB-C。 ## 协议架构 ### 三大原语 1. **Tools** — AI 可执行的操作 2. **Resources** — AI 可读取的数据 3. **Prompts** — 可复用的提示模板 ### 传输协议 stdio(本地)、HTTP+SSE(远程)、Streamable HTTP(现代远程)。 ### SDK TypeScript、Python、Kotlin、C#。 ## 常见问题 **Q: 只限 Claude?** A: 不,开放标准,Cursor/Codex 等都支持。 **Q: 能用 Python 写?** A: 能,`mcp` 包功能完整。 ## 来源与致谢 > [modelcontextprotocol/specification](https://github.com/modelcontextprotocol/specification) — MIT --- Source: https://tokrepo.com/en/workflows/3252f257-53c7-4a55-bf5e-81b1257f7fc6 Author: MCP Hub