@@ -3,6 +3,7 @@ import { ToolAnnotations, Tool } from "@modelcontextprotocol/sdk/types.js";
33import { reportToolCall } from './telemetry.js' ;
44import { debug } from './logger.js' ;
55import { CloudBaseOptions } from '../types.js' ;
6+ import { shouldRegisterTool } from './cloud-mode.js' ;
67import os from 'os' ;
78
89// 扩展 McpServer 类型以包含 ide
@@ -139,25 +140,31 @@ function createWrappedHandler(name: string, handler: any, server: ExtendedMcpSer
139140}
140141
141142/**
142- * 包装 MCP Server 的 registerTool 方法,添加数据上报功能
143+ * 包装 MCP Server 的 registerTool 方法,添加数据上报功能和条件注册
143144 * @param server MCP Server 实例
144145 */
145146export function wrapServerWithTelemetry ( server : McpServer ) : void {
146147 // 保存原始的 registerTool 方法
147148 const originalRegisterTool = server . registerTool . bind ( server ) ;
148149
149- // 重写 registerTool 方法,添加数据上报功能
150+ // Override the registerTool method to add telemetry and conditional registration
150151 server . registerTool = function ( toolName : string , toolConfig : any , handler : any ) {
151-
152- // 记录工具注册信息
153- debug ( `注册工具: ${ toolName } ` , {
152+ // If the tool should not be registered in the current mode, do not register and return undefined
153+ if ( ! shouldRegisterTool ( toolName ) ) {
154+ debug ( `Cloud mode: skipping registration of incompatible tool: ${ toolName } ` ) ;
155+ // Explicitly return undefined to satisfy the expected type
156+ return undefined as any ;
157+ }
158+
159+ // Log tool registration info
160+ debug ( `Registering tool: ${ toolName } ` , {
154161 toolConfig
155162 } ) ;
156163
157- // 使用包装后的处理函数,传递服务器实例
164+ // Use the wrapped handler, passing the server instance
158165 const wrappedHandler = createWrappedHandler ( toolName , handler , server as ExtendedMcpServer ) ;
159-
160- // 调用原始 registerTool 方法
166+
167+ // Call the original registerTool method
161168 return originalRegisterTool ( toolName , toolConfig , wrappedHandler ) ;
162169 } ;
163170}
0 commit comments