Skip to content

The instructions for /agents/guides/remote-mcp-server with Auth and Auth are missing steps and/or out of date #22343

@jschlesser

Description

@jschlesser

Regarding https://developers.cloudflare.com/agents/guides/remote-mcp-server/

Someone should walk through the instructions and update both the template and the instructions for the section for Authorization and Authentication.

The docs have the user install a template
npm create cloudflare@latest -- my-mcp-server-github-auth --template=cloudflare/ai/demos/remote-mcp-github-oauth

That template has a source file github-handler.cs that references an environment variable COOKIE_ENCRYPTION_KEY

Later in the docs there is a copyable set of terminal instructions to set up .dev.env, this should include the COOKIE_ENCRYPTION_KEY

The worker-configuration.d.ts file Env section needs changes as well, this worked for me:

declare namespace Cloudflare {
interface Env {
OAUTH_KV: KVNamespace;
GITHUB_CLIENT_ID: string;
GITHUB_CLIENT_SECRET: string;
COOKIE_ENCRYPTION_KEY: string;
MCP_OBJECT: DurableObjectNamespace<import("./src/index").MyMCP>;
AI: Ai;
}
}
interface Env extends Cloudflare.Env {}

The index file needed to be updated with the following for the export of OAuthProvider
export default new OAuthProvider({
apiRoute: "/sse",
apiHandlers: {
'/sse': MyMCP.serveSSE('/sse'),
'/mcp': MyMCP.serve('/mcp'),
},
defaultHandler: GitHubHandler,
authorizeEndpoint: "/authorize",
tokenEndpoint: "/token",
clientRegistrationEndpoint: "/register",
});

With all of those changes, I was able to get the MCP Inspector instructions to work.

Metadata

Metadata

Labels

product:agentsBuild and deploy AI-powered Agents on Cloudflare that can act autonomously.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions