
MCP Golang (mcp-golang)
Author: metoro-io
Description: Unofficial Go implementation of the Model Context Protocol (MCP) for building MCP servers and clients with type-safe tool argument structs, automatic schema generation, and multiple transports (stdio, HTTP, Gin, SSE). Docs: https://mcpgolang.com
Stars: 1.2k
Forks: 119
License: MIT License
Category: Open Source
Overview
Installation
hello
Say hello to a person (example tool registered on the server via RegisterTool).
calculate
Perform a calculation based on the provided operation and operands (example tool name invoked by the client via CallTool).
FAQs
How do I migrate from mcp-golang to mcp-go if maintenance becomes a concern?
Migration involves refactoring tool registration from struct tags to builder patterns. Replace automatic schema generation with explicit AddString, AddNumber, and AddBoolean calls on tool definitions. Transport initialization changes but business logic stays intact. The biggest effort is rewriting argument structs into builder chains, though both libraries share stdio and SSE transports, making the underlying protocol migration straightforward.
Can mcp-golang handle concurrent tool requests safely under high load?
The content does not explicitly document concurrent request handling. However, the Gin transport has a known panic risk under certain methods, suggesting concurrency safety is not guaranteed out-of-the-box. Teams should implement recovery middleware, perform load testing on their specific transport choice, and ensure tool handler functions are goroutine-safe before deploying under high concurrency scenarios.
How does mcp-golang's automatic JSON schema generation work with nested structs and complex types?
The library recursively processes nested structs through the same jsonschema tag reflection mechanism used for top-level fields. Complex types like slices, maps, and pointers are automatically converted to their JSON schema equivalents with appropriate type constraints, oneOf patterns for unions, and nested object definitions that preserve the full type hierarchy without manual schema composition.
What are the differences between the stdio, HTTP, SSE, and Gin transports in mcp-golang and when should I use each one?
Stdio launches subprocesses for desktop integrations, HTTP handles stateless requests, SSE enables real-time bidirectional communication with long-lived connections, and Gin embeds MCP into existing web servers. Choose stdio for Claude Desktop, HTTP for serverless functions, SSE when clients need push notifications, and Gin when adding MCP to established Go services without separate processes.
How do I add recovery middleware to prevent panics when using mcp-golang's Gin transport in production?
Use Gin's built-in recovery middleware by calling `router.Use(gin.Recovery())` before registering the MCP transport handler. This middleware catches panics in your Gin routes and returns a 500 error instead of crashing the server. Apply it globally to your router instance, not to individual route groups, to ensure all MCP endpoint handlers are protected from unexpected runtime panics.
How do I configure logging for an MCP server?
MCP servers configure logging through framework-specific libraries like Winston for Node.js, Python's logging module, or Zap for Go. Set log levels via environment variables, inject structured JSON loggers into server initialization, and route output to console or files. Production deployments should enable correlation IDs per session and redact sensitive parameters to prevent credential leakage.