-
Notifications
You must be signed in to change notification settings - Fork 326
Upgrade MCP SDK to v1.25.1 #752
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
327b8c5
upgrade mcp and native example
mattzcarey 48087db
fix: fallback error handling since mcp v1.24.0
mattzcarey 98cfcb2
fix lockfile
mattzcarey aae1db9
add some tests
mattzcarey 50cb24b
Merge branch 'main' into feat-upgrade-mcp
threepointone fdfdb11
Update @modelcontextprotocol/sdk to v1.25.2
mattzcarey a46e680
reset on main
mattzcarey 2bfc876
Merge remote-tracking branch 'origin/main' into feat-upgrade-mcp
mattzcarey eebb17a
Update @modelcontextprotocol/sdk to v1.25.2
mattzcarey 5b43783
pin package version
mattzcarey 185692d
changeset
mattzcarey c897ff1
typo
mattzcarey 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,5 @@ | ||
| --- | ||
| "agents": patch | ||
| --- | ||
|
|
||
| bump mcp sdk version to 1.25.2. changes error handling for not found see: https://github.com/cloudflare/agents/pull/752/changes#diff-176ef2d2154e76a8eb7862efb323210f8f1b434f6a9ff3f06abc87d8616855c9R25-R31 |
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,22 @@ | ||
| # MCP Server Example | ||
|
|
||
| This example demonstrates how to use `WebStandardStreamableHTTPServerTransport` to create an unauthenticated stateless MCP server. | ||
|
|
||
| In this example we do not use the `agents` package, but instead use the `@modelcontextprotocol/sdk` package directly to create an MCP server that "just works" on Cloudflare Workers. | ||
|
|
||
| This is THE simplest way to get started with MCP on Cloudflare. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run dev | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| You can test the MCP server using the MCP Inspector or any MCP client that supports the `streamable-http` transport. | ||
|
|
||
| ## Adding State | ||
|
|
||
| To create a stateful MCP server, you can use an `Agent` to keep the state of the session/transport. See the [`mcp-elicitation`](../mcp-elicitation) example for more information. |
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,9 @@ | ||
| /* eslint-disable */ | ||
| // Generated by Wrangler by running `wrangler types env.d.ts --include-runtime false` (hash: b739a9c19cff1463949c4db47674ed86) | ||
| declare namespace Cloudflare { | ||
| interface GlobalProps { | ||
| mainModule: typeof import("./src/index"); | ||
| } | ||
| interface Env {} | ||
| } | ||
| interface Env extends Cloudflare.Env {} |
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,13 @@ | ||
| { | ||
| "name": "@cloudflare/agents-mcp-server", | ||
| "description": "zero config stateless MCP Server on Cloudflare", | ||
| "author": "Matt Carey <[email protected]>", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "wrangler dev", | ||
| "deploy": "wrangler deploy", | ||
| "types": "wrangler types env.d.ts --include-runtime false" | ||
| } | ||
| } |
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,54 @@ | ||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { z } from "zod"; | ||
| import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js"; | ||
|
|
||
| const server = new McpServer({ | ||
| name: "Hello MCP Server", | ||
| version: "1.0.0" | ||
| }); | ||
|
|
||
| server.registerTool( | ||
| "hello", | ||
| { | ||
| description: "Returns a greeting message", | ||
| inputSchema: { name: z.string().optional() } | ||
| }, | ||
| async ({ name }) => { | ||
| return { | ||
| content: [ | ||
| { | ||
| text: `Hello, ${name ?? "World"}!`, | ||
| type: "text" | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| const transport = new WebStandardStreamableHTTPServerTransport(); | ||
| server.connect(transport); | ||
|
|
||
| const corsHeaders = { | ||
| "Access-Control-Allow-Origin": "*", | ||
| "Access-Control-Allow-Methods": "GET, POST, DELETE, OPTIONS", | ||
| "Access-Control-Allow-Headers": | ||
| "Content-Type, Accept, mcp-session-id, mcp-protocol-version", | ||
| "Access-Control-Expose-Headers": "mcp-session-id", | ||
| "Access-Control-Max-Age": "86400" | ||
| }; | ||
|
|
||
| function withCors(response: Response): Response { | ||
| for (const [key, value] of Object.entries(corsHeaders)) { | ||
| response.headers.set(key, value); | ||
| } | ||
| return response; | ||
| } | ||
|
|
||
| export default { | ||
| fetch: async (request: Request, _env: Env, _ctx: ExecutionContext) => { | ||
| if (request.method === "OPTIONS") { | ||
| return new Response(null, { headers: corsHeaders }); | ||
| } | ||
| return withCors(await transport.handleRequest(request)); | ||
| } | ||
| }; |
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,3 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json" | ||
| } |
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,11 @@ | ||
| { | ||
| "compatibility_date": "2025-10-08", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| "main": "src/index.ts", | ||
| "name": "mcp-server", | ||
| "observability": { | ||
| "logs": { | ||
| "enabled": true | ||
| } | ||
| } | ||
| } |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dethroned. Maybe worth a mention here that this is now supported directly in the mcp library and a link to the new example?
Just a nit, don't have to do this now