Log_parser

MCP: technical decisions

Technical decisions

| Decision | Choice | Why | Rejected | |—|—|—|—| | Depth | Production-grade, lean | teammates will use it over the internet | prototype | | SDK | official mcp package (FastMCP), stateless_http=True, json_response=True, streamable_http_path="/", mounted at /mcp; FastAPI lifespan runs mcp.session_manager.run() | standard; stateless works with any worker count | hand-rolled JSON-RPC | | Where | new logpipe/server/mcp.py with build_mcp(app) -> FastMCP, mounted in create_app (logpipe/server/app.py:50) | one deploy, same URL and TLS as the UI | separate service or stdio | | Tool implementation | each tool calls the app’s own /api route through httpx.AsyncClient(transport=ASGITransport(app)) and forwards the caller’s Authorization header | reuses all route glue (validate_sql, template listing, query validation) and works on all three stores for free | calling Server directly, which would duplicate the closures in app.py | | Auth | extend the require_login middleware (app.py:58). /mcp* always needs a valid mcp key. On /api/* a valid mcp Bearer key is accepted, instead of the cookie, only when (method, path) matches MCP_ROUTES, a module-level regex allowlist. The key is stored on request.state.key. | one enforcement point, so even curl with an MCP key cannot apply a batch | per-tool checks | | Keys | Server._store_key / create_key take scope (core.py:342/360). POST /api/keys accepts scope. agent_key (app.py:111) rejects scope mcp. Keys.tsx gets a select and a badge. | reuses the key store, hashing and revocation | new token system | | Note-only on incidents | the PUT /api/incidents/{id} route: if the caller is an mcp key and status differs from the current one, return 403. The tool sends the current status itself. | the allowlist can’t see the request body | separate route | | Attribution | optional by param on set_incident, update_draft, decide_all, merge_drafts (core.py:1284/768/794/805). The routes pass request.state.key["name"] when present, and save_query stores by. The web UI shows “by X” next to incident notes and drafts. | small change, visible to the team | audit log collection | | Output caps | tools default limit=100 and clamp to 500. List-style results are cut to the cap and carry truncated: true plus a hint (“narrow filters or use log_histogram/log_facets”). | protects the AI’s context | cursors | | Tests | tests/test_mcp.py against the memory store with TestClient(create_app(server)), following the fixture pattern in tests/test_server.py:54 | matches repo | — |

Tool → route map (all on the MCP_ROUTES allowlist)

Prompts

Implementation order

Commit after each step once its tests pass. Branch: worktree-feat-mcp. No Claude attribution lines. Open the PR against Niang931.

  1. Write docs/plan/persona.md, features.md and tech-decisions.md from this file.
  2. uv add mcp. Add the key scope in core, the intake check and the keys route, with tests.
  3. Middleware allowlist, request.state.key and the incident status guard, with tests: an mcp key can GET logs, gets 403 on apply, and gets 403 on a status change.
  4. mcp.py: tools, caps, prompts, the mount and the lifespan, with a test that lists tools and calls search_logs plus one write through the MCP endpoint.
  5. Attribution by in core and routes, plus the web display.
  6. Keys.tsx scope select and badge.
  7. README section.

Verification

Risks