@anastops/mcp-server 1.1.2 → 2.0.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/handlers/handlers.base.d.ts +20 -4
- package/dist/handlers/handlers.base.d.ts.map +1 -1
- package/dist/handlers/handlers.base.js +32 -17
- package/dist/handlers/handlers.base.js.map +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/index.js +84 -100
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/tool-definitions.d.ts +701 -1673
- package/dist/handlers/tool-definitions.d.ts.map +1 -1
- package/dist/handlers/tool-definitions.js +459 -402
- package/dist/handlers/tool-definitions.js.map +1 -1
- package/dist/handlers/types.d.ts +1 -0
- package/dist/handlers/types.d.ts.map +1 -1
- package/dist/handlers/v3/agent-tools.d.ts +280 -0
- package/dist/handlers/v3/agent-tools.d.ts.map +1 -0
- package/dist/handlers/v3/agent-tools.js +460 -0
- package/dist/handlers/v3/agent-tools.js.map +1 -0
- package/dist/handlers/v3/index.d.ts +31 -0
- package/dist/handlers/v3/index.d.ts.map +1 -0
- package/dist/handlers/v3/index.js +56 -0
- package/dist/handlers/v3/index.js.map +1 -0
- package/dist/handlers/v3/routing-integration-example.d.ts +258 -0
- package/dist/handlers/v3/routing-integration-example.d.ts.map +1 -0
- package/dist/handlers/v3/routing-integration-example.js +454 -0
- package/dist/handlers/v3/routing-integration-example.js.map +1 -0
- package/dist/handlers/v3/routing-middleware.d.ts +191 -0
- package/dist/handlers/v3/routing-middleware.d.ts.map +1 -0
- package/dist/handlers/v3/routing-middleware.js +425 -0
- package/dist/handlers/v3/routing-middleware.js.map +1 -0
- package/dist/handlers/v3/session-tools.d.ts +269 -0
- package/dist/handlers/v3/session-tools.d.ts.map +1 -0
- package/dist/handlers/v3/session-tools.js +716 -0
- package/dist/handlers/v3/session-tools.js.map +1 -0
- package/dist/handlers/v3/task-tools.d.ts +18 -0
- package/dist/handlers/v3/task-tools.d.ts.map +1 -0
- package/dist/handlers/v3/task-tools.js +916 -0
- package/dist/handlers/v3/task-tools.js.map +1 -0
- package/dist/handlers/v3/utility-tools.d.ts +99 -0
- package/dist/handlers/v3/utility-tools.d.ts.map +1 -0
- package/dist/handlers/v3/utility-tools.js +878 -0
- package/dist/handlers/v3/utility-tools.js.map +1 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing-integration-example.js","sourceRoot":"","sources":["../../../src/handlers/v3/routing-integration-example.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/D,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;IAEvC,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,YAAY,CACjB,gBAAgB,CAAC,gBAAgB,EAAE;QACjC,MAAM,EAAE;YACN,cAAc,EAAE,CAAC,WAAW,CAAC;YAC7B,OAAO,EAAE,mBAAmB;SAC7B;QACD,IAAI,EAAE;YACJ,cAAc,EAAE,CAAC,YAAY,CAAC;YAC9B,OAAO,EAAE,mBAAmB;SAC7B;QACD,OAAO,EAAE;YACP,cAAc,EAAE,CAAC,YAAY,CAAC;YAC9B,OAAO,EAAE,mBAAmB;SAC7B;Q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ACjB,kBAAkB;AAClB,qBAAqB;AACrB,uBAAuB;AACvB,4BAA4B;AAC5B,gBAAgB;AAChB,uBAAuB;AACvB,EAAE;AACF,+EAA+E"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP v3.0 - Operation Routing Middleware
|
|
3
|
+
*
|
|
4
|
+
* Provides validation and routing for consolidated tools with operation parameters.
|
|
5
|
+
* Handles:
|
|
6
|
+
* - Parameter validation (operation, required fields)
|
|
7
|
+
* - Operation routing to appropriate handlers
|
|
8
|
+
* - Error handling (invalid operations, missing params, handler failures)
|
|
9
|
+
* - Type safety with comprehensive TypeScript types
|
|
10
|
+
*
|
|
11
|
+
* @module handlers/v3/routing-middleware
|
|
12
|
+
*/
|
|
13
|
+
import type { HandlerContext } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Result of operation validation
|
|
16
|
+
*/
|
|
17
|
+
export interface ValidationResult {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
operation?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
missingFields?: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Operation handler function signature
|
|
25
|
+
*/
|
|
26
|
+
export type OperationHandler<TArgs = Record<string, unknown>, TResult = unknown> = (args: TArgs, context: HandlerContext) => Promise<TResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Map of operation names to their handlers
|
|
29
|
+
*/
|
|
30
|
+
export type OperationHandlerMap<TResult = unknown> = Map<string, OperationHandler<Record<string, unknown>, TResult>>;
|
|
31
|
+
/**
|
|
32
|
+
* Tool handler registry mapping tool names to operation handlers
|
|
33
|
+
*/
|
|
34
|
+
export type ToolHandlerMap = Map<string, OperationHandlerMap>;
|
|
35
|
+
/**
|
|
36
|
+
* Required fields configuration for each operation
|
|
37
|
+
* Maps operation names to arrays of required field names
|
|
38
|
+
*/
|
|
39
|
+
export type OperationRequiredFields = Map<string, string[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Tool configuration for validation and routing
|
|
42
|
+
*/
|
|
43
|
+
export interface ToolConfig {
|
|
44
|
+
/** Tool name (e.g., 'session_manage') */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Allowed operations for this tool */
|
|
47
|
+
allowedOperations: string[];
|
|
48
|
+
/** Required fields for each operation */
|
|
49
|
+
requiredFields: OperationRequiredFields;
|
|
50
|
+
/** Operation handlers */
|
|
51
|
+
handlers: OperationHandlerMap;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Router configuration for all tools
|
|
55
|
+
*/
|
|
56
|
+
export interface RouterConfig {
|
|
57
|
+
tools: Map<string, ToolConfig>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Operation router interface
|
|
61
|
+
*/
|
|
62
|
+
export interface OperationRouter {
|
|
63
|
+
/**
|
|
64
|
+
* Validate operation and parameters
|
|
65
|
+
*/
|
|
66
|
+
validateOperation: (toolName: string, params: Record<string, unknown>) => ValidationResult;
|
|
67
|
+
/**
|
|
68
|
+
* Route tool call to appropriate handler
|
|
69
|
+
*/
|
|
70
|
+
routeToolCall: (toolName: string, params: Record<string, unknown>, context: HandlerContext) => Promise<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Get required fields for a specific operation
|
|
73
|
+
*/
|
|
74
|
+
getRequiredFields: (toolName: string, operation: string) => string[] | null;
|
|
75
|
+
/**
|
|
76
|
+
* Register a new tool configuration
|
|
77
|
+
*/
|
|
78
|
+
registerTool: (config: ToolConfig) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a tool is registered
|
|
81
|
+
*/
|
|
82
|
+
hasTool: (toolName: string) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Get all registered tool names
|
|
85
|
+
*/
|
|
86
|
+
getToolNames: () => string[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create an operation router instance
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const router = createOperationRouter();
|
|
94
|
+
*
|
|
95
|
+
* // Register tool
|
|
96
|
+
* router.registerTool({
|
|
97
|
+
* name: 'session_manage',
|
|
98
|
+
* allowedOperations: ['create', 'fork', 'archive', 'delete'],
|
|
99
|
+
* requiredFields: new Map([
|
|
100
|
+
* ['create', ['objective']],
|
|
101
|
+
* ['fork', ['session_id']],
|
|
102
|
+
* ['archive', ['session_id']],
|
|
103
|
+
* ['delete', ['session_id', 'confirm']]
|
|
104
|
+
* ]),
|
|
105
|
+
* handlers: new Map([
|
|
106
|
+
* ['create', handleCreate],
|
|
107
|
+
* ['fork', handleFork],
|
|
108
|
+
* ['archive', handleArchive],
|
|
109
|
+
* ['delete', handleDelete]
|
|
110
|
+
* ])
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // Validate and route
|
|
114
|
+
* const result = await router.routeToolCall('session_manage', {
|
|
115
|
+
* operation: 'create',
|
|
116
|
+
* objective: 'Build feature X'
|
|
117
|
+
* }, context);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function createOperationRouter(): OperationRouter;
|
|
121
|
+
/**
|
|
122
|
+
* Create a tool config from operation definitions
|
|
123
|
+
*
|
|
124
|
+
* Convenience function for building tool configurations with a cleaner API.
|
|
125
|
+
*
|
|
126
|
+
* @param name - Tool name
|
|
127
|
+
* @param operations - Map of operation names to their configuration
|
|
128
|
+
* @returns ToolConfig ready for registration
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const config = createToolConfig('session_manage', {
|
|
133
|
+
* create: {
|
|
134
|
+
* requiredFields: ['objective'],
|
|
135
|
+
* handler: handleCreate
|
|
136
|
+
* },
|
|
137
|
+
* fork: {
|
|
138
|
+
* requiredFields: ['session_id'],
|
|
139
|
+
* handler: handleFork
|
|
140
|
+
* },
|
|
141
|
+
* archive: {
|
|
142
|
+
* requiredFields: ['session_id'],
|
|
143
|
+
* handler: handleArchive
|
|
144
|
+
* }
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* router.registerTool(config);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function createToolConfig(name: string, operations: Record<string, {
|
|
151
|
+
requiredFields: string[];
|
|
152
|
+
handler: OperationHandler;
|
|
153
|
+
}>): ToolConfig;
|
|
154
|
+
/**
|
|
155
|
+
* Validate that parameters match expected types
|
|
156
|
+
*
|
|
157
|
+
* @param params - Parameters to validate
|
|
158
|
+
* @param schema - Schema defining expected types for each field
|
|
159
|
+
* @returns Validation result with type errors if any
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const result = validateParameterTypes(
|
|
164
|
+
* { concurrency: '5', auto_execute: true },
|
|
165
|
+
* { concurrency: 'number', auto_execute: 'boolean' }
|
|
166
|
+
* );
|
|
167
|
+
* // Returns: { valid: false, error: 'concurrency must be number, got string' }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function validateParameterTypes(params: Record<string, unknown>, schema: Record<string, 'string' | 'number' | 'boolean' | 'array' | 'object'>): ValidationResult;
|
|
171
|
+
/**
|
|
172
|
+
* Build error response with standardized format
|
|
173
|
+
*
|
|
174
|
+
* @param toolName - Name of the tool that failed
|
|
175
|
+
* @param operation - Operation that failed
|
|
176
|
+
* @param error - Error message or Error object
|
|
177
|
+
* @returns Standardized error object
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* throw buildErrorResponse('session_manage', 'create', 'objective is required');
|
|
182
|
+
* // Error: [session_manage.create] objective is required
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function buildErrorResponse(toolName: string, operation: string | undefined, error: string | Error): Error;
|
|
186
|
+
/**
|
|
187
|
+
* Singleton router instance for global use
|
|
188
|
+
* Use this for registering all v3.0 tools
|
|
189
|
+
*/
|
|
190
|
+
export declare const globalRouter: OperationRouter;
|
|
191
|
+
//# sourceMappingURL=routing-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing-middleware.d.ts","sourceRoot":"","sources":["../../../src/handlers/v3/routing-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMlD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,IAAI,CACjF,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,OAAO,GAAG,OAAO,IAAI,GAAG,CACtD,MAAM,EACN,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,yCAAyC;IACzC,cAAc,EAAE,uBAAuB,CAAC;IACxC,yBAAyB;IACzB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,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,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC,GAC3E,gBAAgB,CAyBlB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,KAAK,EAAE,MAAM,GAAG,KAAK,GACpB,KAAK,CAOP;AAMD;;;GAGG;AACH,eAAO,MAAM,YAAY,iBAA0B,CAAC"}
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP v3.0 - Operation Routing Middleware
|
|
3
|
+
*
|
|
4
|
+
* Provides validation and routing for consolidated tools with operation parameters.
|
|
5
|
+
* Handles:
|
|
6
|
+
* - Parameter validation (operation, required fields)
|
|
7
|
+
* - Operation routing to appropriate handlers
|
|
8
|
+
* - Error handling (invalid operations, missing params, handler failures)
|
|
9
|
+
* - Type safety with comprehensive TypeScript types
|
|
10
|
+
*
|
|
11
|
+
* @module handlers/v3/routing-middleware
|
|
12
|
+
*/
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Router Implementation
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Create an operation router instance
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const router = createOperationRouter();
|
|
22
|
+
*
|
|
23
|
+
* // Register tool
|
|
24
|
+
* router.registerTool({
|
|
25
|
+
* name: 'session_manage',
|
|
26
|
+
* allowedOperations: ['create', 'fork', 'archive', 'delete'],
|
|
27
|
+
* requiredFields: new Map([
|
|
28
|
+
* ['create', ['objective']],
|
|
29
|
+
* ['fork', ['session_id']],
|
|
30
|
+
* ['archive', ['session_id']],
|
|
31
|
+
* ['delete', ['session_id', 'confirm']]
|
|
32
|
+
* ]),
|
|
33
|
+
* handlers: new Map([
|
|
34
|
+
* ['create', handleCreate],
|
|
35
|
+
* ['fork', handleFork],
|
|
36
|
+
* ['archive', handleArchive],
|
|
37
|
+
* ['delete', handleDelete]
|
|
38
|
+
* ])
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Validate and route
|
|
42
|
+
* const result = await router.routeToolCall('session_manage', {
|
|
43
|
+
* operation: 'create',
|
|
44
|
+
* objective: 'Build feature X'
|
|
45
|
+
* }, context);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function createOperationRouter() {
|
|
49
|
+
const tools = new Map();
|
|
50
|
+
return {
|
|
51
|
+
/**
|
|
52
|
+
* Validate operation parameter and required fields
|
|
53
|
+
*
|
|
54
|
+
* @param toolName - Name of the tool being called
|
|
55
|
+
* @param params - Parameters passed to the tool
|
|
56
|
+
* @returns Validation result with details
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = router.validateOperation('session_manage', {
|
|
61
|
+
* operation: 'create',
|
|
62
|
+
* objective: 'Build feature'
|
|
63
|
+
* });
|
|
64
|
+
* // Returns: { valid: true, operation: 'create' }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Error cases
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Missing operation parameter
|
|
70
|
+
* router.validateOperation('session_manage', {})
|
|
71
|
+
* // Returns: { valid: false, error: 'operation parameter is required' }
|
|
72
|
+
*
|
|
73
|
+
* // Invalid operation
|
|
74
|
+
* router.validateOperation('session_manage', { operation: 'invalid' })
|
|
75
|
+
* // Returns: { valid: false, error: 'Invalid operation: invalid. Allowed: create, fork, archive, delete' }
|
|
76
|
+
*
|
|
77
|
+
* // Missing required fields
|
|
78
|
+
* router.validateOperation('session_manage', { operation: 'create' })
|
|
79
|
+
* // Returns: { valid: false, error: '...', missingFields: ['objective'] }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
validateOperation(toolName, params) {
|
|
83
|
+
// Check if tool is registered
|
|
84
|
+
const toolConfig = tools.get(toolName);
|
|
85
|
+
if (!toolConfig) {
|
|
86
|
+
return {
|
|
87
|
+
valid: false,
|
|
88
|
+
error: `Unknown tool: ${toolName}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Check if operation parameter exists
|
|
92
|
+
const operation = params['operation'];
|
|
93
|
+
if (operation === undefined || operation === null || operation === '') {
|
|
94
|
+
return {
|
|
95
|
+
valid: false,
|
|
96
|
+
error: `operation parameter is required for tool: ${toolName}`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Validate operation type
|
|
100
|
+
if (typeof operation !== 'string') {
|
|
101
|
+
return {
|
|
102
|
+
valid: false,
|
|
103
|
+
error: `operation must be a string, got ${typeof operation}`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Check if operation is allowed
|
|
107
|
+
if (!toolConfig.allowedOperations.includes(operation)) {
|
|
108
|
+
return {
|
|
109
|
+
valid: false,
|
|
110
|
+
error: `Invalid operation: ${operation}. Allowed operations for ${toolName}: ${toolConfig.allowedOperations.join(', ')}`,
|
|
111
|
+
operation,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Check required fields for this operation
|
|
115
|
+
const requiredFields = toolConfig.requiredFields.get(operation);
|
|
116
|
+
if (requiredFields && requiredFields.length > 0) {
|
|
117
|
+
const missingFields = [];
|
|
118
|
+
for (const field of requiredFields) {
|
|
119
|
+
const value = params[field];
|
|
120
|
+
// Check if field is missing or empty
|
|
121
|
+
if (value === undefined || value === null) {
|
|
122
|
+
missingFields.push(field);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Special validation for strings (must not be empty)
|
|
126
|
+
if (typeof value === 'string' && value.trim() === '') {
|
|
127
|
+
missingFields.push(field);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// Special validation for arrays (must not be empty if required)
|
|
131
|
+
if (Array.isArray(value) && value.length === 0 && requiredFields.includes(field)) {
|
|
132
|
+
missingFields.push(field);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (missingFields.length > 0) {
|
|
137
|
+
return {
|
|
138
|
+
valid: false,
|
|
139
|
+
error: `Missing required fields for operation '${operation}': ${missingFields.join(', ')}`,
|
|
140
|
+
operation,
|
|
141
|
+
missingFields,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Validation passed
|
|
146
|
+
return {
|
|
147
|
+
valid: true,
|
|
148
|
+
operation,
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Route tool call to appropriate operation handler
|
|
153
|
+
*
|
|
154
|
+
* @param toolName - Name of the tool being called
|
|
155
|
+
* @param params - Parameters passed to the tool
|
|
156
|
+
* @param context - Handler context with shared state
|
|
157
|
+
* @returns Promise resolving to handler result
|
|
158
|
+
* @throws Error if validation fails or handler is not found
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const result = await router.routeToolCall(
|
|
163
|
+
* 'session_manage',
|
|
164
|
+
* { operation: 'create', objective: 'Build feature' },
|
|
165
|
+
* context
|
|
166
|
+
* );
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @example Error handling
|
|
170
|
+
* ```typescript
|
|
171
|
+
* try {
|
|
172
|
+
* await router.routeToolCall('session_manage', { operation: 'invalid' }, context);
|
|
173
|
+
* } catch (error) {
|
|
174
|
+
* console.error('Routing failed:', error.message);
|
|
175
|
+
* // 'Invalid operation: invalid. Allowed: create, fork, archive, delete'
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async routeToolCall(toolName, params, context) {
|
|
180
|
+
// Validate operation and parameters
|
|
181
|
+
const validation = this.validateOperation(toolName, params);
|
|
182
|
+
if (!validation.valid) {
|
|
183
|
+
throw new Error(validation.error);
|
|
184
|
+
}
|
|
185
|
+
const operation = validation.operation;
|
|
186
|
+
const toolConfig = tools.get(toolName);
|
|
187
|
+
// Get handler for this operation
|
|
188
|
+
const handler = toolConfig.handlers.get(operation);
|
|
189
|
+
if (!handler) {
|
|
190
|
+
throw new Error(`No handler registered for operation '${operation}' in tool '${toolName}'`);
|
|
191
|
+
}
|
|
192
|
+
// Execute handler with error handling
|
|
193
|
+
try {
|
|
194
|
+
return await handler(params, context);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// Wrap handler errors with context
|
|
198
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
199
|
+
throw new Error(`Handler failed for ${toolName}.${operation}: ${errorMessage}`);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* Get required fields for a specific tool operation
|
|
204
|
+
*
|
|
205
|
+
* @param toolName - Name of the tool
|
|
206
|
+
* @param operation - Operation name
|
|
207
|
+
* @returns Array of required field names, or null if tool/operation not found
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const fields = router.getRequiredFields('session_manage', 'create');
|
|
212
|
+
* // Returns: ['objective']
|
|
213
|
+
*
|
|
214
|
+
* const fields2 = router.getRequiredFields('session_manage', 'fork');
|
|
215
|
+
* // Returns: ['session_id']
|
|
216
|
+
*
|
|
217
|
+
* const fields3 = router.getRequiredFields('unknown_tool', 'create');
|
|
218
|
+
* // Returns: null
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
getRequiredFields(toolName, operation) {
|
|
222
|
+
const toolConfig = tools.get(toolName);
|
|
223
|
+
if (!toolConfig) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const fields = toolConfig.requiredFields.get(operation);
|
|
227
|
+
return fields ?? null;
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* Register a new tool configuration
|
|
231
|
+
*
|
|
232
|
+
* @param config - Tool configuration including operations and handlers
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* router.registerTool({
|
|
237
|
+
* name: 'task_manage',
|
|
238
|
+
* allowedOperations: ['create', 'complete', 'cancel'],
|
|
239
|
+
* requiredFields: new Map([
|
|
240
|
+
* ['create', ['session_id', 'type', 'description', 'prompt']],
|
|
241
|
+
* ['complete', ['task_id', 'content']],
|
|
242
|
+
* ['cancel', ['task_id']]
|
|
243
|
+
* ]),
|
|
244
|
+
* handlers: new Map([
|
|
245
|
+
* ['create', handleTaskCreate],
|
|
246
|
+
* ['complete', handleTaskComplete],
|
|
247
|
+
* ['cancel', handleTaskCancel]
|
|
248
|
+
* ])
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
registerTool(config) {
|
|
253
|
+
// Validate config
|
|
254
|
+
if (config.name === undefined || config.name === null || config.name.trim() === '') {
|
|
255
|
+
throw new Error('Tool name is required');
|
|
256
|
+
}
|
|
257
|
+
if (config.allowedOperations === undefined ||
|
|
258
|
+
config.allowedOperations === null ||
|
|
259
|
+
config.allowedOperations.length === 0) {
|
|
260
|
+
throw new Error(`Tool ${config.name} must have at least one allowed operation`);
|
|
261
|
+
}
|
|
262
|
+
if (config.handlers === undefined || config.handlers === null || config.handlers.size === 0) {
|
|
263
|
+
throw new Error(`Tool ${config.name} must have at least one handler`);
|
|
264
|
+
}
|
|
265
|
+
// Validate that all allowed operations have handlers
|
|
266
|
+
for (const operation of config.allowedOperations) {
|
|
267
|
+
if (operation !== undefined && operation !== null && !config.handlers.has(operation)) {
|
|
268
|
+
throw new Error(`Tool ${config.name}: no handler registered for operation '${operation}'`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// Validate that all handlers correspond to allowed operations
|
|
272
|
+
for (const operation of config.handlers.keys()) {
|
|
273
|
+
if (operation !== undefined &&
|
|
274
|
+
operation !== null &&
|
|
275
|
+
!config.allowedOperations.includes(operation)) {
|
|
276
|
+
throw new Error(`Tool ${config.name}: handler registered for unknown operation '${operation}'`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
tools.set(config.name, config);
|
|
280
|
+
},
|
|
281
|
+
/**
|
|
282
|
+
* Check if a tool is registered
|
|
283
|
+
*
|
|
284
|
+
* @param toolName - Name of the tool to check
|
|
285
|
+
* @returns True if tool is registered
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* if (router.hasTool('session_manage')) {
|
|
290
|
+
* // Tool is available
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
hasTool(toolName) {
|
|
295
|
+
return tools.has(toolName);
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* Get all registered tool names
|
|
299
|
+
*
|
|
300
|
+
* @returns Array of tool names
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const toolNames = router.getToolNames();
|
|
305
|
+
* // Returns: ['session_manage', 'session_query', 'task_manage', ...]
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
getToolNames() {
|
|
309
|
+
return Array.from(tools.keys());
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
// ============================================================================
|
|
314
|
+
// Helper Functions
|
|
315
|
+
// ============================================================================
|
|
316
|
+
/**
|
|
317
|
+
* Create a tool config from operation definitions
|
|
318
|
+
*
|
|
319
|
+
* Convenience function for building tool configurations with a cleaner API.
|
|
320
|
+
*
|
|
321
|
+
* @param name - Tool name
|
|
322
|
+
* @param operations - Map of operation names to their configuration
|
|
323
|
+
* @returns ToolConfig ready for registration
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const config = createToolConfig('session_manage', {
|
|
328
|
+
* create: {
|
|
329
|
+
* requiredFields: ['objective'],
|
|
330
|
+
* handler: handleCreate
|
|
331
|
+
* },
|
|
332
|
+
* fork: {
|
|
333
|
+
* requiredFields: ['session_id'],
|
|
334
|
+
* handler: handleFork
|
|
335
|
+
* },
|
|
336
|
+
* archive: {
|
|
337
|
+
* requiredFields: ['session_id'],
|
|
338
|
+
* handler: handleArchive
|
|
339
|
+
* }
|
|
340
|
+
* });
|
|
341
|
+
*
|
|
342
|
+
* router.registerTool(config);
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export function createToolConfig(name, operations) {
|
|
346
|
+
const allowedOperations = Object.keys(operations);
|
|
347
|
+
const requiredFields = new Map();
|
|
348
|
+
const handlers = new Map();
|
|
349
|
+
for (const [operation, config] of Object.entries(operations)) {
|
|
350
|
+
requiredFields.set(operation, config.requiredFields);
|
|
351
|
+
handlers.set(operation, config.handler);
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
name,
|
|
355
|
+
allowedOperations,
|
|
356
|
+
requiredFields,
|
|
357
|
+
handlers,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Validate that parameters match expected types
|
|
362
|
+
*
|
|
363
|
+
* @param params - Parameters to validate
|
|
364
|
+
* @param schema - Schema defining expected types for each field
|
|
365
|
+
* @returns Validation result with type errors if any
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const result = validateParameterTypes(
|
|
370
|
+
* { concurrency: '5', auto_execute: true },
|
|
371
|
+
* { concurrency: 'number', auto_execute: 'boolean' }
|
|
372
|
+
* );
|
|
373
|
+
* // Returns: { valid: false, error: 'concurrency must be number, got string' }
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
export function validateParameterTypes(params, schema) {
|
|
377
|
+
const errors = [];
|
|
378
|
+
for (const [field, expectedType] of Object.entries(schema)) {
|
|
379
|
+
const value = params[field];
|
|
380
|
+
if (value === undefined || value === null) {
|
|
381
|
+
continue; // Skip validation for missing fields (handled by required field check)
|
|
382
|
+
}
|
|
383
|
+
const actualType = Array.isArray(value) ? 'array' : typeof value;
|
|
384
|
+
if (actualType !== expectedType) {
|
|
385
|
+
errors.push(`Field '${field}' must be ${expectedType}, got ${actualType}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (errors.length > 0) {
|
|
389
|
+
return {
|
|
390
|
+
valid: false,
|
|
391
|
+
error: errors.join('; '),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return { valid: true };
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Build error response with standardized format
|
|
398
|
+
*
|
|
399
|
+
* @param toolName - Name of the tool that failed
|
|
400
|
+
* @param operation - Operation that failed
|
|
401
|
+
* @param error - Error message or Error object
|
|
402
|
+
* @returns Standardized error object
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* throw buildErrorResponse('session_manage', 'create', 'objective is required');
|
|
407
|
+
* // Error: [session_manage.create] objective is required
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
export function buildErrorResponse(toolName, operation, error) {
|
|
411
|
+
const message = error instanceof Error ? error.message : error;
|
|
412
|
+
const prefix = operation !== undefined && operation !== null && operation !== ''
|
|
413
|
+
? `[${toolName}.${operation}]`
|
|
414
|
+
: `[${toolName}]`;
|
|
415
|
+
return new Error(`${prefix} ${message}`);
|
|
416
|
+
}
|
|
417
|
+
// ============================================================================
|
|
418
|
+
// Exports
|
|
419
|
+
// ============================================================================
|
|
420
|
+
/**
|
|
421
|
+
* Singleton router instance for global use
|
|
422
|
+
* Use this for registering all v3.0 tools
|
|
423
|
+
*/
|
|
424
|
+
export const globalRouter = createOperationRouter();
|
|
425
|
+
//# sourceMappingURL=routing-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing-middleware.js","sourceRoot":"","sources":["../../../src/handlers/v3/routing-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAyGH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,KAAK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