loading…
Search for a command to run...
loading…
A lightweight template for deploying stateless Model Context Protocol (MCP) servers on Cloudflare Workers using the Agents SDK. It provides a simple way to wrap
A lightweight template for deploying stateless Model Context Protocol (MCP) servers on Cloudflare Workers using the Agents SDK. It provides a simple way to wrap MCP tools into Worker-compatible fetch handlers for serverless tool-calling capabilities.
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.
createMcpHandler — the Agents SDK helper that wraps an McpServer into a Worker-compatible fetch handlerMcpServer, pass it to createMcpHandler, donenpm 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.
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);
}
};
McpAgent and Durable ObjectsДобавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"mcp-worker": {
"command": "npx",
"args": []
}
}
}