@identikey/coding-mcp 2.0.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/LICENSE +21 -0
- package/README.md +134 -0
- package/build/common/apiClient.d.ts +14 -0
- package/build/common/apiClient.d.ts.map +1 -0
- package/build/common/apiClient.js +68 -0
- package/build/common/personaClient.d.ts +48 -0
- package/build/common/personaClient.d.ts.map +1 -0
- package/build/common/personaClient.js +101 -0
- package/build/common/promptBuilder.d.ts +10 -0
- package/build/common/promptBuilder.d.ts.map +1 -0
- package/build/common/promptBuilder.js +14 -0
- package/build/common/providerConfig.d.ts +23 -0
- package/build/common/providerConfig.d.ts.map +1 -0
- package/build/common/providerConfig.js +43 -0
- package/build/common/tokenFormatter.d.ts +12 -0
- package/build/common/tokenFormatter.d.ts.map +1 -0
- package/build/common/tokenFormatter.js +24 -0
- package/build/core/CommandDispatcher.d.ts +81 -0
- package/build/core/CommandDispatcher.d.ts.map +1 -0
- package/build/core/CommandDispatcher.js +242 -0
- package/build/core/ToolCommand.d.ts +188 -0
- package/build/core/ToolCommand.d.ts.map +1 -0
- package/build/core/ToolCommand.js +63 -0
- package/build/core/ToolRegistry.d.ts +80 -0
- package/build/core/ToolRegistry.d.ts.map +1 -0
- package/build/core/ToolRegistry.js +279 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +329 -0
- package/build/infra/eventBus.d.ts +120 -0
- package/build/infra/eventBus.d.ts.map +1 -0
- package/build/infra/eventBus.js +138 -0
- package/build/personas/ada/index.d.ts +15 -0
- package/build/personas/ada/index.d.ts.map +1 -0
- package/build/personas/ada/index.js +121 -0
- package/build/personas/atlas/index.d.ts +13 -0
- package/build/personas/atlas/index.d.ts.map +1 -0
- package/build/personas/atlas/index.js +65 -0
- package/build/personas/charles/index.d.ts +18 -0
- package/build/personas/charles/index.d.ts.map +1 -0
- package/build/personas/charles/index.js +190 -0
- package/build/personas/hermes/index.d.ts +13 -0
- package/build/personas/hermes/index.d.ts.map +1 -0
- package/build/personas/hermes/index.js +61 -0
- package/build/personas/iris/index.d.ts +13 -0
- package/build/personas/iris/index.d.ts.map +1 -0
- package/build/personas/iris/index.js +61 -0
- package/build/personas/router.d.ts +18 -0
- package/build/personas/router.d.ts.map +1 -0
- package/build/personas/router.js +302 -0
- package/build/personas/sentinel/index.d.ts +13 -0
- package/build/personas/sentinel/index.d.ts.map +1 -0
- package/build/personas/sentinel/index.js +62 -0
- package/build/personas/types.d.ts +91 -0
- package/build/personas/types.d.ts.map +1 -0
- package/build/personas/types.js +60 -0
- package/build/personas/xavier/index.d.ts +14 -0
- package/build/personas/xavier/index.d.ts.map +1 -0
- package/build/personas/xavier/index.js +80 -0
- package/build/prompts/architectPrompts.d.ts +5 -0
- package/build/prompts/architectPrompts.d.ts.map +1 -0
- package/build/prompts/architectPrompts.js +58 -0
- package/build/prompts/codeadvicePrompts.d.ts +5 -0
- package/build/prompts/codeadvicePrompts.d.ts.map +1 -0
- package/build/prompts/codeadvicePrompts.js +13 -0
- package/build/prompts/researcherPrompts.d.ts +2 -0
- package/build/prompts/researcherPrompts.d.ts.map +1 -0
- package/build/prompts/researcherPrompts.js +39 -0
- package/build/tools/architect.d.ts +32 -0
- package/build/tools/architect.d.ts.map +1 -0
- package/build/tools/architect.js +75 -0
- package/build/tools/ask.d.ts +39 -0
- package/build/tools/ask.d.ts.map +1 -0
- package/build/tools/ask.js +139 -0
- package/build/tools/codeReview.d.ts +22 -0
- package/build/tools/codeReview.d.ts.map +1 -0
- package/build/tools/codeReview.js +35 -0
- package/build/tools/codeadvice.d.ts +29 -0
- package/build/tools/codeadvice.d.ts.map +1 -0
- package/build/tools/codeadvice.js +56 -0
- package/build/tools/discover.d.ts +24 -0
- package/build/tools/discover.d.ts.map +1 -0
- package/build/tools/discover.js +220 -0
- package/build/tools/persona.d.ts +48 -0
- package/build/tools/persona.d.ts.map +1 -0
- package/build/tools/persona.js +108 -0
- package/build/tools/researcher.d.ts +61 -0
- package/build/tools/researcher.d.ts.map +1 -0
- package/build/tools/researcher.js +346 -0
- package/build/tools/screenshot.d.ts +28 -0
- package/build/tools/screenshot.d.ts.map +1 -0
- package/build/tools/screenshot.js +46 -0
- package/package.json +56 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Dispatcher - Replaces the monolithic switch statement
|
|
3
|
+
* Routes MCP requests to appropriate tool commands with structured error handling
|
|
4
|
+
*/
|
|
5
|
+
import { ToolNotFoundError, ToolValidationError, ToolExecutionError, ToolTimeoutError, ToolError } from './ToolCommand.js';
|
|
6
|
+
import { eventBus } from '../infra/eventBus.js';
|
|
7
|
+
import { ZodError } from 'zod';
|
|
8
|
+
export class CommandDispatcher {
|
|
9
|
+
registry;
|
|
10
|
+
eventBus;
|
|
11
|
+
config;
|
|
12
|
+
activeExecutions = new Map();
|
|
13
|
+
executionCounter = 0;
|
|
14
|
+
constructor(registry, eventBusInstance, config = {}) {
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
this.eventBus = eventBusInstance || eventBus;
|
|
17
|
+
this.config = {
|
|
18
|
+
defaultTimeout: config.defaultTimeout || 30000, // 30 seconds
|
|
19
|
+
enableTracing: config.enableTracing ?? true,
|
|
20
|
+
maxConcurrentExecutions: config.maxConcurrentExecutions || 10
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Dispatch an MCP tool request to the appropriate command
|
|
25
|
+
*/
|
|
26
|
+
async dispatch(request) {
|
|
27
|
+
const { name: toolName, arguments: args } = request.params;
|
|
28
|
+
const requestId = this.generateRequestId();
|
|
29
|
+
const startTime = Date.now();
|
|
30
|
+
try {
|
|
31
|
+
// Check concurrent execution limit
|
|
32
|
+
if (this.activeExecutions.size >= this.config.maxConcurrentExecutions) {
|
|
33
|
+
throw new ToolError(`Maximum concurrent executions (${this.config.maxConcurrentExecutions}) reached`, 'RESOURCE_ERROR', toolName);
|
|
34
|
+
}
|
|
35
|
+
// Get the tool command
|
|
36
|
+
const tool = this.registry.get(toolName);
|
|
37
|
+
if (!tool) {
|
|
38
|
+
throw new ToolNotFoundError(toolName);
|
|
39
|
+
}
|
|
40
|
+
// Track active execution
|
|
41
|
+
this.activeExecutions.set(requestId, { toolName, startTime });
|
|
42
|
+
// Emit execution start event
|
|
43
|
+
this.eventBus.emit('tool:execute:start', {
|
|
44
|
+
name: toolName,
|
|
45
|
+
requestId,
|
|
46
|
+
args
|
|
47
|
+
});
|
|
48
|
+
// Execute the tool with timeout
|
|
49
|
+
const result = await this.executeWithTimeout(tool, args, requestId, startTime);
|
|
50
|
+
// Clean up active execution tracking
|
|
51
|
+
this.activeExecutions.delete(requestId);
|
|
52
|
+
// Emit execution end event
|
|
53
|
+
const executionTime = Date.now() - startTime;
|
|
54
|
+
this.eventBus.emit('tool:execute:end', {
|
|
55
|
+
name: toolName,
|
|
56
|
+
requestId,
|
|
57
|
+
success: result.success,
|
|
58
|
+
executionTime
|
|
59
|
+
});
|
|
60
|
+
// Return MCP-compatible response
|
|
61
|
+
if (result.success && result.result) {
|
|
62
|
+
return this.formatMCPResponse(result.result);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw result.error || new ToolExecutionError(toolName, 'Unknown execution error');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// Clean up active execution tracking
|
|
70
|
+
this.activeExecutions.delete(requestId);
|
|
71
|
+
// Convert to ToolError if not already
|
|
72
|
+
const toolError = this.normalizeError(error, toolName);
|
|
73
|
+
// Emit error event
|
|
74
|
+
this.eventBus.emit('tool:error', {
|
|
75
|
+
name: toolName,
|
|
76
|
+
error: toolError,
|
|
77
|
+
requestId
|
|
78
|
+
});
|
|
79
|
+
// Emit execution end event with failure
|
|
80
|
+
const executionTime = Date.now() - startTime;
|
|
81
|
+
this.eventBus.emit('tool:execute:end', {
|
|
82
|
+
name: toolName,
|
|
83
|
+
requestId,
|
|
84
|
+
success: false,
|
|
85
|
+
executionTime
|
|
86
|
+
});
|
|
87
|
+
// Return error response in MCP format
|
|
88
|
+
return this.formatErrorResponse(toolError);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Execute a tool with timeout and validation
|
|
93
|
+
*/
|
|
94
|
+
async executeWithTimeout(tool, args, requestId, startTime) {
|
|
95
|
+
try {
|
|
96
|
+
// Validate arguments using tool's schema
|
|
97
|
+
let validatedArgs;
|
|
98
|
+
try {
|
|
99
|
+
validatedArgs = tool.schema.parse(args);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof ZodError) {
|
|
103
|
+
throw new ToolValidationError(tool.name, `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`, error);
|
|
104
|
+
}
|
|
105
|
+
throw new ToolValidationError(tool.name, 'Failed to validate arguments', error);
|
|
106
|
+
}
|
|
107
|
+
// Create execution context
|
|
108
|
+
const context = {
|
|
109
|
+
eventBus: this.eventBus,
|
|
110
|
+
requestId,
|
|
111
|
+
startTime,
|
|
112
|
+
config: tool.metadata?.constraints
|
|
113
|
+
};
|
|
114
|
+
// Determine timeout (tool-specific or default)
|
|
115
|
+
const timeout = tool.metadata?.constraints?.maxExecutionTime || this.config.defaultTimeout;
|
|
116
|
+
// Execute with timeout
|
|
117
|
+
const result = await this.withTimeout(tool.execute(validatedArgs, context), timeout, tool.name);
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
result,
|
|
121
|
+
executionTime: Date.now() - startTime,
|
|
122
|
+
metadata: {
|
|
123
|
+
toolName: tool.name,
|
|
124
|
+
version: tool.version,
|
|
125
|
+
requestId
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
error: this.normalizeError(error, tool.name),
|
|
133
|
+
executionTime: Date.now() - startTime,
|
|
134
|
+
metadata: {
|
|
135
|
+
toolName: tool.name,
|
|
136
|
+
version: tool.version,
|
|
137
|
+
requestId
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Execute a promise with timeout
|
|
144
|
+
*/
|
|
145
|
+
async withTimeout(promise, timeoutMs, toolName) {
|
|
146
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
reject(new ToolTimeoutError(toolName, timeoutMs));
|
|
149
|
+
}, timeoutMs);
|
|
150
|
+
});
|
|
151
|
+
return Promise.race([promise, timeoutPromise]);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Normalize errors to ToolError instances
|
|
155
|
+
*/
|
|
156
|
+
normalizeError(error, toolName) {
|
|
157
|
+
if (error instanceof ToolError) {
|
|
158
|
+
return error;
|
|
159
|
+
}
|
|
160
|
+
if (error instanceof Error) {
|
|
161
|
+
return new ToolExecutionError(toolName, error.message, error);
|
|
162
|
+
}
|
|
163
|
+
return new ToolExecutionError(toolName, String(error));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Format successful result as MCP response
|
|
167
|
+
*/
|
|
168
|
+
formatMCPResponse(result) {
|
|
169
|
+
// If result is already in MCP format, return as-is
|
|
170
|
+
if (this.isMCPResponse(result)) {
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
// Convert to MCP format
|
|
174
|
+
return {
|
|
175
|
+
content: [{
|
|
176
|
+
type: "text",
|
|
177
|
+
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
|
|
178
|
+
}]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Format error as MCP response
|
|
183
|
+
*/
|
|
184
|
+
formatErrorResponse(error) {
|
|
185
|
+
const errorMessage = this.config.enableTracing
|
|
186
|
+
? `${error.message}\n\nError Code: ${error.code}\nTool: ${error.toolName || 'unknown'}`
|
|
187
|
+
: error.message;
|
|
188
|
+
return {
|
|
189
|
+
content: [{
|
|
190
|
+
type: "text",
|
|
191
|
+
text: `Error: ${errorMessage}`
|
|
192
|
+
}]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if result is already in MCP response format
|
|
197
|
+
*/
|
|
198
|
+
isMCPResponse(result) {
|
|
199
|
+
return (typeof result === 'object' &&
|
|
200
|
+
result !== null &&
|
|
201
|
+
'content' in result &&
|
|
202
|
+
Array.isArray(result.content));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Generate unique request ID
|
|
206
|
+
*/
|
|
207
|
+
generateRequestId() {
|
|
208
|
+
return `req_${Date.now()}_${++this.executionCounter}`;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get active executions for monitoring
|
|
212
|
+
*/
|
|
213
|
+
getActiveExecutions() {
|
|
214
|
+
return new Map(this.activeExecutions);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get dispatcher statistics
|
|
218
|
+
*/
|
|
219
|
+
getStats() {
|
|
220
|
+
// This would need execution history tracking for accurate stats
|
|
221
|
+
// For now, return basic info
|
|
222
|
+
return {
|
|
223
|
+
activeExecutions: this.activeExecutions.size,
|
|
224
|
+
totalExecutions: this.executionCounter,
|
|
225
|
+
averageExecutionTime: 0, // Would need history tracking
|
|
226
|
+
errorRate: 0 // Would need error tracking
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Create dispatcher with default configuration
|
|
231
|
+
*/
|
|
232
|
+
static create(registry, config) {
|
|
233
|
+
return new CommandDispatcher(registry, eventBus, config);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a simple dispatch function for MCP server integration
|
|
238
|
+
*/
|
|
239
|
+
export function createDispatchHandler(registry, config) {
|
|
240
|
+
const dispatcher = new CommandDispatcher(registry, eventBus, config);
|
|
241
|
+
return (request) => dispatcher.dispatch(request);
|
|
242
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types and interfaces for the MCP Tool Command system
|
|
3
|
+
* Follows the Command pattern for pluggable tool architecture
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import type { EventBus } from "../infra/eventBus.js";
|
|
7
|
+
/**
|
|
8
|
+
* Context provided to each tool execution
|
|
9
|
+
*/
|
|
10
|
+
export interface CommandContext {
|
|
11
|
+
/** Event bus for inter-tool communication */
|
|
12
|
+
eventBus: EventBus;
|
|
13
|
+
/** Request metadata */
|
|
14
|
+
requestId?: string;
|
|
15
|
+
/** Tool execution start time */
|
|
16
|
+
startTime: number;
|
|
17
|
+
/** Tool-specific configuration */
|
|
18
|
+
config?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Tool command interface - all MCP tools must implement this
|
|
22
|
+
*/
|
|
23
|
+
export interface ToolCommand<TArgs = any, TResult = any> {
|
|
24
|
+
/** Unique tool identifier */
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** Human-readable description */
|
|
27
|
+
readonly description: string;
|
|
28
|
+
/** Zod schema for argument validation */
|
|
29
|
+
readonly schema: z.ZodSchema<TArgs>;
|
|
30
|
+
/** Tool version (semantic versioning) */
|
|
31
|
+
readonly version?: string;
|
|
32
|
+
/** Tool metadata */
|
|
33
|
+
readonly metadata?: ToolMetadata;
|
|
34
|
+
/** Execute the tool with validated arguments */
|
|
35
|
+
execute(args: TArgs, context: CommandContext): Promise<TResult>;
|
|
36
|
+
/** Optional lifecycle hooks */
|
|
37
|
+
onLoad?(): void | Promise<void>;
|
|
38
|
+
onUnload?(): void | Promise<void>;
|
|
39
|
+
/** Health check for the tool */
|
|
40
|
+
healthCheck?(): Promise<ToolHealthStatus>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tool metadata for discovery and management
|
|
44
|
+
*/
|
|
45
|
+
export interface ToolMetadata {
|
|
46
|
+
/** Tool category */
|
|
47
|
+
category?: string;
|
|
48
|
+
/** Author information */
|
|
49
|
+
author?: string;
|
|
50
|
+
/** Tool tags for filtering */
|
|
51
|
+
tags?: string[];
|
|
52
|
+
/** Execution constraints */
|
|
53
|
+
constraints?: {
|
|
54
|
+
maxExecutionTime?: number;
|
|
55
|
+
maxMemory?: number;
|
|
56
|
+
requiresSandbox?: boolean;
|
|
57
|
+
};
|
|
58
|
+
/** Dependencies */
|
|
59
|
+
dependencies?: string[];
|
|
60
|
+
/** Configuration schema */
|
|
61
|
+
configSchema?: z.ZodSchema<any>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Tool health status
|
|
65
|
+
*/
|
|
66
|
+
export interface ToolHealthStatus {
|
|
67
|
+
healthy: boolean;
|
|
68
|
+
message?: string;
|
|
69
|
+
lastChecked: number;
|
|
70
|
+
metrics?: {
|
|
71
|
+
executionCount?: number;
|
|
72
|
+
averageExecutionTime?: number;
|
|
73
|
+
errorRate?: number;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Tool registration info
|
|
78
|
+
*/
|
|
79
|
+
export interface ToolRegistration {
|
|
80
|
+
tool: ToolCommand;
|
|
81
|
+
registeredAt: number;
|
|
82
|
+
source: string;
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Tool execution result wrapper
|
|
87
|
+
*/
|
|
88
|
+
export interface ToolExecutionResult<T = any> {
|
|
89
|
+
success: boolean;
|
|
90
|
+
result?: T;
|
|
91
|
+
error?: ToolError;
|
|
92
|
+
executionTime: number;
|
|
93
|
+
metadata?: {
|
|
94
|
+
toolName: string;
|
|
95
|
+
version?: string;
|
|
96
|
+
requestId?: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Base class for tool errors
|
|
101
|
+
*/
|
|
102
|
+
export declare class ToolError extends Error {
|
|
103
|
+
readonly code: ToolErrorCode;
|
|
104
|
+
readonly toolName?: string | undefined;
|
|
105
|
+
readonly cause?: Error | undefined;
|
|
106
|
+
constructor(message: string, code: ToolErrorCode, toolName?: string | undefined, cause?: Error | undefined);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Specific error types
|
|
110
|
+
*/
|
|
111
|
+
export declare class ToolNotFoundError extends ToolError {
|
|
112
|
+
constructor(toolName: string);
|
|
113
|
+
}
|
|
114
|
+
export declare class DuplicateToolError extends ToolError {
|
|
115
|
+
constructor(toolName: string);
|
|
116
|
+
}
|
|
117
|
+
export declare class ToolValidationError extends ToolError {
|
|
118
|
+
constructor(toolName: string, validationMessage: string, cause?: Error);
|
|
119
|
+
}
|
|
120
|
+
export declare class ToolExecutionError extends ToolError {
|
|
121
|
+
constructor(toolName: string, executionMessage: string, cause?: Error);
|
|
122
|
+
}
|
|
123
|
+
export declare class ToolTimeoutError extends ToolError {
|
|
124
|
+
constructor(toolName: string, timeout: number);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Tool error codes
|
|
128
|
+
*/
|
|
129
|
+
export type ToolErrorCode = 'TOOL_NOT_FOUND' | 'DUPLICATE_TOOL' | 'VALIDATION_ERROR' | 'EXECUTION_ERROR' | 'TIMEOUT_ERROR' | 'SANDBOX_ERROR' | 'PERMISSION_ERROR' | 'RESOURCE_ERROR' | 'UNKNOWN_ERROR';
|
|
130
|
+
/**
|
|
131
|
+
* Tool lifecycle states
|
|
132
|
+
*/
|
|
133
|
+
export declare enum ToolLifecycle {
|
|
134
|
+
LOADING = "loading",
|
|
135
|
+
READY = "ready",
|
|
136
|
+
ERROR = "error",
|
|
137
|
+
UNLOADING = "unloading",
|
|
138
|
+
DISPOSED = "disposed"
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Event types for tool system
|
|
142
|
+
*/
|
|
143
|
+
export interface ToolEventMap {
|
|
144
|
+
'tool:registered': {
|
|
145
|
+
name: string;
|
|
146
|
+
version?: string;
|
|
147
|
+
source: string;
|
|
148
|
+
};
|
|
149
|
+
'tool:unregistered': {
|
|
150
|
+
name: string;
|
|
151
|
+
reason?: string;
|
|
152
|
+
};
|
|
153
|
+
'tool:execute:start': {
|
|
154
|
+
name: string;
|
|
155
|
+
requestId?: string;
|
|
156
|
+
args: any;
|
|
157
|
+
};
|
|
158
|
+
'tool:execute:end': {
|
|
159
|
+
name: string;
|
|
160
|
+
requestId?: string;
|
|
161
|
+
success: boolean;
|
|
162
|
+
executionTime: number;
|
|
163
|
+
};
|
|
164
|
+
'tool:error': {
|
|
165
|
+
name: string;
|
|
166
|
+
error: ToolError;
|
|
167
|
+
requestId?: string;
|
|
168
|
+
};
|
|
169
|
+
'tool:lifecycle': {
|
|
170
|
+
name: string;
|
|
171
|
+
state: ToolLifecycle;
|
|
172
|
+
metadata?: any;
|
|
173
|
+
};
|
|
174
|
+
'tool:health': {
|
|
175
|
+
name: string;
|
|
176
|
+
status: ToolHealthStatus;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Utility type for MCP tool responses
|
|
181
|
+
*/
|
|
182
|
+
export interface MCPToolResponse {
|
|
183
|
+
content: Array<{
|
|
184
|
+
type: "text";
|
|
185
|
+
text: string;
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=ToolCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCommand.d.ts","sourceRoot":"","sources":["../../src/core/ToolCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,QAAQ,EAAE,QAAQ,CAAC;IACnB,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAA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ACnB,OAAO,EAAE,OAAO,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,SAAS,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,aAAa,CAAC;QACrB,QAAQ,CAAC,EAAE,GAAG,CAAC;KAChB,CAAC;IACF,aAAa,EAAE;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,gBAAgB,CAAC;KAC1B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types and interfaces for the MCP Tool Command system
|
|
3
|
+
* Follows the Command pattern for pluggable tool architecture
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base class for tool errors
|
|
7
|
+
*/
|
|
8
|
+
export class ToolError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
toolName;
|
|
11
|
+
cause;
|
|
12
|
+
constructor(message, code, toolName, cause) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.toolName = toolName;
|
|
16
|
+
this.cause = cause;
|
|
17
|
+
this.name = 'ToolError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Specific error types
|
|
22
|
+
*/
|
|
23
|
+
export class ToolNotFoundError extends ToolError {
|
|
24
|
+
constructor(toolName) {
|
|
25
|
+
super(`Tool '${toolName}' not found`, 'TOOL_NOT_FOUND', toolName);
|
|
26
|
+
this.name = 'ToolNotFoundError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class DuplicateToolError extends ToolError {
|
|
30
|
+
constructor(toolName) {
|
|
31
|
+
super(`Tool '${toolName}' is already registered`, 'DUPLICATE_TOOL', toolName);
|
|
32
|
+
this.name = 'DuplicateToolError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ToolValidationError extends ToolError {
|
|
36
|
+
constructor(toolName, validationMessage, cause) {
|
|
37
|
+
super(`Validation failed for tool '${toolName}': ${validationMessage}`, 'VALIDATION_ERROR', toolName, cause);
|
|
38
|
+
this.name = 'ToolValidationError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class ToolExecutionError extends ToolError {
|
|
42
|
+
constructor(toolName, executionMessage, cause) {
|
|
43
|
+
super(`Execution failed for tool '${toolName}': ${executionMessage}`, 'EXECUTION_ERROR', toolName, cause);
|
|
44
|
+
this.name = 'ToolExecutionError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class ToolTimeoutError extends ToolError {
|
|
48
|
+
constructor(toolName, timeout) {
|
|
49
|
+
super(`Tool '${toolName}' execution timed out after ${timeout}ms`, 'TIMEOUT_ERROR', toolName);
|
|
50
|
+
this.name = 'ToolTimeoutError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Tool lifecycle states
|
|
55
|
+
*/
|
|
56
|
+
export var ToolLifecycle;
|
|
57
|
+
(function (ToolLifecycle) {
|
|
58
|
+
ToolLifecycle["LOADING"] = "loading";
|
|
59
|
+
ToolLifecycle["READY"] = "ready";
|
|
60
|
+
ToolLifecycle["ERROR"] = "error";
|
|
61
|
+
ToolLifecycle["UNLOADING"] = "unloading";
|
|
62
|
+
ToolLifecycle["DISPOSED"] = "disposed";
|
|
63
|
+
})(ToolLifecycle || (ToolLifecycle = {}));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry - Central hub for managing MCP tool commands
|
|
3
|
+
* Implements the Command pattern with EventBus integration
|
|
4
|
+
*/
|
|
5
|
+
import { ToolCommand, ToolRegistration, ToolHealthStatus } from './ToolCommand.js';
|
|
6
|
+
import { type EventBus } from '../infra/eventBus.js';
|
|
7
|
+
export declare class ToolRegistry {
|
|
8
|
+
private tools;
|
|
9
|
+
private healthCache;
|
|
10
|
+
private readonly eventBus;
|
|
11
|
+
constructor(eventBusInstance?: EventBus);
|
|
12
|
+
/**
|
|
13
|
+
* Register a new tool command
|
|
14
|
+
*/
|
|
15
|
+
register(tool: ToolCommand, source?: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Unregister a tool command
|
|
18
|
+
*/
|
|
19
|
+
unregister(name: string, reason?: string): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Get a registered tool by name
|
|
22
|
+
*/
|
|
23
|
+
get(name: string): ToolCommand | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get tool registration info
|
|
26
|
+
*/
|
|
27
|
+
getRegistration(name: string): ToolRegistration | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a tool is registered
|
|
30
|
+
*/
|
|
31
|
+
has(name: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* List all registered tools
|
|
34
|
+
*/
|
|
35
|
+
list(): ToolCommand[];
|
|
36
|
+
/**
|
|
37
|
+
* List all tool registrations (including disabled)
|
|
38
|
+
*/
|
|
39
|
+
listRegistrations(): ToolRegistration[];
|
|
40
|
+
/**
|
|
41
|
+
* Get tool names only
|
|
42
|
+
*/
|
|
43
|
+
getToolNames(): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Get registry statistics
|
|
46
|
+
*/
|
|
47
|
+
getStats(): {
|
|
48
|
+
totalTools: number;
|
|
49
|
+
enabledTools: number;
|
|
50
|
+
disabledTools: number;
|
|
51
|
+
categories: Record<string, number>;
|
|
52
|
+
sources: Record<string, number>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Enable/disable a tool
|
|
56
|
+
*/
|
|
57
|
+
setEnabled(name: string, enabled: boolean): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check tool health
|
|
60
|
+
*/
|
|
61
|
+
checkHealth(name: string, useCache?: boolean): Promise<ToolHealthStatus>;
|
|
62
|
+
/**
|
|
63
|
+
* Check health of all tools
|
|
64
|
+
*/
|
|
65
|
+
checkAllHealth(): Promise<Record<string, ToolHealthStatus>>;
|
|
66
|
+
/**
|
|
67
|
+
* Clear all tools (for testing or shutdown)
|
|
68
|
+
*/
|
|
69
|
+
clear(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Handle system shutdown
|
|
72
|
+
*/
|
|
73
|
+
private handleShutdown;
|
|
74
|
+
/**
|
|
75
|
+
* Create a new registry instance (for testing)
|
|
76
|
+
*/
|
|
77
|
+
static create(eventBusInstance?: EventBus): ToolRegistry;
|
|
78
|
+
}
|
|
79
|
+
export declare const toolRegistry: ToolRegistry;
|
|
80
|
+
//# sourceMappingURL=ToolRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.d.ts","sourceRoot":"","sources":["../../src/core/ToolRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,gBAAgB,EAKhB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE/D,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;gBAExB,gBAAgB,CAAC,EAAE,QAAQ;IAOvC;;OAEG;IACG,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,GAAE,MAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiE5E;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,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