-
Notifications
You must be signed in to change notification settings - Fork 286
Workers bindings mcp #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
669184c
feat: add workers bindings mcp server
deloreyj 001cb7e
feat: Add workers-bindings mcp server with KV tools
deloreyj 8308712
chore: fix formatting issues
deloreyj 01adb3e
chore: remove biome, add eslint config, remove unused files, add test…
deloreyj 9d0c435
chore: fix type issues and PR feedback
deloreyj 3f24617
chore: fix types in sandbox-container app
deloreyj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| CLOUDFLARE_CLIENT_ID= | ||
| CLOUDFLARE_CLIENT_SECRET= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** @type {import("eslint").Linter.Config} */ | ||
| module.exports = { | ||
| root: true, | ||
| extends: ['@repo/eslint-config/default.cjs'], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| node_modules | ||
|
|
||
| .nx | ||
| .idea | ||
| .vscode | ||
| .zed | ||
| # Logs | ||
|
|
||
| logs | ||
| _.log | ||
| npm-debug.log_ | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| lerna-debug.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
|
||
| report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
|
||
| # Runtime data | ||
|
|
||
| pids | ||
| _.pid | ||
| _.seed | ||
| \*.pid.lock | ||
|
|
||
| # Directory for instrumented libs generated by jscoverage/JSCover | ||
|
|
||
| lib-cov | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
|
|
||
| coverage | ||
| \*.lcov | ||
|
|
||
| # nyc test coverage | ||
|
|
||
| .nyc_output | ||
|
|
||
| # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
|
||
| .grunt | ||
|
|
||
| # Bower dependency directory (https://bower.io/) | ||
|
|
||
| bower_components | ||
|
|
||
| # node-waf configuration | ||
|
|
||
| .lock-wscript | ||
|
|
||
| # Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
|
||
| build/Release | ||
|
|
||
| # Dependency directories | ||
|
|
||
| node_modules/ | ||
| jspm_packages/ | ||
|
|
||
| # Snowpack dependency directory (https://snowpack.dev/) | ||
|
|
||
| web_modules/ | ||
|
|
||
| # TypeScript cache | ||
|
|
||
| \*.tsbuildinfo | ||
|
|
||
| # Optional npm cache directory | ||
|
|
||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
|
|
||
| .eslintcache | ||
|
|
||
| # Optional stylelint cache | ||
|
|
||
| .stylelintcache | ||
|
|
||
| # Microbundle cache | ||
|
|
||
| .rpt2_cache/ | ||
| .rts2_cache_cjs/ | ||
| .rts2_cache_es/ | ||
| .rts2_cache_umd/ | ||
|
|
||
| # Optional REPL history | ||
|
|
||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
|
|
||
| \*.tgz | ||
|
|
||
| # Yarn Integrity file | ||
|
|
||
| .yarn-integrity | ||
|
|
||
| # dotenv environment variable files | ||
|
|
||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # parcel-bundler cache (https://parceljs.org/) | ||
|
|
||
| .cache | ||
| .parcel-cache | ||
|
|
||
| # Next.js build output | ||
|
|
||
| .next | ||
| out | ||
|
|
||
| # Nuxt.js build / generate output | ||
|
|
||
| .nuxt | ||
| dist | ||
|
|
||
| # Gatsby files | ||
|
|
||
| .cache/ | ||
|
|
||
| # Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
|
||
| # https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
|
||
| # public | ||
|
|
||
| # vuepress build output | ||
|
|
||
| .vuepress/dist | ||
|
|
||
| # vuepress v2.x temp and cache directory | ||
|
|
||
| .temp | ||
| .cache | ||
|
|
||
| # Docusaurus cache and generated files | ||
|
|
||
| .docusaurus | ||
|
|
||
| # Serverless directories | ||
|
|
||
| .serverless/ | ||
|
|
||
| # FuseBox cache | ||
|
|
||
| .fusebox/ | ||
|
|
||
| # DynamoDB Local files | ||
|
|
||
| .dynamodb/ | ||
|
|
||
| # TernJS port file | ||
|
|
||
| .tern-port | ||
|
|
||
| # Stores VSCode versions used for testing VSCode extensions | ||
|
|
||
| .vscode-test | ||
|
|
||
| # yarn v2 | ||
|
|
||
| .yarn/cache | ||
| .yarn/unplugged | ||
| .yarn/build-state.yml | ||
| .yarn/install-state.gz | ||
| .pnp.\* | ||
|
|
||
| # wrangler project | ||
|
|
||
| .dev.vars | ||
| .wrangler/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Remote MCP Server on Cloudflare | ||
|
|
||
| Let's get a remote MCP server up-and-running on Cloudflare Workers complete with OAuth login! | ||
|
|
||
| ## Develop locally | ||
|
|
||
| ```bash | ||
| # clone the repository | ||
| git clone [email protected]:cloudflare/ai.git | ||
|
|
||
| # install dependencies | ||
| cd ai | ||
| npm install | ||
|
|
||
| # run locally | ||
| npx nx dev remote-mcp-server | ||
| ``` | ||
|
|
||
| You should be able to open [`http://localhost:8787/`](http://localhost:8787/) in your browser | ||
|
|
||
| ## Connect the MCP inspector to your server | ||
|
|
||
| To explore your new MCP api, you can use the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector). | ||
|
|
||
| - Start it with `npx @modelcontextprotocol/inspector` | ||
| - [Within the inspector](http://localhost:5173), switch the Transport Type to `SSE` and enter `http://localhost:8787/sse` as the URL of the MCP server to connect to, and click "Connect" | ||
| - You will navigate to a (mock) user/password login screen. Input any email and pass to login. | ||
| - You should be redirected back to the MCP Inspector and you can now list and call any defined tools! | ||
|
|
||
| <div align="center"> | ||
| <img src="img/mcp-inspector-sse-config.png" alt="MCP Inspector with the above config" width="600"/> | ||
| </div> | ||
|
|
||
| <div align="center"> | ||
| <img src="img/mcp-inspector-successful-tool-call.png" alt="MCP Inspector with after a tool call" width="600"/> | ||
| </div> | ||
|
|
||
| ## Connect Claude Desktop to your local MCP server | ||
|
|
||
| The MCP inspector is great, but we really want to connect this to Claude! Follow [Anthropic's Quickstart](https://modelcontextprotocol.io/quickstart/user) and within Claude Desktop go to Settings > Developer > Edit Config to find your configuration file. | ||
|
|
||
| Open the file in your text editor and replace it with this configuration: | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "math": { | ||
| "command": "npx", | ||
| "args": ["mcp-remote", "http://localhost:8787/sse"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This will run a local proxy and let Claude talk to your MCP server over HTTP | ||
|
|
||
| When you open Claude a browser window should open and allow you to login. You should see the tools available in the bottom right. Given the right prompt Claude should ask to call the tool. | ||
|
|
||
| <div align="center"> | ||
| <img src="img/available-tools.png" alt="Clicking on the hammer icon shows a list of available tools" width="600"/> | ||
| </div> | ||
|
|
||
| <div align="center"> | ||
| <img src="img/claude-does-math-the-fancy-way.png" alt="Claude answers the prompt 'I seem to have lost my calculator and have run out of fingers. Could you use the math tool to add 23 and 19?' by invoking the MCP add tool" width="600"/> | ||
| </div> | ||
|
|
||
| ## Deploy to Cloudflare | ||
|
|
||
| 1. `npx wrangler kv namespace create OAUTH_KV` | ||
| 2. Follow the guidance to add the kv namespace ID to `wrangler.jsonc` | ||
| 3. `npm run deploy` | ||
|
|
||
| ## Call your newly deployed remote MCP server from a remote MCP client | ||
|
|
||
| Just like you did above in "Develop locally", run the MCP inspector: | ||
|
|
||
| `npx @modelcontextprotocol/inspector@latest` | ||
|
|
||
| Then enter the `workers.dev` URL (ex: `worker-name.account-name.workers.dev/sse`) of your Worker in the inspector as the URL of the MCP server to connect to, and click "Connect". | ||
|
|
||
| You've now connected to your MCP server from a remote MCP client. | ||
|
|
||
| ## Connect Claude Desktop to your remote MCP server | ||
|
|
||
| Update the Claude configuration file to point to your `workers.dev` URL (ex: `worker-name.account-name.workers.dev/sse`) and restart Claude | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "math": { | ||
| "command": "npx", | ||
| "args": ["mcp-remote", "https://worker-name.account-name.workers.dev/sse"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Debugging | ||
|
|
||
| Should anything go wrong it can be helpful to restart Claude, or to try connecting directly to your | ||
| MCP server on the command line with the following command. | ||
|
|
||
| ```bash | ||
| npx mcp-remote http://localhost:8787/sse | ||
| ``` | ||
|
|
||
| In some rare cases it may help to clear the files added to `~/.mcp-auth` | ||
|
|
||
| ```bash | ||
| rm -rf ~/.mcp-auth | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name": "remote-mcp-server", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "check:lint": "run-eslint-workers", | ||
| "check:types": "run-tsc", | ||
| "deploy": "wrangler deploy", | ||
deloreyj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "dev": "wrangler dev", | ||
| "start": "wrangler dev", | ||
| "types": "wrangler types", | ||
| "test": "vitest" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/vitest-pool-workers": "0.8.14", | ||
| "@cloudflare/workers-types": "4.20250410.0", | ||
| "@types/node": "22.14.1", | ||
| "marked": "15.0.7", | ||
| "typescript": "5.5.4", | ||
| "vitest": "3.0.9", | ||
| "workers-mcp": "^0.1.0-3", | ||
deloreyj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "wrangler": "4.10.0" | ||
| }, | ||
| "dependencies": { | ||
| "@cloudflare/workers-oauth-provider": "0.0.2", | ||
| "@modelcontextprotocol/sdk": "1.8.0", | ||
| "@repo/mcp-common": "workspace:*", | ||
| "agents": "0.0.49", | ||
| "hono": "4.7.6", | ||
| "zod": "3.24.2" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.