Documentation
¶
Overview ¶
Package mcp is Workgraph's Model Context Protocol tool set, shared by both transports (wg-p4h.11).
One definition, two ways in. `wg mcp` speaks stdio, for Claude Code and Codex on a laptop; control-api serves the same tools over Streamable HTTP at /mcp, for the clients that cannot spawn a local process — Claude Cowork's sandbox, claude.ai in a browser, and the phone apps. Those three are where the people actually are, and none of them can install a binary or hold an environment variable.
The tools lived in cmd/wg/mcp.go and are here so the two transports cannot drift. A remote tool set that lags the local one by a release is worse than no remote tool set: the model reads the tool list as its prompt, and a stale prompt is a confidently wrong one.
CURATED, NOT GENERATED, which is the decision worth arguing with and is carried over unchanged from ADR-0025. Exposing all the API's operations would give a model dozens of tools and no judgement. The tool list IS the prompt — it is what the model reads before deciding — so a long one makes every decision worse rather than more capable. Six tools, and the omissions are deliberate:
approvals no credential may decide an approval, so a tool for it would be
a tool that always fails
tokens minting needs an interactive session; a tool would teach the
model to attempt what it cannot do
node paths the execution node's own surface, authorised by a different
credential entirely
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Routes = []Route{ {Tool: "workgraph_inbox", Method: http.MethodGet, Path: "/v1/inbox", ReadOnly: true}, {Tool: "workgraph_ask", Method: http.MethodGet, Path: "/v1/ask", ReadOnly: true}, {Tool: "workgraph_work_list", Method: http.MethodGet, Path: "/v1/work", ReadOnly: true}, {Tool: "workgraph_bead", Method: http.MethodGet, Path: "/v1/work/{bead}", ReadOnly: true}, {Tool: "workgraph_job", Method: http.MethodGet, Path: "/v1/work/jobs/{id}", ReadOnly: true}, {Tool: "workgraph_project_list", Method: http.MethodGet, Path: "/v1/projects", ReadOnly: true}, {Tool: "workgraph_beads_file", Method: http.MethodPost, Path: "/v1/work/beads"}, {Tool: "workgraph_project_create", Method: http.MethodPost, Path: "/v1/projects"}, {Tool: "workgraph_repositories_attach", Method: http.MethodPost, Path: "/v1/projects/{slug}/repositories"}, {Tool: "workgraph_dispatch", Method: http.MethodPost, Path: "/v1/work/{bead}/dispatch", SpendsMoney: true}, }
Routes is the tool-to-route table, in the order the tools are advertised.
Order matters more than it looks: the model reads the list top to bottom, and the read-only tools come first so that the cheapest useful thing is the first thing it sees.
Functions ¶
Types ¶
type Caller ¶
type Caller interface {
Call(ctx context.Context, method, path string, body any) (status int, respBody []byte, err error)
}
Caller performs one Workgraph API operation and returns the raw answer.
The two transports supply different implementations and neither is a special case of the other. `wg` calls the API over HTTPS with a personal token; control-api dispatches into its own authenticated mux in process, with the caller's Access identity already attached — no request leaves the node, so a tool call does not pay for a round trip through Cloudflare and back, and cannot be refused by Access for lacking a cookie it never had.
Returning (status, body) rather than a decoded type is deliberate. The refusal a model needs to read is the SERVER'S OWN WORDS, and every layer that re-describes an error makes the model reason about a paraphrase.
type Observer ¶
Observer is told about each tool call, for the log.
The tool name, who called it and how it went — and NOT the arguments. A brief is a paragraph of somebody's intent and a question is a question; neither belongs in a log that operators and CI read. Same rule that took prompt bodies out of the gateway logs (wg-90f), applied before the mistake rather than after it.
type Options ¶
type Options struct {
// Caller performs the API operations.
Caller Caller
// Version is reported in serverInfo, so a client's logs say which build
// answered. The same reason the interface carries a build stamp.
Version string
// HasShell says whether the person on the other end has a command line.
//
// It changes exactly one thing: what an expired credential tells the model
// to do. Over stdio the answer is `wg login`; over a connector there is no
// login command and the answer is to reconnect in the client. Getting this
// wrong sends the model hunting for a shell that does not exist, which is
// the failure that made this whole bead necessary.
HasShell bool
// Observe is called after each tool call. Optional; nil logs nothing, which
// is what the stdio transport wants — its stdout IS the protocol stream, so
// a log line written there would corrupt the conversation.
Observe Observer
}
Options configures a server.
type Refusal ¶
type Refusal int
Refusal is how a tool call failed, in the same terms as the CLI's exit codes.
The table in skills/workgraph/SKILL.md is the contract an agent has already been taught, so the semantics are identical here and only the carrier changes: an exit code becomes a tool result the model can read.
const ( // RefusalNone means the call succeeded. RefusalNone Refusal = 0 // RefusalOther is a fault rather than a decision: a 5xx, a timeout, a // malformed answer. Worth retrying once. RefusalOther Refusal = 1 // RefusalUnauthenticated is exit 3: no usable credential. RefusalUnauthenticated Refusal = 3 // RefusalForbidden is exit 4: this credential or role may not. RefusalForbidden Refusal = 4 // RefusalPolicy is exit 5: refused by policy or budget. A normal answer // the model can act on, not a transport failure. RefusalPolicy Refusal = 5 // RefusalRateLimited is exit 6. RefusalRateLimited Refusal = 6 // RefusalConflict is exit 7. RefusalConflict Refusal = 7 )
func Classify ¶
Classify maps an HTTP answer to a refusal, matching cmd/wg's codeFor exactly.
403 is two different problems wearing one status, and they have different fixes: a scope or role refusal needs a different credential, and a policy refusal needs a person. Telling them apart is the whole reason the CLI has two exit codes for it.
type Route ¶
type Route struct {
Tool string
Method string
// Path is the fixed part. A tool that puts an argument in the path or the
// query builds the rest in its handler.
Path string
// ReadOnly mirrors the annotation the client sees. Held here too so the
// test that checks "nothing that spends money is marked read-only" reads
// one table rather than reaching into the SDK's structs.
ReadOnly bool
// SpendsMoney means an agent runs and the person is billed. Every such
// tool must be annotated non-read-only so clients prompt.
SpendsMoney bool
}
Route is one tool's HTTP shape, kept as data so a test can assert the mapping without calling anything.