Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

10.0 KB
Raw Blame
{
  "section_id": "mcp_server",
  "title": "MCP Server",
  "markdown": "Open Executive can run **as an MCP server**, the inverse of the MCP *gateway* (which lets the Executive consume external MCP servers). The server exposes Open Executive's company-grounded context and its specialist council to external MCP clients — Claude Desktop, Cursor, Claude Code, or any other agent — so they can ground themselves in *this* company and pull domain analysis **inside their own loop**, without re-explaining anything.\n\nThis is deliberately *not* another chat channel: Open Executive already has six of those (web, Slack, Discord, Telegram, email, Google Chat). The value here is structured, attachable context plus on-demand specialist analysis.\n\n## Transport & mount\n\nThe server speaks **Streamable-HTTP** and is mounted into the existing FastAPI app at `/mcp` (built with the `FastMCP` SDK, `streamable_http_path=\"/\"` mounted under `/mcp` so the endpoint is exactly `/mcp`). Mounting a sub-app does not run its lifespan, so the API lifespan runs `mcp.session_manager.run()` for the life of the process — without it every `/mcp` request would fail. The module lives at `openexecutive/mcp_server/` and is wired in `api/main.py`.\n\n## Auth\n\nThe `/mcp` endpoint is **not** exempt from the shared-secret middleware, so it is gated exactly like every other route: clients send `x-api-key: $BACKEND_SHARED_SECRET`. There is no second auth system. FastMCP's DNS-rebinding (Host-header) check is disabled because the endpoint authenticates with a header secret rather than a cookie — a browser rebinding attack cannot supply the key — and traffic arrives through the deployment's TLS terminator.\n\n## Who is asking\n\nEvery handler answers as the caller the API already verified. The mounted app shares the outer request's state, so what `caller_gate` decided reaches the handler through FastMCP's request context, and `api.caller.person_id_for` resolves the person by the same rule as the web chat:\n\n| Caller | Asks as |\n|---|---|\n| Open mode, no `x-caller-email` (direct use, local) | the principal |\n| Open mode with `x-caller-email`, or a signed-in person (`x-caller-assertion`) | that person; no one when they are not on the roster |\n| Operator (signed local login) | the principal |\n| Service (signed callers on, only the shared secret) | no one, never the principal |\n\nA deployment that fronts `/mcp` with its own sign-in and stamps the signed caller, as the UI proxy does, therefore gets per-person answers with the web app's rules.\n\n## Resources (read-only context)\n\nCurated company state, pure reads, no LLM calls.\n\n| Resource URI | Contents | Who may read it |\n|---|---|---|\n| `oe://company/profile` | Structured company profile, as a prompt block | anyone |\n| `oe://departments/state` | Departments with goals and cadences | anyone |\n| `oe://today/briefing` | Morning-brief snapshot: department health, roster, proposals | someone on the roster, built as `GET /today` builds it for them (the principal's private rows for the principal alone, an artifact's card for its owner) |\n| `oe://people/roster` | The team on the roster (never contacts) | someone on the roster |\n| `oe://today/activity` | Recent self-initiated Executive activity | the principal alone |\n| `oe://memory/decisions` · `…/initiatives` · `…/advice` | Episodic memory | the principal alone |\n\nA refused read is a JSON-RPC error: \"Only the owner can read this.\" or \"Only someone on the team can read this.\"\n\n## Tools (capabilities)\n\nEach tool carries an MCP title and annotations; descriptions say what a tool does without steering a client between tools.\n\n| Tool | What it does | Annotations |\n|---|---|---|\n| `consult_specialist(specialist, query, context)` | Domain analysis from one of ten specialists (cso, cfo, chro, gc, coo, cmo, cpo, sales, board_comms, triage), each grounded in company knowledge. Stateless. | read-only, closed world |\n| `search_knowledge(query)` | Raw retrieval over the curated knowledge base + indexed company docs | read-only, closed world |\n| `list_workflows()` | Catalog of multi-step executive workflows and their input schemas | read-only, closed world |\n| `ask_executive(message)` | One synthesized Executive answer, as the verified caller | not read-only (the conversation is recorded in memory), not destructive, not idempotent, closed world |\n\n`ask_executive` takes no caller argument. Its session is marked `from_mcp_client`, so by default the turn reads and advises but never acts: the chat loop neither offers nor runs `schedule_tools.MCP_CLIENT_WITHHELD_TOOLS` (everything that sends, posts, books, schedules, runs or changes stored state: the private-turn and unattended sets plus direct messages, alert acks, roster writes and the rest), offers no Act as me, `recall_history` or extension tools, and reaches only gateway reads (`MCP_CLIENT_MCP_TOOLS`, no send or draft). A call the model emits anyway is refused with an error that tells it to send the person to Open Executive itself. A caller that resolves to no one reads and publishes no one's documents.\n\n**May act (opt-in, per request).** `mcp_server.may_act` sets `Session.mcp_client_may_act`. With `BACKEND_SHARED_SECRET` configured it is on only when the request carries `x-mcp-client-actions: on` and the API's shared-secret gate let that request through (the gate marks `request.state.shared_secret_ok` after its `x-api-key` check). With no secret the header is ignored and the `MCP_CLIENT_ACTIONS` setting (default off) decides. On such a turn:\n\n- The speaker's own changes inside Open Executive run directly, each under its own owner-only and person checks: alerts (ack, create, leave out of the brief), open loops (close, assign), follow-ups (schedule, cancel, move), the watch list, goals and department goals, decision outcomes, remembered facts and the company profile. Roster writes stay withheld: a person added on one call would be someone a card reaches on the next, so a new contact goes on an `add_contact` card, which always waits. The turn counts as a verified surface for the caller the API verified (`people_tools._is_verified_speaker_surface`), and `ask_executive` renders the live board so `ack_alert` has its trusted set. No History note or conversation review is taken from it.\n- What reaches another person is never run directly. A message or a meeting goes on an approval card (`propose_actions`, offered alone of Act as me's tools, for a caller with Act as me on). The card follows the person's mode: with Suggested actions not in training, it is carried out at once when their Handle it for me is on (every setting covers people they know), everyone on it is on the roster as team or contact and has been for at least 7 days (`action_cards.SETTLED_AFTER`), there is no new contact on it, an invite is never booked as approved (the meeting gate decides), and the plain-code checks of `action_cards.on_its_own_refusal` find nothing (nothing sensitive, no link or amount, a short message, the daily cap, signed callers), and the turn read no outside text or mail. Otherwise it waits for their tap on the web. Broadcasts, department messages, cancelling and instant meetings stay withheld.\n- Still never offered, a fixed set with a stable tool prefix of its own: `schedule_tools.MCP_CLIENT_ACTING_WITHHELD_TOOLS` (the read-only set minus the changes above: DMs and calendar writes, `load_mcp_server`, `run_script`, `run_python_job`, the workflow tools, `run_executive_research` and the rest). No extension, `recall_history` or mailbox tools, and of the gateway only the reads. A call the model emits anyway is refused with an error telling it to have the person do it in Open Executive.\n- Every audit row the turn writes carries `via`: the client's `clientInfo.name`, or \"an AI app\" (`audit.via_app`), and an approval card keeps it too.\n\n## What's intentionally deferred\n\n**Workflow *execution*** is not exposed over MCP yet. Workflows are long-running async generators (minutes), which would exceed a single tool call's request/response window. The catalog is listed via `list_workflows()`; if execution is added later it will use a job-handle pattern (`start_workflow` → `run_id`, then poll) over the existing run persistence. MCP *prompts* are also skipped — OE workflows are server-executed orchestrations, not message templates.\n\n## Why prompt caching is unaffected\n\nThis path is parallel to chat. Resources are pure reads; `consult_specialist` delegates to the same `BaseAgent.analyze` that the chat path uses, reusing the existing cached system blocks. `ask_executive`'s turn withholds a fixed tool set before the sort (one for a read-only turn, one for a turn that may act), so each has a stable cached tool prefix of its own, like a private or unattended turn.",
  "mermaid": "flowchart TD\n    Client[\"External MCP client<br/>(Claude Desktop / Cursor / agent)\"]:::entry\n    Gate[\"Shared-secret middleware<br/>x-api-key\"]:::entry\n    Caller[\"caller_gate<br/>request.state.caller\"]:::entry\n    Mount[\"/mcp Streamable-HTTP<br/>(FastMCP, mounted in FastAPI)\"]:::compute\n    Who[\"Who is asking<br/>api.caller.person_id_for\"]:::compute\n    Res[\"Resources<br/>owner-only · roster-only · anyone\"]:::compute\n    Tools[\"Tools<br/>consult_specialist · search_knowledge<br/>list_workflows · ask_executive\"]:::compute\n    Exec[\"Executive.chat<br/>from_mcp_client: reads only,<br/>unless mcp_client_may_act\"]:::compute\n    Cards[\"Approval cards<br/>propose_actions · Handle it for me\"]:::compute\n    Spec[\"Specialist council<br/>route_to_specialist → BaseAgent.analyze\"]:::compute\n    Store[(\"ChromaDB + SQLite<br/>company state\")]:::storage\n\n    Client -->|x-api-key| Gate --> Caller --> Mount\n    Mount --> Who\n    Who --> Res\n    Who --> Tools\n    Res --> Store\n    Tools --> Spec\n    Tools --> Exec\n    Exec --> Spec\n    Exec -->|may act: messages, meetings| Cards\n    Tools --> Store\n    Spec --> Store\n\n    classDef entry fill:#1e3a8a,stroke:#60a5fa,color:#fff;\n    classDef compute fill:#312e81,stroke:#a5b4fc,color:#fff;\n    classDef storage fill:#365314,stroke:#a3e635,color:#fff;",
  "generated_at": "2026-10-18T12:45:41Z"
}