@anastops/mcp-server 1.1.2 → 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.
Files changed (57) hide show
  1. package/dist/handlers/handlers.base.d.ts +20 -4
  2. package/dist/handlers/handlers.base.d.ts.map +1 -1
  3. package/dist/handlers/handlers.base.js +32 -17
  4. package/dist/handlers/handlers.base.js.map +1 -1
  5. package/dist/handlers/index.d.ts +5 -4
  6. package/dist/handlers/index.d.ts.map +1 -1
  7. package/dist/handlers/index.js +126 -135
  8. package/dist/handlers/index.js.map +1 -1
  9. package/dist/handlers/tool-definitions.d.ts +1016 -1564
  10. package/dist/handlers/tool-definitions.d.ts.map +1 -1
  11. package/dist/handlers/tool-definitions.js +617 -388
  12. package/dist/handlers/tool-definitions.js.map +1 -1
  13. package/dist/handlers/types.d.ts +34 -0
  14. package/dist/handlers/types.d.ts.map +1 -1
  15. package/dist/handlers/v3/agent-tools.d.ts +280 -0
  16. package/dist/handlers/v3/agent-tools.d.ts.map +1 -0
  17. package/dist/handlers/v3/agent-tools.js +460 -0
  18. package/dist/handlers/v3/agent-tools.js.map +1 -0
  19. package/dist/handlers/v3/index.d.ts +31 -0
  20. package/dist/handlers/v3/index.d.ts.map +1 -0
  21. package/dist/handlers/v3/index.js +56 -0
  22. package/dist/handlers/v3/index.js.map +1 -0
  23. package/dist/handlers/v3/routing-integration-example.d.ts +258 -0
  24. package/dist/handlers/v3/routing-integration-example.d.ts.map +1 -0
  25. package/dist/handlers/v3/routing-integration-example.js +454 -0
  26. package/dist/handlers/v3/routing-integration-example.js.map +1 -0
  27. package/dist/handlers/v3/routing-middleware.d.ts +191 -0
  28. package/dist/handlers/v3/routing-middleware.d.ts.map +1 -0
  29. package/dist/handlers/v3/routing-middleware.js +425 -0
  30. package/dist/handlers/v3/routing-middleware.js.map +1 -0
  31. package/dist/handlers/v3/session-tools.d.ts +303 -0
  32. package/dist/handlers/v3/session-tools.d.ts.map +1 -0
  33. package/dist/handlers/v3/session-tools.js +945 -0
  34. package/dist/handlers/v3/session-tools.js.map +1 -0
  35. package/dist/handlers/v3/task-tools.d.ts +18 -0
  36. package/dist/handlers/v3/task-tools.d.ts.map +1 -0
  37. package/dist/handlers/v3/task-tools.js +1947 -0
  38. package/dist/handlers/v3/task-tools.js.map +1 -0
  39. package/dist/handlers/v3/utility-tools.d.ts +99 -0
  40. package/dist/handlers/v3/utility-tools.d.ts.map +1 -0
  41. package/dist/handlers/v3/utility-tools.js +878 -0
  42. package/dist/handlers/v3/utility-tools.js.map +1 -0
  43. package/dist/handlers.d.ts +1 -1
  44. package/dist/handlers.d.ts.map +1 -1
  45. package/dist/handlers.js +1 -1
  46. package/dist/handlers.js.map +1 -1
  47. package/dist/index.js +12 -2
  48. package/dist/index.js.map +1 -1
  49. package/dist/persistence.d.ts +11 -0
  50. package/dist/persistence.d.ts.map +1 -1
  51. package/dist/persistence.js +77 -0
  52. package/dist/persistence.js.map +1 -1
  53. package/dist/schemas.d.ts +95 -8
  54. package/dist/schemas.d.ts.map +1 -1
  55. package/dist/schemas.js +97 -2
  56. package/dist/schemas.js.map +1 -1
  57. package/package.json +3 -3
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Integration Example: Using Routing Middleware with v3.0 Tools
3
+ *
4
+ * This file demonstrates how to integrate the operation routing middleware
5
+ * with existing v3.0 consolidated tools (session, task, agent management).
6
+ *
7
+ * @module handlers/v3/routing-integration-example
8
+ */
9
+ import type { HandlerContext } from '../types.js';
10
+ import { type OperationRouter } from './routing-middleware.js';
11
+ /**
12
+ * Create and configure the global v3 tools router
13
+ *
14
+ * This function sets up the router with all v3.0 consolidated tools.
15
+ * Call this once during MCP server initialization.
16
+ *
17
+ * @returns Configured OperationRouter instance
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // In server initialization
22
+ * import { setupV3Router } from './routing-integration-example.js';
23
+ *
24
+ * const router = setupV3Router();
25
+ *
26
+ * // Later, in tool call handler
27
+ * const result = await router.routeToolCall(toolName, params, context);
28
+ * ```
29
+ */
30
+ export declare function setupV3Router(): OperationRouter;
31
+ /**
32
+ * Main MCP tool call handler using the router
33
+ *
34
+ * This function should be called from your MCP server's tool call handler.
35
+ * It validates and routes all v3.0 tool calls.
36
+ *
37
+ * @param toolName - Name of the tool being called
38
+ * @param params - Tool parameters from MCP request
39
+ * @param context - Handler context with shared state
40
+ * @returns Promise resolving to tool result
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // In your MCP server's CallToolRequestSchema handler
45
+ * server.setRequestHandler(CallToolRequestSchema, async (request) => {
46
+ * const { name, arguments: params } = request.params;
47
+ *
48
+ * try {
49
+ * const result = await handleV3ToolCall(name, params, context);
50
+ *
51
+ * return {
52
+ * content: [
53
+ * {
54
+ * type: 'text',
55
+ * text: JSON.stringify(result, null, 2)
56
+ * }
57
+ * ]
58
+ * };
59
+ * } catch (error) {
60
+ * return {
61
+ * content: [
62
+ * {
63
+ * type: 'text',
64
+ * text: `Error: ${error.message}`
65
+ * }
66
+ * ],
67
+ * isError: true
68
+ * };
69
+ * }
70
+ * });
71
+ * ```
72
+ */
73
+ export declare function handleV3ToolCall(toolName: string, params: Record<string, unknown>, context: HandlerContext): Promise<unknown>;
74
+ /**
75
+ * Validate v3 tool call parameters without executing
76
+ *
77
+ * Useful for:
78
+ * - Pre-validation before expensive operations
79
+ * - Providing helpful error messages to users
80
+ * - UI form validation
81
+ *
82
+ * @param toolName - Name of the tool
83
+ * @param params - Tool parameters to validate
84
+ * @returns Validation result
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const validation = validateV3ToolCall('session_manage', params);
89
+ *
90
+ * if (!validation.valid) {
91
+ * console.error('Validation failed:', validation.error);
92
+ * if (validation.missingFields) {
93
+ * console.error('Missing fields:', validation.missingFields);
94
+ * }
95
+ * return;
96
+ * }
97
+ *
98
+ * // Proceed with execution
99
+ * const result = await handleV3ToolCall(toolName, params, context);
100
+ * ```
101
+ */
102
+ export declare function validateV3ToolCall(toolName: string, params: Record<string, unknown>): {
103
+ valid: boolean;
104
+ error?: string;
105
+ operation?: string;
106
+ missingFields?: string[];
107
+ };
108
+ /**
109
+ * Get required fields for a v3 tool operation
110
+ *
111
+ * @param toolName - Name of the tool
112
+ * @param operation - Operation name
113
+ * @returns Array of required field names, or null if not found
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const fields = getV3ToolRequiredFields('session_manage', 'create');
118
+ * // Returns: ['objective']
119
+ *
120
+ * // Use in UI to show required field indicators
121
+ * fields?.forEach(field => {
122
+ * markFieldAsRequired(field);
123
+ * });
124
+ * ```
125
+ */
126
+ export declare function getV3ToolRequiredFields(toolName: string, operation: string): string[] | null;
127
+ /**
128
+ * List all available v3 tools
129
+ *
130
+ * @returns Array of tool names
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const tools = listV3Tools();
135
+ * // Returns: ['session_manage', 'session_query', 'task_manage', ...]
136
+ *
137
+ * // Use in CLI help or UI
138
+ * console.log('Available tools:', tools.join(', '));
139
+ * ```
140
+ */
141
+ export declare function listV3Tools(): string[];
142
+ /**
143
+ * Initialize the global router
144
+ * Call this during server startup for better performance
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // In server initialization
149
+ * import { initializeV3Router } from './routing-integration-example.js';
150
+ *
151
+ * async function startServer() {
152
+ * initializeV3Router();
153
+ * // ... rest of server setup
154
+ * }
155
+ * ```
156
+ */
157
+ export declare function initializeV3Router(): void;
158
+ /**
159
+ * Example 1: Basic tool call
160
+ *
161
+ * ```typescript
162
+ * async function createSession(context: HandlerContext) {
163
+ * const session = await handleV3ToolCall(
164
+ * 'session_manage',
165
+ * {
166
+ * operation: 'create',
167
+ * objective: 'Build authentication system',
168
+ * concurrency: 3,
169
+ * auto_execute: true,
170
+ * },
171
+ * context
172
+ * );
173
+ * console.log('Session created:', session);
174
+ * }
175
+ * ```
176
+ *
177
+ * Example 2: Validation before execution
178
+ *
179
+ * ```typescript
180
+ * async function validateBeforeExecution(context: HandlerContext) {
181
+ * const params = {
182
+ * operation: 'create',
183
+ * objective: 'Build feature X',
184
+ * };
185
+ *
186
+ * // Validate first
187
+ * const validation = validateV3ToolCall('session_manage', params);
188
+ *
189
+ * if (!validation.valid) {
190
+ * console.error('Invalid parameters:', validation.error);
191
+ * return;
192
+ * }
193
+ *
194
+ * // Execute only if valid
195
+ * const result = await handleV3ToolCall('session_manage', params, context);
196
+ * console.log('Result:', result);
197
+ * }
198
+ * ```
199
+ *
200
+ * Example 3: Error handling
201
+ *
202
+ * ```typescript
203
+ * async function handleErrors(context: HandlerContext) {
204
+ * try {
205
+ * const result = await handleV3ToolCall(
206
+ * 'session_manage',
207
+ * {
208
+ * operation: 'fork',
209
+ * session_id: 'invalid-id',
210
+ * },
211
+ * context
212
+ * );
213
+ * console.log('Forked:', result);
214
+ * } catch (error) {
215
+ * if (error instanceof Error) {
216
+ * // Parse error for user-friendly message
217
+ * if (error.message.includes('Session not found')) {
218
+ * console.error('The session you tried to fork does not exist');
219
+ * } else if (error.message.includes('Missing required fields')) {
220
+ * console.error('Please provide all required fields');
221
+ * } else {
222
+ * console.error('Operation failed:', error.message);
223
+ * }
224
+ * }
225
+ * }
226
+ * }
227
+ * ```
228
+ *
229
+ * Example 4: Dynamic UI generation
230
+ *
231
+ * ```typescript
232
+ * function generateUI() {
233
+ * const operation = 'create';
234
+ * const requiredFields = getV3ToolRequiredFields('session_manage', operation);
235
+ *
236
+ * if (requiredFields) {
237
+ * console.log('Required fields for session_manage.create:');
238
+ * requiredFields.forEach((field) => {
239
+ * console.log(`- ${field} *`);
240
+ * });
241
+ * }
242
+ * }
243
+ * ```
244
+ *
245
+ * Example 5: Help command
246
+ *
247
+ * ```typescript
248
+ * function showHelp() {
249
+ * const tools = listV3Tools();
250
+ *
251
+ * console.log('Available v3.0 MCP tools:');
252
+ * tools.forEach((tool) => {
253
+ * console.log(`- ${tool}`);
254
+ * });
255
+ * }
256
+ * ```
257
+ */
258
+ //# sourceMappingURL=routing-integration-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing-integration-example.d.ts","sourceRoot":"","sources":["../../../src/handlers/v3/routing-integration-example.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAYjC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,IAAI,eAAe,CA4K/C;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAWlF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAG5F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAGtC;AAYD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG"}
@@ -0,0 +1,454 @@
1
+ /**
2
+ * Integration Example: Using Routing Middleware with v3.0 Tools
3
+ *
4
+ * This file demonstrates how to integrate the operation routing middleware
5
+ * with existing v3.0 consolidated tools (session, task, agent management).
6
+ *
7
+ * @module handlers/v3/routing-integration-example
8
+ */
9
+ import { handleAgentManage, handleAgentQuery } from './agent-tools.js';
10
+ import { createOperationRouter, createToolConfig, } from './routing-middleware.js';
11
+ import { handleSessionManage, handleSessionQuery, handleSessionQueueConfig, } from './session-tools.js';
12
+ import { handleTool as handleTaskTool } from './task-tools.js';
13
+ // ============================================================================
14
+ // Router Setup
15
+ // ============================================================================
16
+ /**
17
+ * Create and configure the global v3 tools router
18
+ *
19
+ * This function sets up the router with all v3.0 consolidated tools.
20
+ * Call this once during MCP server initialization.
21
+ *
22
+ * @returns Configured OperationRouter instance
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // In server initialization
27
+ * import { setupV3Router } from './routing-integration-example.js';
28
+ *
29
+ * const router = setupV3Router();
30
+ *
31
+ * // Later, in tool call handler
32
+ * const result = await router.routeToolCall(toolName, params, context);
33
+ * ```
34
+ */
35
+ export function setupV3Router() {
36
+ const router = createOperationRouter();
37
+ // -------------------------------------------------------------------------
38
+ // Session Management Tools
39
+ // -------------------------------------------------------------------------
40
+ /**
41
+ * session_manage: Create, fork, archive, delete sessions
42
+ */
43
+ router.registerTool(createToolConfig('session_manage', {
44
+ create: {
45
+ requiredFields: ['objective'],
46
+ handler: handleSessionManage,
47
+ },
48
+ fork: {
49
+ requiredFields: ['session_id'],
50
+ handler: handleSessionManage,
51
+ },
52
+ archive: {
53
+ requiredFields: ['session_id'],
54
+ handler: handleSessionManage,
55
+ },
56
+ delete: {
57
+ requiredFields: ['confirm'],
58
+ handler: handleSessionManage,
59
+ },
60
+ }));
61
+ /**
62
+ * session_query: Get status, list sessions, generate reports
63
+ */
64
+ router.registerTool(createToolConfig('session_query', {
65
+ status: {
66
+ requiredFields: ['session_id'],
67
+ handler: handleSessionQuery,
68
+ },
69
+ list: {
70
+ requiredFields: [],
71
+ handler: handleSessionQuery,
72
+ },
73
+ report: {
74
+ requiredFields: [],
75
+ handler: handleSessionQuery,
76
+ },
77
+ }));
78
+ /**
79
+ * session_queue_config: Configure queue settings, query queue status
80
+ */
81
+ router.registerTool(createToolConfig('session_queue_config', {
82
+ configure: {
83
+ requiredFields: ['session_id'],
84
+ handler: handleSessionQueueConfig,
85
+ },
86
+ status: {
87
+ requiredFields: ['session_id'],
88
+ handler: handleSessionQueueConfig,
89
+ },
90
+ }));
91
+ // -------------------------------------------------------------------------
92
+ // Task Management Tools
93
+ // -------------------------------------------------------------------------
94
+ /**
95
+ * task_manage: Create, complete, cancel tasks (single and batch)
96
+ */
97
+ router.registerTool(createToolConfig('task_manage', {
98
+ create: {
99
+ requiredFields: ['session_id'],
100
+ handler: async (args, context) => handleTaskTool('task_manage', args, context),
101
+ },
102
+ complete: {
103
+ requiredFields: ['task_id', 'content'],
104
+ handler: async (args, context) => handleTaskTool('task_manage', args, context),
105
+ },
106
+ cancel: {
107
+ requiredFields: ['task_id'],
108
+ handler: async (args, context) => handleTaskTool('task_manage', args, context),
109
+ },
110
+ }));
111
+ /**
112
+ * task_execute: Execute tasks (single or batch, with queue support)
113
+ */
114
+ router.registerTool(createToolConfig('task_execute', {
115
+ execute: {
116
+ requiredFields: [], // Either task_id or task_ids required, validated in handler
117
+ handler: async (args, context) => handleTaskTool('task_execute', args, context),
118
+ },
119
+ }));
120
+ /**
121
+ * task_query: Get task status, list tasks
122
+ */
123
+ router.registerTool(createToolConfig('task_query', {
124
+ status: {
125
+ requiredFields: ['task_id'],
126
+ handler: async (args, context) => handleTaskTool('task_query', args, context),
127
+ },
128
+ list: {
129
+ requiredFields: ['session_id'],
130
+ handler: async (args, context) => handleTaskTool('task_query', args, context),
131
+ },
132
+ }));
133
+ /**
134
+ * task_retry: Retry failed tasks
135
+ */
136
+ router.registerTool(createToolConfig('task_retry', {
137
+ retry: {
138
+ requiredFields: ['task_id'],
139
+ handler: async (args, context) => handleTaskTool('task_retry', args, context),
140
+ },
141
+ }));
142
+ // -------------------------------------------------------------------------
143
+ // Agent Management Tools
144
+ // -------------------------------------------------------------------------
145
+ /**
146
+ * agent_manage: Create, deploy, retire agents
147
+ */
148
+ router.registerTool(createToolConfig('agent_manage', {
149
+ create: {
150
+ requiredFields: ['session_id', 'role'],
151
+ handler: handleAgentManage,
152
+ },
153
+ deploy: {
154
+ requiredFields: ['agent_id', 'task_id'],
155
+ handler: handleAgentManage,
156
+ },
157
+ retire: {
158
+ requiredFields: ['agent_id'],
159
+ handler: handleAgentManage,
160
+ },
161
+ }));
162
+ /**
163
+ * agent_query: Get agent status, list agents
164
+ */
165
+ router.registerTool(createToolConfig('agent_query', {
166
+ status: {
167
+ requiredFields: ['agent_id'],
168
+ handler: handleAgentQuery,
169
+ },
170
+ list: {
171
+ requiredFields: ['session_id'],
172
+ handler: handleAgentQuery,
173
+ },
174
+ }));
175
+ return router;
176
+ }
177
+ // ============================================================================
178
+ // MCP Server Integration
179
+ // ============================================================================
180
+ /**
181
+ * Main MCP tool call handler using the router
182
+ *
183
+ * This function should be called from your MCP server's tool call handler.
184
+ * It validates and routes all v3.0 tool calls.
185
+ *
186
+ * @param toolName - Name of the tool being called
187
+ * @param params - Tool parameters from MCP request
188
+ * @param context - Handler context with shared state
189
+ * @returns Promise resolving to tool result
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * // In your MCP server's CallToolRequestSchema handler
194
+ * server.setRequestHandler(CallToolRequestSchema, async (request) => {
195
+ * const { name, arguments: params } = request.params;
196
+ *
197
+ * try {
198
+ * const result = await handleV3ToolCall(name, params, context);
199
+ *
200
+ * return {
201
+ * content: [
202
+ * {
203
+ * type: 'text',
204
+ * text: JSON.stringify(result, null, 2)
205
+ * }
206
+ * ]
207
+ * };
208
+ * } catch (error) {
209
+ * return {
210
+ * content: [
211
+ * {
212
+ * type: 'text',
213
+ * text: `Error: ${error.message}`
214
+ * }
215
+ * ],
216
+ * isError: true
217
+ * };
218
+ * }
219
+ * });
220
+ * ```
221
+ */
222
+ export async function handleV3ToolCall(toolName, params, context) {
223
+ // Get or create router instance
224
+ const router = globalV3Router ?? setupV3Router();
225
+ // Validate tool exists
226
+ if (!router.hasTool(toolName)) {
227
+ throw new Error(`Unknown tool: ${toolName}. Available tools: ${router.getToolNames().join(', ')}`);
228
+ }
229
+ // Route to appropriate handler
230
+ return router.routeToolCall(toolName, params, context);
231
+ }
232
+ /**
233
+ * Validate v3 tool call parameters without executing
234
+ *
235
+ * Useful for:
236
+ * - Pre-validation before expensive operations
237
+ * - Providing helpful error messages to users
238
+ * - UI form validation
239
+ *
240
+ * @param toolName - Name of the tool
241
+ * @param params - Tool parameters to validate
242
+ * @returns Validation result
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * const validation = validateV3ToolCall('session_manage', params);
247
+ *
248
+ * if (!validation.valid) {
249
+ * console.error('Validation failed:', validation.error);
250
+ * if (validation.missingFields) {
251
+ * console.error('Missing fields:', validation.missingFields);
252
+ * }
253
+ * return;
254
+ * }
255
+ *
256
+ * // Proceed with execution
257
+ * const result = await handleV3ToolCall(toolName, params, context);
258
+ * ```
259
+ */
260
+ export function validateV3ToolCall(toolName, params) {
261
+ const router = globalV3Router ?? setupV3Router();
262
+ if (!router.hasTool(toolName)) {
263
+ return {
264
+ valid: false,
265
+ error: `Unknown tool: ${toolName}`,
266
+ };
267
+ }
268
+ return router.validateOperation(toolName, params);
269
+ }
270
+ /**
271
+ * Get required fields for a v3 tool operation
272
+ *
273
+ * @param toolName - Name of the tool
274
+ * @param operation - Operation name
275
+ * @returns Array of required field names, or null if not found
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const fields = getV3ToolRequiredFields('session_manage', 'create');
280
+ * // Returns: ['objective']
281
+ *
282
+ * // Use in UI to show required field indicators
283
+ * fields?.forEach(field => {
284
+ * markFieldAsRequired(field);
285
+ * });
286
+ * ```
287
+ */
288
+ export function getV3ToolRequiredFields(toolName, operation) {
289
+ const router = globalV3Router ?? setupV3Router();
290
+ return router.getRequiredFields(toolName, operation);
291
+ }
292
+ /**
293
+ * List all available v3 tools
294
+ *
295
+ * @returns Array of tool names
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const tools = listV3Tools();
300
+ * // Returns: ['session_manage', 'session_query', 'task_manage', ...]
301
+ *
302
+ * // Use in CLI help or UI
303
+ * console.log('Available tools:', tools.join(', '));
304
+ * ```
305
+ */
306
+ export function listV3Tools() {
307
+ const router = globalV3Router ?? setupV3Router();
308
+ return router.getToolNames();
309
+ }
310
+ // ============================================================================
311
+ // Global Router Instance (Singleton)
312
+ // ============================================================================
313
+ /**
314
+ * Global router instance
315
+ * Initialized lazily on first use
316
+ */
317
+ let globalV3Router = null;
318
+ /**
319
+ * Initialize the global router
320
+ * Call this during server startup for better performance
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * // In server initialization
325
+ * import { initializeV3Router } from './routing-integration-example.js';
326
+ *
327
+ * async function startServer() {
328
+ * initializeV3Router();
329
+ * // ... rest of server setup
330
+ * }
331
+ * ```
332
+ */
333
+ export function initializeV3Router() {
334
+ if (globalV3Router === null) {
335
+ globalV3Router = setupV3Router();
336
+ }
337
+ }
338
+ // ============================================================================
339
+ // Usage Examples (in comments for documentation)
340
+ // ============================================================================
341
+ /**
342
+ * Example 1: Basic tool call
343
+ *
344
+ * ```typescript
345
+ * async function createSession(context: HandlerContext) {
346
+ * const session = await handleV3ToolCall(
347
+ * 'session_manage',
348
+ * {
349
+ * operation: 'create',
350
+ * objective: 'Build authentication system',
351
+ * concurrency: 3,
352
+ * auto_execute: true,
353
+ * },
354
+ * context
355
+ * );
356
+ * console.log('Session created:', session);
357
+ * }
358
+ * ```
359
+ *
360
+ * Example 2: Validation before execution
361
+ *
362
+ * ```typescript
363
+ * async function validateBeforeExecution(context: HandlerContext) {
364
+ * const params = {
365
+ * operation: 'create',
366
+ * objective: 'Build feature X',
367
+ * };
368
+ *
369
+ * // Validate first
370
+ * const validation = validateV3ToolCall('session_manage', params);
371
+ *
372
+ * if (!validation.valid) {
373
+ * console.error('Invalid parameters:', validation.error);
374
+ * return;
375
+ * }
376
+ *
377
+ * // Execute only if valid
378
+ * const result = await handleV3ToolCall('session_manage', params, context);
379
+ * console.log('Result:', result);
380
+ * }
381
+ * ```
382
+ *
383
+ * Example 3: Error handling
384
+ *
385
+ * ```typescript
386
+ * async function handleErrors(context: HandlerContext) {
387
+ * try {
388
+ * const result = await handleV3ToolCall(
389
+ * 'session_manage',
390
+ * {
391
+ * operation: 'fork',
392
+ * session_id: 'invalid-id',
393
+ * },
394
+ * context
395
+ * );
396
+ * console.log('Forked:', result);
397
+ * } catch (error) {
398
+ * if (error instanceof Error) {
399
+ * // Parse error for user-friendly message
400
+ * if (error.message.includes('Session not found')) {
401
+ * console.error('The session you tried to fork does not exist');
402
+ * } else if (error.message.includes('Missing required fields')) {
403
+ * console.error('Please provide all required fields');
404
+ * } else {
405
+ * console.error('Operation failed:', error.message);
406
+ * }
407
+ * }
408
+ * }
409
+ * }
410
+ * ```
411
+ *
412
+ * Example 4: Dynamic UI generation
413
+ *
414
+ * ```typescript
415
+ * function generateUI() {
416
+ * const operation = 'create';
417
+ * const requiredFields = getV3ToolRequiredFields('session_manage', operation);
418
+ *
419
+ * if (requiredFields) {
420
+ * console.log('Required fields for session_manage.create:');
421
+ * requiredFields.forEach((field) => {
422
+ * console.log(`- ${field} *`);
423
+ * });
424
+ * }
425
+ * }
426
+ * ```
427
+ *
428
+ * Example 5: Help command
429
+ *
430
+ * ```typescript
431
+ * function showHelp() {
432
+ * const tools = listV3Tools();
433
+ *
434
+ * console.log('Available v3.0 MCP tools:');
435
+ * tools.forEach((tool) => {
436
+ * console.log(`- ${tool}`);
437
+ * });
438
+ * }
439
+ * ```
440
+ */
441
+ // ============================================================================
442
+ // Exports
443
+ // ============================================================================
444
+ // Note: All exports are declared inline with their function definitions above
445
+ // This includes:
446
+ // - setupV3Router
447
+ // - handleV3ToolCall
448
+ // - validateV3ToolCall
449
+ // - getV3ToolRequiredFields
450
+ // - listV3Tools
451
+ // - initializeV3Router
452
+ //
453
+ // Usage examples are provided in comments above (see "Usage Examples" section)
454
+ //# sourceMappingURL=routing-integration-example.js.map