45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
|
|
package tools
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"code.nochebuena.dev/einherjar/mcp/internal/index"
|
||
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||
|
|
)
|
||
|
|
|
||
|
|
type getComplianceInput struct {
|
||
|
|
Module string `json:"module" jsonschema:"the module name, e.g. core"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type getComplianceOutput struct {
|
||
|
|
Module string `json:"module"`
|
||
|
|
InterfaceAsserts []index.InterfaceAssert `json:"interfaceAsserts"`
|
||
|
|
Tests []index.ComplianceTest `json:"tests"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func registerGetCompliance(s *mcp.Server, idx *index.Index) {
|
||
|
|
mcp.AddTool(s, &mcp.Tool{
|
||
|
|
Name: "get_compliance",
|
||
|
|
Description: "Return a module's machine-checked conventions from compliance_test.go: every `var _ Iface = impl` interface assertion (the contracts the module promises to satisfy) and every Test* function (the structural rules the module enforces on itself). Use this before writing or reviewing code in a module to learn which conventions are actively guarded.",
|
||
|
|
}, func(ctx context.Context, req *mcp.CallToolRequest, args getComplianceInput) (*mcp.CallToolResult, getComplianceOutput, error) {
|
||
|
|
m := idx.FindModule(args.Module)
|
||
|
|
if m == nil {
|
||
|
|
return errorResult("module not found: " + args.Module), getComplianceOutput{}, nil
|
||
|
|
}
|
||
|
|
asserts := m.Compliance.InterfaceAsserts
|
||
|
|
if asserts == nil {
|
||
|
|
asserts = []index.InterfaceAssert{}
|
||
|
|
}
|
||
|
|
tests := m.Compliance.Tests
|
||
|
|
if tests == nil {
|
||
|
|
tests = []index.ComplianceTest{}
|
||
|
|
}
|
||
|
|
out := getComplianceOutput{
|
||
|
|
Module: m.Name,
|
||
|
|
InterfaceAsserts: asserts,
|
||
|
|
Tests: tests,
|
||
|
|
}
|
||
|
|
return jsonText(out), out, nil
|
||
|
|
})
|
||
|
|
}
|