Skip to content

Commit d7fcbd6

Browse files
chore(internal): fix MCP cloudflare worker builds
1 parent d03a562 commit d7fcbd6

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

packages/mcp-server/cloudflare-worker/package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@
1818
},
1919
"dependencies": {
2020
"@cloudflare/workers-oauth-provider": "^0.0.5",
21-
"@modelcontextprotocol/sdk": "^1.27.1",
22-
"agents": "^0.8.5",
21+
"@modelcontextprotocol/sdk": "1.28.0",
22+
"agents": "~0.8.7",
2323
"hono": "^4.12.4",
2424
"@imagekit/api-mcp": "latest",
25-
"zod": "^3.24.4"
25+
"@imagekit/nodejs": "latest"
26+
},
27+
"// overrides": "agents pins @modelcontextprotocol/sdk exactly; the three override blocks below force npm/yarn/pnpm to dedupe to that same version. Keep all four @modelcontextprotocol/sdk values in sync. See src/index.ts for the full rationale.",
28+
"overrides": {
29+
"@modelcontextprotocol/sdk": "1.28.0"
30+
},
31+
"resolutions": {
32+
"@modelcontextprotocol/sdk": "1.28.0"
33+
},
34+
"pnpm": {
35+
"overrides": {
36+
"@modelcontextprotocol/sdk": "1.28.0"
37+
}
2638
}
2739
}

packages/mcp-server/cloudflare-worker/src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { makeOAuthConsent } from './app';
2+
// `agents` and `@modelcontextprotocol/sdk` versions must stay in sync with the
3+
// pins/overrides in package.json. `agents` declares an exact pin on
4+
// `@modelcontextprotocol/sdk`; if our resolved version drifts, npm installs a
5+
// second copy under `agents/node_modules/`, and `initMcpServer`'s runtime
6+
// `instanceof McpServer` check fails because the two `McpServer` classes are
7+
// distinct constructors.
28
import { McpAgent } from 'agents/mcp';
39
import OAuthProvider from '@cloudflare/workers-oauth-provider';
4-
import { McpOptions, initMcpServer, server, ClientOptions } from '@imagekit/api-mcp/server';
10+
import { ClientOptions } from '@imagekit/nodejs';
11+
import { McpOptions } from '@imagekit/api-mcp/options';
12+
import { initMcpServer, newMcpServer } from '@imagekit/api-mcp/server';
513
import type { ExportedHandler } from '@cloudflare/workers-types';
614

715
type MCPProps = {
@@ -51,11 +59,15 @@ const serverConfig: ServerConfig = {
5159
};
5260

5361
export class MyMCP extends McpAgent<Env, unknown, MCPProps> {
54-
server = server;
62+
server = newMcpServer({});
5563

5664
async init() {
65+
if (this.props == null) {
66+
throw new Error('MCP props are not initialized');
67+
}
68+
5769
initMcpServer({
58-
server: this.server,
70+
server: await this.server,
5971
clientOptions: this.props.clientProps,
6072
mcpOptions: this.props.clientConfig,
6173
});

0 commit comments

Comments
 (0)