Skip to content

feat(mcp): MCP endpoint (/api/mcp) reusing chat tools + Bearer-key auth - #16

Closed
jcfrei wants to merge 1 commit into
masterfrom
feat/mcp-endpoint
Closed

feat(mcp): MCP endpoint (/api/mcp) reusing chat tools + Bearer-key auth#16
jcfrei wants to merge 1 commit into
masterfrom
feat/mcp-endpoint

Conversation

@jcfrei

@jcfrei jcfrei commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What

A POST /api/mcp endpoint exposing the ERP's fine-grained tool surface to LLM agents (Claude, Codex) over MCP's Streamable HTTP transport (JSON-RPC 2.0: initialize / tools/list / tools/call / notifications).

How it reuses everything

  • Schemas: build_tools() — the live, plugin-widened tool list.
  • Execution: the same TOOL_HANDLERS (so every write runs validate()).
  • Auth: get_current_user — a Bearer API key acts as its user at the key's role, exactly like REST, gated by the same rest_api_enabled flag. No separate MCP credential.

Role scoping (mirrors REST)

viewer = reads; manager = writes; admin = delete_master. Enforced on both tools/list (filtered) and tools/call (defence in depth). Chat-session-only tools are excluded.

Modularity

The tool list is built from the live registries, so a plugin that registers doctypes/masters (e.g. the internal CRM's lead/contact/activity) is exposed automatically — no MCP-specific code in the plugin. The endpoint lives in core; its surface composes from core + whatever plugins are loaded.

Settings UX

Right after a key is created, the API-keys page shows the MCP URL (<origin>/api/mcp) and ready-to-paste Claude and Codex config, noting the key's role governs access.

Tests

tests/test_mcp.py — initialize, role-scoped tools/list, read + write tools/call, viewer write-denial, notifications, no-key rejection, unknown tool/method errors. SQLite + Postgres in CI.

🤖 Generated with Claude Code

Exposes the ERP's fine-grained tool surface to LLM agents over MCP Streamable
HTTP (JSON-RPC). Reuses build_tools() schemas + TOOL_HANDLERS (validated) and
get_current_user (Bearer key acts as its user at the key's role), gated by
rest_api_enabled. Role-scoped: viewer=read, manager=write, admin=delete;
chat-session tools excluded. Registry-driven, so plugin doctypes/masters are
exposed automatically. Settings shows the MCP URL + Claude/Codex config after
key creation. tests/test_mcp.py (SQLite + Postgres in CI).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jcfrei added a commit that referenced this pull request Jul 31, 2026
feat(mcp): MCP endpoint (/api/mcp) reusing chat tools + Bearer-key auth (#16)

Fine-grained ERP tool surface for LLM agents over MCP Streamable HTTP. Reuses
build_tools() + TOOL_HANDLERS (validated) and Bearer-key auth (key acts as its
user at its role), gated by rest_api_enabled. Registry-driven → plugin doctypes
exposed automatically. Settings shows MCP URL + Claude/Codex config.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jcfrei

jcfrei commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Released as v0.6.12.

@jcfrei jcfrei closed this Jul 31, 2026
@jcfrei
jcfrei deleted the feat/mcp-endpoint branch July 31, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant