cd839c7f0c
Implement Model Context Protocol (MCP) support so Flynn can spawn MCP server processes, discover their tools, and make them available to the agent alongside builtin tools. - McpClient: wraps @modelcontextprotocol/sdk with StdioClientTransport for process lifecycle, tool discovery (listTools), and invocation (callTool) - McpManager: lifecycle management for multiple MCP servers with startAll/stopAll/restart, tool bridging into ToolRegistry - Bridge: converts MCP tools to Flynn Tool interface with mcp:<server>:<tool> namespacing to avoid collisions with builtin tools - Config: add env and cwd fields to mcp server schema - ToolRegistry: add unregister() method for MCP server cleanup - Daemon: wire McpManager into startup and shutdown lifecycle - Tests: 28 new tests (bridge, manager, registry unregister)
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
/**
|
|
* MCP (Model Context Protocol) type definitions.
|
|
*
|
|
* Internal types for Flynn's MCP client integration.
|
|
* These wrap the SDK types into simpler forms used by the bridge and manager.
|
|
*/
|
|
|
|
/** Configuration for a single MCP server from flynn.yaml. */
|
|
export interface McpServerConfig {
|
|
/** Unique name for this server (used as tool name prefix). */
|
|
name: string;
|
|
/** Executable command to spawn the server process. */
|
|
command: string;
|
|
/** Arguments passed to the command. */
|
|
args: string[];
|
|
/** Optional environment variables for the server process. */
|
|
env?: Record<string, string>;
|
|
/** Optional working directory for the server process. */
|
|
cwd?: string;
|
|
}
|
|
|
|
/** Connection status of an MCP server. */
|
|
export type McpServerStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
|
|
/** Information about a tool discovered from an MCP server. */
|
|
export interface McpToolInfo {
|
|
/** Tool name as reported by the MCP server. */
|
|
name: string;
|
|
/** Human-readable description. */
|
|
description: string;
|
|
/** JSON Schema for the tool's input parameters. */
|
|
inputSchema: {
|
|
type: 'object';
|
|
properties?: Record<string, unknown>;
|
|
required?: string[];
|
|
};
|
|
}
|
|
|
|
/** Runtime state of a connected MCP server. */
|
|
export interface McpServerState {
|
|
/** Config this server was started from. */
|
|
config: McpServerConfig;
|
|
/** Current connection status. */
|
|
status: McpServerStatus;
|
|
/** Tools discovered from this server. */
|
|
tools: McpToolInfo[];
|
|
/** Error message if status is 'error'. */
|
|
error?: string;
|
|
}
|