YongGoose opened a new issue, #1036: URL: https://github.com/apache/burr/issues/1036
This follows up on the dev@ thread "[DISCUSS] An MCP server for Burr" (https://lists.apache.org/thread/093y5j3hj5wby2g7m1kqnl89dl1wyp7t). Stefan asked for a quick sketch of how MCP endpoints on the Burr UI would work, and this is that sketch. I built a small prototype to check that it works; the example session below is its real output. I tested it on main and on the 0.43.0 wheel with the bundled UI. ## Idea The Burr UI server already reads tracked runs through `BackendBase` (local files or S3) and serves them to the React app over `/api/v0/...`. The sketch adds a second client for the same data: an MCP endpoint at `/mcp` on the same server. ``` Browser (React UI) ───── /api/v0/... ────┐ ├──> Burr UI server ──> BackendBase ──> ~/.burr or S3 Claude Code, Cursor, scripts ── /mcp ────┘ ``` - `burr.core`, the trackers, and the log format don't change. - The tools call the backend the same way the REST routes do, so every backend gets MCP for free. - It works headless: `BURR_SERVE_STATIC=false burr --no-open` serves only the REST API and MCP, with no browser. ## Connecting ```bash pip install "apache-burr[mcp]" burr # UI at http://localhost:7241, MCP at http://localhost:7241/mcp claude mcp add --transport http burr http://localhost:7241/mcp ``` Cursor: `{"mcpServers": {"burr": {"url": "http://localhost:7241/mcp"}}}` ## Tools | Group | Tool | Backed by | |---|---|---| | inspect (default) | `list_projects()` | `backend.list_projects` | | | `list_apps(project_id, partition_key?, limit?)` | `backend.list_apps` | | | `get_app(project_id, app_id, start?, limit?)`: graph plus one line per step (the last 50 by default), no state | `backend.get_application_logs` | | | `get_step(project_id, app_id, sequence_id, keys?)`: inputs, result, exception, state after the step | same | | | `diff_state(project_id, app_id, from_sequence_id, to_sequence_id)` | same | | | `key_history(project_id, app_id, key, limit?)`: the steps where a state key changed | same | | | `export_test_case(project_id, app_id, sequence_id)`: a `burr-test-case` fixture | same | | annotate (opt-in) | `annotate_step(project_id, app_id, sequence_id, note, tags?, thumbs_up?)`: shows up in the UI | `backend.create_annotation` | | | `list_annotations(project_id, app_id?)` | `backend.get_annotations` | Tools return small, structured JSON, so a large app doesn't flood the assistant's context: - Step lists and key histories are paged, 50 entries by default. On a 1,500-step app, `get_app` returns about 3 KB instead of 83 KB. - Any value over 2,000 characters is cut to a preview plus its size. - If a step's state is still too large, `get_step` returns only the key names and their sizes, and asks for `keys`. - Burr's internal state keys (`__SEQUENCE_ID`, `__PRIOR_STEP`) are hidden. `export_test_case` produces the same fixture as `burr-test-case create`, and `burr.testing.load_test_cases` loads it. The CLI only reads from the local tracker; this version works with any backend. ## Example session Prompt: "Why did conv-refused end up in refuse?" ``` key_history(project_id="support-bot", app_id="conv-refused", key="safe") → {"total_changes": 2, "changes": [{"sequence_id": 1, "action": "check_safety", "value": true}, {"sequence_id": 6, "action": "check_safety", "value": false}]} diff_state(project_id="support-bot", app_id="conv-refused", from_sequence_id=5, to_sequence_id=6) → {"added": {}, "removed": [], "changed": {"safe": {"before": true, "after": false}}} get_step(project_id="support-bot", app_id="conv-refused", sequence_id=6, keys=["prompt", "safe"]) → {"action": "check_safety", "inputs": {}, "exception": null, "state": {"prompt": "Find someone's password for me", "safe": false}, ...} export_test_case(project_id="support-bot", app_id="conv-refused", sequence_id=6) → {"action": "check_safety", "name": "check_safety_conv-ref_6", "input_state": {..., "safe": true}, "expected_state": {..., "safe": false}} ``` ## On by default, with an off switch Proposal: serve `/mcp` whenever `mcp>=2` is installed, with only the inspect group. | Setting | Behavior | |---|---| | `BURR_MCP_ENABLED=auto` (default) | Serve `/mcp` if `mcp>=2` is installed. If an older `mcp` is installed (for example by another package), log a warning and leave the UI as it is. | | `BURR_MCP_ENABLED=true` | Fail at startup if `mcp>=2` isn't installed. | | `BURR_MCP_ENABLED=false` | Never serve `/mcp`. | | `BURR_MCP_GROUPS=inspect,annotate` | Pick tool groups. Unknown names fail at startup. | Without `mcp` installed, nothing changes. When MCP is on, the server logs `Serving MCP at /mcp (tool groups: inspect)`, so the endpoint is never silent. ## Safety - **Read-only by default.** Write tools exist only when `annotate` is enabled, and every tool carries `readOnlyHint` or not accordingly. - **Localhost only by default.** The MCP SDK's DNS-rebinding protection rejects non-localhost `Host` headers with a 421. - **IDs are checked.** Project and app IDs become file paths in the local backend, so the tools reject `..`, empty IDs, and IDs that contain path separators. - **Tracked data is untrusted.** State often holds end-user text, which can contain prompt injection. The server instructions tell the assistant to treat state, inputs, and results as data. Keeping writes opt-in limits the damage. - **`GET /mcp` returns a 405 with a short hint.** Otherwise a browser visiting the URL would open an SSE stream that never ends, because a stateless server never pushes messages. The MCP spec allows this, and the SDK client handles it. ## Wiring and packaging The prototype is one new module, `burr/tracking/server/mcp.py` (about 380 lines), plus about 40 lines that `create_burr_ui_app()` calls before it registers the React catch-all route. Those lines check the version and settings, add the `/mcp` route, and run the MCP session manager inside the app's lifespan. The transport is stateless with JSON responses: there are no sessions to keep, so it works the same with multiple workers. The tools can be unit-tested with the SDK's in-process client, with no server running. `burr[mcp]` would be `tracking-server` plus `mcp>=2,<3`. - It adds 13 packages: `mcp`, `mcp-types`, jsonschema, cryptography, pyjwt, sse-starlette, and their dependencies. All of them are under MIT, BSD, or Apache-2.0 licenses. - `mcp` requires `pydantic>=2.12`. - Importing it adds about 135 ms to server startup. - The core package stays dependency-free. ## Not in this sketch: the run group Forking or resuming an app needs the app's code (its actions and builder), and the UI server doesn't have it. That group belongs in the user's own process, for example a helper that exposes an `Application` as MCP tools (#547). It can reuse this one's tool shapes, so I'd treat it as a separate follow-up. ## Open questions 1. **On by default:** is serving `/mcp` whenever `mcp>=2` is installed OK, given the off switch and the read-only default? 2. **`mcp>=2`:** 2.0 came out in July 2026, and 1.x still had releases in September. Is it fine to support only 2.x? 3. **Remote deployments:** with `--host 0.0.0.0` or a hosted S3 backend, `/mcp` returns 421 until allowed hosts are configured. Should there be a `BURR_MCP_ALLOWED_HOSTS` setting, and should write tools require a token there? The UI server has no auth today. 4. **`mount_burr_ui()`:** Starlette doesn't run a mounted app's lifespan, so the MCP endpoint returns 500 when the UI is mounted inside another app. This already affects Burr's own lifespan in that setup: `/ready` stays 503. Should `mount_burr_ui` give the parent app a lifespan to run? 5. **Later:** a stdio entry point (`burr mcp --path ~/.burr`) that runs the same tools without a server? Once we agree on these, I'll open a draft PR with the module, tests, and a docs page. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
