Files
mcp/internal/tools/get_adr.go
T

41 lines
1.2 KiB
Go
Raw Normal View History

package tools
import (
"context"
"strings"
"code.nochebuena.dev/einherjar/mcp/internal/index"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type getADRInput struct {
Module string `json:"module" jsonschema:"the module name owning the ADR, e.g. core"`
ID string `json:"id" jsonschema:"the ADR identifier, e.g. ADR-001"`
}
type getADROutput struct {
Module string `json:"module"`
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
}
func registerGetADR(s *mcp.Server, idx *index.Index) {
mcp.AddTool(s, &mcp.Tool{
Name: "get_adr",
Description: "Fetch the full markdown body of one architectural decision record by module and ID.",
}, func(ctx context.Context, req *mcp.CallToolRequest, args getADRInput) (*mcp.CallToolResult, getADROutput, error) {
m := idx.FindModule(args.Module)
if m == nil {
return errorResult("module not found: " + args.Module), getADROutput{}, nil
}
for _, a := range m.ADRs {
if strings.EqualFold(a.ID, args.ID) {
out := getADROutput{Module: m.Name, ID: a.ID, Title: a.Title, Body: a.Body}
return jsonText(out), out, nil
}
}
return errorResult("ADR not found: " + args.ID + " in module " + args.Module), getADROutput{}, nil
})
}