Skip to content

Conversation

jmorrell-cloudflare
Copy link
Collaborator

@jmorrell-cloudflare jmorrell-cloudflare commented Apr 17, 2025

Note: Stacked on top of #200 *

This adds support for the new Streamable HTTP transport alongside the existing SSE transport. No code changes on the client should be necessary, and you can serve both at once with the same codebase.

This only supports POST requests for now. Resumability et al will come later, which should also not require any further changes to user code.

Setting up a worker to serve these transports on different endpoints would look like this:

export default {
	fetch(request: Request, env: Env, ctx: ExecutionContext) {
		let url = new URL(request.url);
		let path = url.pathname;
		if (path.startsWith('/sse')) {
			return MyMcpAgent.serveSSE('/sse').fetch(request, env, ctx);
		}
		if (path.startsWith('/mcp')) {
			return MyMcpAgent.serve('/mcp').fetch(request, env, ctx);
		}
	},
};

Initial testing with the unreleased MCP Inspector branch seems to work well!

  • Not sure if you can set up a stacked diff on github when both branches are remote so that you can only see the second set of changes here? Please let me know the secret it is

Copy link

changeset-bot bot commented Apr 17, 2025

🦋 Changeset detected

Latest commit: fa36b3f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
hono-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jmorrell-cloudflare jmorrell-cloudflare changed the title 2/ Add support for HTTP Streamable MCP Transport 3/ Add support for HTTP Streamable MCP Transport Apr 22, 2025
@jmorrell-cloudflare jmorrell-cloudflare force-pushed the jmorrell/02-streaming-transport-support branch from c01c998 to 414463e Compare April 22, 2025 22:53
@jmorrell-cloudflare jmorrell-cloudflare force-pushed the jmorrell/02-streaming-transport-support branch 2 times, most recently from d0595d2 to 93bf206 Compare April 23, 2025 03:42
@jmorrell-cloudflare jmorrell-cloudflare marked this pull request as ready for review April 23, 2025 03:53
@threepointone
Copy link
Collaborator

this is breaking types in the /mcp example. let's pair and figure it out.

@threepointone threepointone force-pushed the jmorrell/02-streaming-transport-support branch from 1e82664 to 2c14889 Compare April 23, 2025 12:00
@threepointone
Copy link
Collaborator

passed lints/typechecks, now running tests in CI too

@threepointone
Copy link
Collaborator

The tests pass, but seem to log this workerd error. Wonder what that's about

workerd/io/worker.c++:2097: info: uncaught exception; source = Uncaught; stack = Error: /worker.ts changed, invalidating this Durable Object. Please retry the `DurableObjectStub#fetch()` call.
    at home/runner/work/agents/agents/node_modules/@cloudflare/vitest-pool-workers/dist/worker/lib/cloudflare/test-internal.mjs:508:15
workerd/jsg/exception.c++:140: info: Annotating with brokenness; internalMessage = jsg.Error: /worker.ts changed, invalidating this Durable Object. Please retry the `DurableObjectStub#fetch()` call.; brokennessReason = broken.inputGateBroken

@threepointone threepointone merged commit 90db5ba into cloudflare:main Apr 23, 2025
1 check passed
@jmorrell-cloudflare jmorrell-cloudflare deleted the jmorrell/02-streaming-transport-support branch April 23, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants