@claude-flow/cli 3.38.9 → 3.38.12
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/.claude/helpers/.helpers-version +1 -1
- package/.claude/helpers/helpers.manifest.json +2 -2
- package/catalog-manifest.json +2 -2
- package/dist/src/commands/doctor.js +53 -8
- package/dist/src/commands/hooks.js +3 -2
- package/dist/src/commands/mcp.js +4 -3
- package/dist/src/init/executor.d.ts +6 -0
- package/dist/src/init/executor.js +5 -3
- package/dist/src/init/helper-refresh.d.ts +16 -9
- package/dist/src/init/helper-refresh.js +177 -20
- package/dist/src/init/settings-generator.js +6 -2
- package/dist/src/log-filters.d.ts +3 -3
- package/dist/src/mcp-server.d.ts +1 -0
- package/dist/src/mcp-server.js +39 -3
- package/dist/src/mcp-tools/neural-tools.js +4 -3
- package/dist/src/memory/memory-bridge.d.ts +8 -0
- package/dist/src/memory/memory-bridge.js +18 -0
- package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
- package/node_modules/@claude-flow/mcp/README.md +429 -0
- package/node_modules/@claude-flow/mcp/dist/connection-pool.d.ts +36 -0
- package/node_modules/@claude-flow/mcp/dist/connection-pool.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/connection-pool.js +273 -0
- package/node_modules/@claude-flow/mcp/dist/connection-pool.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/index.d.ts +75 -0
- package/node_modules/@claude-flow/mcp/dist/index.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/index.js +85 -0
- package/node_modules/@claude-flow/mcp/dist/index.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/oauth.d.ts +146 -0
- package/node_modules/@claude-flow/mcp/dist/oauth.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/oauth.js +318 -0
- package/node_modules/@claude-flow/mcp/dist/oauth.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/prompt-registry.d.ts +90 -0
- package/node_modules/@claude-flow/mcp/dist/prompt-registry.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/prompt-registry.js +209 -0
- package/node_modules/@claude-flow/mcp/dist/prompt-registry.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/rate-limiter.d.ts +86 -0
- package/node_modules/@claude-flow/mcp/dist/rate-limiter.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/rate-limiter.js +197 -0
- package/node_modules/@claude-flow/mcp/dist/rate-limiter.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/resource-registry.d.ts +144 -0
- package/node_modules/@claude-flow/mcp/dist/resource-registry.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/resource-registry.js +405 -0
- package/node_modules/@claude-flow/mcp/dist/resource-registry.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/sampling.d.ts +102 -0
- package/node_modules/@claude-flow/mcp/dist/sampling.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/sampling.js +268 -0
- package/node_modules/@claude-flow/mcp/dist/sampling.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/schema-validator.d.ts +30 -0
- package/node_modules/@claude-flow/mcp/dist/schema-validator.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/schema-validator.js +182 -0
- package/node_modules/@claude-flow/mcp/dist/schema-validator.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/server.d.ts +125 -0
- package/node_modules/@claude-flow/mcp/dist/server.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/server.js +849 -0
- package/node_modules/@claude-flow/mcp/dist/server.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/session-manager.d.ts +55 -0
- package/node_modules/@claude-flow/mcp/dist/session-manager.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/session-manager.js +252 -0
- package/node_modules/@claude-flow/mcp/dist/session-manager.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/task-manager.d.ts +81 -0
- package/node_modules/@claude-flow/mcp/dist/task-manager.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/task-manager.js +337 -0
- package/node_modules/@claude-flow/mcp/dist/task-manager.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/tool-registry.d.ts +96 -0
- package/node_modules/@claude-flow/mcp/dist/tool-registry.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/tool-registry.js +399 -0
- package/node_modules/@claude-flow/mcp/dist/tool-registry.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/http.d.ts +60 -0
- package/node_modules/@claude-flow/mcp/dist/transport/http.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/http.js +503 -0
- package/node_modules/@claude-flow/mcp/dist/transport/http.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/index.d.ts +50 -0
- package/node_modules/@claude-flow/mcp/dist/transport/index.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/index.js +181 -0
- package/node_modules/@claude-flow/mcp/dist/transport/index.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/stdio.d.ts +43 -0
- package/node_modules/@claude-flow/mcp/dist/transport/stdio.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/stdio.js +194 -0
- package/node_modules/@claude-flow/mcp/dist/transport/stdio.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.d.ts +65 -0
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.js +314 -0
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.js.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/types.d.ts +482 -0
- package/node_modules/@claude-flow/mcp/dist/types.d.ts.map +1 -0
- package/node_modules/@claude-flow/mcp/dist/types.js +40 -0
- package/node_modules/@claude-flow/mcp/dist/types.js.map +1 -0
- package/node_modules/@claude-flow/mcp/package.json +50 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
- package/node_modules/@claude-flow/security/dist/path-validator.d.ts +23 -0
- package/node_modules/@claude-flow/security/dist/path-validator.d.ts.map +1 -1
- package/node_modules/@claude-flow/security/dist/path-validator.js +128 -27
- package/node_modules/@claude-flow/security/dist/path-validator.js.map +1 -1
- package/package.json +9 -2
- package/.claude/.proven-config-version +0 -1
- package/.claude/proven-config.json +0 -42
|
@@ -199,11 +199,12 @@ function ensureEmbeddings() {
|
|
|
199
199
|
})();
|
|
200
200
|
return embeddingsPromise;
|
|
201
201
|
}
|
|
202
|
-
// Storage paths
|
|
202
|
+
// Storage paths. Note: `.claude-flow/neural/patterns.json` is a SEPARATE
|
|
203
|
+
// file owned by the ReasoningBank store in memory/intelligence.ts — this
|
|
204
|
+
// module only ever reads/writes MODELS_FILE, never a patterns.json.
|
|
203
205
|
const STORAGE_DIR = '.claude-flow';
|
|
204
206
|
const NEURAL_DIR = 'neural';
|
|
205
207
|
const MODELS_FILE = 'models.json';
|
|
206
|
-
const PATTERNS_FILE = 'patterns.json';
|
|
207
208
|
function getNeuralDir() {
|
|
208
209
|
return join(getProjectCwd(), STORAGE_DIR, NEURAL_DIR);
|
|
209
210
|
}
|
|
@@ -262,7 +263,7 @@ export function getNeuralStoreStats() {
|
|
|
262
263
|
patternCount: patterns.length,
|
|
263
264
|
byType,
|
|
264
265
|
modelCount: Object.values(store.models ?? {}).length,
|
|
265
|
-
source: '.claude-flow/neural/
|
|
266
|
+
source: '.claude-flow/neural/models.json (loadNeuralStore)',
|
|
266
267
|
};
|
|
267
268
|
}
|
|
268
269
|
/**
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @module v3/cli/memory-bridge
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* #3024: AgentDB's optional native controller stack can abort the whole Node
|
|
21
|
+
* process on Windows during registry initialization (a Rust allocation panic),
|
|
22
|
+
* which cannot be caught by JavaScript. Keep the CLI/MCP server on the
|
|
23
|
+
* sql.js + local-embedding path there until the native dependency is proven
|
|
24
|
+
* safe. Advanced users and CI can opt back in explicitly for diagnosis.
|
|
25
|
+
*/
|
|
26
|
+
export declare function shouldDisableNativeBridge(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): boolean;
|
|
19
27
|
/**
|
|
20
28
|
* Should this init-time log line be swallowed?
|
|
21
29
|
*
|
|
@@ -38,6 +38,18 @@ const ACTIVE_MEMORY_ROW_SQL = `(status = 'active' OR status IS NULL)`;
|
|
|
38
38
|
* better-sqlite3 bridge") the caller has no way to check.
|
|
39
39
|
*/
|
|
40
40
|
let bridgeFailureReason = null;
|
|
41
|
+
/**
|
|
42
|
+
* #3024: AgentDB's optional native controller stack can abort the whole Node
|
|
43
|
+
* process on Windows during registry initialization (a Rust allocation panic),
|
|
44
|
+
* which cannot be caught by JavaScript. Keep the CLI/MCP server on the
|
|
45
|
+
* sql.js + local-embedding path there until the native dependency is proven
|
|
46
|
+
* safe. Advanced users and CI can opt back in explicitly for diagnosis.
|
|
47
|
+
*/
|
|
48
|
+
export function shouldDisableNativeBridge(platform = process.platform, env = process.env) {
|
|
49
|
+
if (env.CLAUDE_FLOW_DISABLE_BRIDGE === '1')
|
|
50
|
+
return true;
|
|
51
|
+
return platform === 'win32' && env.CLAUDE_FLOW_ENABLE_NATIVE_BRIDGE_ON_WINDOWS !== '1';
|
|
52
|
+
}
|
|
41
53
|
/**
|
|
42
54
|
* ADR-323: reuse memory-initializer's provenance-type allowlist rather than
|
|
43
55
|
* duplicating it (drift risk). Lazy CJS require for the same circular-ESM-
|
|
@@ -154,6 +166,12 @@ export function shouldSuppressInitLog(msg) {
|
|
|
154
166
|
* Returns null if @claude-flow/memory is not available.
|
|
155
167
|
*/
|
|
156
168
|
async function getRegistry(dbPath) {
|
|
169
|
+
if (shouldDisableNativeBridge()) {
|
|
170
|
+
bridgeFailureReason = process.platform === 'win32'
|
|
171
|
+
? 'AgentDB native bridge disabled on Windows after #3024; set CLAUDE_FLOW_ENABLE_NATIVE_BRIDGE_ON_WINDOWS=1 to opt in'
|
|
172
|
+
: 'AgentDB native bridge disabled by CLAUDE_FLOW_DISABLE_BRIDGE=1';
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
157
175
|
if (bridgeAvailable === false)
|
|
158
176
|
return null;
|
|
159
177
|
if (registryInstance)
|
|
File without changes
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# @claude-flow/mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@claude-flow/mcp)
|
|
4
|
+
[](https://www.npmjs.com/package/@claude-flow/mcp)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://modelcontextprotocol.io)
|
|
8
|
+
[](https://github.com/ruvnet/claude-flow)
|
|
9
|
+
|
|
10
|
+
> **MCP 2025-11-25 Compliant** - Standalone Model Context Protocol server implementation with full Resources, Prompts, and Tasks support
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **MCP 2025-11-25 Compliant** - Full specification support
|
|
15
|
+
- **High-Performance Server** - <400ms startup time
|
|
16
|
+
- **Multiple Transports** - stdio, HTTP, WebSocket, in-process
|
|
17
|
+
- **Resources** - list, read, subscribe with caching
|
|
18
|
+
- **Prompts** - templates with arguments and embedded resources
|
|
19
|
+
- **Tasks** - Async operations with progress and cancellation
|
|
20
|
+
- **Pagination** - Cursor-based pagination for large datasets
|
|
21
|
+
- **Connection Pooling** - Max 10 connections, configurable
|
|
22
|
+
- **Fast Tool Registry** - O(1) lookup, <10ms registration
|
|
23
|
+
- **Session Management** - Timeout handling, authentication
|
|
24
|
+
- **Security** - CORS, Helmet, auth tokens
|
|
25
|
+
- **Zero Dependencies** - No @claude-flow/* dependencies
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @claude-flow/mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { quickStart, defineTool } from '@claude-flow/mcp';
|
|
37
|
+
|
|
38
|
+
// Create and start server
|
|
39
|
+
const server = await quickStart({
|
|
40
|
+
transport: 'stdio',
|
|
41
|
+
name: 'My MCP Server',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Register custom tools
|
|
45
|
+
server.registerTool(defineTool(
|
|
46
|
+
'greet',
|
|
47
|
+
'Greet a user',
|
|
48
|
+
{
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
name: { type: 'string', description: 'User name' }
|
|
52
|
+
},
|
|
53
|
+
required: ['name']
|
|
54
|
+
},
|
|
55
|
+
async ({ name }) => ({ message: `Hello, ${name}!` })
|
|
56
|
+
));
|
|
57
|
+
|
|
58
|
+
// Start listening
|
|
59
|
+
await server.start();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Transports
|
|
63
|
+
|
|
64
|
+
### Stdio (Default)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { createMCPServer } from '@claude-flow/mcp';
|
|
68
|
+
|
|
69
|
+
const server = createMCPServer({
|
|
70
|
+
transport: 'stdio',
|
|
71
|
+
name: 'Stdio Server',
|
|
72
|
+
}, logger);
|
|
73
|
+
|
|
74
|
+
await server.start();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### HTTP
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const server = createMCPServer({
|
|
81
|
+
transport: 'http',
|
|
82
|
+
host: 'localhost',
|
|
83
|
+
port: 3000,
|
|
84
|
+
corsEnabled: true,
|
|
85
|
+
corsOrigins: ['http://localhost:8080'],
|
|
86
|
+
auth: {
|
|
87
|
+
enabled: true,
|
|
88
|
+
method: 'token',
|
|
89
|
+
tokens: ['secret-token'],
|
|
90
|
+
},
|
|
91
|
+
}, logger);
|
|
92
|
+
|
|
93
|
+
await server.start();
|
|
94
|
+
// Server at http://localhost:3000
|
|
95
|
+
// WebSocket at ws://localhost:3000/ws
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### WebSocket
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const server = createMCPServer({
|
|
102
|
+
transport: 'websocket',
|
|
103
|
+
host: 'localhost',
|
|
104
|
+
port: 3001,
|
|
105
|
+
maxConnections: 100,
|
|
106
|
+
heartbeatInterval: 30000,
|
|
107
|
+
}, logger);
|
|
108
|
+
|
|
109
|
+
await server.start();
|
|
110
|
+
// WebSocket at ws://localhost:3001/ws
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Tool Registry
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { createToolRegistry, defineTool } from '@claude-flow/mcp';
|
|
117
|
+
|
|
118
|
+
const registry = createToolRegistry(logger);
|
|
119
|
+
|
|
120
|
+
// Register tool
|
|
121
|
+
registry.register({
|
|
122
|
+
name: 'calculate',
|
|
123
|
+
description: 'Perform calculations',
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: {
|
|
127
|
+
expression: { type: 'string' }
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
handler: async ({ expression }) => {
|
|
131
|
+
return { result: eval(expression) };
|
|
132
|
+
},
|
|
133
|
+
category: 'math',
|
|
134
|
+
tags: ['calculator'],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Execute tool
|
|
138
|
+
const result = await registry.execute('calculate', { expression: '2 + 2' });
|
|
139
|
+
|
|
140
|
+
// Search tools
|
|
141
|
+
const mathTools = registry.getByCategory('math');
|
|
142
|
+
const stats = registry.getStats();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Session Management
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { createSessionManager } from '@claude-flow/mcp';
|
|
149
|
+
|
|
150
|
+
const sessions = createSessionManager(logger, {
|
|
151
|
+
maxSessions: 100,
|
|
152
|
+
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Create session
|
|
156
|
+
const session = sessions.createSession('http');
|
|
157
|
+
|
|
158
|
+
// Initialize with client info
|
|
159
|
+
sessions.initializeSession(session.id, {
|
|
160
|
+
protocolVersion: '2024-11-05', // MCP spec: YYYY-MM-DD string
|
|
161
|
+
capabilities: { tools: { listChanged: true } },
|
|
162
|
+
clientInfo: { name: 'Claude', version: '1.0' },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Get metrics
|
|
166
|
+
const metrics = sessions.getSessionMetrics();
|
|
167
|
+
// { total: 1, active: 1, authenticated: 0, expired: 0 }
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Connection Pool
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { createConnectionPool } from '@claude-flow/mcp';
|
|
174
|
+
|
|
175
|
+
const pool = createConnectionPool({
|
|
176
|
+
maxConnections: 10,
|
|
177
|
+
minConnections: 2,
|
|
178
|
+
idleTimeout: 30000,
|
|
179
|
+
acquireTimeout: 5000,
|
|
180
|
+
}, logger, 'http');
|
|
181
|
+
|
|
182
|
+
// Acquire connection
|
|
183
|
+
const conn = await pool.acquire();
|
|
184
|
+
|
|
185
|
+
// Use connection...
|
|
186
|
+
|
|
187
|
+
// Release back to pool
|
|
188
|
+
pool.release(conn);
|
|
189
|
+
|
|
190
|
+
// Get stats
|
|
191
|
+
const stats = pool.getStats();
|
|
192
|
+
// { totalConnections: 5, idleConnections: 4, busyConnections: 1, ... }
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## API Reference
|
|
196
|
+
|
|
197
|
+
### Server
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
interface IMCPServer {
|
|
201
|
+
start(): Promise<void>;
|
|
202
|
+
stop(): Promise<void>;
|
|
203
|
+
registerTool(tool: MCPTool): boolean;
|
|
204
|
+
registerTools(tools: MCPTool[]): { registered: number; failed: string[] };
|
|
205
|
+
getHealthStatus(): Promise<{ healthy: boolean; error?: string; metrics?: Record<string, number> }>;
|
|
206
|
+
getMetrics(): MCPServerMetrics;
|
|
207
|
+
getSessions(): MCPSession[];
|
|
208
|
+
getSession(sessionId: string): MCPSession | undefined;
|
|
209
|
+
terminateSession(sessionId: string): boolean;
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Tool
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
interface MCPTool<TInput = unknown, TOutput = unknown> {
|
|
217
|
+
name: string;
|
|
218
|
+
description: string;
|
|
219
|
+
inputSchema: JSONSchema;
|
|
220
|
+
handler: (input: TInput, context?: ToolContext) => Promise<TOutput>;
|
|
221
|
+
category?: string;
|
|
222
|
+
tags?: string[];
|
|
223
|
+
cacheable?: boolean;
|
|
224
|
+
cacheTTL?: number;
|
|
225
|
+
timeout?: number;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Transport
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
interface ITransport {
|
|
233
|
+
readonly type: TransportType;
|
|
234
|
+
start(): Promise<void>;
|
|
235
|
+
stop(): Promise<void>;
|
|
236
|
+
onRequest(handler: RequestHandler): void;
|
|
237
|
+
onNotification(handler: NotificationHandler): void;
|
|
238
|
+
sendNotification?(notification: MCPNotification): Promise<void>;
|
|
239
|
+
getHealthStatus(): Promise<TransportHealthStatus>;
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Built-in Tools
|
|
244
|
+
|
|
245
|
+
The server automatically registers these system tools:
|
|
246
|
+
|
|
247
|
+
| Tool | Description |
|
|
248
|
+
|------|-------------|
|
|
249
|
+
| `system/info` | Get server information |
|
|
250
|
+
| `system/health` | Get health status |
|
|
251
|
+
| `system/metrics` | Get server metrics |
|
|
252
|
+
| `tools/list-detailed` | List all tools with details |
|
|
253
|
+
|
|
254
|
+
## Resources (MCP 2025-11-25)
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { createMCPServer, createTextResource } from '@claude-flow/mcp';
|
|
258
|
+
|
|
259
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
260
|
+
const resourceRegistry = server.getResourceRegistry();
|
|
261
|
+
|
|
262
|
+
// Register a text resource
|
|
263
|
+
const { resource, handler } = createTextResource(
|
|
264
|
+
'file://readme.txt',
|
|
265
|
+
'README',
|
|
266
|
+
'Welcome to the application!',
|
|
267
|
+
{ mimeType: 'text/plain' }
|
|
268
|
+
);
|
|
269
|
+
resourceRegistry.registerResource(resource, handler);
|
|
270
|
+
|
|
271
|
+
// Register with custom handler
|
|
272
|
+
resourceRegistry.registerResource(
|
|
273
|
+
{
|
|
274
|
+
uri: 'db://users/{id}',
|
|
275
|
+
name: 'User Data',
|
|
276
|
+
description: 'Get user by ID',
|
|
277
|
+
mimeType: 'application/json',
|
|
278
|
+
},
|
|
279
|
+
async (uri) => {
|
|
280
|
+
const id = uri.split('/').pop();
|
|
281
|
+
const user = await fetchUser(id);
|
|
282
|
+
return [{ uri, mimeType: 'application/json', text: JSON.stringify(user) }];
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// Subscribe to updates
|
|
287
|
+
resourceRegistry.subscribe('file://readme.txt', (uri, content) => {
|
|
288
|
+
console.log('Resource updated:', uri);
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Prompts (MCP 2025-11-25)
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { createMCPServer, definePrompt, textMessage, interpolate } from '@claude-flow/mcp';
|
|
296
|
+
|
|
297
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
298
|
+
const promptRegistry = server.getPromptRegistry();
|
|
299
|
+
|
|
300
|
+
// Define a prompt with arguments
|
|
301
|
+
const codeReviewPrompt = definePrompt(
|
|
302
|
+
'code_review',
|
|
303
|
+
'Review code for quality and best practices',
|
|
304
|
+
async (args) => [
|
|
305
|
+
textMessage('user', `Please review this ${args.language} code:\n\n${args.code}`),
|
|
306
|
+
],
|
|
307
|
+
{
|
|
308
|
+
title: 'Code Review',
|
|
309
|
+
arguments: [
|
|
310
|
+
{ name: 'code', description: 'The code to review', required: true },
|
|
311
|
+
{ name: 'language', description: 'Programming language', required: false },
|
|
312
|
+
],
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
promptRegistry.register(codeReviewPrompt);
|
|
317
|
+
|
|
318
|
+
// Get prompt with arguments
|
|
319
|
+
const result = await promptRegistry.get('code_review', {
|
|
320
|
+
code: 'function hello() { return "world"; }',
|
|
321
|
+
language: 'JavaScript',
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Tasks (MCP 2025-11-25)
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
import { createMCPServer } from '@claude-flow/mcp';
|
|
329
|
+
|
|
330
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
331
|
+
const taskManager = server.getTaskManager();
|
|
332
|
+
|
|
333
|
+
// Create a long-running task
|
|
334
|
+
const taskId = taskManager.createTask(async (reportProgress, signal) => {
|
|
335
|
+
for (let i = 0; i <= 100; i += 10) {
|
|
336
|
+
if (signal.aborted) throw new Error('Task cancelled');
|
|
337
|
+
|
|
338
|
+
reportProgress({
|
|
339
|
+
progress: i,
|
|
340
|
+
total: 100,
|
|
341
|
+
message: `Processing... ${i}%`,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
await new Promise(r => setTimeout(r, 100));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return { success: true, processedItems: 100 };
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Get task status
|
|
351
|
+
const status = taskManager.getTask(taskId);
|
|
352
|
+
|
|
353
|
+
// Wait for completion
|
|
354
|
+
const result = await taskManager.waitForTask(taskId);
|
|
355
|
+
|
|
356
|
+
// Cancel a task
|
|
357
|
+
taskManager.cancelTask(taskId, 'User requested cancellation');
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## MCP Methods Supported
|
|
361
|
+
|
|
362
|
+
| Method | Description |
|
|
363
|
+
|--------|-------------|
|
|
364
|
+
| `initialize` | Initialize connection |
|
|
365
|
+
| `tools/list` | List available tools |
|
|
366
|
+
| `tools/call` | Execute a tool |
|
|
367
|
+
| `resources/list` | List resources with pagination |
|
|
368
|
+
| `resources/read` | Read resource content |
|
|
369
|
+
| `resources/subscribe` | Subscribe to updates |
|
|
370
|
+
| `resources/unsubscribe` | Unsubscribe from updates |
|
|
371
|
+
| `prompts/list` | List prompts with pagination |
|
|
372
|
+
| `prompts/get` | Get prompt with arguments |
|
|
373
|
+
| `tasks/status` | Get task status |
|
|
374
|
+
| `tasks/cancel` | Cancel a running task |
|
|
375
|
+
| `completion/complete` | Auto-complete arguments |
|
|
376
|
+
| `logging/setLevel` | Set log level |
|
|
377
|
+
| `ping` | Keep-alive |
|
|
378
|
+
|
|
379
|
+
## Performance Targets
|
|
380
|
+
|
|
381
|
+
| Metric | Target |
|
|
382
|
+
|--------|--------|
|
|
383
|
+
| Server startup | <400ms |
|
|
384
|
+
| Tool registration | <10ms |
|
|
385
|
+
| Tool execution overhead | <50ms |
|
|
386
|
+
| Connection acquire | <5ms |
|
|
387
|
+
| Connection release | <1ms |
|
|
388
|
+
|
|
389
|
+
## Security
|
|
390
|
+
|
|
391
|
+
### Authentication
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
const server = createMCPServer({
|
|
395
|
+
auth: {
|
|
396
|
+
enabled: true,
|
|
397
|
+
method: 'token',
|
|
398
|
+
tokens: ['your-secret-token'],
|
|
399
|
+
},
|
|
400
|
+
}, logger);
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### CORS
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
const server = createMCPServer({
|
|
407
|
+
transport: 'http',
|
|
408
|
+
corsEnabled: true,
|
|
409
|
+
corsOrigins: ['https://your-domain.com'],
|
|
410
|
+
}, logger);
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Error Codes
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
const ErrorCodes = {
|
|
417
|
+
PARSE_ERROR: -32700,
|
|
418
|
+
INVALID_REQUEST: -32600,
|
|
419
|
+
METHOD_NOT_FOUND: -32601,
|
|
420
|
+
INVALID_PARAMS: -32602,
|
|
421
|
+
INTERNAL_ERROR: -32603,
|
|
422
|
+
SERVER_NOT_INITIALIZED: -32002,
|
|
423
|
+
AUTHENTICATION_REQUIRED: -32001,
|
|
424
|
+
};
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
MIT
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @claude-flow/mcp - Connection Pool
|
|
3
|
+
*
|
|
4
|
+
* High-performance connection pooling
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
import type { PooledConnection, ConnectionPoolStats, ConnectionPoolConfig, IConnectionPool, ILogger, TransportType } from './types.js';
|
|
8
|
+
export declare class ConnectionPool extends EventEmitter implements IConnectionPool {
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly transportType;
|
|
11
|
+
private readonly config;
|
|
12
|
+
private readonly connections;
|
|
13
|
+
private readonly waitingClients;
|
|
14
|
+
private evictionTimer?;
|
|
15
|
+
private connectionCounter;
|
|
16
|
+
private isShuttingDown;
|
|
17
|
+
private stats;
|
|
18
|
+
constructor(config: Partial<ConnectionPoolConfig> | undefined, logger: ILogger, transportType?: TransportType);
|
|
19
|
+
private initializeMinConnections;
|
|
20
|
+
private createConnection;
|
|
21
|
+
acquire(): Promise<PooledConnection>;
|
|
22
|
+
private waitForConnection;
|
|
23
|
+
release(connection: PooledConnection): void;
|
|
24
|
+
destroy(connection: PooledConnection): void;
|
|
25
|
+
getStats(): ConnectionPoolStats;
|
|
26
|
+
drain(): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
private startEvictionTimer;
|
|
29
|
+
private stopEvictionTimer;
|
|
30
|
+
private evictIdleConnections;
|
|
31
|
+
private recordAcquireTime;
|
|
32
|
+
getConnections(): PooledConnection[];
|
|
33
|
+
isHealthy(): boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function createConnectionPool(config: Partial<ConnectionPoolConfig> | undefined, logger: ILogger, transportType?: TransportType): ConnectionPool;
|
|
36
|
+
//# sourceMappingURL=connection-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../src/connection-pool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EAEpB,eAAe,EACf,OAAO,EACP,aAAa,EACd,MAAM,YAAY,CAAC;AAoDpB,qBAAa,cAAe,SAAQ,YAAa,YAAW,eAAe;IAmBvE,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAnBhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IACzE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;IACtD,OAAO,CAAC,aAAa,CAAC,CAAiB;IACvC,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,cAAc,CAAkB;IAExC,OAAO,CAAC,KAAK,CAOX;gBAGA,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,YAAK,EACzB,MAAM,EAAE,OAAO,EACf,aAAa,GAAE,aAA4B;YAQhD,wBAAwB;YAWxB,gBAAgB;IAaxB,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAiC1C,OAAO,CAAC,iBAAiB;IA4BzB,OAAO,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI;IAuB3C,OAAO,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI;IAoB3C,QAAQ,IAAI,mBAAmB;IAwBzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,oBAAoB;IAwB5B,OAAO,CAAC,iBAAiB;IAMzB,cAAc,IAAI,gBAAgB,EAAE;IAIpC,SAAS,IAAI,OAAO;CAGrB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,YAAK,EAC1C,MAAM,EAAE,OAAO,EACf,aAAa,GAAE,aAA4B,GAC1C,cAAc,CAEhB"}
|