feat: MCP SDK >=1.19 compatibility\n\n- upgrade @modelcontextprotocol…#38
feat: MCP SDK >=1.19 compatibility\n\n- upgrade @modelcontextprotocol…#38antoan wants to merge 5 commits intoadeze:masterfrom
Conversation
…/sdk to ^1.20.1\n- convert Zod input schemas to JSON Schema for registerTool\n- fallback to minimal {type:'object'} schema for safety\n- ensure getManifest emits JSON-Schema-friendly tool definitions\n
Summary of ChangesHello @antoan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on updating the project's integration with the Model Context Protocol (MCP) SDK to support versions 1.19 and above. The primary goal is to ensure that tool registration and manifest generation processes are fully compatible with the new SDK's JSON Schema requirements for tool input definitions, enhancing robustness and future-proofing the application. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to add compatibility with MCP SDK >=1.19 by updating dependencies and adapting to the new schema requirements. The dependency updates are correct, but the implementation for converting Zod schemas to JSON schemas is incomplete. Currently, it uses a generic placeholder schema, which will prevent tools from being used correctly. My review includes critical suggestions to properly implement the schema conversion using zod-to-json-schema. I've also suggested an improvement to the new helper script to make it more robust.
| const tools = toolConfigs.map((config) => ({ | ||
| name: config.name, | ||
| description: config.description, | ||
| inputSchema: { type: "object", properties: {}, additionalProperties: true }, | ||
| })); |
There was a problem hiding this comment.
The manifest generation for tools is using a generic, empty inputSchema. This defeats the purpose of schema definition, as clients (like language models) won't know what parameters a tool accepts. The PR description mentions converting Zod schemas to JSON schemas, and zodToJsonSchema is even imported, but this implementation doesn't use it. You should use the imported zodToJsonSchema function to convert each tool's Zod schema into a proper JSON schema. It's also good practice to wrap this conversion in a try...catch block and fall back to the generic schema only if the conversion fails, as intended by the PR description.
const tools = toolConfigs.map((config) => {
let inputSchema: any;
try {
inputSchema = zodToJsonSchema(config.inputSchema);
} catch (e) {
console.error(`Failed to convert Zod schema to JSON Schema for tool "${config.name}" in manifest:`, e);
inputSchema = { type: "object", properties: {}, additionalProperties: true };
}
return {
name: config.name,
description: config.description,
inputSchema,
};
});
src/services/raindropmcp.service.ts
Outdated
There was a problem hiding this comment.
The inputSchema is hardcoded to a generic object, which means the MCP server won't have the actual schema for tool input validation and discovery. The PR's goal is to convert Zod schemas to JSON schemas, but this is not being done. You should use zodToJsonSchema to perform the conversion. A try...catch block is recommended to handle any potential conversion errors and fall back to a generic schema, as mentioned in the PR description.
let inputSchema: any;
try {
// Convert Zod schema to a JSON Schema object compatible with MCP SDK >= 1.19
inputSchema = zodToJsonSchema(config.inputSchema);
} catch (e) {
console.error(`Failed to convert Zod schema to JSON Schema for tool "${config.name}":`, e);
// Fallback to minimal schema for safety
inputSchema = { type: "object", properties: {}, additionalProperties: true };
}| const svc = new RaindropMCPService(); | ||
| const server = svc.getServer(); | ||
| const tools = (server)._tools || []; | ||
| for (const t of tools) { | ||
| console.log(JSON.stringify({ name: t.name, type: t.inputSchema?.type, inputSchema: t.inputSchema }, null, 2)); | ||
| } |
There was a problem hiding this comment.
This script accesses the private _tools property of the server. It's better to use the public listTools() method available on the RaindropMCPService instance. This avoids relying on internal implementation details that might change in the future. Note that listTools() is an async method, so the script needs to be adapted to handle the promise.
| const svc = new RaindropMCPService(); | |
| const server = svc.getServer(); | |
| const tools = (server)._tools || []; | |
| for (const t of tools) { | |
| console.log(JSON.stringify({ name: t.name, type: t.inputSchema?.type, inputSchema: t.inputSchema }, null, 2)); | |
| } | |
| async function printTools() { | |
| const svc = new RaindropMCPService(); | |
| const tools = await svc.listTools(); | |
| for (const t of tools) { | |
| console.log(JSON.stringify({ name: t.name, type: t.inputSchema?.type, inputSchema: t.inputSchema }, null, 2)); | |
| } | |
| } | |
| printTools().catch(console.error); |
…efault zod for legacy clients\n- json for MCP SDK 1.19+ validators\n
- Goose 1.11+ requires JSON Schema (no more Zod shapes) - Remove conditional logic; toObjectJsonSchema() always applied - Simplifies codebase and aligns with MCP SDK 1.19+ requirements
- zod-to-json-schema 3.24.6 is incompatible with Zod 4.x - Zod 4.x was producing invalid JSON Schema (type: 'string' for z.object()) - Downgraded zod from ^4.1.9 to ^3.23.8 - Simplified toObjectJsonSchema() function - now works correctly - Validated with MCP Inspector: all tools pass schema validation - Goose 1.11.1 still fails with 'keyValidator._parse' error (client bug)
…/sdk to ^1.20.1\n- convert Zod input schemas to JSON Schema for registerTool\n- fallback to minimal {type:'object'} schema for safety\n- ensure getManifest emits JSON-Schema-friendly tool definitions\n