Skip to content

feat: add generic kernel-owned MCP runtime - #1495

Open
sethkarten wants to merge 19 commits into
mainfrom
feat/generic-mcp-runtime
Open

feat: add generic kernel-owned MCP runtime#1495
sethkarten wants to merge 19 commits into
mainfrom
feat/generic-mcp-runtime

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the pre-imported mcp.list_tools(server) and mcp.call_tool(server, tool, arguments) API for user-configured MCP servers
  • keep one initialized kernel-owned generation per server, with discovery-before-ready, serialized replacement, bounded startup/call/close, cancellation, and tool filters at listing and dispatch
  • support anonymous/bearer/static-header/existing-OAuth Streamable HTTP and argv-only stdio with tagged environment references and scrubbed ambient environment
  • ignore project-local MCP declarations for execution while preserving authored Linear and Notion wrappers

Tests

  • cd prime-agent-runtime && uv run --with pytest python -m pytest -q test (74 passed; includes real keyless stdio and Streamable HTTP fixtures)
  • cd packages/coding-agent && npx tsx ../../node_modules/vitest/dist/cli.js --run test/mcp-manager.test.ts test/settings-manager.test.ts test/ipython-bootstrap.test.ts test/kernel-bootstrap.test.ts (77 passed)
  • cd packages/coding-agent && unset RLM_DEPTH RLM_MAX_DEPTH && npx tsx ../../node_modules/vitest/dist/cli.js --run test/agent-session-recursion.test.ts (96 passed)
  • cd packages/coding-agent && npx tsx ../../node_modules/vitest/dist/cli.js --run test/kernel-startup.test.ts test/kernel-abort.test.ts (6 passed)
  • npm run check
  • git diff --check

Note

High Risk
Touches kernel bootstrap, subprocess stdio MCP, credential handling, and global settings persistence; outdated kernels without the new runtime will fail readiness checks.

Overview
Adds a kernel-owned generic MCP client (rlm.mcp) with list_tools, call_tool, reload, and close, supporting Streamable HTTP and stdio transports, per-server connection reuse, startup/call timeouts, tool allow/deny filters, and redacted stdio startup diagnostics.

CLI and TUI can persist user MCP servers via mcp add|list|get|remove (and /mcp equivalents). Entries live only in global ~/.prime/agent/settings.json; project MCP configs are no longer used for execution. Stdio secrets are env-var references only; list/get output shows name and transport, not commands or tokens.

The system prompt advertises enabled generic servers and await mcp.list_tools / await mcp.call_tool when IPython is active. Kernel bootstrap now requires callable mcp.list_tools and mcp.call_tool. Catalog names (e.g. Linear/Notion) cannot be overridden for the generic API; authored wrappers keep their login flow.

Settings writes use atomic temp-file rename with mode 0600.

Reviewed by Cursor Bugbot for commit ce6c27b. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add kernel-owned generic MCP runtime with HTTP and stdio transport support

  • Adds rlm/mcp.py, a new kernel-owned MCP client registry supporting HTTP (with OAuth/bearer auth) and stdio transports, with tool discovery, invocation, lifecycle management (reload/close), and automatic Jupyter kernel shutdown integration.
  • Adds prime-agent mcp add/list/get/remove CLI subcommands backed by mcp-command.ts and routed through public-command.ts; /mcp in the TUI gains the same subcommands.
  • Exposes mcp.list_tools and mcp.call_tool as pre-imported Python APIs in the kernel bootstrap; the system prompt advertises enabled generic MCP servers with usage examples when IPython is active.
  • Introduces SettingsManager.getGlobalMcpServers/setGlobalMcpServer/removeGlobalMcpServer for managing MCP server configs scoped to global (user-level) settings only, replacing the previous merged-settings approach.
  • Settings writes are now atomic (write-then-rename, mode 0600) in settings-manager.ts.
  • Diagnostic output from stdio server stderr is captured, bounded, and redacted of secrets before surfacing in McpStartupError.
  • Risk: McpServerConfig shape changed (env values are now {"env": "NAME"} tag objects for stdio; getMcpServers() replaced by getGlobalMcpServers()), which may break existing integrations relying on the prior merged config behavior.

Macroscope summarized ce6c27b.

Comment thread packages/coding-agent/src/core/mcp/mcp-manager.ts Outdated
Comment thread prime-agent-runtime/src/rlm/mcp.py Outdated
Comment thread packages/coding-agent/src/core/mcp/mcp-manager.ts Outdated
Comment thread prime-agent-runtime/src/rlm/mcp.py
Comment thread prime-agent-runtime/src/rlm/mcp.py Outdated
Comment thread packages/coding-agent/src/core/mcp/mcp-manager.ts
Comment thread prime-agent-runtime/src/rlm/mcp.py
Comment thread prime-agent-runtime/src/rlm/mcp.py
Comment thread prime-agent-runtime/src/rlm/mcp.py Outdated
Comment thread prime-agent-runtime/src/rlm/mcp.py Outdated
Comment thread packages/coding-agent/src/core/mcp/mcp-command.ts Outdated
Comment thread packages/coding-agent/src/core/mcp/mcp-manager.ts
Comment thread packages/coding-agent/src/core/mcp/mcp-command.ts Outdated
Comment thread prime-agent-runtime/src/rlm/mcp.py
Comment thread packages/coding-agent/src/core/mcp/mcp-manager.ts Outdated
Comment thread packages/coding-agent/src/core/settings-manager.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2929f6d. Configure here.

Comment thread prime-agent-runtime/src/rlm/mcp.py
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