Skip to content

Commit 6cbbf75

Browse files
fix: 确保工具响应始终为对象格式
Co-authored-by: aider (vertex_ai/gemini-2.5-pro) <aider@aider.chat>
1 parent 24459e3 commit 6cbbf75

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/mcp-server/src/gemini-client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ export class GeminiApiClient {
8181

8282
try {
8383
const parsed = JSON.parse(msg.content as string);
84+
8485
// The Gemini API expects an object for the response.
85-
// If the parsed content is a primitive (string, number, boolean),
86-
// it must be wrapped in an object.
87-
if (typeof parsed === 'object' && parsed !== null) {
86+
// If the parsed content is a non-null, non-array object, use it directly.
87+
// Otherwise, wrap primitives, arrays, or null in an object.
88+
if (
89+
typeof parsed === 'object' &&
90+
parsed !== null &&
91+
!Array.isArray(parsed)
92+
) {
8893
responsePayload = parsed as Record<string, unknown>;
8994
} else {
9095
responsePayload = { output: parsed };

0 commit comments

Comments
 (0)