Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

Implement MCP server using @modelcontextprotocol/sdk:

  • createMcpServer() factory with transport-agnostic architecture
  • TypedTool/TypedResource wrappers for schema validation
  • Handler-based request processing with Result pattern
  • Server lifecycle management (start/stop)
  • Comprehensive test coverage (33 tests)

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Resolves #46

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Implements MCP (Model Context Protocol) server framework using @modelcontextprotocol/sdk with transport-agnostic architecture, typed handlers, and Result pattern integration
  • Adds comprehensive test suite with33 tests covering server creation, tool registration, error handling, and pagination support following TDD principles
  • Includes custom Zod-to-JSON Schema converter for MCP protocol compatibility with extensive support for complex Zod types and validation constraints

Important Files Changed

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.ts for the no-op start/stop methods and packages/mcp/src/schema.ts for 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
Loading

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

name: tool.name,
description: tool.description,
inputSchema: jsonSchema,
handler: tool.handler as StoredTool["handler"],
Copy link

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.

@galligan galligan changed the base branch from p3-15/mcp/types-interfaces to graphite-base/78 January 23, 2026 21:32
@galligan galligan force-pushed the p3-16/mcp/server-impl branch from d264bd0 to d24df4b Compare January 23, 2026 21:40
@galligan galligan changed the base branch from graphite-base/78 to p3-15/mcp/types-interfaces January 23, 2026 21:40
@galligan
Copy link
Contributor Author

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.

@galligan
Copy link
Contributor Author

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.

galligan and others added 2 commits January 23, 2026 18:06
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>
@galligan galligan force-pushed the p3-16/mcp/server-impl branch from d24df4b to bd9332b Compare January 23, 2026 23:09
@galligan galligan force-pushed the p3-15/mcp/types-interfaces branch from ac4a0b1 to d91d9f1 Compare January 23, 2026 23:09
@galligan
Copy link
Contributor Author

Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants