How kakkky/mcp-sdk-go works
Project Type & Purpose
• This is an SDK (library/tool) implemented in Go for the Model Context Protocol (MCP).
• It provides two main facets:
• A client library (client/)
• A server library (mcp-server/ plus wrapper McpServer)
• Underlying both is a shared “protocol engine” (shared/) and a transport abstraction (stdio).
• Example programs (in examples/) show how to wire the client and server into stand-alone processes.
Main Components
A. Shared Core (shared/)
• schema: JSON-RPC schema definitions (requests, notifications, errors, capabilities, etc.)
• protocol: Core JSON-RPC engine (enforce capabilities, handlers)
• transport: Abstraction over I/O (stdio read/write buffers, interfaces)
• utilities: Helpers (e.g. URI template processor)
B. Client Library (client/)
• client.Client: high-level client API (ListTools, CallTool, ListResources, Ping, etc.)
• Under the hood uses shared/protocol + shared/transport via a stdio client transport
• Mock packages for unit tests
C. Server Library (mcp-server/)
• Server: low-level JSON-RPC engine (SetRequestHandler, SendNotification, Ping, etc.)
• McpServer: façade over Server adding Tool/Resource/Prompt registration APIs
• ResourceTemplate support (URI templating)
• Capability validators, request handler wiring
• Uses same shared/protocol + shared/transport via a stdio server transport
D. Examples
• examples/client: shows spawning a server process and using the client API
• examples/server: shows wiring up a McpServer with Tools/Resources/Prompts
Interactions & Data Flow
[ Client Process ] <–STDIO/JSON-RPC–> [ Server Process ]
• Inside Client Process:
• client.NewClient → shared.Protocol → transport.NewStdioClientTransport → os.Stdin/os.Stdout
• On connect: initialization handshake (capabilities) → operation phase → client.SendXXX() calls → JSON-RPC requests
• Inside Server Process:
• mcpserver.NewMcpServer → Server (shared.Protocol) → transport.NewStdioServerTransport → os.Stdin/os.Stdout
• On connect: handles init requests, then dispatches to registered Tool/Resource/Prompt handlers → sends JSON-RPC responses/notifications
Architectural Patterns & Design Principles
• Layered architecture:
• Transport layer (stdio) at bottom
• Protocol layer (JSON-RPC handling, capability negotiation) in middle
• SDK façade (Client, McpServer) at top
• Facade pattern: McpServer wraps lower-level Server to simplify registration of Tools/Resources/Prompts
• Plugin/registration pattern: Users register callbacks for tools, resources, prompts at runtime
• Interface segregation: Transport is pluggable; additional transports (HTTP, SSE) can be added later