🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
checkpoint: File edit:
rUv2deb04253dd1
diff --git a/v3/@claude-flow/cli/src/commands/agent.ts b/v3/@claude-flow/cli/src/commands/agent.tsindex 147309286a..3323dce232 100644--- a/v3/@claude-flow/cli/src/commands/agent.ts+++ b/v3/@claude-flow/cli/src/commands/agent.ts@@ -6,6 +6,7 @@import type { Command, CommandContext, CommandResult } from '../types.js';import { output } from '../output.js';import { select, confirm, input } from '../prompt.js';+import { callMCPTool, MCPClientError } from '../mcp-client.js';// Available agent types with descriptionsconst AGENT_TYPES = [diff --git a/v3/@claude-flow/cli/src/mcp-client.ts b/v3/@claude-flow/cli/src/mcp-client.tsnew file mode 100644index 0000000000..b152bef1d0--- /dev/null+++ b/v3/@claude-flow/cli/src/mcp-client.ts@@ -0,0 +1,226 @@+/**+ * V3 CLI MCP Client+ *+ * Thin wrapper for calling MCP tools from CLI commands.+ * Implements ADR-005: MCP-First API Design - CLI as thin wrapper around MCP tools+ *+ * This provides a simple interface for CLI commands to call MCP tools without+ * containing hardcoded business logic. All business logic lives in MCP tool handlers.+ */++import type { MCPTool } from '../../../mcp/types.js';++// Import MCP tool handlers+import { agentTools } from '../../../mcp/tools/agent-tools.js';+import { swarmTools } from '../../../mcp/tools/swarm-tools.js';+import { memoryTools } from '../../../mcp/tools/memory-tools.js';+import { configTools } from '../../../mcp/tools/config-tools.js';++/**+ * MCP Tool Registry+ * Maps tool names to their handler functions+ */+const TOOL_REGISTRY = new Map<string, MCPTool>();++// Register all tools+function registerTools(tools: MCPTool[]): void {+ tools.forEach(tool => {+ TOOL_REGISTRY.set(tool.name, tool);+ });+}++// Initialize registry with all available tools+registerTools([...agentTools, ...swarmTools, ...memoryTools, ...configTools]);++/**+ * MCP Client Error+ */+export class MCPClientError extends Error {+ constructor(+ message: string,+ public toolName: string,+ public cause?: Error+ ) {+ super(message);+ this.name = 'MCPClientError';+ }+}++/**+ * Call an MCP tool by name with input parameters+ *+ * @param toolName - Name of the MCP tool (e.g., 'agent/spawn', 'swarm/init')+ * @param input - Input parameters for the tool+ * @param context - Optional tool context+ * @returns Promise resolving to tool result+ * @throws {MCPClientError} If tool not found or execution fails+ *+ * @example+ * ```typescript+ * // Spawn an agent+ * const result = await callMCPTool('agent/spawn', {+ * agentType: 'coder',+ * priority: 'normal'+ * });+ *+ * // Initialize swarm+ * const swarm = await callMCPTool('swarm/init', {+ * topology: 'hierarchical-mesh',+ * maxAgents: 15+ * });+ * ```+ */+export async function callMCPTool<T = unknown>(+ toolName: string,+ input: Record<string, unknown> = {},+ context?: Record<string, unknown>+): Promise<T> {+ // Look up tool in registry+ const tool = TOOL_REGISTRY.get(toolName);++ if (!tool) {+ throw new MCPClientError(+ `MCP tool not found: ${toolName}`,+ toolName+ );+ }++ try {+ // Call the tool handler+ const result = await tool.handler(input, context);+ return result as T;+ } catch (error) {+ // Wrap and re-throw with context+ throw new MCPClientError(+ `Failed to execute MCP tool '${toolName}': ${error instanceof Error ? error.message : String(error)}`,+ toolName,+ error instanceof Error ? error : undefined+ );+ }+}++/**+ * Get tool metadata by name+ *+ * @param toolName - Name of the MCP tool+ * @returns Tool metadata or undefined if not found+ */+export function getToolMetadata(toolName: string): Omit<MCPTool, 'handler'> | undefined {+ const tool = TOOL_REGISTRY.get(toolName);++ if (!tool) {+ return undefined;+ }++ // Return everything except the handler function+ return {+ name: tool.name,+ description: tool.description,+ inputSchema: tool.inputSchema,+ category: tool.category,+ tags: tool.tags,+ version: tool.version,+ cacheable: tool.cacheable,+ cacheTTL: tool.cacheTTL,+ };+}++/**+ * List all available MCP tools+ *+ * @param category - Optional category filter+ * @returns Array of tool metadata+ */+export function listMCPTools(category?: string): Array<Omit<MCPTool, 'handler'>> {+ const tools = Array.from(TOOL_REGISTRY.values());++ const filtered = category+ ? tools.filter(t => t.category === category)+ : tools;++ return filtered.map(tool => ({+ name: tool.name,+ description: tool.description,+ inputSchema: tool.inputSchema,+ category: tool.category,+ tags: tool.tags,+ version: tool.version,+ cacheable: tool.cacheable,+ cacheTTL: tool.cacheTTL,+ }));+}++/**+ * Check if an MCP tool exists+ *+ * @param toolName - Name of the MCP tool+ * @returns True if tool exists+ */+export function hasTool(toolName: string): boolean {+ return TOOL_REGISTRY.has(toolName);+}++/**+ * Get all tool categories+ *+ * @returns Array of unique categories+ */+export function getToolCategories(): string[] {+ const categories = new Set<string>();++ TOOL_REGISTRY.forEach(tool => {+ if (tool.category) {+ categories.add(tool.category);+ }+ });++ return Array.from(categories).sort();+}++/**+ * Validate tool input against schema+ *+ * @param toolName - Name of the MCP tool+ * @param input - Input to validate+ * @returns Validation result with errors if any+ */+export function validateToolInput(+ toolName: string,+ input: Record<string, unknown>+): { valid: boolean; errors?: string[] } {+ const tool = TOOL_REGISTRY.get(toolName);++ if (!tool) {+ return {+ valid: false,+ errors: [`Tool '${toolName}' not found`],+ };+ }++ // Basic validation - check required fields+ const schema = tool.inputSchema;+ const errors: string[] = [];++ if (schema.required && Array.isArray(schema.required)) {+ for (const requiredField of schema.required) {+ if (!(requiredField in input)) {+ errors.push(`Missing required field: ${requiredField}`);+ }+ }+ }++ return {+ valid: errors.length === 0,+ errors: errors.length > 0 ? errors : undefined,+ };+}++export default {+ callMCPTool,+ getToolMetadata,+ listMCPTools,+ hasTool,+ getToolCategories,+ validateToolInput,+ MCPClientError,+};