Skip to main content
Glama

MCP 服务器 (createMcpHandler)

在 Cloudflare Workers 上运行无状态 MCP 服务器的最简单方法。使用 Agents SDK 中的 createMcpHandler 一行代码处理所有 MCP 协议细节。

它演示了什么

  • createMcpHandler — Agents SDK 的辅助函数,将 McpServer 工厂转换为 Workers 兼容的 fetch 处理器

  • 最简设置 — 在工厂中定义工具,将工厂传递给 createMcpHandler,完成

  • 无状态 — 无需 Durable Objects,无需持久状态,每个请求独立处理

Related MCP server: createMcpHandler MCP Server

运行

pnpm install
pnpm start

打开浏览器查看内置的测试工具,或连接到 MCP Inspector(地址为 http://localhost:5173/mcp)。

工作原理

import { McpServer } from "@modelcontextprotocol/server";
import { createMcpHandler } from "agents/mcp/server";
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(request, env, ctx) {
    return createMcpHandler(createServer)(request, env, ctx);
  }
} satisfies ExportedHandler;

相关示例

F
license - not found
-
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

  • Cloudflare Workers MCP server: crypto-signal

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Indxxr/mcp-worker'

If you have feedback or need assistance with the MCP directory API, please join our Discord server