How thinkinaixyz/go-mcp works
Project Type and Purpose
• Type: An open‑source Go SDK/library implementing the Model Context Protocol (MCP).
• Purpose: Provide a modular, high‑performance, strongly‑typed API for bidirectional communication between AI applications and external systems over multiple transports.
File Structure
• Top‑level “client” and “server” packages → User Layer APIs.
• “protocol” package → Core MCP types, encoding/decoding, tool definitions.
• “transport” package → Transport interface and concrete implementations (SSE, HTTP POST, Stdio).
• “pkg” → Shared utilities (logging, JSON helper, sync primitives).
• “examples” and “docs” → Usage samples and design documentation.
README Insights
• Confirms a three‑layer architecture: Transport, Protocol, User.
• Shows supported transports (HTTP SSE/POST, Stdio).
• Mentions extensibility via a unified transport interface.
Main Components
a. External Systems / Consumer Applications
• AI applications or any Go program that uses Go‑MCP as client or server.
b. User Layer
• client package: MCP Client API
• server package: MCP Server API + Session Manager
c. Protocol Layer
• protocol package: message types (Initialize, CallTool, Progress, etc.), JSON‑RPC handling, validation
d. Transport Layer
• transport package: Transport interface
• Implementations: SSE client/server, HTTP POST, Stdio client/server, mock transports for testing
e. Utilities
• pkg package: common helpers (logging, errors, atomic booleans, maps)
f. Examples & Integration Points
• examples/* showing standalone servers, Gin integration, filesystem client, etc.
Relationships and Data Flow
• Consumer App → (calls) → User Layer (Client API)
→ (invokes) → Protocol Layer (marshal/unmarshal JSONRPC)
→ (sends/receives) → Transport Layer → External Endpoint (HTTP SSE or stdio)
• On Server side: External Endpoint → Transport Layer → Protocol Layer → Server API → Business Logic → reverse path for responses.
Architectural Patterns and Principles
• Layered Architecture: Strict separation of concerns.
• Interface Abstraction: Transport interface decouples protocol from concrete network/IO.
• Dependency Inversion: Higher layers define interfaces; lower layers implement them.
• Modularity & Extensibility: New transport protocols can be added without touching protocol or user layer.
Technologies and Frameworks
• Go modules + standard library (net/http, encoding/json, concurrency primitives)
• JSON‑RPC pattern for protocol messages
• HTTP Server‑Sent Events (SSE) and HTTP POST for web transports
• Standard I/O streams for local IPC
• Gin (example integration)