Phase 11, part 5: the JSON API
/api/v1 offers the MCP tools as plain HTTP for scripts: GET /api/v1/tools lists what a key may call, POST /api/v1/<tool> calls one with JSON. Each call goes through /mcp internally, so keys, scopes, limits, logging and approvals are the same. /api/v1/docs documents every tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -413,3 +413,29 @@ func addTools(s *mcp.Server, d *db.DB, c *Caller) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// AllTools lists every tool there is, as an agent with every scope would
|
||||
// see it: for the API's documentation.
|
||||
func AllTools(ctx context.Context, d *db.DB, version string, more func(*mcp.Server, *Caller)) ([]*mcp.Tool, error) {
|
||||
srv := mcp.NewServer(&mcp.Implementation{Name: "supermarket", Version: version}, nil)
|
||||
addTools(srv, d, nil)
|
||||
if more != nil {
|
||||
more(srv, nil)
|
||||
}
|
||||
ct, st := mcp.NewInMemoryTransports()
|
||||
ss, err := srv.Connect(ctx, st, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer ss.Close()
|
||||
cs, err := mcp.NewClient(&mcp.Implementation{Name: "docs"}, nil).Connect(ctx, ct, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cs.Close()
|
||||
res, err := cs.ListTools(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.Tools, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user