examples/mcp/crud/README.md
A complete CRUD service with MCP integration — the kind of service you'd actually build in production.
@example tagsdescription tags for agentsgo run .
# List all MCP tools
curl http://localhost:3001/mcp/tools | jq
# Create a contact
curl -X POST http://localhost:3001/mcp/call \
-H 'Content-Type: application/json' \
-d '{"tool": "contacts.Contacts.Create", "arguments": {"name": "Dave", "email": "[email protected]"}}'
# Search contacts
curl -X POST http://localhost:3001/mcp/call \
-H 'Content-Type: application/json' \
-d '{"tool": "contacts.Contacts.Search", "arguments": {"query": "engineer"}}'
micro mcp serve
Then ask: "List all contacts and find the engineers."
// Create adds a new contact to the book. Name and email are required.
//
// @example {"name": "Dave Wilson", "email": "[email protected]", "role": "Engineer"}
func (h *Contacts) Create(ctx context.Context, req *CreateRequest, rsp *CreateResponse) error {
type Contact struct {
ID string `json:"id" description:"Unique contact identifier"`
Name string `json:"name" description:"Full name"`
Email string `json:"email" description:"Email address"`
}
Only update fields that are provided (non-empty), so agents can change one field without overwriting others:
if req.Name != "" {
contact.Name = req.Name
}