@claude-flow/mcp 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/README.md +428 -0
- package/__tests__/integration.test.ts +449 -0
- package/__tests__/mcp.test.ts +641 -0
- package/dist/connection-pool.d.ts +36 -0
- package/dist/connection-pool.d.ts.map +1 -0
- package/dist/connection-pool.js +273 -0
- package/dist/connection-pool.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +146 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +318 -0
- package/dist/oauth.js.map +1 -0
- package/dist/prompt-registry.d.ts +90 -0
- package/dist/prompt-registry.d.ts.map +1 -0
- package/dist/prompt-registry.js +209 -0
- package/dist/prompt-registry.js.map +1 -0
- package/dist/rate-limiter.d.ts +86 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +197 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/resource-registry.d.ts +144 -0
- package/dist/resource-registry.d.ts.map +1 -0
- package/dist/resource-registry.js +405 -0
- package/dist/resource-registry.js.map +1 -0
- package/dist/sampling.d.ts +102 -0
- package/dist/sampling.d.ts.map +1 -0
- package/dist/sampling.js +268 -0
- package/dist/sampling.js.map +1 -0
- package/dist/schema-validator.d.ts +30 -0
- package/dist/schema-validator.d.ts.map +1 -0
- package/dist/schema-validator.js +182 -0
- package/dist/schema-validator.js.map +1 -0
- package/dist/server.d.ts +122 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +829 -0
- package/dist/server.js.map +1 -0
- package/dist/session-manager.d.ts +55 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +252 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/task-manager.d.ts +81 -0
- package/dist/task-manager.d.ts.map +1 -0
- package/dist/task-manager.js +337 -0
- package/dist/task-manager.js.map +1 -0
- package/dist/tool-registry.d.ts +88 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +353 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/transport/http.d.ts +55 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +446 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/index.d.ts +50 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +181 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/stdio.d.ts +43 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +194 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport/websocket.d.ts +65 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +314 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types.d.ts +473 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
- package/src/connection-pool.ts +344 -0
- package/src/index.ts +253 -0
- package/src/oauth.ts +447 -0
- package/src/prompt-registry.ts +296 -0
- package/src/rate-limiter.ts +266 -0
- package/src/resource-registry.ts +530 -0
- package/src/sampling.ts +363 -0
- package/src/schema-validator.ts +213 -0
- package/src/server.ts +1134 -0
- package/src/session-manager.ts +339 -0
- package/src/task-manager.ts +427 -0
- package/src/tool-registry.ts +475 -0
- package/src/transport/http.ts +532 -0
- package/src/transport/index.ts +233 -0
- package/src/transport/stdio.ts +252 -0
- package/src/transport/websocket.ts +396 -0
- package/src/types.ts +664 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @claude-flow/mcp - Connection Pool
|
|
3
|
+
*
|
|
4
|
+
* High-performance connection pooling
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import type {
|
|
9
|
+
PooledConnection,
|
|
10
|
+
ConnectionPoolStats,
|
|
11
|
+
ConnectionPoolConfig,
|
|
12
|
+
ConnectionState,
|
|
13
|
+
IConnectionPool,
|
|
14
|
+
ILogger,
|
|
15
|
+
TransportType,
|
|
16
|
+
} from './types.js';
|
|
17
|
+
|
|
18
|
+
const DEFAULT_POOL_CONFIG: ConnectionPoolConfig = {
|
|
19
|
+
maxConnections: 10,
|
|
20
|
+
minConnections: 2,
|
|
21
|
+
idleTimeout: 30000,
|
|
22
|
+
acquireTimeout: 5000,
|
|
23
|
+
maxWaitingClients: 50,
|
|
24
|
+
evictionRunInterval: 10000,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
class ManagedConnection implements PooledConnection {
|
|
28
|
+
public state: ConnectionState = 'idle';
|
|
29
|
+
public lastUsedAt: Date;
|
|
30
|
+
public useCount: number = 0;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
public readonly id: string,
|
|
34
|
+
public readonly transport: TransportType,
|
|
35
|
+
public readonly createdAt: Date = new Date(),
|
|
36
|
+
public metadata?: Record<string, unknown>
|
|
37
|
+
) {
|
|
38
|
+
this.lastUsedAt = this.createdAt;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
acquire(): void {
|
|
42
|
+
this.state = 'busy';
|
|
43
|
+
this.lastUsedAt = new Date();
|
|
44
|
+
this.useCount++;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
release(): void {
|
|
48
|
+
this.state = 'idle';
|
|
49
|
+
this.lastUsedAt = new Date();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
isExpired(idleTimeout: number): boolean {
|
|
53
|
+
if (this.state !== 'idle') return false;
|
|
54
|
+
return Date.now() - this.lastUsedAt.getTime() > idleTimeout;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
isHealthy(): boolean {
|
|
58
|
+
return this.state !== 'error' && this.state !== 'closed';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface WaitingClient {
|
|
63
|
+
resolve: (connection: PooledConnection) => void;
|
|
64
|
+
reject: (error: Error) => void;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class ConnectionPool extends EventEmitter implements IConnectionPool {
|
|
69
|
+
private readonly config: ConnectionPoolConfig;
|
|
70
|
+
private readonly connections: Map<string, ManagedConnection> = new Map();
|
|
71
|
+
private readonly waitingClients: WaitingClient[] = [];
|
|
72
|
+
private evictionTimer?: NodeJS.Timeout;
|
|
73
|
+
private connectionCounter: number = 0;
|
|
74
|
+
private isShuttingDown: boolean = false;
|
|
75
|
+
|
|
76
|
+
private stats = {
|
|
77
|
+
totalAcquired: 0,
|
|
78
|
+
totalReleased: 0,
|
|
79
|
+
totalCreated: 0,
|
|
80
|
+
totalDestroyed: 0,
|
|
81
|
+
acquireTimeTotal: 0,
|
|
82
|
+
acquireCount: 0,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
constructor(
|
|
86
|
+
config: Partial<ConnectionPoolConfig> = {},
|
|
87
|
+
private readonly logger: ILogger,
|
|
88
|
+
private readonly transportType: TransportType = 'in-process'
|
|
89
|
+
) {
|
|
90
|
+
super();
|
|
91
|
+
this.config = { ...DEFAULT_POOL_CONFIG, ...config };
|
|
92
|
+
this.startEvictionTimer();
|
|
93
|
+
this.initializeMinConnections();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private async initializeMinConnections(): Promise<void> {
|
|
97
|
+
const promises: Promise<ManagedConnection>[] = [];
|
|
98
|
+
for (let i = 0; i < this.config.minConnections; i++) {
|
|
99
|
+
promises.push(this.createConnection());
|
|
100
|
+
}
|
|
101
|
+
await Promise.all(promises);
|
|
102
|
+
this.logger.debug('Connection pool initialized', {
|
|
103
|
+
minConnections: this.config.minConnections,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async createConnection(): Promise<ManagedConnection> {
|
|
108
|
+
const id = `conn-${++this.connectionCounter}-${Date.now()}`;
|
|
109
|
+
const connection = new ManagedConnection(id, this.transportType);
|
|
110
|
+
|
|
111
|
+
this.connections.set(id, connection);
|
|
112
|
+
this.stats.totalCreated++;
|
|
113
|
+
|
|
114
|
+
this.emit('pool:connection:created', { connectionId: id });
|
|
115
|
+
this.logger.debug('Connection created', { id, total: this.connections.size });
|
|
116
|
+
|
|
117
|
+
return connection;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async acquire(): Promise<PooledConnection> {
|
|
121
|
+
const startTime = performance.now();
|
|
122
|
+
|
|
123
|
+
if (this.isShuttingDown) {
|
|
124
|
+
throw new Error('Connection pool is shutting down');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (const connection of this.connections.values()) {
|
|
128
|
+
if (connection.state === 'idle' && connection.isHealthy()) {
|
|
129
|
+
connection.acquire();
|
|
130
|
+
this.stats.totalAcquired++;
|
|
131
|
+
this.recordAcquireTime(startTime);
|
|
132
|
+
|
|
133
|
+
this.emit('pool:connection:acquired', { connectionId: connection.id });
|
|
134
|
+
this.logger.debug('Connection acquired from pool', { id: connection.id });
|
|
135
|
+
|
|
136
|
+
return connection;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (this.connections.size < this.config.maxConnections) {
|
|
141
|
+
const connection = await this.createConnection();
|
|
142
|
+
connection.acquire();
|
|
143
|
+
this.stats.totalAcquired++;
|
|
144
|
+
this.recordAcquireTime(startTime);
|
|
145
|
+
|
|
146
|
+
this.emit('pool:connection:acquired', { connectionId: connection.id });
|
|
147
|
+
return connection;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return this.waitForConnection(startTime);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private waitForConnection(startTime: number): Promise<PooledConnection> {
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
if (this.waitingClients.length >= this.config.maxWaitingClients) {
|
|
156
|
+
reject(new Error('Connection pool exhausted - max waiting clients reached'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const client: WaitingClient = {
|
|
161
|
+
resolve: (connection) => {
|
|
162
|
+
this.recordAcquireTime(startTime);
|
|
163
|
+
resolve(connection);
|
|
164
|
+
},
|
|
165
|
+
reject,
|
|
166
|
+
timestamp: Date.now(),
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
this.waitingClients.push(client);
|
|
170
|
+
|
|
171
|
+
setTimeout(() => {
|
|
172
|
+
const index = this.waitingClients.indexOf(client);
|
|
173
|
+
if (index !== -1) {
|
|
174
|
+
this.waitingClients.splice(index, 1);
|
|
175
|
+
reject(new Error(`Connection acquire timeout after ${this.config.acquireTimeout}ms`));
|
|
176
|
+
}
|
|
177
|
+
}, this.config.acquireTimeout);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
release(connection: PooledConnection): void {
|
|
182
|
+
const managed = this.connections.get(connection.id);
|
|
183
|
+
if (!managed) {
|
|
184
|
+
this.logger.warn('Attempted to release unknown connection', { id: connection.id });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const waitingClient = this.waitingClients.shift();
|
|
189
|
+
if (waitingClient) {
|
|
190
|
+
managed.acquire();
|
|
191
|
+
this.stats.totalAcquired++;
|
|
192
|
+
this.emit('pool:connection:acquired', { connectionId: connection.id });
|
|
193
|
+
waitingClient.resolve(managed);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
managed.release();
|
|
198
|
+
this.stats.totalReleased++;
|
|
199
|
+
|
|
200
|
+
this.emit('pool:connection:released', { connectionId: connection.id });
|
|
201
|
+
this.logger.debug('Connection released to pool', { id: connection.id });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
destroy(connection: PooledConnection): void {
|
|
205
|
+
const managed = this.connections.get(connection.id);
|
|
206
|
+
if (!managed) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
managed.state = 'closed';
|
|
211
|
+
this.connections.delete(connection.id);
|
|
212
|
+
this.stats.totalDestroyed++;
|
|
213
|
+
|
|
214
|
+
this.emit('pool:connection:destroyed', { connectionId: connection.id });
|
|
215
|
+
this.logger.debug('Connection destroyed', { id: connection.id });
|
|
216
|
+
|
|
217
|
+
if (this.connections.size < this.config.minConnections && !this.isShuttingDown) {
|
|
218
|
+
this.createConnection().catch((err) => {
|
|
219
|
+
this.logger.error('Failed to create replacement connection', err);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getStats(): ConnectionPoolStats {
|
|
225
|
+
let idleCount = 0;
|
|
226
|
+
let busyCount = 0;
|
|
227
|
+
|
|
228
|
+
for (const connection of this.connections.values()) {
|
|
229
|
+
if (connection.state === 'idle') idleCount++;
|
|
230
|
+
else if (connection.state === 'busy') busyCount++;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
totalConnections: this.connections.size,
|
|
235
|
+
idleConnections: idleCount,
|
|
236
|
+
busyConnections: busyCount,
|
|
237
|
+
pendingRequests: this.waitingClients.length,
|
|
238
|
+
totalAcquired: this.stats.totalAcquired,
|
|
239
|
+
totalReleased: this.stats.totalReleased,
|
|
240
|
+
totalCreated: this.stats.totalCreated,
|
|
241
|
+
totalDestroyed: this.stats.totalDestroyed,
|
|
242
|
+
avgAcquireTime: this.stats.acquireCount > 0
|
|
243
|
+
? this.stats.acquireTimeTotal / this.stats.acquireCount
|
|
244
|
+
: 0,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async drain(): Promise<void> {
|
|
249
|
+
this.isShuttingDown = true;
|
|
250
|
+
this.logger.info('Draining connection pool');
|
|
251
|
+
|
|
252
|
+
while (this.waitingClients.length > 0) {
|
|
253
|
+
const client = this.waitingClients.shift();
|
|
254
|
+
client?.reject(new Error('Connection pool is draining'));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const maxWait = 10000;
|
|
258
|
+
const startTime = Date.now();
|
|
259
|
+
|
|
260
|
+
while (Date.now() - startTime < maxWait) {
|
|
261
|
+
let busyCount = 0;
|
|
262
|
+
for (const connection of this.connections.values()) {
|
|
263
|
+
if (connection.state === 'busy') busyCount++;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (busyCount === 0) break;
|
|
267
|
+
|
|
268
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.logger.info('Connection pool drained');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async clear(): Promise<void> {
|
|
275
|
+
this.stopEvictionTimer();
|
|
276
|
+
await this.drain();
|
|
277
|
+
|
|
278
|
+
for (const connection of this.connections.values()) {
|
|
279
|
+
connection.state = 'closed';
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.connections.clear();
|
|
283
|
+
this.logger.info('Connection pool cleared');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private startEvictionTimer(): void {
|
|
287
|
+
this.evictionTimer = setInterval(() => {
|
|
288
|
+
this.evictIdleConnections();
|
|
289
|
+
}, this.config.evictionRunInterval);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private stopEvictionTimer(): void {
|
|
293
|
+
if (this.evictionTimer) {
|
|
294
|
+
clearInterval(this.evictionTimer);
|
|
295
|
+
this.evictionTimer = undefined;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private evictIdleConnections(): void {
|
|
300
|
+
if (this.isShuttingDown) return;
|
|
301
|
+
|
|
302
|
+
const toEvict: ManagedConnection[] = [];
|
|
303
|
+
|
|
304
|
+
for (const connection of this.connections.values()) {
|
|
305
|
+
if (
|
|
306
|
+
connection.isExpired(this.config.idleTimeout) &&
|
|
307
|
+
this.connections.size > this.config.minConnections
|
|
308
|
+
) {
|
|
309
|
+
toEvict.push(connection);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
for (const connection of toEvict) {
|
|
314
|
+
this.destroy(connection);
|
|
315
|
+
this.logger.debug('Evicted idle connection', { id: connection.id });
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (toEvict.length > 0) {
|
|
319
|
+
this.logger.info('Evicted idle connections', { count: toEvict.length });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private recordAcquireTime(startTime: number): void {
|
|
324
|
+
const duration = performance.now() - startTime;
|
|
325
|
+
this.stats.acquireTimeTotal += duration;
|
|
326
|
+
this.stats.acquireCount++;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
getConnections(): PooledConnection[] {
|
|
330
|
+
return Array.from(this.connections.values());
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
isHealthy(): boolean {
|
|
334
|
+
return !this.isShuttingDown && this.connections.size >= this.config.minConnections;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function createConnectionPool(
|
|
339
|
+
config: Partial<ConnectionPoolConfig> = {},
|
|
340
|
+
logger: ILogger,
|
|
341
|
+
transportType: TransportType = 'in-process'
|
|
342
|
+
): ConnectionPool {
|
|
343
|
+
return new ConnectionPool(config, logger, transportType);
|
|
344
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @claude-flow/mcp - Standalone MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Zero-dependency MCP (Model Context Protocol) implementation
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - High-performance server with <400ms startup
|
|
8
|
+
* - Connection pooling with max 10 connections
|
|
9
|
+
* - Multiple transport support (stdio, http, websocket, in-process)
|
|
10
|
+
* - Fast tool registry with <10ms registration
|
|
11
|
+
* - Session management with timeout handling
|
|
12
|
+
* - Comprehensive metrics and monitoring
|
|
13
|
+
*
|
|
14
|
+
* @module @claude-flow/mcp
|
|
15
|
+
* @version 3.0.0
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Core types
|
|
19
|
+
export type {
|
|
20
|
+
JsonRpcVersion,
|
|
21
|
+
RequestId,
|
|
22
|
+
MCPMessage,
|
|
23
|
+
MCPRequest,
|
|
24
|
+
MCPResponse,
|
|
25
|
+
MCPNotification,
|
|
26
|
+
MCPError,
|
|
27
|
+
TransportType,
|
|
28
|
+
AuthMethod,
|
|
29
|
+
AuthConfig,
|
|
30
|
+
LoadBalancerConfig,
|
|
31
|
+
ConnectionPoolConfig,
|
|
32
|
+
MCPServerConfig,
|
|
33
|
+
SessionState,
|
|
34
|
+
MCPSession,
|
|
35
|
+
MCPClientInfo,
|
|
36
|
+
MCPCapabilities,
|
|
37
|
+
MCPProtocolVersion,
|
|
38
|
+
MCPInitializeParams,
|
|
39
|
+
MCPInitializeResult,
|
|
40
|
+
JSONSchema,
|
|
41
|
+
ToolContext,
|
|
42
|
+
ToolHandler,
|
|
43
|
+
MCPTool,
|
|
44
|
+
ToolCallResult,
|
|
45
|
+
ToolRegistrationOptions,
|
|
46
|
+
RequestHandler,
|
|
47
|
+
NotificationHandler,
|
|
48
|
+
TransportHealthStatus,
|
|
49
|
+
ITransport,
|
|
50
|
+
ConnectionState,
|
|
51
|
+
PooledConnection,
|
|
52
|
+
ConnectionPoolStats,
|
|
53
|
+
IConnectionPool,
|
|
54
|
+
ToolCallMetrics,
|
|
55
|
+
MCPServerMetrics,
|
|
56
|
+
SessionMetrics,
|
|
57
|
+
MCPEventType,
|
|
58
|
+
MCPEvent,
|
|
59
|
+
EventHandler,
|
|
60
|
+
LogLevel,
|
|
61
|
+
ILogger,
|
|
62
|
+
// MCP 2025-11-25 types
|
|
63
|
+
MCPResource,
|
|
64
|
+
ResourceContent,
|
|
65
|
+
ResourceTemplate,
|
|
66
|
+
ResourceListResult,
|
|
67
|
+
ResourceReadResult,
|
|
68
|
+
PromptArgument,
|
|
69
|
+
MCPPrompt,
|
|
70
|
+
PromptRole,
|
|
71
|
+
ContentAnnotations,
|
|
72
|
+
TextContent,
|
|
73
|
+
ImageContent,
|
|
74
|
+
AudioContent,
|
|
75
|
+
EmbeddedResource,
|
|
76
|
+
PromptContent,
|
|
77
|
+
PromptMessage,
|
|
78
|
+
PromptListResult,
|
|
79
|
+
PromptGetResult,
|
|
80
|
+
TaskState,
|
|
81
|
+
MCPTask,
|
|
82
|
+
TaskProgress,
|
|
83
|
+
TaskResult,
|
|
84
|
+
PaginatedRequest,
|
|
85
|
+
PaginatedResult,
|
|
86
|
+
ProgressNotification,
|
|
87
|
+
CancellationParams,
|
|
88
|
+
SamplingMessage,
|
|
89
|
+
ModelPreferences,
|
|
90
|
+
CreateMessageRequest,
|
|
91
|
+
CreateMessageResult,
|
|
92
|
+
Root,
|
|
93
|
+
RootsListResult,
|
|
94
|
+
MCPLogLevel,
|
|
95
|
+
LoggingMessage,
|
|
96
|
+
CompletionReference,
|
|
97
|
+
CompletionArgument,
|
|
98
|
+
CompletionResult,
|
|
99
|
+
} from './types.js';
|
|
100
|
+
|
|
101
|
+
// Error handling
|
|
102
|
+
export { ErrorCodes, MCPServerError } from './types.js';
|
|
103
|
+
|
|
104
|
+
// Server
|
|
105
|
+
import { MCPServer, createMCPServer } from './server.js';
|
|
106
|
+
export { MCPServer, createMCPServer };
|
|
107
|
+
export type { IMCPServer } from './server.js';
|
|
108
|
+
|
|
109
|
+
// Tool Registry
|
|
110
|
+
export { ToolRegistry, createToolRegistry, defineTool } from './tool-registry.js';
|
|
111
|
+
|
|
112
|
+
// Session Manager
|
|
113
|
+
import { SessionManager, createSessionManager } from './session-manager.js';
|
|
114
|
+
export { SessionManager, createSessionManager };
|
|
115
|
+
export type { SessionConfig } from './session-manager.js';
|
|
116
|
+
|
|
117
|
+
// Connection Pool
|
|
118
|
+
export { ConnectionPool, createConnectionPool } from './connection-pool.js';
|
|
119
|
+
|
|
120
|
+
// Resource Registry (MCP 2025-11-25)
|
|
121
|
+
export {
|
|
122
|
+
ResourceRegistry,
|
|
123
|
+
createResourceRegistry,
|
|
124
|
+
createTextResource,
|
|
125
|
+
createFileResource,
|
|
126
|
+
} from './resource-registry.js';
|
|
127
|
+
export type { ResourceHandler, SubscriptionCallback, ResourceRegistryOptions } from './resource-registry.js';
|
|
128
|
+
|
|
129
|
+
// Prompt Registry (MCP 2025-11-25)
|
|
130
|
+
export {
|
|
131
|
+
PromptRegistry,
|
|
132
|
+
createPromptRegistry,
|
|
133
|
+
definePrompt,
|
|
134
|
+
textMessage,
|
|
135
|
+
resourceMessage,
|
|
136
|
+
interpolate,
|
|
137
|
+
} from './prompt-registry.js';
|
|
138
|
+
export type { PromptHandler, PromptDefinition, PromptRegistryOptions } from './prompt-registry.js';
|
|
139
|
+
|
|
140
|
+
// Task Manager (MCP 2025-11-25)
|
|
141
|
+
export { TaskManager, createTaskManager } from './task-manager.js';
|
|
142
|
+
export type { TaskExecutor, TaskManagerOptions } from './task-manager.js';
|
|
143
|
+
|
|
144
|
+
// Schema Validator
|
|
145
|
+
export {
|
|
146
|
+
validateSchema,
|
|
147
|
+
formatValidationErrors,
|
|
148
|
+
createValidator,
|
|
149
|
+
} from './schema-validator.js';
|
|
150
|
+
export type { ValidationError, ValidationResult } from './schema-validator.js';
|
|
151
|
+
|
|
152
|
+
// Rate Limiter
|
|
153
|
+
export {
|
|
154
|
+
RateLimiter,
|
|
155
|
+
createRateLimiter,
|
|
156
|
+
rateLimitMiddleware,
|
|
157
|
+
} from './rate-limiter.js';
|
|
158
|
+
export type { RateLimitConfig, RateLimitResult } from './rate-limiter.js';
|
|
159
|
+
|
|
160
|
+
// Sampling (Server-initiated LLM)
|
|
161
|
+
export {
|
|
162
|
+
SamplingManager,
|
|
163
|
+
createSamplingManager,
|
|
164
|
+
createMockProvider,
|
|
165
|
+
createAnthropicProvider,
|
|
166
|
+
} from './sampling.js';
|
|
167
|
+
export type { LLMProvider, SamplingConfig, SamplingContext } from './sampling.js';
|
|
168
|
+
|
|
169
|
+
// OAuth 2.1
|
|
170
|
+
export {
|
|
171
|
+
OAuthManager,
|
|
172
|
+
createOAuthManager,
|
|
173
|
+
oauthMiddleware,
|
|
174
|
+
InMemoryTokenStorage,
|
|
175
|
+
createGitHubOAuthConfig,
|
|
176
|
+
createGoogleOAuthConfig,
|
|
177
|
+
} from './oauth.js';
|
|
178
|
+
export type {
|
|
179
|
+
OAuthConfig,
|
|
180
|
+
OAuthTokens,
|
|
181
|
+
TokenStorage,
|
|
182
|
+
AuthorizationRequest,
|
|
183
|
+
} from './oauth.js';
|
|
184
|
+
|
|
185
|
+
// Transport layer
|
|
186
|
+
export {
|
|
187
|
+
createTransport,
|
|
188
|
+
createInProcessTransport,
|
|
189
|
+
TransportManager,
|
|
190
|
+
createTransportManager,
|
|
191
|
+
DEFAULT_TRANSPORT_CONFIGS,
|
|
192
|
+
StdioTransport,
|
|
193
|
+
HttpTransport,
|
|
194
|
+
WebSocketTransport,
|
|
195
|
+
} from './transport/index.js';
|
|
196
|
+
|
|
197
|
+
export type {
|
|
198
|
+
TransportConfig,
|
|
199
|
+
StdioTransportConfig,
|
|
200
|
+
HttpTransportConfig,
|
|
201
|
+
WebSocketTransportConfig,
|
|
202
|
+
} from './transport/index.js';
|
|
203
|
+
|
|
204
|
+
// Import types for quickStart
|
|
205
|
+
import type { MCPServerConfig, ILogger } from './types.js';
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Quick start function to create and configure an MCP server
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* import { quickStart } from '@claude-flow/mcp';
|
|
213
|
+
*
|
|
214
|
+
* const server = await quickStart({
|
|
215
|
+
* transport: 'stdio',
|
|
216
|
+
* name: 'My MCP Server',
|
|
217
|
+
* });
|
|
218
|
+
*
|
|
219
|
+
* server.registerTool({
|
|
220
|
+
* name: 'my-tool',
|
|
221
|
+
* description: 'My custom tool',
|
|
222
|
+
* inputSchema: { type: 'object', properties: {} },
|
|
223
|
+
* handler: async () => ({ result: 'success' }),
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* await server.start();
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export async function quickStart(
|
|
230
|
+
config: Partial<MCPServerConfig>,
|
|
231
|
+
logger?: ILogger
|
|
232
|
+
): Promise<MCPServer> {
|
|
233
|
+
const defaultLogger: ILogger = logger || {
|
|
234
|
+
debug: (msg, data) => console.debug(`[DEBUG] ${msg}`, data || ''),
|
|
235
|
+
info: (msg, data) => console.info(`[INFO] ${msg}`, data || ''),
|
|
236
|
+
warn: (msg, data) => console.warn(`[WARN] ${msg}`, data || ''),
|
|
237
|
+
error: (msg, data) => console.error(`[ERROR] ${msg}`, data || ''),
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const server = createMCPServer(config, defaultLogger);
|
|
241
|
+
|
|
242
|
+
return server;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Module version
|
|
247
|
+
*/
|
|
248
|
+
export const VERSION = '3.0.0';
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Module name
|
|
252
|
+
*/
|
|
253
|
+
export const MODULE_NAME = '@claude-flow/mcp';
|