@claude-flow/cli 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agentic-flow/intelligence.json +16 -0
- package/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude-flow/metrics/performance.json +87 -0
- package/.claude-flow/metrics/task-metrics.json +10 -0
- package/README.md +1186 -0
- package/__tests__/README.md +140 -0
- package/__tests__/TEST_SUMMARY.md +144 -0
- package/__tests__/cli.test.ts +558 -0
- package/__tests__/commands.test.ts +726 -0
- package/__tests__/config-adapter.test.ts +362 -0
- package/__tests__/config-loading.test.ts +106 -0
- package/__tests__/coverage/.tmp/coverage-0.json +1 -0
- package/__tests__/coverage/.tmp/coverage-1.json +1 -0
- package/__tests__/coverage/.tmp/coverage-2.json +1 -0
- package/__tests__/coverage/.tmp/coverage-3.json +1 -0
- package/__tests__/coverage/.tmp/coverage-4.json +1 -0
- package/__tests__/coverage/.tmp/coverage-5.json +1 -0
- package/__tests__/mcp-client.test.ts +480 -0
- package/__tests__/p1-commands.test.ts +1064 -0
- package/bin/cli.js +14 -0
- package/dist/src/commands/agent.d.ts +8 -0
- package/dist/src/commands/agent.d.ts.map +1 -0
- package/dist/src/commands/agent.js +803 -0
- package/dist/src/commands/agent.js.map +1 -0
- package/dist/src/commands/config.d.ts +8 -0
- package/dist/src/commands/config.d.ts.map +1 -0
- package/dist/src/commands/config.js +406 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/hive-mind.d.ts +8 -0
- package/dist/src/commands/hive-mind.d.ts.map +1 -0
- package/dist/src/commands/hive-mind.js +627 -0
- package/dist/src/commands/hive-mind.js.map +1 -0
- package/dist/src/commands/hooks.d.ts +8 -0
- package/dist/src/commands/hooks.d.ts.map +1 -0
- package/dist/src/commands/hooks.js +2098 -0
- package/dist/src/commands/hooks.js.map +1 -0
- package/dist/src/commands/index.d.ts +51 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +105 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/init.d.ts +8 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +532 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/mcp.d.ts +11 -0
- package/dist/src/commands/mcp.d.ts.map +1 -0
- package/dist/src/commands/mcp.js +662 -0
- package/dist/src/commands/mcp.js.map +1 -0
- package/dist/src/commands/memory.d.ts +8 -0
- package/dist/src/commands/memory.d.ts.map +1 -0
- package/dist/src/commands/memory.js +911 -0
- package/dist/src/commands/memory.js.map +1 -0
- package/dist/src/commands/migrate.d.ts +8 -0
- package/dist/src/commands/migrate.d.ts.map +1 -0
- package/dist/src/commands/migrate.js +398 -0
- package/dist/src/commands/migrate.js.map +1 -0
- package/dist/src/commands/process.d.ts +10 -0
- package/dist/src/commands/process.d.ts.map +1 -0
- package/dist/src/commands/process.js +566 -0
- package/dist/src/commands/process.js.map +1 -0
- package/dist/src/commands/session.d.ts +8 -0
- package/dist/src/commands/session.d.ts.map +1 -0
- package/dist/src/commands/session.js +750 -0
- package/dist/src/commands/session.js.map +1 -0
- package/dist/src/commands/start.d.ts +8 -0
- package/dist/src/commands/start.d.ts.map +1 -0
- package/dist/src/commands/start.js +398 -0
- package/dist/src/commands/start.js.map +1 -0
- package/dist/src/commands/status.d.ts +8 -0
- package/dist/src/commands/status.d.ts.map +1 -0
- package/dist/src/commands/status.js +560 -0
- package/dist/src/commands/status.js.map +1 -0
- package/dist/src/commands/swarm.d.ts +8 -0
- package/dist/src/commands/swarm.d.ts.map +1 -0
- package/dist/src/commands/swarm.js +573 -0
- package/dist/src/commands/swarm.js.map +1 -0
- package/dist/src/commands/task.d.ts +8 -0
- package/dist/src/commands/task.d.ts.map +1 -0
- package/dist/src/commands/task.js +671 -0
- package/dist/src/commands/task.js.map +1 -0
- package/dist/src/commands/workflow.d.ts +8 -0
- package/dist/src/commands/workflow.d.ts.map +1 -0
- package/dist/src/commands/workflow.js +617 -0
- package/dist/src/commands/workflow.js.map +1 -0
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +185 -0
- package/dist/src/config-adapter.js.map +1 -0
- package/dist/src/index.d.ts +55 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +312 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +264 -0
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -0
- package/dist/src/init/claudemd-generator.d.ts +15 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +626 -0
- package/dist/src/init/claudemd-generator.js.map +1 -0
- package/dist/src/init/executor.d.ts +11 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +647 -0
- package/dist/src/init/executor.js.map +1 -0
- package/dist/src/init/helpers-generator.d.ts +42 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +613 -0
- package/dist/src/init/helpers-generator.js.map +1 -0
- package/dist/src/init/index.d.ts +12 -0
- package/dist/src/init/index.d.ts.map +1 -0
- package/dist/src/init/index.js +15 -0
- package/dist/src/init/index.js.map +1 -0
- package/dist/src/init/mcp-generator.d.ts +18 -0
- package/dist/src/init/mcp-generator.d.ts.map +1 -0
- package/dist/src/init/mcp-generator.js +71 -0
- package/dist/src/init/mcp-generator.js.map +1 -0
- package/dist/src/init/settings-generator.d.ts +14 -0
- package/dist/src/init/settings-generator.d.ts.map +1 -0
- package/dist/src/init/settings-generator.js +257 -0
- package/dist/src/init/settings-generator.js.map +1 -0
- package/dist/src/init/statusline-generator.d.ts +14 -0
- package/dist/src/init/statusline-generator.d.ts.map +1 -0
- package/dist/src/init/statusline-generator.js +206 -0
- package/dist/src/init/statusline-generator.js.map +1 -0
- package/dist/src/init/types.d.ts +240 -0
- package/dist/src/init/types.d.ts.map +1 -0
- package/dist/src/init/types.js +210 -0
- package/dist/src/init/types.js.map +1 -0
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +189 -0
- package/dist/src/mcp-client.js.map +1 -0
- package/dist/src/mcp-server.d.ts +153 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +448 -0
- package/dist/src/mcp-server.js.map +1 -0
- package/dist/src/mcp-tools/agent-tools.d.ts +8 -0
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/agent-tools.js +90 -0
- package/dist/src/mcp-tools/agent-tools.js.map +1 -0
- package/dist/src/mcp-tools/config-tools.d.ts +8 -0
- package/dist/src/mcp-tools/config-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/config-tools.js +86 -0
- package/dist/src/mcp-tools/config-tools.js.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts +41 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.js +1646 -0
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -0
- package/dist/src/mcp-tools/index.d.ts +12 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -0
- package/dist/src/mcp-tools/index.js +11 -0
- package/dist/src/mcp-tools/index.js.map +1 -0
- package/dist/src/mcp-tools/memory-tools.d.ts +8 -0
- package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/memory-tools.js +87 -0
- package/dist/src/mcp-tools/memory-tools.js.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts +8 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.js +67 -0
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -0
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/types.js +7 -0
- package/dist/src/mcp-tools/types.js.map +1 -0
- package/dist/src/output.d.ts +117 -0
- package/dist/src/output.d.ts.map +1 -0
- package/dist/src/output.js +471 -0
- package/dist/src/output.js.map +1 -0
- package/dist/src/parser.d.ts +41 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +353 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +501 -0
- package/dist/src/prompt.js.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +38 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/CONFIG_LOADING.md +236 -0
- package/docs/IMPLEMENTATION_COMPLETE.md +421 -0
- package/docs/MCP_CLIENT_GUIDE.md +620 -0
- package/docs/REFACTORING_SUMMARY.md +247 -0
- package/package.json +29 -0
- package/src/commands/agent.ts +941 -0
- package/src/commands/config.ts +452 -0
- package/src/commands/hive-mind.ts +762 -0
- package/src/commands/hooks.ts +2603 -0
- package/src/commands/index.ts +115 -0
- package/src/commands/init.ts +597 -0
- package/src/commands/mcp.ts +753 -0
- package/src/commands/memory.ts +1063 -0
- package/src/commands/migrate.ts +447 -0
- package/src/commands/process.ts +617 -0
- package/src/commands/session.ts +891 -0
- package/src/commands/start.ts +457 -0
- package/src/commands/status.ts +705 -0
- package/src/commands/swarm.ts +648 -0
- package/src/commands/task.ts +792 -0
- package/src/commands/workflow.ts +742 -0
- package/src/config-adapter.ts +210 -0
- package/src/index.ts +383 -0
- package/src/infrastructure/in-memory-repositories.ts +310 -0
- package/src/init/claudemd-generator.ts +631 -0
- package/src/init/executor.ts +756 -0
- package/src/init/helpers-generator.ts +628 -0
- package/src/init/index.ts +60 -0
- package/src/init/mcp-generator.ts +83 -0
- package/src/init/settings-generator.ts +274 -0
- package/src/init/statusline-generator.ts +211 -0
- package/src/init/types.ts +447 -0
- package/src/mcp-client.ts +227 -0
- package/src/mcp-server.ts +571 -0
- package/src/mcp-tools/agent-tools.ts +92 -0
- package/src/mcp-tools/config-tools.ts +88 -0
- package/src/mcp-tools/hooks-tools.ts +1819 -0
- package/src/mcp-tools/index.ts +12 -0
- package/src/mcp-tools/memory-tools.ts +89 -0
- package/src/mcp-tools/swarm-tools.ts +69 -0
- package/src/mcp-tools/types.ts +33 -0
- package/src/output.ts +593 -0
- package/src/parser.ts +417 -0
- package/src/prompt.ts +619 -0
- package/src/types.ts +287 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 CLI MCP Client
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper for calling MCP tools from CLI commands.
|
|
5
|
+
* Implements ADR-005: MCP-First API Design - CLI as thin wrapper around MCP tools
|
|
6
|
+
*
|
|
7
|
+
* This provides a simple interface for CLI commands to call MCP tools without
|
|
8
|
+
* containing hardcoded business logic. All business logic lives in MCP tool handlers.
|
|
9
|
+
*/
|
|
10
|
+
// Import MCP tool handlers from local package
|
|
11
|
+
import { agentTools } from './mcp-tools/agent-tools.js';
|
|
12
|
+
import { swarmTools } from './mcp-tools/swarm-tools.js';
|
|
13
|
+
import { memoryTools } from './mcp-tools/memory-tools.js';
|
|
14
|
+
import { configTools } from './mcp-tools/config-tools.js';
|
|
15
|
+
import { hooksTools } from './mcp-tools/hooks-tools.js';
|
|
16
|
+
/**
|
|
17
|
+
* MCP Tool Registry
|
|
18
|
+
* Maps tool names to their handler functions
|
|
19
|
+
*/
|
|
20
|
+
const TOOL_REGISTRY = new Map();
|
|
21
|
+
// Register all tools
|
|
22
|
+
function registerTools(tools) {
|
|
23
|
+
tools.forEach(tool => {
|
|
24
|
+
TOOL_REGISTRY.set(tool.name, tool);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// Initialize registry with all available tools
|
|
28
|
+
registerTools([...agentTools, ...swarmTools, ...memoryTools, ...configTools, ...hooksTools]);
|
|
29
|
+
/**
|
|
30
|
+
* MCP Client Error
|
|
31
|
+
*/
|
|
32
|
+
export class MCPClientError extends Error {
|
|
33
|
+
toolName;
|
|
34
|
+
cause;
|
|
35
|
+
constructor(message, toolName, cause) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.toolName = toolName;
|
|
38
|
+
this.cause = cause;
|
|
39
|
+
this.name = 'MCPClientError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Call an MCP tool by name with input parameters
|
|
44
|
+
*
|
|
45
|
+
* @param toolName - Name of the MCP tool (e.g., 'agent/spawn', 'swarm/init')
|
|
46
|
+
* @param input - Input parameters for the tool
|
|
47
|
+
* @param context - Optional tool context
|
|
48
|
+
* @returns Promise resolving to tool result
|
|
49
|
+
* @throws {MCPClientError} If tool not found or execution fails
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Spawn an agent
|
|
54
|
+
* const result = await callMCPTool('agent/spawn', {
|
|
55
|
+
* agentType: 'coder',
|
|
56
|
+
* priority: 'normal'
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // Initialize swarm
|
|
60
|
+
* const swarm = await callMCPTool('swarm/init', {
|
|
61
|
+
* topology: 'hierarchical-mesh',
|
|
62
|
+
* maxAgents: 15
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export async function callMCPTool(toolName, input = {}, context) {
|
|
67
|
+
// Look up tool in registry
|
|
68
|
+
const tool = TOOL_REGISTRY.get(toolName);
|
|
69
|
+
if (!tool) {
|
|
70
|
+
throw new MCPClientError(`MCP tool not found: ${toolName}`, toolName);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
// Call the tool handler
|
|
74
|
+
const result = await tool.handler(input, context);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// Wrap and re-throw with context
|
|
79
|
+
throw new MCPClientError(`Failed to execute MCP tool '${toolName}': ${error instanceof Error ? error.message : String(error)}`, toolName, error instanceof Error ? error : undefined);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get tool metadata by name
|
|
84
|
+
*
|
|
85
|
+
* @param toolName - Name of the MCP tool
|
|
86
|
+
* @returns Tool metadata or undefined if not found
|
|
87
|
+
*/
|
|
88
|
+
export function getToolMetadata(toolName) {
|
|
89
|
+
const tool = TOOL_REGISTRY.get(toolName);
|
|
90
|
+
if (!tool) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
// Return everything except the handler function
|
|
94
|
+
return {
|
|
95
|
+
name: tool.name,
|
|
96
|
+
description: tool.description,
|
|
97
|
+
inputSchema: tool.inputSchema,
|
|
98
|
+
category: tool.category,
|
|
99
|
+
tags: tool.tags,
|
|
100
|
+
version: tool.version,
|
|
101
|
+
cacheable: tool.cacheable,
|
|
102
|
+
cacheTTL: tool.cacheTTL,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* List all available MCP tools
|
|
107
|
+
*
|
|
108
|
+
* @param category - Optional category filter
|
|
109
|
+
* @returns Array of tool metadata
|
|
110
|
+
*/
|
|
111
|
+
export function listMCPTools(category) {
|
|
112
|
+
const tools = Array.from(TOOL_REGISTRY.values());
|
|
113
|
+
const filtered = category
|
|
114
|
+
? tools.filter(t => t.category === category)
|
|
115
|
+
: tools;
|
|
116
|
+
return filtered.map(tool => ({
|
|
117
|
+
name: tool.name,
|
|
118
|
+
description: tool.description,
|
|
119
|
+
inputSchema: tool.inputSchema,
|
|
120
|
+
category: tool.category,
|
|
121
|
+
tags: tool.tags,
|
|
122
|
+
version: tool.version,
|
|
123
|
+
cacheable: tool.cacheable,
|
|
124
|
+
cacheTTL: tool.cacheTTL,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if an MCP tool exists
|
|
129
|
+
*
|
|
130
|
+
* @param toolName - Name of the MCP tool
|
|
131
|
+
* @returns True if tool exists
|
|
132
|
+
*/
|
|
133
|
+
export function hasTool(toolName) {
|
|
134
|
+
return TOOL_REGISTRY.has(toolName);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get all tool categories
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of unique categories
|
|
140
|
+
*/
|
|
141
|
+
export function getToolCategories() {
|
|
142
|
+
const categories = new Set();
|
|
143
|
+
TOOL_REGISTRY.forEach(tool => {
|
|
144
|
+
if (tool.category) {
|
|
145
|
+
categories.add(tool.category);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return Array.from(categories).sort();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Validate tool input against schema
|
|
152
|
+
*
|
|
153
|
+
* @param toolName - Name of the MCP tool
|
|
154
|
+
* @param input - Input to validate
|
|
155
|
+
* @returns Validation result with errors if any
|
|
156
|
+
*/
|
|
157
|
+
export function validateToolInput(toolName, input) {
|
|
158
|
+
const tool = TOOL_REGISTRY.get(toolName);
|
|
159
|
+
if (!tool) {
|
|
160
|
+
return {
|
|
161
|
+
valid: false,
|
|
162
|
+
errors: [`Tool '${toolName}' not found`],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Basic validation - check required fields
|
|
166
|
+
const schema = tool.inputSchema;
|
|
167
|
+
const errors = [];
|
|
168
|
+
if (schema.required && Array.isArray(schema.required)) {
|
|
169
|
+
for (const requiredField of schema.required) {
|
|
170
|
+
if (!(requiredField in input)) {
|
|
171
|
+
errors.push(`Missing required field: ${requiredField}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
valid: errors.length === 0,
|
|
177
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export default {
|
|
181
|
+
callMCPTool,
|
|
182
|
+
getToolMetadata,
|
|
183
|
+
listMCPTools,
|
|
184
|
+
hasTool,
|
|
185
|
+
getToolCategories,
|
|
186
|
+
validateToolInput,
|
|
187
|
+
MCPClientError,
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=mcp-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client.js","sourceRoot":"","sources":["../../src/mcp-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,8CAA8C;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEjD,qBAAqB;AACrB,SAAS,aAAa,CAAC,KAAgB;IACrC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,+CAA+C;AAC/C,aAAa,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,UAAU,EAAE,GAAG,WAAW,EAAE,GAAG,WAAW,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;AAE7F;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAG9B;IACA;IAHT,YACE,OAAe,EACR,QAAgB,EAChB,KAAa;QAEpB,KAAK,CAAC,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
|
|
2
|
+
* V3 CLI MCP Server Management
|
|
3
|
+
*
|
|
4
|
+
* Provides server lifecycle management for MCP integration:
|
|
5
|
+
* - Start/stop/status methods with process management
|
|
6
|
+
* - Health check endpoint integration
|
|
7
|
+
* - Graceful shutdown handling
|
|
8
|
+
* - PID file management for daemon detection
|
|
9
|
+
* - Event-based status monitoring
|
|
10
|
+
*
|
|
11
|
+
* Performance Targets:
|
|
12
|
+
* - Server startup: <400ms
|
|
13
|
+
* - Health check: <10ms
|
|
14
|
+
* - Graceful shutdown: <5s
|
|
15
|
+
*
|
|
16
|
+
* @module @claude-flow/cli/mcp-server
|
|
17
|
+
* @version 3.0.0
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from 'events';
|
|
20
|
+
/**
|
|
21
|
+
* MCP Server configuration
|
|
22
|
+
*/
|
|
23
|
+
export interface MCPServerOptions {
|
|
24
|
+
transport?: 'stdio' | 'http' | 'websocket';
|
|
25
|
+
host?: string;
|
|
26
|
+
port?: number;
|
|
27
|
+
pidFile?: string;
|
|
28
|
+
logFile?: string;
|
|
29
|
+
tools?: string[] | 'all';
|
|
30
|
+
daemonize?: boolean;
|
|
31
|
+
timeout?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* MCP Server status
|
|
35
|
+
*/
|
|
36
|
+
export interface MCPServerStatus {
|
|
37
|
+
running: boolean;
|
|
38
|
+
pid?: number;
|
|
39
|
+
transport?: string;
|
|
40
|
+
host?: string;
|
|
41
|
+
port?: number;
|
|
42
|
+
uptime?: number;
|
|
43
|
+
tools?: number;
|
|
44
|
+
startedAt?: string;
|
|
45
|
+
health?: {
|
|
46
|
+
healthy: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
metrics?: Record<string, number>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* MCP Server Manager
|
|
53
|
+
*
|
|
54
|
+
* Manages the lifecycle of the MCP server process
|
|
55
|
+
*/
|
|
56
|
+
export declare class MCPServerManager extends EventEmitter {
|
|
57
|
+
private options;
|
|
58
|
+
private process?;
|
|
59
|
+
private server?;
|
|
60
|
+
private startTime?;
|
|
61
|
+
private healthCheckInterval?;
|
|
62
|
+
constructor(options?: MCPServerOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Start the MCP server
|
|
65
|
+
*/
|
|
66
|
+
start(): Promise<MCPServerStatus>;
|
|
67
|
+
/**
|
|
68
|
+
* Stop the MCP server
|
|
69
|
+
*/
|
|
70
|
+
stop(force?: boolean): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get server status
|
|
73
|
+
*/
|
|
74
|
+
getStatus(): Promise<MCPServerStatus>;
|
|
75
|
+
/**
|
|
76
|
+
* Check server health
|
|
77
|
+
*/
|
|
78
|
+
checkHealth(): Promise<{
|
|
79
|
+
healthy: boolean;
|
|
80
|
+
error?: string;
|
|
81
|
+
metrics?: Record<string, number>;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Restart the server
|
|
85
|
+
*/
|
|
86
|
+
restart(): Promise<MCPServerStatus>;
|
|
87
|
+
/**
|
|
88
|
+
* Start stdio server process
|
|
89
|
+
*/
|
|
90
|
+
private startStdioServer;
|
|
91
|
+
/**
|
|
92
|
+
* Start HTTP server in-process
|
|
93
|
+
*/
|
|
94
|
+
private startHttpServer;
|
|
95
|
+
/**
|
|
96
|
+
* Wait for server to be ready
|
|
97
|
+
*/
|
|
98
|
+
private waitForReady;
|
|
99
|
+
/**
|
|
100
|
+
* Wait for process to exit
|
|
101
|
+
*/
|
|
102
|
+
private waitForExit;
|
|
103
|
+
/**
|
|
104
|
+
* Start health monitoring
|
|
105
|
+
*/
|
|
106
|
+
private startHealthMonitoring;
|
|
107
|
+
/**
|
|
108
|
+
* Write PID file
|
|
109
|
+
*/
|
|
110
|
+
private writePidFile;
|
|
111
|
+
/**
|
|
112
|
+
* Read PID file
|
|
113
|
+
*/
|
|
114
|
+
private readPidFile;
|
|
115
|
+
/**
|
|
116
|
+
* Remove PID file
|
|
117
|
+
*/
|
|
118
|
+
private removePidFile;
|
|
119
|
+
/**
|
|
120
|
+
* Check if process is running
|
|
121
|
+
*/
|
|
122
|
+
private isProcessRunning;
|
|
123
|
+
/**
|
|
124
|
+
* Make HTTP request
|
|
125
|
+
*/
|
|
126
|
+
private httpRequest;
|
|
127
|
+
/**
|
|
128
|
+
* Sleep utility
|
|
129
|
+
*/
|
|
130
|
+
private sleep;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create MCP server manager
|
|
134
|
+
*/
|
|
135
|
+
export declare function createMCPServerManager(options?: MCPServerOptions): MCPServerManager;
|
|
136
|
+
/**
|
|
137
|
+
* Get or create server manager singleton
|
|
138
|
+
*/
|
|
139
|
+
export declare function getServerManager(options?: MCPServerOptions): MCPServerManager;
|
|
140
|
+
/**
|
|
141
|
+
* Quick start MCP server
|
|
142
|
+
*/
|
|
143
|
+
export declare function startMCPServer(options?: MCPServerOptions): Promise<MCPServerStatus>;
|
|
144
|
+
/**
|
|
145
|
+
* Quick stop MCP server
|
|
146
|
+
*/
|
|
147
|
+
export declare function stopMCPServer(force?: boolean): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Get MCP server status
|
|
150
|
+
*/
|
|
151
|
+
export declare function getMCPServerStatus(): Promise<MCPServerStatus>;
|
|
152
|
+
export default MCPServerManager;
|
|
153
|
+
//# sourceMappingURL=mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAOtC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,WAAW,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,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