MCP (Model Context Protocol) Module Overview
The
indusagi/mcpsubpath ships a self-contained MCP implementation (no external transport SDK). The newer clean-roomindusagi/interopbridge wraps the official@modelcontextprotocol/sdkinstead — see "The interop bridge" below.
The MCP module gives indusagi Model Context Protocol support: it connects to external MCP servers, lists their tools, and adapts those tools into AgentTool instances. It can also stand up an MCP server that exposes indusagi's own tools to outside clients.
Primary entrypoint: indusagi/mcp.
Source Map
The indusagi/mcp subpath resolves to src/facade/mcp.ts, which re-exports everything from src/facade/mcp-core/:
src/facade/mcp.ts- Facade;export * from "./mcp-core/index"src/facade/mcp-core/index.ts- Public exports +initializeMCPconvenience functionsrc/facade/mcp-core/client.ts-MCPClientfor single-server connections (stdio + HTTP)src/facade/mcp-core/client-pool.ts-MCPClientPoolfor managing multiple serverssrc/facade/mcp-core/server.ts-MCPServer/createMCPServerto publish tools over stdiosrc/facade/mcp-core/tool-factory.ts- Convert MCP tools intoAgentToolssrc/facade/mcp-core/config.ts- Load/save server configuration filessrc/facade/mcp-core/schema-converter.ts- JSON Schema → TypeBox conversionsrc/facade/mcp-core/types.ts- Protocol and configuration type definitionssrc/facade/mcp-core/errors.ts-MCPError,MCPErrorCode, error factories
Conceptual Flow
- Configure MCP servers in a JSON config file (see "Configuration" below)
loadMCPConfig(cwd)reads and merges the config files intoMCPConnectionOptions[]- Construct an
MCPClientPool({ servers })and callpool.connectAll() - List tools per client with
client.listTools() - Adapt MCP tools into
AgentTools withregisterMCPToolsInRegistry(orcreateMCPToolsMap/createMCPToolsRecord) - Execute tools through the generated
AgentToolor directly viaclient.callTool(name, args) - Tear down with
pool.disconnectAll()
initializeMCP(registry, cwd) performs steps 2-5 in one call.
What This Module Does
- Manages stdio (subprocess) and HTTP (Streamable HTTP / SSE-aware) connections to MCP servers
- Sends JSON-RPC 2.0
initialize,tools/list,tools/call,resources/*, andprompts/*requests - Converts MCP tool
inputSchema(JSON Schema) into TypeBox with passthrough so extra fields never fail validation - Namespaces remote tools as
${serverName}_${toolName}to avoid cross-server collisions - Surfaces structured failures through
MCPError+MCPErrorCode - Exposes indusagi's own tools as an MCP server via
MCPServer
Core Exports
- MCPClient - one connection to one MCP server (stdio or HTTP)
- MCPClientPool - lifecycle and status for many servers
- MCPServer / createMCPServer - publish
AgentTools over stdio - registerMCPToolsInRegistry / createMCPToolsMap / createMCPToolsRecord / createMCPAgentToolFactory - tool adaptation
- loadMCPConfig / saveConfig / saveUserConfig / saveProjectConfig - configuration
- jsonSchemaToTypeBox / convertMCPInputSchema / convertMCPOutputSchema / applyPassthrough - schema conversion
- MCPError / MCPErrorCode / isMCPError / isSessionError - error handling
- initializeMCP - one-call setup that connects servers and registers their tools
The interop bridge (`indusagi/interop`)
The clean-room rebuild adds a separate, parallel MCP layer at indusagi/interop (source: src/interop/). It is built on the official @modelcontextprotocol/sdk rather than the hand-rolled JSON-RPC of mcp-core. It exposes:
- A client side:
ServerEndpoint(one connection),ServerFleet(many endpoints with failure isolation), andmountProtocolBridgeto graft remote tools into a kernelToolRegistry. - A provider host side:
createProviderHost(box)stands up an SDKServerthat publishes a runtimeToolBox's tools to external clients.
The two layers are independent. indusagi/mcp integrates with the AgentTool / ToolRegistry facade; indusagi/interop integrates with the kernel's capabilities and runtime contracts. See the API Reference for the full surface and the Developer Guide for usage.
Quick Example
import { initializeMCP } from "indusagi/mcp";
import { ToolRegistry } from "indusagi/agent";
const registry = new ToolRegistry();
const { pool, toolCount } = await initializeMCP(registry, process.cwd());
console.log(`Connected to ${pool.getAllClients().length} servers with ${toolCount} tools`);
For the full export list see the API Reference. For connecting clients and servers see the Developer Guide.
