chore: import upstream snapshot with attribution
govulncheck / govulncheck (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:33 +08:00
commit e071084ebe
982 changed files with 160368 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
# MCP Hello World Example
The simplest possible MCP-enabled go-micro service.
## What This Shows
- ✅ Automatic documentation extraction from Go comments
- ✅ MCP gateway setup with 3 lines of code
- ✅ Ready for Claude Code integration
- ✅ HTTP endpoint for testing
## Run It
```bash
cd examples/mcp/hello
go run main.go
```
## Test It
### Option 1: HTTP API
```bash
# List available tools
curl http://localhost:3000/mcp/tools | jq
# Call the SayHello tool
curl -X POST http://localhost:3000/mcp/call \
-H "Content-Type: application/json" \
-d '{
"tool": "greeter.Greeter.SayHello",
"input": {"name": "Alice"}
}' | jq
```
### Option 2: Claude Code
In a separate terminal:
```bash
micro mcp serve
```
Add to `~/.claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"greeter": {
"command": "micro",
"args": ["mcp", "serve"]
}
}
}
```
Restart Claude Code and ask:
> "Say hello to Bob using the greeter service"
## How It Works
### 1. Write Normal Go Code
```go
// 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
}
```
### 2. Register the Handler
```go
// Documentation is extracted automatically!
handler := service.Server().NewHandler(new(Greeter))
service.Server().Handle(handler)
```
### 3. Start MCP Gateway
```go
go mcp.ListenAndServe(":3000", mcp.Options{
Registry: service.Options().Registry,
})
```
**That's it!** Your service is now AI-accessible.
## What Gets Extracted
From this code:
```go
// SayHello greets a person by name. Returns a friendly greeting message.
//
// @example {"name": "Alice"}
func (g *Greeter) SayHello(...)
type HelloRequest struct {
Name string `json:"name" description:"Person's name to greet"`
}
```
Claude sees:
```json
{
"name": "greeter.Greeter.SayHello",
"description": "SayHello greets a person by name. Returns a friendly greeting message.",
"inputSchema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Person's name to greet"
}
},
"examples": ["{\"name\": \"Alice\"}"]
}
}
```
## Next Steps
- See `examples/mcp/documented` for a more complete example with multiple endpoints
- Read `/docs/mcp.md` for full documentation
- Check out the [MCP specification](https://modelcontextprotocol.io/)
+65
View File
@@ -0,0 +1,65 @@
// Package main demonstrates a minimal MCP-enabled service.
//
// This is the simplest possible example showing:
// - Automatic documentation extraction from Go comments
// - MCP gateway setup
// - Ready for use with Claude Code
package main
import (
"context"
"log"
"go-micro.dev/v6"
"go-micro.dev/v6/gateway/mcp"
)
// Greeter service handles greeting operations
type Greeter struct{}
// 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
}
// HelloRequest contains the greeting parameters
type HelloRequest struct {
Name string `json:"name" description:"Person's name to greet"`
}
// HelloResponse contains the greeting result
type HelloResponse struct {
Message string `json:"message" description:"The greeting message"`
}
func main() {
// Create service
service := micro.NewService("greeter",
micro.Address(":9090"),
// Start MCP gateway alongside the service
mcp.WithMCP(":3000"),
)
service.Init()
// Register handler — docs extracted automatically from comments
if err := service.Handle(new(Greeter)); err != nil {
log.Fatal(err)
}
log.Println("Greeter service starting...")
log.Println("Service: http://localhost:9090")
log.Println("MCP Gateway: http://localhost:3000")
log.Println("MCP Tools: http://localhost:3000/mcp/tools")
log.Println()
log.Println("Use with Claude Code:")
log.Println(" micro mcp serve")
// Run service
if err := service.Run(); err != nil {
log.Fatal(err)
}
}