Intro to MCP Server Development: Protocol Spec and Implementation Examples

AI Navigate Original / 4/27/2026

💬 OpinionDeveloper Stack & InfrastructureTools & Practical Usage
共有:

Key Points

  • MCP is a standard protocol for agents to connect tools/data
  • 3 capabilities: Tools, Resources, Prompts; ~100-line server
  • Implement permission checks; read third-party server code
  • Local (stdio) / Remote (HTTP+SSE); MCP is the agent-era USB-C

What Is MCP

Model Context Protocol (MCP) is a standard protocol for AI agents to connect to external tools/data sources. Proposed by Anthropic in 2024, with many clients/servers published from 2025.

Why a Standard Was Needed

Each LLM vendor had its own Tool Use, Function Calling spec, requiring per-vendor implementation per tool. MCP is, like USB-C, a standard where "make once, use on multiple clients."

3 Kinds of Capability

Tools

Functions the LLM can call. E.g., "SELECT on a database," "file write," "external API call."

Resources

Data the LLM can read. E.g., "file list," "latest log," "DB schema."

Prompts

Reusable prompt templates. E.g., "code-review checklist," "minutes template."

Server Implementation (TypeScript)

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server(
  { name: "weather-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

server.setRequestHandler("tools/list", async () => ({
  tools: [
    {
      name: "get_weather",
      description: "Get the weather",
      inputSchema: {
        type: "object",
        properties: { city: { type: "string" } },
        required: ["city"],
      },
    },
  ],
}));

server.setRequestHandler("tools/call", async (req) => {
  if (req.params.name === "get_weather") {
    const city = req.params.arguments.city;
    const weather = await fetchWeather(city);
    return { content: [{ type: "text", text: weather }] };
  }
  throw new Error("Unknown tool");
});

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

Server Implementation (Python)

from mcp.server import Server
from mcp.server.stdio import stdio_server

server = Server("weather-server")

@server.list_tools()
async def list_tools():
    return [{"name": "get_weather", "description": "...", "inputSchema": {...}}]

@server.call_tool()
async def call_tool(name, arguments):
    if name == "get_weather":
        return [{"type": "text", "text": fetch_weather(arguments["city"])}]

async def main():
    async with stdio_server() as (read, write):
        await server.run(read, write, ...)

Client Configuration

Example Claude Desktop config file:

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/path/to/weather-server/index.js"]
    }
  }
}

Main MCP Servers (Official/Community)

  • filesystem: file read/write
  • github: Issue / PR operations
  • slack: message send/search
  • postgres: SQL execution
  • puppeteer: browser operation
  • memory: cross-conversation memory
  • sequential-thinking: thinking-process support
  • browserbase: cloud browser

Security Considerations

  • Always implement permission checks on the server side
  • Restrict access to confidential files (filesystem server uses ALLOWED_DIRS env var)
  • When using a third-party MCP server, always read the code
  • Mind supply-chain attacks (malicious servers via npm/PyPI)

Production Operation Patterns

Local (stdio)

Claude Desktop local execution. Launched as a child process.

Remote (HTTP / SSE)

The HTTP+SSE transport added in 2025. Can be provided to multiple users via cloud. Deployable to Cloudflare Workers etc.

Testing and Debugging

  • Visualize requests/responses with the MCP Inspector (official tool)
  • Unit test: call tool functions directly
  • Integration test: call from an actual client (Claude Desktop)

2026 Trends

  • OpenAI, Google moving to MCP support
  • Marketplaces (Smithery, Glama) gaining momentum
  • Standardization of Auth, streaming responses
  • Feature for agents to dynamically discover/connect MCP

Summary

MCP is the "USB-C" of the agent era. With the ease of writing in ~100 lines of TypeScript/Python and the distribution power of being usable immediately from Claude Desktop/Code, it spread explosively in 2025-2026. Integrating with internal tools raises AI agents' practicality a notch.