Phase 11, part 2: module tools over MCP

Agents get each module's tools by their scopes: reading tools with read,
the others with read and act. Content (drafts and items; writing, editing
and discarding drafts), Prospects (signals, review, outreach, suppression;
outreach drafts and edits), SEO (the morning check, What to write next,
links, changes; editing a proposal), Sites and Metrics (reading) and the
Market (list, get, save). They call what the pages call, and what an agent
changes is in the audit log as the agent. Nothing that leaves Supermarket
is offered yet: that waits for approvals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:31:43 -07:00
co-authored by Claude Opus 5.5
parent da2d56f8d2
commit bfb74e7700
6 changed files with 903 additions and 6 deletions
+8 -2
View File
@@ -41,7 +41,10 @@ type Authenticator func(r *http.Request, key string) (*Caller, error)
// Handler returns the /mcp handler. Each request needs an agent's key
// ("Authorization: Bearer sm_…"), and is offered only the tools the
// agent's scopes allow.
func Handler(d *db.DB, version string, auth Authenticator) http.Handler {
//
// more adds the app's module tools for the caller (the web package has
// them, as they call what its pages call); nil for none.
func Handler(d *db.DB, version string, auth Authenticator, more func(*mcp.Server, *Caller)) http.Handler {
var mu sync.Mutex
servers := map[string]*mcp.Server{} // by the scopes' signature: a few at most
h := mcp.NewStreamableHTTPHandler(func(r *http.Request) *mcp.Server {
@@ -54,6 +57,9 @@ func Handler(d *db.DB, version string, auth Authenticator) http.Handler {
}
srv := mcp.NewServer(&mcp.Implementation{Name: "supermarket", Version: version}, nil)
addTools(srv, d, c)
if more != nil {
more(srv, c)
}
servers[sig] = srv
return srv
}, &mcp.StreamableHTTPOptions{Stateless: true, JSONResponse: true})
@@ -77,7 +83,7 @@ func Handler(d *db.DB, version string, auth Authenticator) http.Handler {
type callerKey struct{}
// scopes are what tools are offered by: each, read or act.
var scopes = []string{"market", "crm"}
var scopes = []string{"content", "prospects", "seo", "sites", "metrics", "market", "crm"}
// signature names the tools a caller gets.
func signature(c *Caller) string {