11import express , { Request , Response , NextFunction , Application } from 'express' ;
2- // [FIX] Correctly import 'Server' and 'JSONRPCError' from the SDK's server entry point.
3- import { Server , JSONRPCError } from '@modelcontextprotocol/sdk/server/index.js' ;
2+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js' ;
43import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js' ;
54import { z } from 'zod' ;
65import {
@@ -40,14 +39,12 @@ const requestLogger = (req: Request, res: Response, next: NextFunction) => {
4039export class GcliMcpBridge {
4140 private readonly config : Config ;
4241 private readonly cliVersion : string ;
43- // [FIX] Use the correct class name 'Server'
44- private readonly mcpServer : Server ;
42+ private readonly mcpServer : McpServer ;
4543
4644 constructor ( config : Config , cliVersion : string ) {
4745 this . config = config ;
4846 this . cliVersion = cliVersion ;
49- // [FIX] Instantiate the correct class 'Server'
50- this . mcpServer = new Server (
47+ this . mcpServer = new McpServer (
5148 {
5249 name : 'gemini-cli-mcp-server' ,
5350 version : this . cliVersion ,
@@ -144,7 +141,6 @@ export class GcliMcpBridge {
144141 description : tool . description ,
145142 inputSchema : inputSchema ,
146143 } ,
147- // [FIX] Add explicit types for args and extra, and implement the try/catch block.
148144 async (
149145 args : Record < string , unknown > ,
150146 extra : { signal : AbortSignal } ,
@@ -159,15 +155,9 @@ export class GcliMcpBridge {
159155 errorMessage ,
160156 ) ;
161157
162- const userFacingMessage = `Error executing tool '${ tool . name } ': Quota exceeded. Do not retry. Upstream error: ${ errorMessage } ` ;
163-
164- throw new JSONRPCError (
165- - 32000 ,
166- userFacingMessage ,
167- {
168- toolName : tool . name ,
169- originalError : errorMessage ,
170- } ,
158+ // 简单地抛出一个Error,MCP SDK会自动处理为适当的JSON-RPC错误
159+ throw new Error (
160+ `Error executing tool '${ tool . name } ': ${ errorMessage } ` ,
171161 ) ;
172162 }
173163 } ,
0 commit comments