Skip to content

Commit 334b681

Browse files
fix: 修复 mcp-server 构建错误
Co-authored-by: aider (vertex_ai/gemini-2.5-pro) <aider@aider.chat>
1 parent 9005d6d commit 334b681

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

packages/mcp-server/src/bridge/openai.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function createOpenAIRouter(config: Config): Router {
2727
const stream = body.stream !== false;
2828

2929
if (!body.messages || body.messages.length === 0) {
30-
return res.status(400).json({ error: 'messages is required' });
30+
res.status(400).json({ error: 'messages is required' });
31+
return;
3132
}
3233

3334
// 将 OpenAI 格式的 messages 转换为 Gemini 格式
@@ -39,7 +40,8 @@ export function createOpenAIRouter(config: Config): Router {
3940

4041
const lastMessage = history.pop();
4142
if (!lastMessage) {
42-
return res.status(400).json({ error: 'No message to send.' });
43+
res.status(400).json({ error: 'No message to send.' });
44+
return;
4345
}
4446

4547
try {
@@ -58,7 +60,7 @@ export function createOpenAIRouter(config: Config): Router {
5860
res.flushHeaders(); // 立即发送头信息
5961

6062
const geminiStream = await oneShotChat.sendMessageStream({
61-
message: lastMessage.parts,
63+
message: lastMessage.parts || [],
6264
});
6365
const openAIStream = createOpenAIStreamTransformer(body.model);
6466

@@ -83,7 +85,7 @@ export function createOpenAIRouter(config: Config): Router {
8385
} else {
8486
// --- 非流式响应(为了完整性) ---
8587
const result = await oneShotChat.sendMessage({
86-
message: lastMessage.parts,
88+
message: lastMessage.parts || [],
8789
});
8890
const responseText =
8991
result.candidates?.[0]?.content?.parts?.[0]?.text || '';

packages/mcp-server/src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ import {
1818
loadEnvironment,
1919
loadSandboxConfig,
2020
} from '@google/gemini-cli/public-api';
21-
import {
22-
loadSettings,
23-
type Settings,
24-
loadExtensions,
25-
type Extension,
26-
getCliVersion,
27-
loadEnvironment,
28-
loadSandboxConfig,
29-
} from '@google/gemini-cli/public-api';
3021
import { GcliMcpBridge } from './bridge/bridge.js';
3122
import { createOpenAIRouter } from './bridge/openai.js';
3223
import express from 'express';
@@ -142,17 +133,6 @@ async function startMcpServer() {
142133
selectedAuthType = selectedAuthType || AuthType.USE_GEMINI;
143134
await config.refreshAuth(selectedAuthType);
144135

145-
// Initialize Auth - this is critical to initialize the tool registry and gemini client
146-
let selectedAuthType = settings.merged.selectedAuthType;
147-
if (!selectedAuthType && !process.env.GEMINI_API_KEY) {
148-
console.error(
149-
'Auth missing: Please set `selectedAuthType` in .gemini/settings.json or set the GEMINI_API_KEY environment variable.',
150-
);
151-
process.exit(1);
152-
}
153-
selectedAuthType = selectedAuthType || AuthType.USE_GEMINI;
154-
await config.refreshAuth(selectedAuthType);
155-
156136
// 4. 初始化并启动 MCP 桥接服务 和 OpenAI 服务
157137
const mcpBridge = new GcliMcpBridge(config, cliVersion);
158138

0 commit comments

Comments
 (0)