1
0
mirror of https://github.com/go-micro/go-micro.git synced 2026-04-30 19:15:24 +02:00
Files
Asim Aslam 7a5d86a2a4 Claude/update docs roadmap f zd2 j (#2885)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: consolidate top-level directories, reduce framework bloat

Move internal/non-public packages behind internal/ or into their
parent packages where they belong:

- deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway)
- profile/ → service/profile/ (preset plugin profiles are a service concern)
- scripts/ → internal/scripts/ (install script is not public API)
- test/ → internal/test/ (test harness is not public API)
- util/ → internal/util/ (internal helpers shouldn't be imported externally)

Also fixes CLAUDE.md merge conflict markers and updates project
structure documentation.

All import paths updated. Build and tests pass.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: redesign model package to match framework conventions

Rename model.Database interface to model.Model (consistent with
client.Client, server.Server, store.Store). Remove generics in
favor of interface{}-based API with reflection.

Key changes:
- model.Model interface: Register once, CRUD infers table from type
- DefaultModel + NewModel() + package-level convenience functions
- Schema registered via Register(&User{}), no per-call schema passing
- Memory implementation as default (in model package, like store)
- memory/sqlite/postgres backends updated for new interface
- protoc-gen-micro generates RegisterXModel() instead of generic factory
- All docs, blog, and README updated

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: clarify blog post 7 uses modular monolith, not multi-service

Blog post 7 demonstrated all handlers in a single process but framed
it as microservices without acknowledging the architectural difference.

- Add "A Note on Architecture" section explaining this is a modular
  monolith demo and pointing to micro/blog for multi-service
- Clarify that handlers can be broken out into separate services later
- Fix "service registry" language to match single-process reality
- Restructure "Adding MCP to Existing Services" to distinguish the
  in-process approach from registry-based gateway options
- Update closing to acknowledge both paradigms
- Fix README type names (&CommentService{} -> &Comments{}, etc.)

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 13:13:31 +00:00
..

MCP Examples

Examples demonstrating Model Context Protocol (MCP) integration with go-micro.

Examples

hello - Minimal Example Start Here

The simplest possible MCP-enabled service. Perfect for learning the basics.

What it shows:

  • Automatic documentation extraction from Go comments
  • MCP gateway setup with 3 lines
  • Ready for Claude Code

Run it:

cd hello
go run main.go

crud - CRUD Contact Book

A realistic service with create, read, update, delete, list, and search operations. Shows how to document a full API for agents with @example tags, description struct tags, validation errors, and partial updates.

Run it:

cd crud
go run main.go

workflow - Cross-Service Orchestration

Three services (Inventory, Orders, Notifications) showing how an AI agent orchestrates multi-step workflows: search products, check stock, reserve inventory, place order, send confirmation — all from a single natural language request.

Run it:

cd workflow
go run main.go

platform - Agent Platform Showcase

A complete platform (Users, Posts, Comments, Mail) mirroring micro/blog. Shows how existing microservices become agent-accessible with zero code changes — agents can sign up, write posts, comment, tag, and send mail through natural language.

Run it:

cd platform
go run main.go

Complete example showing all MCP features with a user service.

What it shows:

  • Multiple endpoints (GetUser, CreateUser)
  • Rich documentation with examples
  • Per-endpoint auth scopes via server.WithEndpointScopes()
  • Pre-populated test data
  • Production-ready patterns

Run it:

cd documented
go run main.go

Quick Start

1. Write Your Service

Add Go doc comments to your handler methods:

// SayHello greets a person by name. Returns a friendly greeting message.
//
// @example {"name": "Alice"}
func (g *Greeter) 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"`
}

2. Register Handler (Auto-Extracts Docs!)

handler := service.Server().NewHandler(new(Greeter))
service.Server().Handle(handler)

3. Start MCP Gateway

go mcp.ListenAndServe(":3000", mcp.Options{
    Registry: service.Options().Registry,
})

Testing

HTTP API

# List tools
curl http://localhost:3000/mcp/tools | jq

# Call a tool
curl -X POST http://localhost:3000/mcp/call \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "greeter.Greeter.SayHello",
    "input": {"name": "Alice"}
  }' | jq

Claude Code (Stdio)

Start MCP server:

micro mcp serve

Add to ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "my-services": {
      "command": "micro",
      "args": ["mcp", "serve"]
    }
  }
}

Restart Claude Code and ask Claude to use your services!

Features

Automatic Documentation Extraction

Just write Go comments - documentation is extracted automatically:

  • Go doc comments → Tool descriptions
  • @example tags → Example inputs for AI
  • Struct tags → Parameter descriptions

Multiple Transports

  • Stdio - For Claude Code (recommended)
  • HTTP/SSE - For web-based agents

MCP Command Line

# Start MCP server
micro mcp serve              # Stdio (for Claude Code)
micro mcp serve --address :3000  # HTTP/SSE (for web agents)

# List available tools
micro mcp list               # Human-readable list
micro mcp list --json        # JSON output

# Test a tool
micro mcp test <tool-name> '{"key": "value"}'

# Generate documentation
micro mcp docs               # Markdown format
micro mcp docs --format json # JSON format
micro mcp docs --output tools.md  # Save to file

# Export to different formats
micro mcp export langchain   # Python LangChain tools
micro mcp export openapi     # OpenAPI 3.0 spec
micro mcp export json        # Raw JSON definitions

For detailed examples, see CLI Examples.

Zero Configuration

  • No manual tool registration
  • No API wrappers
  • No code generation
  • Just write normal Go code!

Per-Tool Auth Scopes

Declare required scopes when registering a handler:

handler := service.Server().NewHandler(
    new(BlogService),
    server.WithEndpointScopes("Blog.Create", "blog:write"),
    server.WithEndpointScopes("Blog.Delete", "blog:admin"),
)

Or define scopes at the gateway layer without changing services:

mcp.Serve(mcp.Options{
    Registry: reg,
    Auth:     authProvider,
    Scopes: map[string][]string{
        "blog.Blog.Create": {"blog:write"},
        "blog.Blog.Delete": {"blog:admin"},
    },
})

Tracing, Rate Limiting & Audit Logging

Every tool call generates a trace ID that propagates through the RPC chain. Configure rate limiting and audit logging at the gateway:

mcp.Serve(mcp.Options{
    Registry: reg,
    Auth:     authProvider,
    RateLimit: &mcp.RateLimitConfig{
        RequestsPerSecond: 10,
        Burst:             20,
    },
    AuditFunc: func(r mcp.AuditRecord) {
        log.Printf("[audit] trace=%s tool=%s account=%s allowed=%v",
            r.TraceID, r.Tool, r.AccountID, r.Allowed)
    },
})

Documentation

Learn More