@@ -166,14 +166,16 @@ export class McpServer {
166166 ) ;
167167
168168 this . server . setRequestHandler ( 'tools/call' , async ( request , ctx ) : Promise < CallToolResult | CreateTaskResult > => {
169+ // Tool lookup errors are JSON-RPC errors, not tool errors
170+ const tool = this . _registeredTools [ request . params . name ] ;
171+ if ( ! tool ) {
172+ throw new ProtocolError ( ProtocolErrorCode . InvalidParams , `Tool ${ request . params . name } not found` ) ;
173+ }
174+ if ( ! tool . enabled ) {
175+ throw new ProtocolError ( ProtocolErrorCode . InvalidParams , `Tool ${ request . params . name } disabled` ) ;
176+ }
177+
169178 try {
170- const tool = this . _registeredTools [ request . params . name ] ;
171- if ( ! tool ) {
172- throw new ProtocolError ( ProtocolErrorCode . InvalidParams , `Tool ${ request . params . name } not found` ) ;
173- }
174- if ( ! tool . enabled ) {
175- throw new ProtocolError ( ProtocolErrorCode . InvalidParams , `Tool ${ request . params . name } disabled` ) ;
176- }
177179
178180 const isTaskRequest = ! ! request . params . task ;
179181 const taskSupport = tool . execution ?. taskSupport ;
@@ -213,9 +215,8 @@ export class McpServer {
213215 await this . validateToolOutput ( tool , result , request . params . name ) ;
214216 return result ;
215217 } catch ( error ) {
216- if ( error instanceof ProtocolError ) {
217- // Protocol errors should be returned as JSON-RPC errors, not wrapped in CallToolResult
218- throw error ;
218+ if ( error instanceof ProtocolError && error . code === ProtocolErrorCode . UrlElicitationRequired ) {
219+ throw error ; // Return the error to the caller without wrapping in CallToolResult
219220 }
220221 return this . createToolError ( error instanceof Error ? error . message : String ( error ) ) ;
221222 }
0 commit comments