feat(introspect): routes, tokens and --json, over one query layer an MCP server can reuse #18

Merged
chrnx merged 2 commits from feat/introspect-json into develop 2026-10-31 01:35:22 +00:00
Owner

Part F of the plan to make it easier for LLMs to generate correct green-tea apps. An agent that inspects an app should read its graph instead of guessing it.

  • New commands:
    • matcha routes lists every route with its transport and chain.
    • matcha tokens lists every token, who provides it and who needs it, handlers included.
  • --json on explain, routes and tokens: prints exactly one JSON document on stdout. A refused query (an unknown pattern) prints {"error":{code,message,registered}} on stderr and exits 1.
  • One query layer: src/introspect.rs holds a Query enum whose variants map one-to-one to future MCP tools. Each query returns a single JSON envelope, and cmd_graph.rs only renders it. A future matcha mcp would be a thin layer on top, with no second implementation.
  • Existing output unchanged: graph, explain (text) and openapi print exactly what they printed before.
  • New dependency: serde_json 1.0.154 (dtolnay, published 2026-10-11).

Verified:

  • cargo test passes, with new unit tests for the envelope, the structured refusal, and the text layout of explain and tokens.
  • clippy and fmt are clean.
  • starter-smoke.sh node passes.
  • On a real starter: routes, tokens, explain and --json, including the error case.
Part F of the plan to make it easier for LLMs to generate correct green-tea apps. An agent that inspects an app should read its graph instead of guessing it. - **New commands:** - `matcha routes` lists every route with its transport and chain. - `matcha tokens` lists every token, who provides it and who needs it, handlers included. - **`--json` on `explain`, `routes` and `tokens`:** prints exactly one JSON document on stdout. A refused query (an unknown pattern) prints `{"error":{code,message,registered}}` on stderr and exits 1. - **One query layer:** `src/introspect.rs` holds a `Query` enum whose variants map one-to-one to future MCP tools. Each query returns a single JSON envelope, and `cmd_graph.rs` only renders it. A future `matcha mcp` would be a thin layer on top, with no second implementation. - **Existing output unchanged:** `graph`, `explain` (text) and `openapi` print exactly what they printed before. - **New dependency:** `serde_json` 1.0.154 (dtolnay, published 2026-10-11). **Verified:** - `cargo test` passes, with new unit tests for the envelope, the structured refusal, and the text layout of `explain` and `tokens`. - `clippy` and `fmt` are clean. - `starter-smoke.sh node` passes. - On a real starter: `routes`, `tokens`, `explain` and `--json`, including the error case.
chrnx added 1 commit 2026-10-30 15:51:33 +00:00
feat(introspect): routes, tokens and --json, over one query layer an MCP server can reuse
CI / installer (macos-14) (pull_request) Successful in 4s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Successful in 30s
CI / starter (deno) (pull_request) Successful in 32s
CI / starter (edge) (pull_request) Successful in 36s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 14s
CI / starter (node) (pull_request) Successful in 32s
a4827f2e13
Agents that inspect a green-tea app should read its graph instead of
guessing it.

- Add `matcha routes`: every route with its transport and chain.
- Add `matcha tokens`: every token, who provides it and who needs it,
  handlers included.
- explain, routes and tokens take --json. It prints one JSON document
  on stdout; a refused query prints a structured error on stderr and
  exits 1.

All introspection now goes through src/introspect.rs. Each Query
variant runs one script that prints a single JSON envelope, and the
CLI renders the data as text unless --json is given. Text output is
unchanged. A future `matcha mcp` serves the same queries as tools
without a second implementation, which is why the formatting moved
from the generated script into Rust.

Adds serde_json (dtolnay, 1.0.154).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx added 1 commit 2026-10-30 15:54:31 +00:00
fix(tokens): name the request as the source of its built-in tokens
CI / installer (macos-14) (pull_request) Successful in 3s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Successful in 30s
CI / starter (deno) (pull_request) Successful in 31s
CI / starter (edge) (pull_request) Successful in 36s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 13s
CI / starter (node) (pull_request) Successful in 33s
9acb0b34c9
matcha tokens listed req as '— (nothing provides it)'. An agent reading
that would write a provider for req. A needed token with no producing
node must come from the request (req, params, body, …): app.ready() has
already validated the graph, so a truly missing token would have failed
it. Mark those source: "request" in the JSON and 'the request (built
in)' in the text.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit ea510c5112 into develop 2026-10-31 01:35:22 +00:00
Sign in to join this conversation.