|
1 | 1 | 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. |
2 | 8 | import { McpAgent } from 'agents/mcp'; |
3 | 9 | 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'; |
5 | 13 | import type { ExportedHandler } from '@cloudflare/workers-types'; |
6 | 14 |
|
7 | 15 | type MCPProps = { |
@@ -51,11 +59,15 @@ const serverConfig: ServerConfig = { |
51 | 59 | }; |
52 | 60 |
|
53 | 61 | export class MyMCP extends McpAgent<Env, unknown, MCPProps> { |
54 | | - server = server; |
| 62 | + server = newMcpServer({}); |
55 | 63 |
|
56 | 64 | async init() { |
| 65 | + if (this.props == null) { |
| 66 | + throw new Error('MCP props are not initialized'); |
| 67 | + } |
| 68 | + |
57 | 69 | initMcpServer({ |
58 | | - server: this.server, |
| 70 | + server: await this.server, |
59 | 71 | clientOptions: this.props.clientProps, |
60 | 72 | mcpOptions: this.props.clientConfig, |
61 | 73 | }); |
|
0 commit comments