YongGoose opened a new pull request, #1050:
URL: https://github.com/apache/burr/pull/1050
Implements #1036.
This adds an MCP endpoint at `/mcp` on the Burr UI server, as sketched in
the issue. Coding assistants and scripts can inspect tracked runs through the
same `BackendBase` the REST API uses. I'm opening it as a draft because the
open questions in the issue haven't been settled yet.
## Changes
- `burr/tracking/server/mcp_endpoint.py` (new) holds the tools and
`mount_mcp()`.
- inspect group (default, read-only): `list_projects`, `list_apps`,
`get_app`, `get_step`, `diff_state`, `key_history`, `export_test_case`.
- annotate group (opt-in): `annotate_step`, `list_annotations`. On a
backend without annotations (S3), the server logs a warning and skips them.
- Results are small by default. Step lists and key histories return the
last 50 entries, and values over 2,000 characters come back as a preview plus
their size. `start`/`limit` reach the rest, and `max_chars=None` returns full
values.
- The transport is stateless with JSON responses. `GET /mcp` returns a 405
with a hint instead of an SSE stream that never ends. The SDK's session manager
can only run once, so the transport is recreated if the app's lifespan runs
again.
- `run.py`: `create_burr_ui_app()` calls `_mount_mcp()` before the React
catch-all route. Three settings control it, and a bad value fails at startup:
- `BURR_MCP_ENABLED=auto|true|false`. `auto` serves `/mcp` when `mcp>=2`
is installed, and logs a warning if an older `mcp` is.
- `BURR_MCP_GROUPS` picks the tool groups.
- `BURR_MCP_MAX_CHARS` is a server-side ceiling on value size that callers
can't raise, even with `max_chars=None`. It is unset by default. This was
suggested in review on #1036.
- `_transform_state_to_test_case` moves from `burr.cli.__main__` to
`burr.testing`. That lets the server produce the `burr-test-case` fixture
format without the CLI's dependencies. The CLI now imports it from there.
- `pyproject.toml` gets a new `mcp` extra (`tracking-server` plus
`mcp>=2,<3`). The CI test job installs it so the new tests run.
- Docs: a new "MCP endpoint" section in `docs/concepts/tracking.rst`.
## How I tested this
- `tests/tracking/test_mcp_endpoint.py` (new, 24 tests):
- Every tool, called through the SDK's in-process client on runs tracked
by a small Burr app, including a failed step.
- Paging, previews and full values, the server-side ceiling, tool groups,
and annotations.
- Over HTTP with `TestClient`: `tools/list`, `GET` returns 405, a
non-localhost `Host` gets 421, and the lifespan can run twice.
- Settings validation, and `auto` with `mcp` 1.x and with no `mcp`
installed (the version is faked).
- The full `tests/` suite in Linux containers with `mcp` 2.3.0, excluding
the persister integration and Bedrock tests: Python 3.12 had 787 passed and 1
skipped; Python 3.10 had 785 passed and 3 skipped.
- A real server started with `burr` (local backend,
`BURR_SERVE_STATIC=false`), called over HTTP with the MCP Python SDK client:
- Called each tool on tracked runs. On a 1,500-step app, the default
`get_app` returned 3,317 B, against 92,107 B for all steps.
- Saved an `export_test_case` result, loaded it with `burr.testing`, and
ran it against the action.
- Checked that an annotation written through MCP shows up in
`/api/v0/{project}/annotations`.
- `BURR_MCP_MAX_CHARS=300` capped values, `BURR_MCP_ENABLED=false` gave a
404, and an unknown group failed at startup.
- black, isort, flake8 (pre-commit versions) and the ASF header check on the
changed files.
## Notes
- Two changes outside this PR are related:
- ID validation in `LocalBackend`, from the review on #1036. This PR
doesn't check IDs itself, so until that lands, a `..` in an ID reaches the
local backend the same way it does through `/api/v0` today.
- #1041 is needed for the UI mounted with `mount_burr_ui()`. Without it,
the parent app never runs the UI's lifespan, so `/mcp` returns 500 there, the
same way `/ready` stays 503.
- The module is `mcp_endpoint.py`, not `mcp.py` as in the issue. Running
`python burr/tracking/server/run.py` puts that directory first on `sys.path`,
where a `mcp.py` would shadow the `mcp` package.
- `/mcp` only accepts localhost `Host` headers, which is the SDK's default.
A remote setup (for example `--host 0.0.0.0` behind a hostname) gets a 421
until allowed hosts are configurable. That's open question 3 in the issue, and
`/mcp` should ideally share that setting with a Host check for `/api/v0`.
- I've only tested the local backend and the MCP Python SDK client. I
haven't tried the S3 backend, Claude Code or Cursor yet.
## Checklist
- [x] PR has an informative and human-readable title (this will be pulled
into the release notes)
- [x] Changes are limited to a single goal (no scope creep)
- [x] Code passed the pre-commit check & code is left cleaner/nicer than
when first encountered.
- [x] Any _change_ in functionality is tested
- [x] New functions are documented (with a description, list of inputs, and
expected output)
- [x] Placeholder code is flagged / future TODOs are captured in comments
- [x] Project documentation has been updated if adding/changing
functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]