Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
DEPRECATED: Replaced by mcp-app-builder. Previously used to build ChatGPT apps with interactive React widgets via mcp-use.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/server/proxy.md
1# Server Proxying & Composition23The `mcp-use` TypeScript SDK allows you to easily proxy and compose multiple MCP servers into a single unified "Aggregator" server.45This is extremely useful when you have multiple microservices or specialized MCP servers (like a database server, a weather server, and an internal API server) and you want to expose all of their tools, resources, and prompts through a single unified endpoint.67## High-Level API (Config Object)89Pass a configuration object directly to `server.proxy()`. The keys act as the **namespaces** for the child servers to prevent naming collisions.1011```typescript12import { MCPServer } from "mcp-use/server";13import path from "node:path";1415const server = new MCPServer({ name: "UnifiedServer", version: "1.0.0" });1617// The SDK handles all connections, sessions, and synchronization automatically18await server.proxy({19// Proxy a local TypeScript server (using the 'tsx' runner)20database: {21command: "tsx",22args: [path.resolve(__dirname, "./db-server.ts")]23},2425// Proxy a local Python FastMCP server26weather: {27command: "uv",28args: ["run", "weather_server.py"],29env: { ...process.env, FASTMCP_LOG_LEVEL: "ERROR" }30},3132// Proxy a remote server over HTTP33manufact: {34url: "https://manufact.com/docs/mcp"35}36});3738// Start the unified server39await server.listen(3000);40```4142In the example above, the `database` tools will be prefixed with `database_` (e.g. `database_query`), the `weather` tools will be prefixed with `weather_` (e.g. `weather_get_forecast`), and so on. Resource URIs will be prefixed like `database://app://config`.4344## Low-Level API (Explicit Session)4546For advanced use cases (dynamic auth headers, manual session lifecycles, or custom connectors), you can inject an explicit `MCPSession` directly into the `proxy` method using the `mcp-use/client` SDK.4748```typescript49import { MCPServer } from "mcp-use/server";50import { MCPClient } from "mcp-use/client";5152const server = new MCPServer({ name: "UnifiedServer", version: "1.0.0" });5354// Create a custom client orchestration55const customClient = new MCPClient({56mcpServers: {57secure_db: {58url: "https://secure-db.example.com/mcp"59}60}61});6263// Manage the session manually64const dbSession = await customClient.createSession("secure_db");6566// Proxy the active session, manually specifying the namespace67await server.proxy(dbSession, { namespace: "secure_db" });6869await server.listen(3000);70```7172## Advanced Features Supported7374The `mcp-use` proxying system goes far beyond simple tool forwarding:75761. **Schema Translation**: Automatically translates raw JSON Schemas from child servers into runtime Zod schemas.772. **LLM Sampling & Elicitation**: Automatically intercepts out-of-band JSONRPC requests (sampling/elicitation) from child servers, resolves the HTTP context of the original user who triggered the tool, and routes the request securely back to that user's client.783. **Progress Tracking**: If a child tool emits `notifications/progress/report`, the Aggregator catches and pipes those directly through the unified `ToolContext` back to the parent client.794. **State Syncing**: The Aggregator listens to `list_changed` events emitted by the child server and instantly forwards them to all connected clients.80