* docs: update all four documentation guides and mark Q2 complete - ai-native-services: add WithMCP one-liner, standalone gateway, WebSocket client example, and OpenTelemetry observability section - mcp-security: add OTel distributed tracing, WebSocket authentication (connection-level and per-message), DeniedReason audit field - tool-descriptions: add manual overrides with WithEndpointDocs and export formats section - agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone gateway production pattern with Docker example - Update roadmap: mark Q2 documentation as complete, Q2 at 100% - Update status: reflect all recent completions, shift priorities https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: add agent demo example and blog post Add examples/agent-demo with a multi-service project management app (projects, tasks, team) that demonstrates AI agents interacting with Go Micro services through MCP. Includes seed data and example prompts. Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking through the example code and showing cross-service agent workflows. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: enable multiple services in a single binary Remove global state mutations from service and cmd option functions so that configuring one service no longer overwrites another's settings. Key changes: - service/options.go: remove all DefaultXxx global writes from option functions; newOptions() now creates fresh Server, Client, Store, and Cache per service while sharing Registry, Broker, and Transport - cmd/cmd.go: newCmd() uses local copies instead of pointers to package globals; Before() no longer mutates DefaultXxx vars - cmd/options.go: remove global mutations from all option functions - service/service.go: export ServiceImpl type for cross-package use - service/group.go: new Group type for multi-service lifecycle - micro.go: add Start/Stop to Service interface, expose Group and NewGroup convenience function - examples/multi-service: working example with two services https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * docs: highlight multi-service binary support Add multi-service section to README with code example, update features list, add to examples index, and note in status summary. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: unify service API and clean up developer experience - Unified service creation: micro.New("name", opts...) as canonical API - Clean handler registration: service.Handle(handler, opts...) accepts server.HandlerOption args directly, no need to reach through Server() - Unexported serviceImpl: users interact through Service interface only - Service groups use Service interface (not concrete type) - Fixed Stop() to properly propagate BeforeStop/AfterStop errors - Fixed store init: error-level log instead of fatal on init failure - Updated all examples to use consistent patterns - Updated README, getting-started, MCP docs, and guides - Added blog post about the DX cleanup https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc --------- Co-authored-by: Claude <noreply@anthropic.com>
5.2 KiB
Model Context Protocol (MCP)
Go Micro provides built-in support for the Model Context Protocol (MCP), enabling AI agents like Claude to discover and interact with your microservices as tools.
Overview
MCP gateway automatically exposes your microservices as AI-accessible tools through:
- Automatic service discovery via the registry
- Dynamic tool generation from service endpoints
- Stdio transport for local AI tools (Claude Code, etc.)
- HTTP/SSE transport for web-based agents
- Automatic documentation extraction from Go comments
Quick Start
1. Add Documentation to Your Service
Simply write Go doc comments on your handler methods:
package main
import (
"context"
"go-micro.dev/v5"
)
type GreeterService struct{}
// SayHello greets a person by name. Returns a friendly greeting message.
//
// @example {"name": "Alice"}
func (g *GreeterService) SayHello(ctx context.Context, req *HelloRequest, rsp *HelloResponse) error {
rsp.Message = "Hello " + req.Name
return nil
}
type HelloRequest struct {
Name string `json:"name" description:"Person's name to greet"`
}
type HelloResponse struct {
Message string `json:"message" description:"Greeting message"`
}
func main() {
service := micro.New("greeter")
service.Init()
// Register handler - docs extracted automatically from comments!
service.Handle(new(GreeterService))
service.Run()
}
That's it! Documentation is automatically extracted from your Go comments.
2. Start the MCP Server
Option A: Stdio Transport (for Claude Code)
# Start your service
go run main.go
# In another terminal, start MCP server with stdio
micro mcp serve
Add to Claude Code config (`~/.claude/claude_desktop_config.json`):
{
"mcpServers": {
"go-micro": {
"command": "micro",
"args": ["mcp", "serve"]
}
}
}
Option B: HTTP Transport (for web agents)
Start MCP gateway with HTTP/SSE:
micro mcp serve --address :3000
Access tools at `http://localhost:3000/mcp/tools`
3. Use Your Service with AI
Claude can now discover and call your service:
User: "Say hello to Bob using the greeter service"
Claude: [calls greeter.GreeterService.SayHello with {"name": "Bob"}]
"Hello Bob"
Features
Automatic Documentation Extraction
Go Micro automatically extracts documentation from your handler method comments at registration time. No extra code needed!
For complete documentation details, see the gateway/mcp package documentation.
Authentication & Scopes for MCP Tools
MCP tool calls go through the same authentication and scope enforcement as regular API calls. This means you can control which tokens (and therefore which users, services, or AI agents) can invoke which tools.
Restricting MCP Tool Access
-
Set endpoint scopes — Visit
/auth/scopesand set required scopes on service endpoints. For example, setinternalonbilling.Billing.Chargeto restrict it. -
Create scoped tokens — Visit
/auth/tokensand create tokens with specific scopes:- A token with scope
internalcan call endpoints requiringinternal - A token with scope
*has unrestricted access (admin) - A token with no matching scope gets
403 Forbidden
- A token with scope
-
Use the token — Pass it in the
Authorizationheader for API/MCP calls:
# List available MCP tools (requires valid token)
curl http://localhost:8080/api/mcp/tools \
-H "Authorization: Bearer <token>"
# Call a specific tool (scope-checked)
curl -X POST http://localhost:8080/api/mcp/call \
-H "Authorization: Bearer <token>" \
-d '{"tool":"greeter.GreeterService.SayHello","input":{"name":"World"}}'
Common MCP Token Patterns
| Use Case | Token Scopes | What It Can Do |
|---|---|---|
| Internal tooling | internal |
Call endpoints tagged with internal scope |
| Production AI agent | greeter, users |
Only call greeter and user service endpoints |
| Admin / debugging | * |
Full access to all tools |
| Read-only agent | readonly |
Call endpoints tagged with readonly scope |
Agent Playground
The agent playground at /agent uses the logged-in user's session token. Scope checks apply based on the scopes of the user's account. The default admin user has * scope (full access).
MCP Command Line
The `micro mcp` command provides tools for working with MCP:
# Start MCP server (stdio by default)
micro mcp serve
# Start with HTTP transport
micro mcp serve --address :3000
# List available tools
micro mcp list
# Test a specific tool
micro mcp test greeter.GreeterService.SayHello
Transport Options
- Stdio - For local AI tools (Claude Code, recommended)
- HTTP/SSE - For web-based agents
See examples for complete usage.
Examples
See `examples/mcp/documented` for a complete working example.