fix(filesystem): emit object input schemas - #4775
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change is a small, well-scoped schema fix whose 14 substitutions are each semantically equivalent to prior definitions, matches an existing repo convention, and is covered by a regression test following an established pattern.
Pull request overview
This PR fixes a JSON Schema compliance bug in server-filesystem (issue #4772), where tools/list responses could omit the required root type: "object" from each tool's inputSchema, causing strict JSON Schema 2020-12 clients (e.g. Claude Desktop's "Cowork and Code" shared pool) to reject the server. It converts every tool registration from raw Zod shapes (Schema.shape / inline field objects) to complete z.object(...) schemas, and adds a real stdio MCP regression test that asserts every tool advertises inputSchema.type: "object".
Changes:
- Replaces raw Zod shapes / inline field objects with the already-defined
z.object(...)named schemas across all 14 filesystem tool registrations (andz.object({})forlist_allowed_directories). - Adds
__tests__/tools-list-schema.test.ts, which spawns the built server over stdio, callstools/list, and checks each tool'sinputSchema.type.
File summaries
| File | Description |
|---|---|
| src/filesystem/index.ts | Registers every tool with a full z.object(...) input schema instead of a raw shape/.shape, ensuring the root type: "object" is emitted. |
| src/filesystem/tests/tools-list-schema.test.ts | New stdio MCP regression test verifying every tool's inputSchema.type is "object". |
Notes from verification:
- All 14 substituted schemas are semantically equivalent to the inline definitions they replace (schemas defined at
index.ts:97-161); handlers already typed their args viaz.infer<typeof …Schema>, so this also removes duplication. - Passing a
z.object(...)(ZodObject) directly toregisterTool'sinputSchemamatches the existing repo convention (src/everything/tools/echo.ts:15), so it is the idiomatic form. - The new test mirrors the existing
directory-tree.mcp-sdk.test.tspattern (spawning../dist/index.js), so its build dependency is not a new concern.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Description
Closes #4772.
server-filesystemregistered tools with raw Zod shapes (Schema.shapeor inline field objects). With older SDK schema conversion, that representation can omit the roottype: "object"from the JSON Schema returned bytools/list, causing strict JSON Schema 2020-12 clients to reject the server.This change:
z.object(...)schema;tools/listand checks every tool'sinputSchema.type.No tool arguments or unrelated servers were changed.
How Has This Been Tested?
npm run build— passed for all workspaces.cd src/filesystem && npx vitest run --coverage __tests__/tools-list-schema.test.ts— passed, 1 test./varvs/private/varrealpath handling and NFD/NFC directory behavior; the same 3 failures reproduce on the parent commit.@modelcontextprotocol/server-filesystem@2025.8.21baseline reproduces the reported strict-client failure for all 13 tools (inputSchema.typeis missing).The new regression test passes on the current repository baseline because the current
@modelcontextprotocol/sdk@1.30.0compatibility layer normalizes raw shapes. The implementation removes that dependency on implicit SDK behavior for future releases.Breaking Changes
None. Tool names, arguments, and handlers are unchanged.
Types of changes
Checklist
AI assistance disclosure
This PR was prepared with OpenAI Codex under human direction. The final diff, test evidence, and issue/PR state were reviewed before submission.
中文说明
关闭 #4772。filesystem 原先把裸 Zod shape 注册给 SDK;在受影响的旧 SDK 转换路径中,
tools/list返回的 JSON Schema 会缺少根级type: "object",严格的 JSON Schema 2020-12 客户端因此拒绝启动。本 PR 将全部 filesystem 工具改为使用完整的z.object(...)schema,并增加真实 stdio MCPtools/list回归测试,确认每个工具都声明inputSchema.type: "object"。工具名称、参数和处理器保持不变。完整测试中的 3 个 Unicode 路径失败在父提交上也能复现,属于当前 macOS 环境基线问题,未将其写成通过。