Skip to content

Let server functions invoke the user's Claude Code MCP tools#23

Open
molefrog wants to merge 1 commit into
mainfrom
claude/mcp-server-function-invoke-pls6ll
Open

Let server functions invoke the user's Claude Code MCP tools#23
molefrog wants to merge 1 commit into
mainfrom
claude/mcp-server-function-invoke-pls6ll

Conversation

@molefrog

@molefrog molefrog commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Server functions (widget/view .server.ts) can now call MCP tools directly
via import { mcp } from 'moi' — mcp.callTool / listTools / listServers —
with no model turn involved.

  • server/mcp-broker.ts: parent-process connection broker. Discovery reuses
    the existing getMcpStatus probe (the CLI has already merged config scopes
    and expanded env vars); the broker dials its own connection with
    @modelcontextprotocol/sdk and pools clients per (workspace, server) with
    an idle TTL. stdio and header-authenticated http/sse servers are
    callable; needs-auth (OAuth) servers, claude.ai connectors, and sdk
    servers are rejected with explanatory errors.
  • functions.ts / functions-worker.ts: worker→parent 'mcp' IPC requests and
    'mcp-result' replies; the worker exposes the API to .server.ts modules
    through a Bun.plugin virtual 'moi' module.
  • moi-scaffold.ts: applet-env.d.ts now declares the server-only mcp API.
  • web.ts: close pooled MCP clients on shutdown so stdio children never
    outlive the server.
  • Tests: fixture stdio MCP server + broker unit tests + a full
    worker-IPC-broker round-trip through callFunction.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01XP4Nv1MGK2UUDDQiuphMUw

Server functions (widget/view .server.ts) can now call MCP tools directly
via `import { mcp } from 'moi'` — mcp.callTool / listTools / listServers —
with no model turn involved.

- server/mcp-broker.ts: parent-process connection broker. Discovery reuses
  the existing getMcpStatus probe (the CLI has already merged config scopes
  and expanded env vars); the broker dials its own connection with
  @modelcontextprotocol/sdk and pools clients per (workspace, server) with
  an idle TTL. stdio and header-authenticated http/sse servers are
  callable; needs-auth (OAuth) servers, claude.ai connectors, and sdk
  servers are rejected with explanatory errors.
- functions.ts / functions-worker.ts: worker→parent 'mcp' IPC requests and
  'mcp-result' replies; the worker exposes the API to .server.ts modules
  through a Bun.plugin virtual 'moi' module.
- moi-scaffold.ts: applet-env.d.ts now declares the server-only mcp API.
- web.ts: close pooled MCP clients on shutdown so stdio children never
  outlive the server.
- Tests: fixture stdio MCP server + broker unit tests + a full
  worker-IPC-broker round-trip through callFunction.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XP4Nv1MGK2UUDDQiuphMUw
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.

2 participants