diff --git a/package-lock.json b/package-lock.json index 9a96d7b..117ad8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcp-framework", - "version": "0.2.0-beta.19", + "version": "0.2.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mcp-framework", - "version": "0.2.0-beta.19", + "version": "0.2.4", "dependencies": { "@types/prompts": "^2.4.9", "commander": "^12.1.0", @@ -27,12 +27,12 @@ "@types/content-type": "^1.1.8", "@types/jest": "^29.5.12", "@types/jsonwebtoken": "^9.0.8", - "@types/node": "^20.11.24", + "@types/node": "^20.17.28", "jest": "^29.7.0", "ts-jest": "^29.1.2" }, "engines": { - "node": ">=20.0.0" + "node": ">=18.19.0" }, "peerDependencies": { "@modelcontextprotocol/sdk": "1.8" @@ -1113,9 +1113,10 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.17.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.9.tgz", - "integrity": "sha512-0JOXkRyLanfGPE2QRCwgxhzlBAvaRdCNMcvbd7jFfpmD4eEXll7LRwy5ymJmyeZqk7Nh7eD2LeUyQ68BbndmXw==", + "version": "20.17.28", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.28.tgz", + "integrity": "sha512-DHlH/fNL6Mho38jTy7/JT7sn2wnXI+wULR6PV4gy4VHLVvnrV/d3pHAMQHhc4gjdLmK2ZiPoMxzp6B3yRajLSQ==", + "license": "MIT", "dependencies": { "undici-types": "~6.19.2" } diff --git a/package.json b/package.json index ed064d2..3ca5537 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "mcp-framework", "version": "0.2.4", - "description": "Framework for building Model Context Protocol (MCP) servers in Typescript", "type": "module", "author": "Alex Andru ", @@ -58,7 +57,7 @@ "@types/content-type": "^1.1.8", "@types/jest": "^29.5.12", "@types/jsonwebtoken": "^9.0.8", - "@types/node": "^20.11.24", + "@types/node": "^20.17.28", "jest": "^29.7.0", "ts-jest": "^29.1.2" } diff --git a/src/core/MCPServer.ts b/src/core/MCPServer.ts index 54d113b..6a320fc 100644 --- a/src/core/MCPServer.ts +++ b/src/core/MCPServer.ts @@ -58,17 +58,16 @@ export interface MCPServerConfig { export type ServerCapabilities = { tools?: { - enabled: true; - }; - schemas?: { - enabled: true; + listChanged?: true; // Optional: Indicates support for list change notifications }; prompts?: { - enabled: true; + listChanged?: true; // Optional: Indicates support for list change notifications }; resources?: { - enabled: true; + listChanged?: true; // Optional: Indicates support for list change notifications + subscribe?: true; // Optional: Indicates support for resource subscriptions }; + // Other standard capabilities like 'logging' or 'completion' could be added here if supported }; export class MCPServer { @@ -83,9 +82,7 @@ export class MCPServer { private serverVersion: string; private basePath: string; private transportConfig: TransportConfig; - private capabilities: ServerCapabilities = { - tools: { enabled: true } - }; + private capabilities: ServerCapabilities = {}; // Initialize as empty private isRunning: boolean = false; private transport?: BaseTransport; private shutdownPromise?: Promise; @@ -188,11 +185,11 @@ export class MCPServer { }); } }; +// Removed misplaced semicolon from previous line - transport.onerror = (error) => { - logger.error(`Transport (${transport.type}) error: ${error.message}\n${error.stack}`); - }; - +transport.onerror = (error: Error) => { + logger.error(`Transport (${transport.type}) error: ${error.message}\n${error.stack}`); +}; return transport; } @@ -236,26 +233,28 @@ export class MCPServer { } private setupHandlers() { - this.server.setRequestHandler(ListToolsRequestSchema, async (request) => { + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available + this.server.setRequestHandler(ListToolsRequestSchema, async (request: any) => { logger.debug(`Received ListTools request: ${JSON.stringify(request)}`); - + const tools = Array.from(this.toolsMap.values()).map( (tool) => tool.toolDefinition ); - + logger.debug(`Found ${tools.length} tools to return`); logger.debug(`Tool definitions: ${JSON.stringify(tools)}`); - + const response = { tools: tools, nextCursor: undefined }; - + logger.debug(`Sending ListTools response: ${JSON.stringify(response)}`); return response; }); - this.server.setRequestHandler(CallToolRequestSchema, async (request) => { + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available + this.server.setRequestHandler(CallToolRequestSchema, async (request: any) => { logger.debug(`Tool call request received for: ${request.params.name}`); logger.debug(`Tool call arguments: ${JSON.stringify(request.params.arguments)}`); @@ -285,6 +284,7 @@ export class MCPServer { }); if (this.capabilities.prompts) { + // No request parameter for ListPrompts this.server.setRequestHandler(ListPromptsRequestSchema, async () => { return { prompts: Array.from(this.promptsMap.values()).map( @@ -293,7 +293,8 @@ export class MCPServer { }; }); - this.server.setRequestHandler(GetPromptRequestSchema, async (request) => { + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available + this.server.setRequestHandler(GetPromptRequestSchema, async (request: any) => { const prompt = this.promptsMap.get(request.params.name); if (!prompt) { throw new Error( @@ -312,6 +313,7 @@ export class MCPServer { } if (this.capabilities.resources) { + // No request parameter for ListResources this.server.setRequestHandler(ListResourcesRequestSchema, async () => { return { resources: Array.from(this.resourcesMap.values()).map( @@ -320,9 +322,10 @@ export class MCPServer { }; }); + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available this.server.setRequestHandler( ReadResourceRequestSchema, - async (request) => { + async (request: any) => { const resource = this.resourcesMap.get(request.params.uri); if (!resource) { throw new Error( @@ -340,7 +343,8 @@ export class MCPServer { } ); - this.server.setRequestHandler(SubscribeRequestSchema, async (request) => { + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available + this.server.setRequestHandler(SubscribeRequestSchema, async (request: any) => { const resource = this.resourcesMap.get(request.params.uri); if (!resource) { throw new Error(`Unknown resource: ${request.params.uri}`); @@ -356,7 +360,8 @@ export class MCPServer { return {}; }); - this.server.setRequestHandler(UnsubscribeRequestSchema, async (request) => { + // TODO: Replace 'any' with the specific inferred request type from the SDK schema if available + this.server.setRequestHandler(UnsubscribeRequestSchema, async (request: any) => { const resource = this.resourcesMap.get(request.params.uri); if (!resource) { throw new Error(`Unknown resource: ${request.params.uri}`); @@ -376,12 +381,12 @@ export class MCPServer { private async detectCapabilities(): Promise { if (await this.promptLoader.hasPrompts()) { - this.capabilities.prompts = { enabled: true }; + this.capabilities.prompts = {}; // Indicate capability exists, but don't claim listChanged logger.debug("Prompts capability enabled"); } if (await this.resourceLoader.hasResources()) { - this.capabilities.resources = { enabled: true }; + this.capabilities.resources = {}; // Indicate capability exists, but don't claim listChanged/subscribe logger.debug("Resources capability enabled"); } diff --git a/src/transports/base.ts b/src/transports/base.ts index 0ba5c1f..a5a54a6 100644 --- a/src/transports/base.ts +++ b/src/transports/base.ts @@ -5,6 +5,16 @@ import { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js"; * Base transport interface */ export interface BaseTransport extends Transport { + // Properties from SDK Transport (explicitly listed for clarity/safety) + onclose?: (() => void) | undefined; + onerror?: ((error: Error) => void) | undefined; + onmessage?: ((message: JSONRPCMessage) => void) | undefined; + + // Methods from SDK Transport (explicitly listed for clarity/safety) + send(message: JSONRPCMessage): Promise; + close(): Promise; + start(): Promise; // Assuming start is also needed, mirroring AbstractTransport + /** * The type of transport (e.g., "stdio", "sse") */