MCP Servers

模型上下文协议服务器、框架、SDK 和模板的综合目录。

tutorial for CBC meeting 3/16

创建于 3/17/2026
更新于 about 7 hours ago
Repository documentation and setup instructions

MCP Server (createMcpHandler)

The simplest way to run a stateless MCP server on Cloudflare Workers. Uses createMcpHandler from the Agents SDK to handle all MCP protocol details in one line.

What it demonstrates

  • createMcpHandler — the Agents SDK helper that wraps an McpServer into a Worker-compatible fetch handler
  • Minimal setup — define tools on an McpServer, pass it to createMcpHandler, done
  • Stateless — no Durable Objects, no persistent state, each request is independent

Running

npm install
npm run dev

Open the browser to see the built-in tool tester, or connect with the MCP Inspector at http://localhost:5173/mcp.

How it works

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

function createServer() {
  const server = new McpServer({ name: "Hello MCP Server", version: "1.0.0" });
  server.registerTool(
    "hello",
    {
      description: "Returns a greeting",
      inputSchema: { name: z.string().optional() }
    },
    async ({ name }) => ({
      content: [{ type: "text", text: `Hello, ${name ?? "World"}!` }]
    })
  );
  return server;
}

export default {
  fetch: async (request, env, ctx) => {
    const server = createServer();
    return createMcpHandler(server)(request, env, ctx);
  }
};

Related examples

快速设置
此服务器的安装指南

安装包 (如果需要)

npx @modelcontextprotocol/server-mcp-worker

Cursor 配置 (mcp.json)

{ "mcpServers": { "aryankeluskar-mcp-worker": { "command": "npx", "args": [ "aryankeluskar-mcp-worker" ] } } }