Let server functions invoke the user's Claude Code MCP tools#23
Open
molefrog wants to merge 1 commit into
Open
Let server functions invoke the user's Claude Code MCP tools#23molefrog wants to merge 1 commit into
molefrog wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.
'mcp-result' replies; the worker exposes the API to .server.ts modules
through a Bun.plugin virtual 'moi' module.
outlive the server.
worker-IPC-broker round-trip through callFunction.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01XP4Nv1MGK2UUDDQiuphMUw