-
Notifications
You must be signed in to change notification settings - Fork 0
feat(mcp): add MCP server implementation with typed handlers #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: p3-15/mcp/types-interfaces
Are you sure you want to change the base?
Conversation
80648b0 to
cb54780
Compare
c36b4d8 to
df2f41f
Compare
cb54780 to
515296e
Compare
df2f41f to
169e1af
Compare
515296e to
00fb00e
Compare
00fb00e to
d264bd0
Compare
Greptile Summary
|
| Filename | Overview |
|---|---|
| packages/mcp/src/server.ts | Core MCP server implementation with tool registration, handler execution, and error translation; start/stop methods are placeholder implementations |
| packages/mcp/src/schema.ts | Custom Zod-to-JSON Schema converter relying on Zod internals via _def property access which may be brittle across version updates |
Confidence score: 4/5
- This PR is generally safe to merge with some considerations around implementation completeness and dependency on Zod internals
- Score reflects solid architecture and comprehensive testing, but deducted one point due to placeholder server lifecycle methods and reliance on potentially unstable Zod internal APIs
- Pay close attention to
packages/mcp/src/server.tsfor the no-op start/stop methods andpackages/mcp/src/schema.tsfor Zod internals usage
Sequence Diagram
sequenceDiagram
participant User
participant McpServer
participant ToolHandler
participant ZodValidator
participant Logger
User->>McpServer: "invokeTool(toolName, input)"
McpServer->>Logger: "debug('Invoking tool')"
McpServer->>McpServer: "Find tool by name"
alt Tool not found
McpServer->>User: "Result.err(McpError 'Tool not found')"
else Tool found
McpServer->>ZodValidator: "zodSchema.safeParse(input)"
alt Input validation fails
ZodValidator->>McpServer: "parseResult.success = false"
McpServer->>Logger: "warn('Input validation failed')"
McpServer->>User: "Result.err(McpError 'Invalid input')"
else Input valid
ZodValidator->>McpServer: "parseResult.success = true"
McpServer->>McpServer: "createHandlerContext()"
McpServer->>ToolHandler: "handler(validatedInput, ctx)"
ToolHandler->>McpServer: "Result<output, error>"
alt Handler returns error
McpServer->>McpServer: "translateError()"
McpServer->>Logger: "debug('Tool returned error')"
McpServer->>User: "Result.err(McpError)"
else Handler success
McpServer->>Logger: "debug('Tool completed successfully')"
McpServer->>User: "Result.ok(output)"
end
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
| name: tool.name, | ||
| description: tool.description, | ||
| inputSchema: jsonSchema, | ||
| handler: tool.handler as StoredTool["handler"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Type assertion loses compile-time safety - the handler types should match but casting bypasses verification
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/mcp/src/server.ts
Line: 169:169
Comment:
**style:** Type assertion loses compile-time safety - the handler types should match but casting bypasses verification
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.378aebe to
ac4a0b1
Compare
d264bd0 to
d24df4b
Compare
|
Addressed review feedback: schema optional detection now checks both sides of Zod pipelines, added schema tests for effects/pipeline optionality, and aligned the no-op logger with trace/fatal. Submitted via gt. |
|
Addressed review feedback: updated optional detection for Zod pipelines (requires both input/output to allow undefined) and added schema tests covering effects/pipeline optionality. Submitted the update with gt. |
Adds schema.ts with zodToJsonSchema() utility for converting Zod schemas to JSON Schema format required by MCP protocol. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d24df4b to
bd9332b
Compare
ac4a0b1 to
d91d9f1
Compare
|
Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR. |

Implement MCP server using @modelcontextprotocol/sdk:
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
Resolves #46