feat(#132): port MCP (Model Context Protocol) infrastructure
Implement MCP Phase 1 infrastructure for agent tool integration with central hub, tool registry, and STDIO transport layers. Components: - McpHubService: Central registry for MCP server lifecycle - StdioTransport: STDIO process communication with JSON-RPC 2.0 - ToolRegistryService: Tool catalog management - McpController: REST API for MCP management Endpoints: - GET/POST /mcp/servers - List/register servers - POST /mcp/servers/:id/start|stop - Lifecycle control - DELETE /mcp/servers/:id - Unregister - GET /mcp/tools - List tools - POST /mcp/tools/:name/invoke - Invoke tool Features: - Full JSON-RPC 2.0 protocol support - Process lifecycle management - Buffered message parsing - Type-safe with no explicit any types - Proper cleanup on shutdown Tests: 85 passing with 90.9% coverage Fixes #132 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
3
apps/api/src/mcp/interfaces/index.ts
Normal file
3
apps/api/src/mcp/interfaces/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./mcp-server.interface";
|
||||
export * from "./mcp-tool.interface";
|
||||
export * from "./mcp-message.interface";
|
||||
47
apps/api/src/mcp/interfaces/mcp-message.interface.ts
Normal file
47
apps/api/src/mcp/interfaces/mcp-message.interface.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* JSON-RPC 2.0 request message for MCP
|
||||
*/
|
||||
export interface McpRequest {
|
||||
/** JSON-RPC version */
|
||||
jsonrpc: "2.0";
|
||||
|
||||
/** Request identifier */
|
||||
id: string | number;
|
||||
|
||||
/** Method name to invoke */
|
||||
method: string;
|
||||
|
||||
/** Optional method parameters */
|
||||
params?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON-RPC 2.0 error object
|
||||
*/
|
||||
export interface McpError {
|
||||
/** Error code */
|
||||
code: number;
|
||||
|
||||
/** Error message */
|
||||
message: string;
|
||||
|
||||
/** Optional additional error data */
|
||||
data?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON-RPC 2.0 response message for MCP
|
||||
*/
|
||||
export interface McpResponse {
|
||||
/** JSON-RPC version */
|
||||
jsonrpc: "2.0";
|
||||
|
||||
/** Request identifier (matches request) */
|
||||
id: string | number;
|
||||
|
||||
/** Result data (present on success) */
|
||||
result?: unknown;
|
||||
|
||||
/** Error object (present on failure) */
|
||||
error?: McpError;
|
||||
}
|
||||
46
apps/api/src/mcp/interfaces/mcp-server.interface.ts
Normal file
46
apps/api/src/mcp/interfaces/mcp-server.interface.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { ChildProcess } from "node:child_process";
|
||||
|
||||
/**
|
||||
* Configuration for an MCP server instance
|
||||
*/
|
||||
export interface McpServerConfig {
|
||||
/** Unique identifier for the server */
|
||||
id: string;
|
||||
|
||||
/** Human-readable name for the server */
|
||||
name: string;
|
||||
|
||||
/** Description of what the server provides */
|
||||
description: string;
|
||||
|
||||
/** Command to execute to start the server */
|
||||
command: string;
|
||||
|
||||
/** Optional command-line arguments */
|
||||
args?: string[];
|
||||
|
||||
/** Optional environment variables */
|
||||
env?: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status of an MCP server
|
||||
*/
|
||||
export type McpServerStatus = "starting" | "running" | "stopped" | "error";
|
||||
|
||||
/**
|
||||
* Runtime state of an MCP server
|
||||
*/
|
||||
export interface McpServer {
|
||||
/** Server configuration */
|
||||
config: McpServerConfig;
|
||||
|
||||
/** Current status */
|
||||
status: McpServerStatus;
|
||||
|
||||
/** Running process (if started) */
|
||||
process?: ChildProcess;
|
||||
|
||||
/** Error message (if in error state) */
|
||||
error?: string;
|
||||
}
|
||||
16
apps/api/src/mcp/interfaces/mcp-tool.interface.ts
Normal file
16
apps/api/src/mcp/interfaces/mcp-tool.interface.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* MCP tool definition from a server
|
||||
*/
|
||||
export interface McpTool {
|
||||
/** Tool name (unique identifier) */
|
||||
name: string;
|
||||
|
||||
/** Human-readable description */
|
||||
description: string;
|
||||
|
||||
/** JSON Schema for tool input */
|
||||
inputSchema: object;
|
||||
|
||||
/** ID of the server providing this tool */
|
||||
serverId: string;
|
||||
}
|
||||
Reference in New Issue
Block a user