@defai.digital/mcp-ecosystem 13.4.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/LICENSE +38 -0
- package/dist/ecosystem-manager.d.ts +31 -0
- package/dist/ecosystem-manager.d.ts.map +1 -0
- package/dist/ecosystem-manager.js +160 -0
- package/dist/ecosystem-manager.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/server-registry.d.ts +96 -0
- package/dist/server-registry.d.ts.map +1 -0
- package/dist/server-registry.js +230 -0
- package/dist/server-registry.js.map +1 -0
- package/dist/tool-discovery.d.ts +94 -0
- package/dist/tool-discovery.d.ts.map +1 -0
- package/dist/tool-discovery.js +226 -0
- package/dist/tool-discovery.js.map +1 -0
- package/dist/tool-router.d.ts +67 -0
- package/dist/tool-router.d.ts.map +1 -0
- package/dist/tool-router.js +151 -0
- package/dist/tool-router.js.map +1 -0
- package/dist/types.d.ts +337 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +197 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: DEFAI Private Limited
|
|
6
|
+
Licensed Work: AutomatosX
|
|
7
|
+
The Licensed Work is (c) 2024-2025 DEFAI Private Limited
|
|
8
|
+
Additional Use Grant: You may make production use of the Licensed Work,
|
|
9
|
+
provided that your organization has less than US$2,000,000 in annual gross
|
|
10
|
+
revenue in the prior fiscal year. "Production use" means use in a live
|
|
11
|
+
production environment to support business or operational activities for end
|
|
12
|
+
users.
|
|
13
|
+
Change Date: Four years after the release date of the Licensed Work version
|
|
14
|
+
Change License: Apache License, Version 2.0
|
|
15
|
+
|
|
16
|
+
Terms
|
|
17
|
+
|
|
18
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
19
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
20
|
+
Licensor may make an Additional Use Grant, above, permitting other uses of the
|
|
21
|
+
Licensed Work. The rights granted to you under this license are subject to the
|
|
22
|
+
following condition.
|
|
23
|
+
|
|
24
|
+
If you make any use of the Licensed Work, you must ensure that the Licensed
|
|
25
|
+
Work, or any modified version of it, carries prominent notices stating that
|
|
26
|
+
you have modified the Licensed Work.
|
|
27
|
+
|
|
28
|
+
This license does not grant permission to use the Licensor's trademarks.
|
|
29
|
+
|
|
30
|
+
The Licensed Work is provided "as is", without warranty of any kind, express
|
|
31
|
+
or implied, including but not limited to the warranties of merchantability,
|
|
32
|
+
fitness for a particular purpose and noninfringement. In no event shall the
|
|
33
|
+
Licensor be liable for any claim, damages or other liability, whether in an
|
|
34
|
+
action of contract, tort or otherwise, arising from, out of or in connection
|
|
35
|
+
with the Licensed Work or the use or other dealings in the Licensed Work.
|
|
36
|
+
|
|
37
|
+
On the Change Date, the Licensed Work will be made available under the Change
|
|
38
|
+
License.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Ecosystem Manager
|
|
3
|
+
*
|
|
4
|
+
* High-level manager for MCP ecosystem operations.
|
|
5
|
+
* Combines server registry, tool discovery, and tool routing.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-MCP-ECO-001: Tool discovery is idempotent
|
|
9
|
+
* - INV-MCP-ECO-002: Failed servers don't block others
|
|
10
|
+
* - INV-MCP-ECO-003: Tool namespacing prevents collisions
|
|
11
|
+
*/
|
|
12
|
+
import type { MCPEcosystemManager, MCPEcosystemManagerOptions } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown by ecosystem manager
|
|
15
|
+
*/
|
|
16
|
+
export declare class MCPEcosystemError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
19
|
+
constructor(code: string, message: string, details?: Record<string, unknown> | undefined);
|
|
20
|
+
static serverNotFound(serverId: string): MCPEcosystemError;
|
|
21
|
+
static toolNotFound(toolName: string): MCPEcosystemError;
|
|
22
|
+
static ambiguousTool(toolName: string, matches: string[]): MCPEcosystemError;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an MCP ecosystem manager
|
|
26
|
+
*/
|
|
27
|
+
export declare function createMCPEcosystemManager(options: MCPEcosystemManagerOptions): MCPEcosystemManager;
|
|
28
|
+
export { createServerRegistryService, ServerRegistryError, type ServerRegistryService, type ServerRegistryServiceOptions, } from './server-registry.js';
|
|
29
|
+
export { createToolDiscoveryService, type ToolDiscoveryService, type ToolDiscoveryServiceOptions, type ServerDiscoveryResult, } from './tool-discovery.js';
|
|
30
|
+
export { createToolRouterService, ToolRouterError, type ToolRouterService, type ToolRouterServiceOptions, } from './tool-router.js';
|
|
31
|
+
//# sourceMappingURL=ecosystem-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecosystem-manager.d.ts","sourceRoot":"","sources":["../src/ecosystem-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAKpB;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;aAExB,IAAI,EAAE,MAAM;aAEZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAMnD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB;IAQ1D,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB;IAQxD,MAAM,CAAC,aAAa,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,GAChB,iBAAiB;CAOrB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAiJrB;AAGD,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,GAClC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Ecosystem Manager
|
|
3
|
+
*
|
|
4
|
+
* High-level manager for MCP ecosystem operations.
|
|
5
|
+
* Combines server registry, tool discovery, and tool routing.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-MCP-ECO-001: Tool discovery is idempotent
|
|
9
|
+
* - INV-MCP-ECO-002: Failed servers don't block others
|
|
10
|
+
* - INV-MCP-ECO-003: Tool namespacing prevents collisions
|
|
11
|
+
*/
|
|
12
|
+
import { MCPEcosystemErrorCodes, LIMIT_DEFAULT } from '@defai.digital/contracts';
|
|
13
|
+
import { createServerRegistryService } from './server-registry.js';
|
|
14
|
+
import { createToolDiscoveryService } from './tool-discovery.js';
|
|
15
|
+
import { createToolRouterService, ToolRouterError } from './tool-router.js';
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown by ecosystem manager
|
|
18
|
+
*/
|
|
19
|
+
export class MCPEcosystemError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
details;
|
|
22
|
+
constructor(code, message, details) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.details = details;
|
|
26
|
+
this.name = 'MCPEcosystemError';
|
|
27
|
+
}
|
|
28
|
+
static serverNotFound(serverId) {
|
|
29
|
+
return new MCPEcosystemError(MCPEcosystemErrorCodes.SERVER_NOT_FOUND, `Server not found: ${serverId}`, { serverId });
|
|
30
|
+
}
|
|
31
|
+
static toolNotFound(toolName) {
|
|
32
|
+
return new MCPEcosystemError(MCPEcosystemErrorCodes.TOOL_NOT_FOUND, `Tool not found: ${toolName}`, { toolName });
|
|
33
|
+
}
|
|
34
|
+
static ambiguousTool(toolName, matches) {
|
|
35
|
+
return new MCPEcosystemError(MCPEcosystemErrorCodes.AMBIGUOUS_TOOL, `Ambiguous tool name "${toolName}". Matches: ${matches.join(', ')}`, { toolName, matches });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates an MCP ecosystem manager
|
|
40
|
+
*/
|
|
41
|
+
export function createMCPEcosystemManager(options) {
|
|
42
|
+
const { serverRegistry: serverStorage, toolRegistry, resourceRegistry, clientFactory, defaultConnectionTimeoutMs = 10000, defaultRequestTimeoutMs = 60000, } = options;
|
|
43
|
+
// Create server registry service
|
|
44
|
+
const serverRegistryService = createServerRegistryService({
|
|
45
|
+
storage: serverStorage,
|
|
46
|
+
clientFactory,
|
|
47
|
+
defaultConnectionTimeoutMs,
|
|
48
|
+
});
|
|
49
|
+
// Create tool discovery service
|
|
50
|
+
const toolDiscoveryService = createToolDiscoveryService({
|
|
51
|
+
serverRegistry: serverRegistryService,
|
|
52
|
+
toolRegistry,
|
|
53
|
+
resourceRegistry,
|
|
54
|
+
serverStorage,
|
|
55
|
+
});
|
|
56
|
+
// Create tool router service
|
|
57
|
+
const toolRouterService = createToolRouterService({
|
|
58
|
+
serverRegistry: serverRegistryService,
|
|
59
|
+
toolDiscovery: toolDiscoveryService,
|
|
60
|
+
defaultRequestTimeoutMs,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
async registerServer(request) {
|
|
64
|
+
const response = await serverRegistryService.register(request);
|
|
65
|
+
// Discover tools if requested and connected
|
|
66
|
+
if (response.success &&
|
|
67
|
+
request.discoverNow !== false &&
|
|
68
|
+
response.server?.status === 'connected') {
|
|
69
|
+
try {
|
|
70
|
+
const discoveryResult = await toolDiscoveryService.discoverServer(request.serverId);
|
|
71
|
+
if (discoveryResult.status === 'success') {
|
|
72
|
+
response.tools = await toolDiscoveryService.getToolsForServer(request.serverId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Ignore discovery errors during registration
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
},
|
|
81
|
+
async unregisterServer(serverId) {
|
|
82
|
+
// Clear tools and resources
|
|
83
|
+
await toolRegistry.clearTools(serverId);
|
|
84
|
+
await resourceRegistry.clearResources(serverId);
|
|
85
|
+
return serverRegistryService.unregister(serverId);
|
|
86
|
+
},
|
|
87
|
+
async getServer(serverId) {
|
|
88
|
+
return serverRegistryService.get(serverId);
|
|
89
|
+
},
|
|
90
|
+
async listServers(request = {}) {
|
|
91
|
+
return serverRegistryService.list({
|
|
92
|
+
limit: request.limit ?? LIMIT_DEFAULT,
|
|
93
|
+
offset: request.offset ?? 0,
|
|
94
|
+
status: request.status,
|
|
95
|
+
enabled: request.enabled,
|
|
96
|
+
capability: request.capability,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
async connectServer(serverId) {
|
|
100
|
+
try {
|
|
101
|
+
await serverRegistryService.connect(serverId);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async disconnectServer(serverId) {
|
|
109
|
+
try {
|
|
110
|
+
await serverRegistryService.disconnect(serverId);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async discover(request = {}) {
|
|
118
|
+
return toolDiscoveryService.discover({
|
|
119
|
+
forceRefresh: request.forceRefresh ?? false,
|
|
120
|
+
includeDisabled: request.includeDisabled ?? false,
|
|
121
|
+
serverIds: request.serverIds,
|
|
122
|
+
filterCapability: request.filterCapability,
|
|
123
|
+
filterCategory: request.filterCategory,
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
async invokeTool(request) {
|
|
127
|
+
return toolRouterService.invoke(request);
|
|
128
|
+
},
|
|
129
|
+
async getTools(serverId) {
|
|
130
|
+
if (serverId) {
|
|
131
|
+
return toolDiscoveryService.getToolsForServer(serverId);
|
|
132
|
+
}
|
|
133
|
+
return toolDiscoveryService.getAllTools();
|
|
134
|
+
},
|
|
135
|
+
async getResources(serverId) {
|
|
136
|
+
if (serverId) {
|
|
137
|
+
return toolDiscoveryService.getResourcesForServer(serverId);
|
|
138
|
+
}
|
|
139
|
+
return toolDiscoveryService.getAllResources();
|
|
140
|
+
},
|
|
141
|
+
async findTool(toolName) {
|
|
142
|
+
try {
|
|
143
|
+
const tool = await toolRouterService.resolveTool(toolName);
|
|
144
|
+
return tool;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (error instanceof ToolRouterError &&
|
|
148
|
+
error.code === MCPEcosystemErrorCodes.AMBIGUOUS_TOOL) {
|
|
149
|
+
throw MCPEcosystemError.ambiguousTool(toolName, error.details?.matches ?? []);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// Re-export services and errors
|
|
157
|
+
export { createServerRegistryService, ServerRegistryError, } from './server-registry.js';
|
|
158
|
+
export { createToolDiscoveryService, } from './tool-discovery.js';
|
|
159
|
+
export { createToolRouterService, ToolRouterError, } from './tool-router.js';
|
|
160
|
+
//# sourceMappingURL=ecosystem-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecosystem-manager.js","sourceRoot":"","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MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,eAAe,GAGhB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Ecosystem Domain
|
|
3
|
+
*
|
|
4
|
+
* Provides integration with external MCP servers for tool discovery
|
|
5
|
+
* and invocation.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export type { MCPClientPort, MCPClientFactory, MCPContentBlock, MCPToolInfo, MCPResourceInfo, MCPToolResult, MCPResourceContent, ServerRegistryPort, ToolRegistryPort, ResourceRegistryPort, MCPEcosystemManager, MCPEcosystemManagerOptions, } from './types.js';
|
|
10
|
+
export { StubMCPClient, StubMCPClientFactory, InMemoryServerRegistry, InMemoryToolRegistry, InMemoryResourceRegistry, } from './types.js';
|
|
11
|
+
export { createServerRegistryService, ServerRegistryError, type ServerRegistryService, type ServerRegistryServiceOptions, } from './server-registry.js';
|
|
12
|
+
export { createToolDiscoveryService, type ToolDiscoveryService, type ToolDiscoveryServiceOptions, type ServerDiscoveryResult, } from './tool-discovery.js';
|
|
13
|
+
export { createToolRouterService, ToolRouterError, type ToolRouterService, type ToolRouterServiceOptions, } from './tool-router.js';
|
|
14
|
+
export { createMCPEcosystemManager, MCPEcosystemError, } from './ecosystem-manager.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,GAClC,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,GAC3B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Ecosystem Domain
|
|
3
|
+
*
|
|
4
|
+
* Provides integration with external MCP servers for tool discovery
|
|
5
|
+
* and invocation.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// Stub implementations for testing
|
|
10
|
+
export { StubMCPClient, StubMCPClientFactory, InMemoryServerRegistry, InMemoryToolRegistry, InMemoryResourceRegistry, } from './types.js';
|
|
11
|
+
// Server registry
|
|
12
|
+
export { createServerRegistryService, ServerRegistryError, } from './server-registry.js';
|
|
13
|
+
// Tool discovery
|
|
14
|
+
export { createToolDiscoveryService, } from './tool-discovery.js';
|
|
15
|
+
// Tool router
|
|
16
|
+
export { createToolRouterService, ToolRouterError, } from './tool-router.js';
|
|
17
|
+
// Ecosystem manager
|
|
18
|
+
export { createMCPEcosystemManager, MCPEcosystemError, } from './ecosystem-manager.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH,mCAAmC;AACnC,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,kBAAkB;AAClB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,GAGpB,MAAM,sBAAsB,CAAC;AAE9B,iBAAiB;AACjB,OAAO,EACL,0BAA0B,GAI3B,MAAM,qBAAqB,CAAC;AAE7B,cAAc;AACd,OAAO,EACL,uBAAuB,EACvB,eAAe,GAGhB,MAAM,kBAAkB,CAAC;AAE1B,oBAAoB;AACpB,OAAO,EACL,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages MCP server registrations and state.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-MCP-ECO-003: Server IDs must be unique
|
|
8
|
+
* - INV-MCP-ECO-200: Server state consistency
|
|
9
|
+
* - INV-MCP-ECO-201: Disabled servers not connected
|
|
10
|
+
*/
|
|
11
|
+
import type { MCPServerConfig, MCPServerState, MCPServerStatus, MCPServerRegisterRequest, MCPServerRegisterResponse, MCPServerListRequest, MCPServerListResponse } from '@defai.digital/contracts';
|
|
12
|
+
import type { ServerRegistryPort, MCPClientPort, MCPClientFactory } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown by server registry operations
|
|
15
|
+
*/
|
|
16
|
+
export declare class ServerRegistryError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
19
|
+
constructor(code: string, message: string, details?: Record<string, unknown> | undefined);
|
|
20
|
+
static serverNotFound(serverId: string): ServerRegistryError;
|
|
21
|
+
static serverExists(serverId: string): ServerRegistryError;
|
|
22
|
+
static connectionFailed(serverId: string, message: string): ServerRegistryError;
|
|
23
|
+
static invalidConfig(message: string): ServerRegistryError;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options for server registry service
|
|
27
|
+
*/
|
|
28
|
+
export interface ServerRegistryServiceOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Storage port for server state
|
|
31
|
+
*/
|
|
32
|
+
storage: ServerRegistryPort;
|
|
33
|
+
/**
|
|
34
|
+
* Factory for creating MCP clients
|
|
35
|
+
*/
|
|
36
|
+
clientFactory: MCPClientFactory;
|
|
37
|
+
/**
|
|
38
|
+
* Default connection timeout in ms
|
|
39
|
+
*/
|
|
40
|
+
defaultConnectionTimeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Server registry service
|
|
44
|
+
*
|
|
45
|
+
* Manages server registrations and connections.
|
|
46
|
+
*/
|
|
47
|
+
export interface ServerRegistryService {
|
|
48
|
+
/**
|
|
49
|
+
* Register a new server
|
|
50
|
+
* INV-MCP-ECO-003: Validates unique server ID
|
|
51
|
+
*/
|
|
52
|
+
register(request: MCPServerRegisterRequest): Promise<MCPServerRegisterResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Unregister a server
|
|
55
|
+
*/
|
|
56
|
+
unregister(serverId: string): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Update server configuration
|
|
59
|
+
*/
|
|
60
|
+
update(serverId: string, config: Partial<MCPServerConfig>): Promise<MCPServerState>;
|
|
61
|
+
/**
|
|
62
|
+
* Get server state
|
|
63
|
+
*/
|
|
64
|
+
get(serverId: string): Promise<MCPServerState | null>;
|
|
65
|
+
/**
|
|
66
|
+
* List servers
|
|
67
|
+
*/
|
|
68
|
+
list(request?: MCPServerListRequest): Promise<MCPServerListResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Connect to a server
|
|
71
|
+
* INV-MCP-ECO-201: Validates server is enabled
|
|
72
|
+
*/
|
|
73
|
+
connect(serverId: string): Promise<MCPClientPort>;
|
|
74
|
+
/**
|
|
75
|
+
* Disconnect from a server
|
|
76
|
+
*/
|
|
77
|
+
disconnect(serverId: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Update server status
|
|
80
|
+
* INV-MCP-ECO-200: State consistency
|
|
81
|
+
*/
|
|
82
|
+
updateStatus(serverId: string, status: MCPServerStatus, error?: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Get active client for server
|
|
85
|
+
*/
|
|
86
|
+
getClient(serverId: string): MCPClientPort | null;
|
|
87
|
+
/**
|
|
88
|
+
* Get all enabled server IDs
|
|
89
|
+
*/
|
|
90
|
+
getEnabledServerIds(): Promise<string[]>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates a server registry service
|
|
94
|
+
*/
|
|
95
|
+
export declare function createServerRegistryService(options: ServerRegistryServiceOptions): ServerRegistryService;
|
|
96
|
+
//# sourceMappingURL=server-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-registry.d.ts","sourceRoot":"","sources":["../src/server-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEtF;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,IAAI,EAAE,MAAM;aAEZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAMnD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB;IAQ5D,MAAM,C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AAC,IAAI,CAAC,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;IAElD;;OAEG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC1C;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GACpC,qBAAqB,CAoOvB"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages MCP server registrations and state.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-MCP-ECO-003: Server IDs must be unique
|
|
8
|
+
* - INV-MCP-ECO-200: Server state consistency
|
|
9
|
+
* - INV-MCP-ECO-201: Disabled servers not connected
|
|
10
|
+
*/
|
|
11
|
+
import { MCPEcosystemErrorCodes, createInitialServerState, LIMIT_DEFAULT, } from '@defai.digital/contracts';
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown by server registry operations
|
|
14
|
+
*/
|
|
15
|
+
export class ServerRegistryError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
details;
|
|
18
|
+
constructor(code, message, details) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.details = details;
|
|
22
|
+
this.name = 'ServerRegistryError';
|
|
23
|
+
}
|
|
24
|
+
static serverNotFound(serverId) {
|
|
25
|
+
return new ServerRegistryError(MCPEcosystemErrorCodes.SERVER_NOT_FOUND, `Server not found: ${serverId}`, { serverId });
|
|
26
|
+
}
|
|
27
|
+
static serverExists(serverId) {
|
|
28
|
+
return new ServerRegistryError(MCPEcosystemErrorCodes.SERVER_EXISTS, `Server already exists: ${serverId}`, { serverId });
|
|
29
|
+
}
|
|
30
|
+
static connectionFailed(serverId, message) {
|
|
31
|
+
return new ServerRegistryError(MCPEcosystemErrorCodes.CONNECTION_FAILED, `Connection failed for ${serverId}: ${message}`, { serverId });
|
|
32
|
+
}
|
|
33
|
+
static invalidConfig(message) {
|
|
34
|
+
return new ServerRegistryError(MCPEcosystemErrorCodes.INVALID_CONFIG, `Invalid server configuration: ${message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a server registry service
|
|
39
|
+
*/
|
|
40
|
+
export function createServerRegistryService(options) {
|
|
41
|
+
const { storage, clientFactory, defaultConnectionTimeoutMs = 10000, } = options;
|
|
42
|
+
// Active clients by server ID
|
|
43
|
+
const clients = new Map();
|
|
44
|
+
return {
|
|
45
|
+
async register(request) {
|
|
46
|
+
const { connectNow, discoverNow: _discoverNow, ...config } = request;
|
|
47
|
+
try {
|
|
48
|
+
// Atomic get-or-create pattern to avoid TOCTOU race condition
|
|
49
|
+
const existingState = await storage.get(config.serverId);
|
|
50
|
+
if (existingState) {
|
|
51
|
+
// Update existing server
|
|
52
|
+
const updatedState = {
|
|
53
|
+
...existingState,
|
|
54
|
+
config: { ...existingState.config, ...config },
|
|
55
|
+
};
|
|
56
|
+
await storage.set(config.serverId, updatedState);
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
server: updatedState,
|
|
60
|
+
created: false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Create new server state
|
|
64
|
+
const serverState = createInitialServerState(config);
|
|
65
|
+
await storage.set(config.serverId, serverState);
|
|
66
|
+
// Optionally connect
|
|
67
|
+
if (connectNow && config.enabled !== false) {
|
|
68
|
+
try {
|
|
69
|
+
await this.connect(config.serverId);
|
|
70
|
+
// Update state after connection
|
|
71
|
+
const updatedState = await storage.get(config.serverId);
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
server: updatedState ?? serverState,
|
|
75
|
+
created: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// Connection failed, but registration succeeded
|
|
80
|
+
const updatedState = await storage.get(config.serverId);
|
|
81
|
+
return {
|
|
82
|
+
success: true,
|
|
83
|
+
server: updatedState ?? serverState,
|
|
84
|
+
created: true,
|
|
85
|
+
error: error instanceof Error ? error.message : 'Connection failed',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
server: serverState,
|
|
92
|
+
created: true,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
created: false,
|
|
99
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
async unregister(serverId) {
|
|
104
|
+
// Disconnect if connected
|
|
105
|
+
if (clients.has(serverId)) {
|
|
106
|
+
await this.disconnect(serverId);
|
|
107
|
+
}
|
|
108
|
+
return storage.delete(serverId);
|
|
109
|
+
},
|
|
110
|
+
async update(serverId, config) {
|
|
111
|
+
const state = await storage.get(serverId);
|
|
112
|
+
if (!state) {
|
|
113
|
+
throw ServerRegistryError.serverNotFound(serverId);
|
|
114
|
+
}
|
|
115
|
+
const updatedConfig = { ...state.config, ...config };
|
|
116
|
+
const updatedState = {
|
|
117
|
+
...state,
|
|
118
|
+
config: updatedConfig,
|
|
119
|
+
};
|
|
120
|
+
// Handle enable/disable
|
|
121
|
+
if (config.enabled === false && state.status !== 'disabled') {
|
|
122
|
+
await this.disconnect(serverId);
|
|
123
|
+
updatedState.status = 'disabled';
|
|
124
|
+
}
|
|
125
|
+
else if (config.enabled === true && state.status === 'disabled') {
|
|
126
|
+
updatedState.status = 'disconnected';
|
|
127
|
+
}
|
|
128
|
+
await storage.set(serverId, updatedState);
|
|
129
|
+
return updatedState;
|
|
130
|
+
},
|
|
131
|
+
async get(serverId) {
|
|
132
|
+
return storage.get(serverId);
|
|
133
|
+
},
|
|
134
|
+
async list(request = {}) {
|
|
135
|
+
const fullRequest = {
|
|
136
|
+
limit: request.limit ?? LIMIT_DEFAULT,
|
|
137
|
+
offset: request.offset ?? 0,
|
|
138
|
+
status: request.status,
|
|
139
|
+
enabled: request.enabled,
|
|
140
|
+
capability: request.capability,
|
|
141
|
+
};
|
|
142
|
+
return storage.list(fullRequest);
|
|
143
|
+
},
|
|
144
|
+
async connect(serverId) {
|
|
145
|
+
const state = await storage.get(serverId);
|
|
146
|
+
if (!state) {
|
|
147
|
+
throw ServerRegistryError.serverNotFound(serverId);
|
|
148
|
+
}
|
|
149
|
+
// INV-MCP-ECO-201: Don't connect disabled servers
|
|
150
|
+
if (!state.config.enabled) {
|
|
151
|
+
throw ServerRegistryError.connectionFailed(serverId, 'Server is disabled');
|
|
152
|
+
}
|
|
153
|
+
// Check if already connected
|
|
154
|
+
const existing = clients.get(serverId);
|
|
155
|
+
if (existing?.isConnected()) {
|
|
156
|
+
return existing;
|
|
157
|
+
}
|
|
158
|
+
// Update status to connecting
|
|
159
|
+
await this.updateStatus(serverId, 'connecting');
|
|
160
|
+
// Create new client
|
|
161
|
+
const client = clientFactory.createClient();
|
|
162
|
+
try {
|
|
163
|
+
// Connect with timeout
|
|
164
|
+
const timeout = state.config.connectionTimeoutMs ?? defaultConnectionTimeoutMs;
|
|
165
|
+
await Promise.race([
|
|
166
|
+
client.connect(state.config),
|
|
167
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Connection timeout')), timeout)),
|
|
168
|
+
]);
|
|
169
|
+
// Store client and update status
|
|
170
|
+
clients.set(serverId, client);
|
|
171
|
+
await this.updateStatus(serverId, 'connected');
|
|
172
|
+
// Update lastConnectedAt
|
|
173
|
+
const updatedState = await storage.get(serverId);
|
|
174
|
+
if (updatedState) {
|
|
175
|
+
await storage.set(serverId, {
|
|
176
|
+
...updatedState,
|
|
177
|
+
lastConnectedAt: new Date().toISOString(),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return client;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
184
|
+
await this.updateStatus(serverId, 'error', message);
|
|
185
|
+
throw ServerRegistryError.connectionFailed(serverId, message);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async disconnect(serverId) {
|
|
189
|
+
const client = clients.get(serverId);
|
|
190
|
+
if (client) {
|
|
191
|
+
try {
|
|
192
|
+
await client.disconnect();
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Ignore disconnect errors
|
|
196
|
+
}
|
|
197
|
+
clients.delete(serverId);
|
|
198
|
+
}
|
|
199
|
+
// Update status
|
|
200
|
+
const state = await storage.get(serverId);
|
|
201
|
+
if (state && state.config.enabled) {
|
|
202
|
+
await this.updateStatus(serverId, 'disconnected');
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
async updateStatus(serverId, status, error) {
|
|
206
|
+
const state = await storage.get(serverId);
|
|
207
|
+
if (!state)
|
|
208
|
+
return;
|
|
209
|
+
const updatedState = {
|
|
210
|
+
...state,
|
|
211
|
+
status,
|
|
212
|
+
lastError: error,
|
|
213
|
+
};
|
|
214
|
+
// Clear error on successful states
|
|
215
|
+
if (status === 'connected' || status === 'disconnected') {
|
|
216
|
+
delete updatedState.lastError;
|
|
217
|
+
}
|
|
218
|
+
await storage.set(serverId, updatedState);
|
|
219
|
+
},
|
|
220
|
+
getClient(serverId) {
|
|
221
|
+
const client = clients.get(serverId);
|
|
222
|
+
return client?.isConnected() ? client : null;
|
|
223
|
+
},
|
|
224
|
+
async getEnabledServerIds() {
|
|
225
|
+
const { servers } = await storage.list({ enabled: true, limit: 1000, offset: 0 });
|
|
226
|
+
return servers.map((s) => s.config.serverId);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=server-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-registry.js","sourceRoot":"","sources":["../src/server-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,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