Installation
AG-UI Adapter
TheAguiAdapter converts MCP tools into the AG-UI protocol format.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
🎉 v2.0.0 is out! Please note that the API may contain breaking changes. See the migration guide and changelog for details.
Use the AG-UI adapter and middleware to expose MCP tools to remote agents like Python LangGraph, AutoGen, and CopilotKit over the AG-UI protocol.
npm install @mcp-ts/sdk @ag-ui/client rxjs
AguiAdapter converts MCP tools into the AG-UI protocol format.
import { MultiSessionClient } from '@mcp-ts/sdk/server';
import { AguiAdapter } from '@mcp-ts/sdk/adapters/agui-adapter';
const client = new MultiSessionClient('user_123');
await client.connect();
const adapter = new AguiAdapter(client);
// Get tools with handlers for server-side execution
const tools = await adapter.getTools();
// Get tool definitions (JSON Schema) for remote agents
const toolDefinitions = await adapter.getToolDefinitions();
import { NextRequest } from "next/server";
import { HttpAgent } from "@ag-ui/client";
import { AguiAdapter } from "@mcp-ts/sdk/adapters/agui-adapter";
import { createMcpMiddleware } from "@mcp-ts/sdk/adapters/agui-middleware";
export const POST = async (req: NextRequest) => {
// Create remote agent connection
const mcpAssistant = new HttpAgent({
url: "http://127.0.0.1:8000/agent",
});
// Connect to MCP servers
const { MultiSessionClient } = await import("@mcp-ts/sdk/server");
const client = new MultiSessionClient("user_123");
await client.connect();
// Create adapter and get tools
const adapter = new AguiAdapter(client);
const mcpTools = await adapter.getTools();
// Add middleware to intercept and execute MCP tools
mcpAssistant.use(createMcpMiddleware({
toolPrefix: 'server-', // Tools starting with this prefix are MCP tools
tools: mcpTools,
}));
// Run the agent...
};
| Event | Description |
|---|---|
TOOL_CALL_START | Records tool name and ID, marks MCP tools as pending |
TOOL_CALL_ARGS | Accumulates streamed arguments |
TOOL_CALL_END | Marks tool call as complete |
RUN_FINISHED | Executes pending MCP tools, emits results, triggers new run |
TOOL_CALL_RESULT | Emitted by middleware with MCP tool results |
createMcpMiddleware({
toolPrefix: 'server-', // Prefix to identify MCP tools (default: 'server-')
tools: mcpTools, // Pre-loaded tools with handlers
});
Was this page helpful?
