|
1 | | -# Building a Remote MCP Server on Cloudflare (Without Auth) |
| 1 | +# Spark Plus |
2 | 2 |
|
3 | | -This example allows you to deploy a remote MCP server that doesn't require authentication on Cloudflare Workers. |
| 3 | +A **collection of multiple separate but related MCP servers** on Cloudflare Workers for UT's AI Spark system. Each server runs as a Durable Object with its own tools and URL path, so it is treated as a separate MCP server for all intents and purposes. |
4 | 4 |
|
5 | | -## Get started: |
| 5 | +## What’s in this repo |
6 | 6 |
|
7 | | -[Deploy to Workers](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/ai/tree/main/demos/remote-mcp-authless) |
| 7 | +- **Servers** – MCP servers defined with `defineMcpServer` / `defineTool`, each bound to a Durable Object and a route. |
| 8 | +- **Shared** – All shared funcionality between servers.`src/shared/mcp-server-creator.ts` is where the `defineMcpServer` function which is how all servers are created. |
8 | 9 |
|
9 | | -This will deploy your MCP server to a URL like: `remote-mcp-server-authless.<your-account>.workers.dev/sse` |
10 | | - |
11 | | -Alternatively, you can use the command line below to get the remote MCP Server created on your local machine: |
| 10 | +## Quick start |
12 | 11 |
|
13 | 12 | ```bash |
14 | | -npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-authless |
| 13 | +npm install |
| 14 | +npm run dev |
15 | 15 | ``` |
16 | 16 |
|
17 | | -## Customizing your MCP Server |
18 | | - |
19 | | -To add your own [tools](https://developers.cloudflare.com/agents/model-context-protocol/tools/) to the MCP server, define each tool inside the `init()` method of `src/index.ts` using `this.server.tool(...)`. |
| 17 | +The Worker runs at `http://localhost:8787`. Each MCP server is served at its path (e.g. `http://localhost:8787/basic-tester`, `http://localhost:8787/other`). |
20 | 18 |
|
21 | | -## Test with MCP Inspector (local) |
| 19 | +## Deploy |
22 | 20 |
|
23 | | -This server uses **Streamable HTTP** at `/mcp`, not stdio. In the Inspector: |
24 | | - |
25 | | -1. Run `npm run dev` so the Worker is at `http://localhost:8787` (or the port Wrangler prints). |
26 | | -2. Run `npx @modelcontextprotocol/inspector@latest` and open the URL it prints. |
27 | | -3. In the Inspector, choose **"Enter URL"** (or equivalent) — do **not** use "Run command (stdio)". |
28 | | -4. Enter `http://localhost:8787/mcp` and click Connect, then List tools. |
| 21 | +```bash |
| 22 | +npm run deploy |
| 23 | +``` |
29 | 24 |
|
30 | | -Using "Run command" / stdio will fail with a 500 because this server is HTTP-only. |
| 25 | +Uses the `spark-plus` Worker name in `wrangler.jsonc`. After deploy, server URLs are `https://spark-plus.<your-subdomain>.workers.dev/<server-path>`. |
31 | 26 |
|
32 | | -## Connect to Cloudflare AI Playground |
| 27 | +## Adding a server |
33 | 28 |
|
34 | | -You can connect to your MCP server from the Cloudflare AI Playground, which is a remote MCP client: |
| 29 | +1. **Implement the server** in `src/servers/<name>/main.ts` using `defineMcpServer` and `defineTool` from `src/shared/mcp-server-creator.ts`. |
| 30 | +2. **Register the Durable Object** in `wrangler.jsonc`: add a migration for the new class and a binding in `durable_objects.bindings`. |
| 31 | +3. **Wire the route** in `src/project-source.ts`: import the server class and its metadata, add the metadata to the `MCP_SERVERS` array, and export the class in the `export { ... }` at the bottom. |
35 | 32 |
|
36 | | -1. Go to [https://playground.ai.cloudflare.com/](https://playground.ai.cloudflare.com/) |
37 | | -2. Enter your deployed MCP server URL (`remote-mcp-server-authless.<your-account>.workers.dev/sse`) |
38 | | -3. You can now use your MCP tools directly from the playground! |
| 33 | +The request handler in `src/project-source.ts` matches the request path to each server’s `url_prefix` and forwards to that server. |
39 | 34 |
|
40 | | -## Connect Claude Desktop to your MCP server |
| 35 | +## Testing with MCP Inspector |
41 | 36 |
|
42 | | -You can also connect to your remote MCP server from local MCP clients, by using the [mcp-remote proxy](https://www.npmjs.com/package/mcp-remote). |
| 37 | +This project uses **Streamable HTTP**, not stdio: |
43 | 38 |
|
44 | | -To connect to your MCP server from Claude Desktop, follow [Anthropic's Quickstart](https://modelcontextprotocol.io/quickstart/user) and within Claude Desktop go to Settings > Developer > Edit Config. |
| 39 | +1. Run `npm run dev` so the Worker is at `http://localhost:8787`. |
| 40 | +2. Run `npx @modelcontextprotocol/inspector@latest` and open the URL it prints. |
| 41 | +3. In the Inspector, choose **“Enter URL”** (do not use “Run command (stdio)”). |
| 42 | +4. Enter a server URL, e.g. `http://localhost:8787/basic-tester`, then Connect and List tools. |
45 | 43 |
|
46 | | -Update with this configuration: |
| 44 | +## Scripts |
47 | 45 |
|
48 | | -```json |
49 | | -{ |
50 | | - "mcpServers": { |
51 | | - "calculator": { |
52 | | - "command": "npx", |
53 | | - "args": [ |
54 | | - "mcp-remote", |
55 | | - "http://localhost:8787/sse" // or remote-mcp-server-authless.your-account.workers.dev/sse |
56 | | - ] |
57 | | - } |
58 | | - } |
59 | | -} |
60 | | -``` |
| 46 | +| Command | Purpose | |
| 47 | +| -------------------- | --------------------------------------------- | |
| 48 | +| `npm run dev` | Local development | |
| 49 | +| `npm run cf-typegen` | Regenerate Worker types after binding changes | |
| 50 | +| `npm run type-check` | TypeScript check | |
| 51 | +| `npm run lint` | Lint; `npm run lint:fix` to fix | |
61 | 52 |
|
62 | | -Restart Claude and you should see the tools become available. |
| 53 | +For Cloudflare Workers and product limits, see [AGENTS.md](./AGENTS.md). |
0 commit comments