49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
|
|
// Package tools wires Einherjar MCP tools to a server. Each tool lives in its
|
||
|
|
// own file alongside its input and output types.
|
||
|
|
package tools
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
|
||
|
|
"code.nochebuena.dev/einherjar/mcp/internal/index"
|
||
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Register binds every tool implemented in this package to s, sharing the
|
||
|
|
// provided index as their backing knowledge.
|
||
|
|
func Register(s *mcp.Server, idx *index.Index) {
|
||
|
|
registerListModules(s, idx)
|
||
|
|
registerGetModule(s, idx)
|
||
|
|
registerSearchSymbols(s, idx)
|
||
|
|
registerGetSymbol(s, idx)
|
||
|
|
registerListADRs(s, idx)
|
||
|
|
registerGetADR(s, idx)
|
||
|
|
registerGetExample(s, idx)
|
||
|
|
registerValidateSnippet(s, idx)
|
||
|
|
registerGetCompliance(s, idx)
|
||
|
|
registerGetChangelog(s, idx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// jsonText returns a CallToolResult whose single text block is the JSON
|
||
|
|
// encoding of v. The same value is also returned as the structured output,
|
||
|
|
// so hosts that surface structured outputs get a typed payload.
|
||
|
|
func jsonText(v any) *mcp.CallToolResult {
|
||
|
|
b, err := json.MarshalIndent(v, "", " ")
|
||
|
|
if err != nil {
|
||
|
|
return &mcp.CallToolResult{
|
||
|
|
IsError: true,
|
||
|
|
Content: []mcp.Content{&mcp.TextContent{Text: "encode error: " + err.Error()}},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return &mcp.CallToolResult{
|
||
|
|
Content: []mcp.Content{&mcp.TextContent{Text: string(b)}},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func errorResult(msg string) *mcp.CallToolResult {
|
||
|
|
return &mcp.CallToolResult{
|
||
|
|
IsError: true,
|
||
|
|
Content: []mcp.Content{&mcp.TextContent{Text: msg}},
|
||
|
|
}
|
||
|
|
}
|