@monoes/mcp 1.0.6 → 2.24.0
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/dist/protocol-types.d.ts +182 -0
- package/dist/protocol-types.d.ts.map +1 -0
- package/dist/protocol-types.js +8 -0
- package/dist/protocol-types.js.map +1 -0
- package/dist/resource-helpers.d.ts +32 -0
- package/dist/resource-helpers.d.ts.map +1 -0
- package/dist/resource-helpers.js +77 -0
- package/dist/resource-helpers.js.map +1 -0
- package/dist/resource-registry.d.ts +2 -24
- package/dist/resource-registry.d.ts.map +1 -1
- package/dist/resource-registry.js +1 -70
- package/dist/resource-registry.js.map +1 -1
- package/dist/server-builtins.d.ts +12 -0
- package/dist/server-builtins.d.ts.map +1 -0
- package/dist/server-builtins.js +165 -0
- package/dist/server-builtins.js.map +1 -0
- package/dist/server-core.d.ts +118 -0
- package/dist/server-core.d.ts.map +1 -0
- package/dist/server-core.js +343 -0
- package/dist/server-core.js.map +1 -0
- package/dist/server-handlers.d.ts +17 -0
- package/dist/server-handlers.d.ts.map +1 -0
- package/dist/server-handlers.js +173 -0
- package/dist/server-handlers.js.map +1 -0
- package/dist/server-routing.d.ts +16 -0
- package/dist/server-routing.d.ts.map +1 -0
- package/dist/server-routing.js +194 -0
- package/dist/server-routing.js.map +1 -0
- package/dist/server.d.ts +2 -115
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -839
- package/dist/server.js.map +1 -1
- package/dist/transport/http-base.d.ts +84 -0
- package/dist/transport/http-base.d.ts.map +1 -0
- package/dist/transport/http-base.js +238 -0
- package/dist/transport/http-base.js.map +1 -0
- package/dist/transport/http.d.ts +5 -69
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +3 -228
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/websocket-base.d.ts +71 -0
- package/dist/transport/websocket-base.d.ts.map +1 -0
- package/dist/transport/websocket-base.js +199 -0
- package/dist/transport/websocket-base.js.map +1 -0
- package/dist/transport/websocket.d.ts +4 -63
- package/dist/transport/websocket.d.ts.map +1 -1
- package/dist/transport/websocket.js +3 -191
- package/dist/transport/websocket.js.map +1 -1
- package/dist/types.d.ts +1 -174
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monoes/mcp - MCP Server (built-ins)
|
|
3
|
+
*
|
|
4
|
+
* Built-in system tools, resources and prompts registered on start().
|
|
5
|
+
*/
|
|
6
|
+
import { arch, platform } from 'node:os';
|
|
7
|
+
import { MCPServerCore } from './server-core.js';
|
|
8
|
+
export class MCPServerBuiltins extends MCPServerCore {
|
|
9
|
+
async registerBuiltInTools() {
|
|
10
|
+
this.registerTool({
|
|
11
|
+
name: 'system/info',
|
|
12
|
+
description: 'Get system information',
|
|
13
|
+
inputSchema: { type: 'object', properties: {} },
|
|
14
|
+
handler: async () => ({
|
|
15
|
+
name: this.serverInfo.name,
|
|
16
|
+
version: this.serverInfo.version,
|
|
17
|
+
platform: platform(),
|
|
18
|
+
arch: arch(),
|
|
19
|
+
runtime: 'Node.js',
|
|
20
|
+
uptime: this.startTime ? Date.now() - this.startTime.getTime() : 0,
|
|
21
|
+
}),
|
|
22
|
+
category: 'system',
|
|
23
|
+
});
|
|
24
|
+
this.registerTool({
|
|
25
|
+
name: 'system/health',
|
|
26
|
+
description: 'Get system health status',
|
|
27
|
+
inputSchema: { type: 'object', properties: {} },
|
|
28
|
+
handler: async () => await this.getHealthStatus(),
|
|
29
|
+
category: 'system',
|
|
30
|
+
cacheable: true,
|
|
31
|
+
cacheTTL: 2000,
|
|
32
|
+
});
|
|
33
|
+
this.registerTool({
|
|
34
|
+
name: 'system/metrics',
|
|
35
|
+
description: 'Get server metrics',
|
|
36
|
+
inputSchema: { type: 'object', properties: {} },
|
|
37
|
+
handler: async () => this.getMetrics(),
|
|
38
|
+
category: 'system',
|
|
39
|
+
cacheable: true,
|
|
40
|
+
cacheTTL: 1000,
|
|
41
|
+
});
|
|
42
|
+
this.registerTool({
|
|
43
|
+
name: 'tools/list-detailed',
|
|
44
|
+
description: 'List all registered tools with details',
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
category: { type: 'string', description: 'Filter by category' },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
handler: async (input) => {
|
|
52
|
+
const params = input;
|
|
53
|
+
if (params.category) {
|
|
54
|
+
return this.toolRegistry.getByCategory(params.category);
|
|
55
|
+
}
|
|
56
|
+
return this.toolRegistry.listTools();
|
|
57
|
+
},
|
|
58
|
+
category: 'system',
|
|
59
|
+
});
|
|
60
|
+
this.logger.info('Built-in tools registered', {
|
|
61
|
+
count: 4,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// P2-1: Populate the Resources registry with system-level resources.
|
|
65
|
+
// The registry scaffolding always shipped empty — these adapter registrations
|
|
66
|
+
// surface monomind's state to MCP clients as app-driven context.
|
|
67
|
+
registerBuiltInResources() {
|
|
68
|
+
this.resourceRegistry.registerResource({
|
|
69
|
+
uri: 'monomind://system/status',
|
|
70
|
+
name: 'System Status',
|
|
71
|
+
description: 'Current monomind MCP server health, uptime, and tool count',
|
|
72
|
+
mimeType: 'application/json',
|
|
73
|
+
}, async (uri) => [
|
|
74
|
+
{
|
|
75
|
+
uri,
|
|
76
|
+
mimeType: 'application/json',
|
|
77
|
+
text: JSON.stringify({
|
|
78
|
+
status: 'running',
|
|
79
|
+
uptime: this.startTime ? Date.now() - this.startTime.getTime() : 0,
|
|
80
|
+
tools: this.toolRegistry.listTools().length,
|
|
81
|
+
version: this.serverInfo.version,
|
|
82
|
+
}, null, 2),
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
this.resourceRegistry.registerResource({
|
|
86
|
+
uri: 'monomind://system/metrics',
|
|
87
|
+
name: 'Server Metrics',
|
|
88
|
+
description: 'Request count, cache hit rate, error rate',
|
|
89
|
+
mimeType: 'application/json',
|
|
90
|
+
}, async (uri) => [
|
|
91
|
+
{
|
|
92
|
+
uri,
|
|
93
|
+
mimeType: 'application/json',
|
|
94
|
+
text: JSON.stringify(this.getMetrics(), null, 2),
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
this.resourceRegistry.registerResource({
|
|
98
|
+
uri: 'monomind://system/tools',
|
|
99
|
+
name: 'Tool Inventory',
|
|
100
|
+
description: 'Complete list of registered MCP tools with categories',
|
|
101
|
+
mimeType: 'application/json',
|
|
102
|
+
}, async (uri) => [
|
|
103
|
+
{
|
|
104
|
+
uri,
|
|
105
|
+
mimeType: 'application/json',
|
|
106
|
+
text: JSON.stringify(this.toolRegistry.listTools(), null, 2),
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
this.logger.info('Built-in resources registered', { count: 3 });
|
|
110
|
+
}
|
|
111
|
+
// P2-2: Populate the Prompts registry with curated workflow templates.
|
|
112
|
+
// These give MCP clients pre-built prompt structures for common dev tasks.
|
|
113
|
+
registerBuiltInPrompts() {
|
|
114
|
+
this.promptRegistry.register({
|
|
115
|
+
name: 'monomind:research-plan',
|
|
116
|
+
description: 'Generate a structured research plan for a topic',
|
|
117
|
+
arguments: [{ name: 'topic', description: 'The research topic', required: true }],
|
|
118
|
+
handler: async (args) => [
|
|
119
|
+
{
|
|
120
|
+
role: 'user',
|
|
121
|
+
content: {
|
|
122
|
+
type: 'text',
|
|
123
|
+
text: `Research plan for: ${args.topic ?? '(unspecified)'}\n\n1. Define scope and key questions\n2. Identify sources and prior work\n3. Outline methodology\n4. Execute research (parallel agents if appropriate)\n5. Synthesize findings\n6. Review and refine`,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
this.promptRegistry.register({
|
|
129
|
+
name: 'monomind:pr-review',
|
|
130
|
+
description: 'Structured pull-request review checklist',
|
|
131
|
+
arguments: [{ name: 'changes', description: 'Description of the changes', required: true }],
|
|
132
|
+
handler: async (args) => [
|
|
133
|
+
{
|
|
134
|
+
role: 'user',
|
|
135
|
+
content: {
|
|
136
|
+
type: 'text',
|
|
137
|
+
text: `PR Review checklist for: ${args.changes ?? '(unspecified)'}\n\n- [ ] Correctness: does the code do what it claims?\n- [ ] Tests: are there tests covering the changes?\n- [ ] Security: any input validation gaps?\n- [ ] Performance: any O(n²) or unnecessary allocations?\n- [ ] Docs: are relevant docs updated?\n- [ ] Breaking changes: any removed APIs or changed behavior?\n- [ ] Honesty: any fabricated metrics or misleading output?`,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
this.promptRegistry.register({
|
|
143
|
+
name: 'monomind:debug-protocol',
|
|
144
|
+
description: 'Systematic root-cause debugging protocol (4-phase)',
|
|
145
|
+
arguments: [
|
|
146
|
+
{
|
|
147
|
+
name: 'symptom',
|
|
148
|
+
description: 'Description of the bug or unexpected behavior',
|
|
149
|
+
required: true,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
handler: async (args) => [
|
|
153
|
+
{
|
|
154
|
+
role: 'user',
|
|
155
|
+
content: {
|
|
156
|
+
type: 'text',
|
|
157
|
+
text: `Debug protocol for: ${args.symptom ?? '(unspecified)'}\n\nPhase 1 — REPRODUCE: Write a test that triggers the bug. Verify it fails.\nPhase 2 — ISOLATE: Binary-search the cause. What's the smallest change that triggers it?\nPhase 3 — FIX: Make the test pass with the minimal code change.\nPhase 4 — VERIFY: Run the full test suite. Confirm no regressions.`,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
this.logger.info('Built-in prompts registered', { count: 3 });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=server-builtins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-builtins.js","sourceRoot":"","sources":["../src/server-builtins.ts"],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,EAAE,MAAe;wBACrB,IAAI,EAAE,uBAAuB,IAAI,CAAC,OAAO,IAAI,eAAe,8SAA8S;qBAC3W;iBACF;aACF;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monoes/mcp - MCP Server (core)
|
|
3
|
+
*
|
|
4
|
+
* Server state, sub-system wiring, public registry/metrics accessors,
|
|
5
|
+
* per-connection session binding and event forwarding. Extended by the
|
|
6
|
+
* handler layers and finally MCPServer (server.ts).
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'node:events';
|
|
9
|
+
import { type ConnectionPool } from './connection-pool.js';
|
|
10
|
+
import { type PromptRegistry } from './prompt-registry.js';
|
|
11
|
+
import { type RateLimiter } from './rate-limiter.js';
|
|
12
|
+
import { type ResourceRegistry } from './resource-registry.js';
|
|
13
|
+
import { type LLMProvider, type SamplingManager } from './sampling.js';
|
|
14
|
+
import { type SessionManager } from './session-manager.js';
|
|
15
|
+
import { type TaskManager } from './task-manager.js';
|
|
16
|
+
import { type ToolRegistry } from './tool-registry.js';
|
|
17
|
+
import type { ILogger, ITransport, MCPCapabilities, MCPProtocolVersion, MCPResponse, MCPServerConfig, MCPServerMetrics, MCPSession, MCPTool } from './types.js';
|
|
18
|
+
export declare abstract class MCPServerCore extends EventEmitter {
|
|
19
|
+
protected readonly logger: ILogger;
|
|
20
|
+
protected readonly orchestrator?: unknown;
|
|
21
|
+
protected readonly swarmCoordinator?: unknown;
|
|
22
|
+
protected readonly config: MCPServerConfig;
|
|
23
|
+
protected readonly toolRegistry: ToolRegistry;
|
|
24
|
+
protected readonly sessionManager: SessionManager;
|
|
25
|
+
protected readonly resourceRegistry: ResourceRegistry;
|
|
26
|
+
protected readonly promptRegistry: PromptRegistry;
|
|
27
|
+
protected readonly taskManager: TaskManager;
|
|
28
|
+
protected readonly connectionPool?: ConnectionPool;
|
|
29
|
+
protected readonly rateLimiter: RateLimiter;
|
|
30
|
+
protected readonly samplingManager: SamplingManager;
|
|
31
|
+
protected transport?: ITransport;
|
|
32
|
+
protected running: boolean;
|
|
33
|
+
protected startTime?: Date;
|
|
34
|
+
protected startupDuration?: number;
|
|
35
|
+
protected currentSession?: MCPSession;
|
|
36
|
+
protected readonly connectionSessions: Map<string, MCPSession>;
|
|
37
|
+
protected resourceSubscriptions: Map<string, Map<string, string>>;
|
|
38
|
+
protected readonly serverInfo: {
|
|
39
|
+
name: string;
|
|
40
|
+
version: string;
|
|
41
|
+
};
|
|
42
|
+
protected readonly protocolVersion: MCPProtocolVersion;
|
|
43
|
+
protected capabilities: MCPCapabilities;
|
|
44
|
+
protected requestStats: {
|
|
45
|
+
total: number;
|
|
46
|
+
successful: number;
|
|
47
|
+
failed: number;
|
|
48
|
+
totalResponseTime: number;
|
|
49
|
+
};
|
|
50
|
+
constructor(config: Partial<MCPServerConfig>, logger: ILogger, orchestrator?: unknown, swarmCoordinator?: unknown);
|
|
51
|
+
/**
|
|
52
|
+
* Get resource registry for external registration
|
|
53
|
+
*/
|
|
54
|
+
getResourceRegistry(): ResourceRegistry;
|
|
55
|
+
/**
|
|
56
|
+
* Get prompt registry for external registration
|
|
57
|
+
*/
|
|
58
|
+
getPromptRegistry(): PromptRegistry;
|
|
59
|
+
/**
|
|
60
|
+
* Get task manager for async operations
|
|
61
|
+
*/
|
|
62
|
+
getTaskManager(): TaskManager;
|
|
63
|
+
/**
|
|
64
|
+
* Get rate limiter for configuration
|
|
65
|
+
*/
|
|
66
|
+
getRateLimiter(): RateLimiter;
|
|
67
|
+
/**
|
|
68
|
+
* Get sampling manager for LLM provider registration
|
|
69
|
+
*/
|
|
70
|
+
getSamplingManager(): SamplingManager;
|
|
71
|
+
/**
|
|
72
|
+
* Register an LLM provider for sampling
|
|
73
|
+
*/
|
|
74
|
+
registerLLMProvider(provider: LLMProvider, isDefault?: boolean): void;
|
|
75
|
+
registerTool(tool: MCPTool): boolean;
|
|
76
|
+
registerTools(tools: MCPTool[]): {
|
|
77
|
+
registered: number;
|
|
78
|
+
failed: string[];
|
|
79
|
+
};
|
|
80
|
+
unregisterTool(name: string): boolean;
|
|
81
|
+
getHealthStatus(): Promise<{
|
|
82
|
+
healthy: boolean;
|
|
83
|
+
error?: string;
|
|
84
|
+
metrics?: Record<string, number>;
|
|
85
|
+
}>;
|
|
86
|
+
getMetrics(): MCPServerMetrics;
|
|
87
|
+
getSessions(): MCPSession[];
|
|
88
|
+
getSession(sessionId: string): MCPSession | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the session bound to a connection without creating one.
|
|
91
|
+
* Multi-client transports (http, websocket) pass a `connectionId`, which is
|
|
92
|
+
* looked up in `connectionSessions`. Single-client transports (stdio,
|
|
93
|
+
* in-process) omit it, falling back to the `currentSession` singleton.
|
|
94
|
+
*/
|
|
95
|
+
protected getSessionForConnection(connectionId?: string): MCPSession | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Bind a newly-created session to a connection: per-connectionId when the
|
|
98
|
+
* transport supports multiple clients, otherwise the singleton fallback.
|
|
99
|
+
*/
|
|
100
|
+
protected bindSessionToConnection(session: MCPSession, connectionId?: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Tear down the session owned by a connection when the transport reports
|
|
103
|
+
* that connection has closed — prevents closed clients' sessions (and any
|
|
104
|
+
* resource subscriptions) from lingering until the idle-timeout sweep.
|
|
105
|
+
*/
|
|
106
|
+
protected closeConnectionSession(connectionId: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Detach every registry subscription owned by a session. Called whenever a
|
|
109
|
+
* session ends (terminated, connection closed, expired, server stopped) so
|
|
110
|
+
* no update callback outlives its session (issue #92).
|
|
111
|
+
*/
|
|
112
|
+
protected purgeSessionSubscriptions(sessionId: string): void;
|
|
113
|
+
protected sendNotification(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
114
|
+
protected getOrCreateSession(connectionId?: string): MCPSession;
|
|
115
|
+
protected createErrorResponse(id: string | number | null, code: number, message: string): MCPResponse;
|
|
116
|
+
private setupEventHandlers;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=server-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-core.d.ts","sourceRoot":"","sources":["../src/server-core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAyB,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,OAAO,EACR,MAAM,YAAY,CAAC;AAgBpB,8BAAsB,aAAc,SAAQ,YAAY;IA2DpD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO;IAClC,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO;IACzC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO;IA5D/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,eA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AAC,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAS3D;IAMD,UAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAQf;IAED,SAAS,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,UAAU,CAa9D;IAED,SAAS,CAAC,mBAAmB,CAC3B,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,WAAW,CAMb;IAED,OAAO,CAAC,kBAAkB;CA2C3B"}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monoes/mcp - MCP Server (core)
|
|
3
|
+
*
|
|
4
|
+
* Server state, sub-system wiring, public registry/metrics accessors,
|
|
5
|
+
* per-connection session binding and event forwarding. Extended by the
|
|
6
|
+
* handler layers and finally MCPServer (server.ts).
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'node:events';
|
|
9
|
+
import { createConnectionPool } from './connection-pool.js';
|
|
10
|
+
import { createPromptRegistry } from './prompt-registry.js';
|
|
11
|
+
import { createRateLimiter } from './rate-limiter.js';
|
|
12
|
+
import { createResourceRegistry } from './resource-registry.js';
|
|
13
|
+
import { createSamplingManager } from './sampling.js';
|
|
14
|
+
import { createSessionManager } from './session-manager.js';
|
|
15
|
+
import { createTaskManager } from './task-manager.js';
|
|
16
|
+
import { createToolRegistry } from './tool-registry.js';
|
|
17
|
+
const DEFAULT_CONFIG = {
|
|
18
|
+
name: 'Monomind MCP Server V1',
|
|
19
|
+
version: '3.0.0',
|
|
20
|
+
transport: 'stdio',
|
|
21
|
+
host: 'localhost',
|
|
22
|
+
port: 3000,
|
|
23
|
+
enableMetrics: true,
|
|
24
|
+
enableCaching: true,
|
|
25
|
+
cacheTTL: 10000,
|
|
26
|
+
logLevel: 'info',
|
|
27
|
+
requestTimeout: 30000,
|
|
28
|
+
maxRequestSize: 10 * 1024 * 1024,
|
|
29
|
+
};
|
|
30
|
+
export class MCPServerCore extends EventEmitter {
|
|
31
|
+
logger;
|
|
32
|
+
orchestrator;
|
|
33
|
+
swarmCoordinator;
|
|
34
|
+
config;
|
|
35
|
+
toolRegistry;
|
|
36
|
+
sessionManager;
|
|
37
|
+
resourceRegistry;
|
|
38
|
+
promptRegistry;
|
|
39
|
+
taskManager;
|
|
40
|
+
connectionPool;
|
|
41
|
+
rateLimiter;
|
|
42
|
+
samplingManager;
|
|
43
|
+
transport;
|
|
44
|
+
running = false;
|
|
45
|
+
startTime;
|
|
46
|
+
startupDuration;
|
|
47
|
+
// Fallback singleton session, used only for transports that are inherently
|
|
48
|
+
// single-client (stdio, in-process) where the transport never supplies a
|
|
49
|
+
// connectionId to handleRequest/handleNotification.
|
|
50
|
+
currentSession;
|
|
51
|
+
// connectionId -> session, for multi-client transports (http, websocket).
|
|
52
|
+
// Without this, every connection shared `currentSession` above and a
|
|
53
|
+
// second client's `initialize` would silently reassign the session out
|
|
54
|
+
// from under the first client (issue #93).
|
|
55
|
+
connectionSessions = new Map();
|
|
56
|
+
// sessionId -> (uri -> subscriptionId). The registry-issued subscriptionId
|
|
57
|
+
// must be retained so resources/unsubscribe (and session teardown) can call
|
|
58
|
+
// resourceRegistry.unsubscribe(id) — without it callbacks leak and phantom
|
|
59
|
+
// notifications fire after unsubscribe (issue #92).
|
|
60
|
+
resourceSubscriptions = new Map();
|
|
61
|
+
serverInfo = {
|
|
62
|
+
name: 'Monomind MCP Server V1',
|
|
63
|
+
version: '3.0.0',
|
|
64
|
+
};
|
|
65
|
+
// MCP 2025-11-25 protocol version
|
|
66
|
+
protocolVersion = {
|
|
67
|
+
major: 2025,
|
|
68
|
+
minor: 11,
|
|
69
|
+
patch: 25,
|
|
70
|
+
};
|
|
71
|
+
// Full MCP 2025-11-25 capabilities
|
|
72
|
+
capabilities = {
|
|
73
|
+
logging: { level: 'info' },
|
|
74
|
+
tools: { listChanged: true },
|
|
75
|
+
resources: { listChanged: true, subscribe: true },
|
|
76
|
+
prompts: { listChanged: true },
|
|
77
|
+
sampling: {},
|
|
78
|
+
};
|
|
79
|
+
requestStats = {
|
|
80
|
+
total: 0,
|
|
81
|
+
successful: 0,
|
|
82
|
+
failed: 0,
|
|
83
|
+
totalResponseTime: 0,
|
|
84
|
+
};
|
|
85
|
+
constructor(config, logger, orchestrator, swarmCoordinator) {
|
|
86
|
+
super();
|
|
87
|
+
this.logger = logger;
|
|
88
|
+
this.orchestrator = orchestrator;
|
|
89
|
+
this.swarmCoordinator = swarmCoordinator;
|
|
90
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
91
|
+
this.toolRegistry = createToolRegistry(logger);
|
|
92
|
+
this.sessionManager = createSessionManager(logger, {
|
|
93
|
+
maxSessions: 100,
|
|
94
|
+
sessionTimeout: 30 * 60 * 1000,
|
|
95
|
+
});
|
|
96
|
+
this.resourceRegistry = createResourceRegistry(logger, {
|
|
97
|
+
enableSubscriptions: true,
|
|
98
|
+
cacheEnabled: true,
|
|
99
|
+
cacheTTL: 60000,
|
|
100
|
+
});
|
|
101
|
+
this.promptRegistry = createPromptRegistry(logger);
|
|
102
|
+
this.taskManager = createTaskManager(logger, {
|
|
103
|
+
maxConcurrentTasks: 10,
|
|
104
|
+
taskTimeout: 300000,
|
|
105
|
+
});
|
|
106
|
+
this.rateLimiter = createRateLimiter(logger, {
|
|
107
|
+
requestsPerSecond: 100,
|
|
108
|
+
burstSize: 200,
|
|
109
|
+
perSessionLimit: 50,
|
|
110
|
+
});
|
|
111
|
+
this.samplingManager = createSamplingManager(logger);
|
|
112
|
+
if (this.config.connectionPool) {
|
|
113
|
+
this.connectionPool = createConnectionPool(this.config.connectionPool, logger, this.config.transport);
|
|
114
|
+
}
|
|
115
|
+
this.setupEventHandlers();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get resource registry for external registration
|
|
119
|
+
*/
|
|
120
|
+
getResourceRegistry() {
|
|
121
|
+
return this.resourceRegistry;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get prompt registry for external registration
|
|
125
|
+
*/
|
|
126
|
+
getPromptRegistry() {
|
|
127
|
+
return this.promptRegistry;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get task manager for async operations
|
|
131
|
+
*/
|
|
132
|
+
getTaskManager() {
|
|
133
|
+
return this.taskManager;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get rate limiter for configuration
|
|
137
|
+
*/
|
|
138
|
+
getRateLimiter() {
|
|
139
|
+
return this.rateLimiter;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get sampling manager for LLM provider registration
|
|
143
|
+
*/
|
|
144
|
+
getSamplingManager() {
|
|
145
|
+
return this.samplingManager;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Register an LLM provider for sampling
|
|
149
|
+
*/
|
|
150
|
+
registerLLMProvider(provider, isDefault = false) {
|
|
151
|
+
this.samplingManager.registerProvider(provider, isDefault);
|
|
152
|
+
}
|
|
153
|
+
registerTool(tool) {
|
|
154
|
+
return this.toolRegistry.register(tool);
|
|
155
|
+
}
|
|
156
|
+
registerTools(tools) {
|
|
157
|
+
return this.toolRegistry.registerBatch(tools);
|
|
158
|
+
}
|
|
159
|
+
unregisterTool(name) {
|
|
160
|
+
return this.toolRegistry.unregister(name);
|
|
161
|
+
}
|
|
162
|
+
async getHealthStatus() {
|
|
163
|
+
try {
|
|
164
|
+
const transportHealth = this.transport
|
|
165
|
+
? await this.transport.getHealthStatus()
|
|
166
|
+
: { healthy: false, error: 'Transport not initialized' };
|
|
167
|
+
const sessionMetrics = this.sessionManager.getSessionMetrics();
|
|
168
|
+
const poolStats = this.connectionPool?.getStats();
|
|
169
|
+
const metrics = {
|
|
170
|
+
registeredTools: this.toolRegistry.getToolCount(),
|
|
171
|
+
totalRequests: this.requestStats.total,
|
|
172
|
+
successfulRequests: this.requestStats.successful,
|
|
173
|
+
failedRequests: this.requestStats.failed,
|
|
174
|
+
totalSessions: sessionMetrics.total,
|
|
175
|
+
activeSessions: sessionMetrics.active,
|
|
176
|
+
...(transportHealth.metrics || {}),
|
|
177
|
+
};
|
|
178
|
+
if (poolStats) {
|
|
179
|
+
metrics.poolConnections = poolStats.totalConnections;
|
|
180
|
+
metrics.poolIdleConnections = poolStats.idleConnections;
|
|
181
|
+
metrics.poolBusyConnections = poolStats.busyConnections;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
healthy: this.running && transportHealth.healthy,
|
|
185
|
+
error: transportHealth.error,
|
|
186
|
+
metrics,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return {
|
|
191
|
+
healthy: false,
|
|
192
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
getMetrics() {
|
|
197
|
+
const sessionMetrics = this.sessionManager.getSessionMetrics();
|
|
198
|
+
const registryStats = this.toolRegistry.getStats();
|
|
199
|
+
return {
|
|
200
|
+
totalRequests: this.requestStats.total,
|
|
201
|
+
successfulRequests: this.requestStats.successful,
|
|
202
|
+
failedRequests: this.requestStats.failed,
|
|
203
|
+
averageResponseTime: this.requestStats.total > 0
|
|
204
|
+
? this.requestStats.totalResponseTime / this.requestStats.total
|
|
205
|
+
: 0,
|
|
206
|
+
activeSessions: sessionMetrics.active,
|
|
207
|
+
toolInvocations: Object.fromEntries(registryStats.topTools.map((t) => [t.name, t.calls])),
|
|
208
|
+
errors: {},
|
|
209
|
+
lastReset: this.startTime || new Date(),
|
|
210
|
+
startupTime: this.startupDuration,
|
|
211
|
+
uptime: this.startTime ? Date.now() - this.startTime.getTime() : 0,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
getSessions() {
|
|
215
|
+
return this.sessionManager.getActiveSessions();
|
|
216
|
+
}
|
|
217
|
+
getSession(sessionId) {
|
|
218
|
+
return this.sessionManager.getSession(sessionId);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolve the session bound to a connection without creating one.
|
|
222
|
+
* Multi-client transports (http, websocket) pass a `connectionId`, which is
|
|
223
|
+
* looked up in `connectionSessions`. Single-client transports (stdio,
|
|
224
|
+
* in-process) omit it, falling back to the `currentSession` singleton.
|
|
225
|
+
*/
|
|
226
|
+
getSessionForConnection(connectionId) {
|
|
227
|
+
if (connectionId) {
|
|
228
|
+
return this.connectionSessions.get(connectionId);
|
|
229
|
+
}
|
|
230
|
+
return this.currentSession;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Bind a newly-created session to a connection: per-connectionId when the
|
|
234
|
+
* transport supports multiple clients, otherwise the singleton fallback.
|
|
235
|
+
*/
|
|
236
|
+
bindSessionToConnection(session, connectionId) {
|
|
237
|
+
if (connectionId) {
|
|
238
|
+
this.connectionSessions.set(connectionId, session);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
this.currentSession = session;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Tear down the session owned by a connection when the transport reports
|
|
246
|
+
* that connection has closed — prevents closed clients' sessions (and any
|
|
247
|
+
* resource subscriptions) from lingering until the idle-timeout sweep.
|
|
248
|
+
*/
|
|
249
|
+
closeConnectionSession(connectionId) {
|
|
250
|
+
const session = this.connectionSessions.get(connectionId);
|
|
251
|
+
this.connectionSessions.delete(connectionId);
|
|
252
|
+
if (session) {
|
|
253
|
+
// closeSession emits 'session:closed', which purges the session's
|
|
254
|
+
// resource subscriptions (see setupEventHandlers).
|
|
255
|
+
this.sessionManager.closeSession(session.id, 'Connection closed');
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Detach every registry subscription owned by a session. Called whenever a
|
|
260
|
+
* session ends (terminated, connection closed, expired, server stopped) so
|
|
261
|
+
* no update callback outlives its session (issue #92).
|
|
262
|
+
*/
|
|
263
|
+
purgeSessionSubscriptions(sessionId) {
|
|
264
|
+
const sessionSubs = this.resourceSubscriptions.get(sessionId);
|
|
265
|
+
if (!sessionSubs) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
for (const subscriptionId of sessionSubs.values()) {
|
|
269
|
+
this.resourceRegistry.unsubscribe(subscriptionId);
|
|
270
|
+
}
|
|
271
|
+
this.resourceSubscriptions.delete(sessionId);
|
|
272
|
+
}
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Notification Sender
|
|
275
|
+
// ============================================================================
|
|
276
|
+
async sendNotification(method, params) {
|
|
277
|
+
if (this.transport?.sendNotification) {
|
|
278
|
+
await this.transport.sendNotification({
|
|
279
|
+
jsonrpc: '2.0',
|
|
280
|
+
method,
|
|
281
|
+
params,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
getOrCreateSession(connectionId) {
|
|
286
|
+
const existing = this.getSessionForConnection(connectionId);
|
|
287
|
+
if (existing) {
|
|
288
|
+
return existing;
|
|
289
|
+
}
|
|
290
|
+
// A client is calling a non-initialize method on a connection that never
|
|
291
|
+
// sent `initialize` (or whose session already expired). Create a fresh
|
|
292
|
+
// session bound to this specific connection rather than reusing/
|
|
293
|
+
// overwriting another client's session.
|
|
294
|
+
const session = this.sessionManager.createSession(this.config.transport);
|
|
295
|
+
this.bindSessionToConnection(session, connectionId);
|
|
296
|
+
return session;
|
|
297
|
+
}
|
|
298
|
+
createErrorResponse(id, code, message) {
|
|
299
|
+
return {
|
|
300
|
+
jsonrpc: '2.0',
|
|
301
|
+
id,
|
|
302
|
+
error: { code, message },
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
setupEventHandlers() {
|
|
306
|
+
this.toolRegistry.on('tool:registered', (name) => {
|
|
307
|
+
this.emit('tool:registered', name);
|
|
308
|
+
});
|
|
309
|
+
this.toolRegistry.on('tool:called', (data) => {
|
|
310
|
+
this.emit('tool:called', data);
|
|
311
|
+
});
|
|
312
|
+
this.toolRegistry.on('tool:completed', (data) => {
|
|
313
|
+
this.emit('tool:completed', data);
|
|
314
|
+
});
|
|
315
|
+
this.toolRegistry.on('tool:error', (data) => {
|
|
316
|
+
this.emit('tool:error', data);
|
|
317
|
+
});
|
|
318
|
+
this.sessionManager.on('session:created', (session) => {
|
|
319
|
+
this.emit('session:created', session);
|
|
320
|
+
});
|
|
321
|
+
this.sessionManager.on('session:closed', (data) => {
|
|
322
|
+
this.purgeSessionSubscriptions(data.session.id);
|
|
323
|
+
this.emit('session:closed', data);
|
|
324
|
+
});
|
|
325
|
+
this.sessionManager.on('session:expired', (session) => {
|
|
326
|
+
this.purgeSessionSubscriptions(session.id);
|
|
327
|
+
// Drop references to the expired session — otherwise `currentSession` /
|
|
328
|
+
// `connectionSessions` keep pointing at a session the manager has
|
|
329
|
+
// already reaped, and subsequent updateActivity calls fail silently
|
|
330
|
+
// against the ghost (issue #93).
|
|
331
|
+
if (this.currentSession?.id === session.id) {
|
|
332
|
+
this.currentSession = undefined;
|
|
333
|
+
}
|
|
334
|
+
for (const [connectionId, s] of this.connectionSessions) {
|
|
335
|
+
if (s.id === session.id) {
|
|
336
|
+
this.connectionSessions.delete(connectionId);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this.emit('session:expired', session);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=server-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-core.js","sourceRoot":"","sources":["../src/server-core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAuB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AACjF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