import { Middleware, Tool, RunAgentInput, AbstractAgent, BaseEvent } from '@ag-ui/client'; import { Observable } from 'rxjs'; /** * Activity type for MCP Apps events */ declare const MCPAppsActivityType = "mcp-apps"; /** * Proxied MCP request structure from the frontend iframe */ interface ProxiedMCPRequest { /** Server hash (MD5 hash of config) */ serverHash: string; /** Server name (optional, for lookup by name) */ serverId?: string; /** The JSON-RPC method to call */ method: string; /** The JSON-RPC params */ params?: Record; } /** * Extract EventWithState type from Middleware.runNextWithState return type */ type ExtractObservableType = T extends Observable ? U : never; type RunNextWithStateReturn = ReturnType; type EventWithState = ExtractObservableType; /** * MCP Client configuration for HTTP transport */ interface MCPClientConfigHTTP { type: "http"; url: string; serverId?: string; } /** * MCP Client configuration for SSE transport */ interface MCPClientConfigSSE { type: "sse"; url: string; headers?: Record; serverId?: string; } /** * MCP Client configuration */ type MCPClientConfig = MCPClientConfigHTTP | MCPClientConfigSSE; /** * Generate a stable server hash from config using MD5 hash. * This allows the frontend to reference servers without knowing their URLs. */ declare function getServerHash(config: MCPClientConfig): string; /** * Configuration for MCPAppsMiddleware */ interface MCPAppsMiddlewareConfig { /** * List of MCP server configurations */ mcpServers?: MCPClientConfig[]; } /** * Extended tool type that includes MCP Apps metadata */ interface MCPAppTool extends Tool { /** UI resource URI from SEP-1865 */ uiResourceUri?: string; } /** * MCP Apps middleware - fetches UI-enabled tools from MCP servers. */ declare class MCPAppsMiddleware extends Middleware { private config; /** Map of serverHash -> server config for proxied requests */ private serverConfigMapByHash; /** Map of serverId -> server config for proxied requests */ private serverConfigMapById; constructor(config?: MCPAppsMiddlewareConfig); run(input: RunAgentInput, next: AbstractAgent): Observable; /** * Handle a proxied MCP request from the frontend iframe. * This bypasses the normal agent flow and directly executes the MCP request. */ private handleProxiedMCPRequest; /** * Execute a generic MCP request (tools/call, resources/read, etc.) */ private executeMCPRequest; /** * Process the event stream, holding back RunFinished events until either: * a) Another event comes -> flush the held RunFinished immediately * b) Stream ends -> do special processing, then flush RunFinished and complete */ private processStream; /** * Execute a tool call on the MCP server and return the raw result */ private executeToolCall; /** * Extract text content from MCP result, fallback to JSON stringified content */ private extractTextContent; /** * Find tool calls that don't have a corresponding result (role: "tool") message */ private findPendingToolCalls; /** * Connect to all configured MCP servers and fetch tools with UI resources */ private fetchUITools; /** * Connect to a single MCP server and fetch its UI-enabled tools */ private fetchToolsFromServer; } export { type EventWithState, type MCPAppTool, MCPAppsActivityType, MCPAppsMiddleware, type MCPAppsMiddlewareConfig, type MCPClientConfig, type MCPClientConfigHTTP, type MCPClientConfigSSE, type ProxiedMCPRequest, getServerHash };