@defai.digital/mcp-server 13.0.3

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 (178) hide show
  1. package/LICENSE +214 -0
  2. package/dist/bin.d.ts +3 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +7 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/bootstrap.d.ts +89 -0
  7. package/dist/bootstrap.d.ts.map +1 -0
  8. package/dist/bootstrap.js +161 -0
  9. package/dist/bootstrap.js.map +1 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +17 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/middleware/rate-limiter.d.ts +136 -0
  15. package/dist/middleware/rate-limiter.d.ts.map +1 -0
  16. package/dist/middleware/rate-limiter.js +262 -0
  17. package/dist/middleware/rate-limiter.js.map +1 -0
  18. package/dist/prompts/agent-guide.d.ts +16 -0
  19. package/dist/prompts/agent-guide.d.ts.map +1 -0
  20. package/dist/prompts/agent-guide.js +391 -0
  21. package/dist/prompts/agent-guide.js.map +1 -0
  22. package/dist/prompts/explain-workflow.d.ts +15 -0
  23. package/dist/prompts/explain-workflow.d.ts.map +1 -0
  24. package/dist/prompts/explain-workflow.js +157 -0
  25. package/dist/prompts/explain-workflow.js.map +1 -0
  26. package/dist/prompts/index.d.ts +39 -0
  27. package/dist/prompts/index.d.ts.map +1 -0
  28. package/dist/prompts/index.js +83 -0
  29. package/dist/prompts/index.js.map +1 -0
  30. package/dist/prompts/review-changes.d.ts +15 -0
  31. package/dist/prompts/review-changes.d.ts.map +1 -0
  32. package/dist/prompts/review-changes.js +102 -0
  33. package/dist/prompts/review-changes.js.map +1 -0
  34. package/dist/prompts/troubleshoot-session.d.ts +15 -0
  35. package/dist/prompts/troubleshoot-session.d.ts.map +1 -0
  36. package/dist/prompts/troubleshoot-session.js +156 -0
  37. package/dist/prompts/troubleshoot-session.js.map +1 -0
  38. package/dist/registry-accessor.d.ts +83 -0
  39. package/dist/registry-accessor.d.ts.map +1 -0
  40. package/dist/registry-accessor.js +153 -0
  41. package/dist/registry-accessor.js.map +1 -0
  42. package/dist/resources/agents.d.ts +40 -0
  43. package/dist/resources/agents.d.ts.map +1 -0
  44. package/dist/resources/agents.js +123 -0
  45. package/dist/resources/agents.js.map +1 -0
  46. package/dist/resources/config.d.ts +57 -0
  47. package/dist/resources/config.d.ts.map +1 -0
  48. package/dist/resources/config.js +222 -0
  49. package/dist/resources/config.js.map +1 -0
  50. package/dist/resources/index.d.ts +38 -0
  51. package/dist/resources/index.d.ts.map +1 -0
  52. package/dist/resources/index.js +132 -0
  53. package/dist/resources/index.js.map +1 -0
  54. package/dist/resources/policies.d.ts +40 -0
  55. package/dist/resources/policies.d.ts.map +1 -0
  56. package/dist/resources/policies.js +122 -0
  57. package/dist/resources/policies.js.map +1 -0
  58. package/dist/resources/sessions.d.ts +30 -0
  59. package/dist/resources/sessions.d.ts.map +1 -0
  60. package/dist/resources/sessions.js +64 -0
  61. package/dist/resources/sessions.js.map +1 -0
  62. package/dist/resources/workflows.d.ts +40 -0
  63. package/dist/resources/workflows.d.ts.map +1 -0
  64. package/dist/resources/workflows.js +143 -0
  65. package/dist/resources/workflows.js.map +1 -0
  66. package/dist/schema-registry.d.ts +23 -0
  67. package/dist/schema-registry.d.ts.map +1 -0
  68. package/dist/schema-registry.js +225 -0
  69. package/dist/schema-registry.js.map +1 -0
  70. package/dist/server.d.ts +63 -0
  71. package/dist/server.d.ts.map +1 -0
  72. package/dist/server.js +393 -0
  73. package/dist/server.js.map +1 -0
  74. package/dist/session-accessor.d.ts +23 -0
  75. package/dist/session-accessor.d.ts.map +1 -0
  76. package/dist/session-accessor.js +39 -0
  77. package/dist/session-accessor.js.map +1 -0
  78. package/dist/shared-registry.d.ts +23 -0
  79. package/dist/shared-registry.d.ts.map +1 -0
  80. package/dist/shared-registry.js +235 -0
  81. package/dist/shared-registry.js.map +1 -0
  82. package/dist/stdio.d.ts +6 -0
  83. package/dist/stdio.d.ts.map +1 -0
  84. package/dist/stdio.js +152 -0
  85. package/dist/stdio.js.map +1 -0
  86. package/dist/tool-namespacing.d.ts +28 -0
  87. package/dist/tool-namespacing.d.ts.map +1 -0
  88. package/dist/tool-namespacing.js +80 -0
  89. package/dist/tool-namespacing.js.map +1 -0
  90. package/dist/tools/ability.d.ts +55 -0
  91. package/dist/tools/ability.d.ts.map +1 -0
  92. package/dist/tools/ability.js +560 -0
  93. package/dist/tools/ability.js.map +1 -0
  94. package/dist/tools/agent.d.ts +73 -0
  95. package/dist/tools/agent.d.ts.map +1 -0
  96. package/dist/tools/agent.js +895 -0
  97. package/dist/tools/agent.js.map +1 -0
  98. package/dist/tools/config.d.ts +36 -0
  99. package/dist/tools/config.d.ts.map +1 -0
  100. package/dist/tools/config.js +265 -0
  101. package/dist/tools/config.js.map +1 -0
  102. package/dist/tools/design.d.ts +42 -0
  103. package/dist/tools/design.d.ts.map +1 -0
  104. package/dist/tools/design.js +736 -0
  105. package/dist/tools/design.js.map +1 -0
  106. package/dist/tools/discuss.d.ts +40 -0
  107. package/dist/tools/discuss.d.ts.map +1 -0
  108. package/dist/tools/discuss.js +331 -0
  109. package/dist/tools/discuss.js.map +1 -0
  110. package/dist/tools/file-system.d.ts +63 -0
  111. package/dist/tools/file-system.d.ts.map +1 -0
  112. package/dist/tools/file-system.js +513 -0
  113. package/dist/tools/file-system.js.map +1 -0
  114. package/dist/tools/guard.d.ts +29 -0
  115. package/dist/tools/guard.d.ts.map +1 -0
  116. package/dist/tools/guard.js +311 -0
  117. package/dist/tools/guard.js.map +1 -0
  118. package/dist/tools/index.d.ts +35 -0
  119. package/dist/tools/index.d.ts.map +1 -0
  120. package/dist/tools/index.js +178 -0
  121. package/dist/tools/index.js.map +1 -0
  122. package/dist/tools/memory.d.ts +101 -0
  123. package/dist/tools/memory.d.ts.map +1 -0
  124. package/dist/tools/memory.js +704 -0
  125. package/dist/tools/memory.js.map +1 -0
  126. package/dist/tools/orchestration.d.ts +58 -0
  127. package/dist/tools/orchestration.d.ts.map +1 -0
  128. package/dist/tools/orchestration.js +714 -0
  129. package/dist/tools/orchestration.js.map +1 -0
  130. package/dist/tools/review.d.ts +40 -0
  131. package/dist/tools/review.d.ts.map +1 -0
  132. package/dist/tools/review.js +319 -0
  133. package/dist/tools/review.js.map +1 -0
  134. package/dist/tools/scaffold.d.ts +27 -0
  135. package/dist/tools/scaffold.d.ts.map +1 -0
  136. package/dist/tools/scaffold.js +495 -0
  137. package/dist/tools/scaffold.js.map +1 -0
  138. package/dist/tools/session.d.ts +75 -0
  139. package/dist/tools/session.d.ts.map +1 -0
  140. package/dist/tools/session.js +749 -0
  141. package/dist/tools/session.js.map +1 -0
  142. package/dist/tools/telemetry.d.ts +58 -0
  143. package/dist/tools/telemetry.d.ts.map +1 -0
  144. package/dist/tools/telemetry.js +638 -0
  145. package/dist/tools/telemetry.js.map +1 -0
  146. package/dist/tools/trace.d.ts +29 -0
  147. package/dist/tools/trace.d.ts.map +1 -0
  148. package/dist/tools/trace.js +191 -0
  149. package/dist/tools/trace.js.map +1 -0
  150. package/dist/tools/workflow.d.ts +26 -0
  151. package/dist/tools/workflow.d.ts.map +1 -0
  152. package/dist/tools/workflow.js +269 -0
  153. package/dist/tools/workflow.js.map +1 -0
  154. package/dist/trace-wrapper.d.ts +79 -0
  155. package/dist/trace-wrapper.d.ts.map +1 -0
  156. package/dist/trace-wrapper.js +151 -0
  157. package/dist/trace-wrapper.js.map +1 -0
  158. package/dist/types.d.ts +185 -0
  159. package/dist/types.d.ts.map +1 -0
  160. package/dist/types.js +11 -0
  161. package/dist/types.js.map +1 -0
  162. package/dist/utils/artifact-store.d.ts +49 -0
  163. package/dist/utils/artifact-store.d.ts.map +1 -0
  164. package/dist/utils/artifact-store.js +102 -0
  165. package/dist/utils/artifact-store.js.map +1 -0
  166. package/dist/utils/index.d.ts +6 -0
  167. package/dist/utils/index.d.ts.map +1 -0
  168. package/dist/utils/index.js +10 -0
  169. package/dist/utils/index.js.map +1 -0
  170. package/dist/utils/response.d.ts +139 -0
  171. package/dist/utils/response.d.ts.map +1 -0
  172. package/dist/utils/response.js +293 -0
  173. package/dist/utils/response.js.map +1 -0
  174. package/dist/validation.d.ts +223 -0
  175. package/dist/validation.d.ts.map +1 -0
  176. package/dist/validation.js +372 -0
  177. package/dist/validation.js.map +1 -0
  178. package/package.json +67 -0
@@ -0,0 +1,191 @@
1
+ import { createListResponse, successResponse, } from '../utils/response.js';
2
+ import { storeArtifact } from '../utils/artifact-store.js';
3
+ import { LIMIT_TRACES } from '@defai.digital/contracts';
4
+ /**
5
+ * Trace list tool definition
6
+ */
7
+ export const traceListTool = {
8
+ name: 'trace_list',
9
+ description: 'List recent execution traces',
10
+ idempotent: true,
11
+ inputSchema: {
12
+ type: 'object',
13
+ properties: {
14
+ limit: {
15
+ type: 'number',
16
+ description: 'Maximum number of traces to return',
17
+ default: LIMIT_TRACES,
18
+ },
19
+ status: {
20
+ type: 'string',
21
+ description: 'Filter by status',
22
+ enum: ['success', 'failure', 'running'],
23
+ },
24
+ },
25
+ },
26
+ };
27
+ /**
28
+ * Trace get tool definition
29
+ */
30
+ export const traceGetTool = {
31
+ name: 'trace_get',
32
+ description: 'Get detailed information about a specific trace',
33
+ idempotent: true,
34
+ inputSchema: {
35
+ type: 'object',
36
+ properties: {
37
+ traceId: {
38
+ type: 'string',
39
+ description: 'The ID of the trace to retrieve',
40
+ },
41
+ },
42
+ required: ['traceId'],
43
+ },
44
+ };
45
+ /**
46
+ * Trace analyze tool definition
47
+ */
48
+ export const traceAnalyzeTool = {
49
+ name: 'trace_analyze',
50
+ description: 'Analyze a trace for performance issues or errors',
51
+ idempotent: true,
52
+ inputSchema: {
53
+ type: 'object',
54
+ properties: {
55
+ traceId: {
56
+ type: 'string',
57
+ description: 'The ID of the trace to analyze',
58
+ },
59
+ },
60
+ required: ['traceId'],
61
+ },
62
+ };
63
+ /**
64
+ * Handler for trace_list tool
65
+ * INV-MCP-RESP-002: Arrays limited to 10 items with pagination
66
+ */
67
+ export const handleTraceList = (args) => {
68
+ const status = args.status;
69
+ // Sample traces
70
+ const traces = [
71
+ {
72
+ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
73
+ label: 'data-pipeline',
74
+ status: 'success',
75
+ durationMs: 5000,
76
+ },
77
+ {
78
+ id: 'b2c3d4e5-f6a7-8901-bcde-f12345678901',
79
+ label: 'code-review',
80
+ status: 'success',
81
+ durationMs: 5000,
82
+ },
83
+ {
84
+ id: 'c3d4e5f6-a7b8-9012-cdef-123456789012',
85
+ label: 'deploy-staging',
86
+ status: 'failure',
87
+ durationMs: 2000,
88
+ },
89
+ ];
90
+ const filtered = status !== undefined
91
+ ? traces.filter((t) => t.status === status)
92
+ : traces;
93
+ // Use createListResponse for automatic pagination (max 10 items)
94
+ return Promise.resolve(createListResponse(filtered, {
95
+ domain: 'traces',
96
+ idField: 'id',
97
+ labelField: 'label',
98
+ limit: 10,
99
+ }));
100
+ };
101
+ /**
102
+ * Handler for trace_get tool
103
+ * INV-MCP-RESP-001: Response < 10KB with summary, events stored as artifact
104
+ */
105
+ export const handleTraceGet = async (args) => {
106
+ const traceId = args.traceId;
107
+ const now = new Date();
108
+ // Sample trace detail - full events stored as artifact
109
+ const fullEvents = [
110
+ {
111
+ eventId: crypto.randomUUID(),
112
+ type: 'run.start',
113
+ sequence: 0,
114
+ timestamp: new Date(now.getTime() - 60000).toISOString(),
115
+ payload: { workflowId: 'data-pipeline' },
116
+ },
117
+ {
118
+ eventId: crypto.randomUUID(),
119
+ type: 'decision.routing',
120
+ sequence: 1,
121
+ timestamp: new Date(now.getTime() - 59500).toISOString(),
122
+ payload: {
123
+ selectedModel: 'claude-3-5-sonnet-20241022',
124
+ provider: 'anthropic',
125
+ },
126
+ },
127
+ {
128
+ eventId: crypto.randomUUID(),
129
+ type: 'step.execute',
130
+ sequence: 2,
131
+ timestamp: new Date(now.getTime() - 59000).toISOString(),
132
+ payload: { stepId: 'step-1', stepName: 'Initialize' },
133
+ status: 'success',
134
+ durationMs: 500,
135
+ },
136
+ {
137
+ eventId: crypto.randomUUID(),
138
+ type: 'step.execute',
139
+ sequence: 3,
140
+ timestamp: new Date(now.getTime() - 57000).toISOString(),
141
+ payload: { stepId: 'step-2', stepName: 'Process' },
142
+ status: 'success',
143
+ durationMs: 2000,
144
+ },
145
+ {
146
+ eventId: crypto.randomUUID(),
147
+ type: 'run.end',
148
+ sequence: 4,
149
+ timestamp: new Date(now.getTime() - 55000).toISOString(),
150
+ payload: { success: true },
151
+ status: 'success',
152
+ },
153
+ ];
154
+ // Store full events as artifact
155
+ const artifactRef = await storeArtifact(`trace:${traceId}`, { events: fullEvents });
156
+ // Return summary with only first/last events
157
+ return successResponse(`Trace ${traceId}: success (5000ms, ${fullEvents.length} events)`, {
158
+ traceId,
159
+ workflowId: 'data-pipeline',
160
+ status: 'success',
161
+ durationMs: 5000,
162
+ eventCount: fullEvents.length,
163
+ // Only include first and last events in response
164
+ firstEvent: { type: fullEvents[0]?.type, timestamp: fullEvents[0]?.timestamp },
165
+ lastEvent: { type: fullEvents[fullEvents.length - 1]?.type, status: 'success' },
166
+ artifactRef,
167
+ hasMore: true,
168
+ });
169
+ };
170
+ /**
171
+ * Handler for trace_analyze tool
172
+ * INV-MCP-RESP-006: Response includes summary field with key metrics only
173
+ */
174
+ export const handleTraceAnalyze = (args) => {
175
+ const traceId = args.traceId;
176
+ // Return optimized analysis with summary and key metrics
177
+ return Promise.resolve(successResponse('Trace OK: 5000ms, 3 steps, no issues', {
178
+ traceId,
179
+ status: 'success',
180
+ performance: {
181
+ totalDuration: 5000,
182
+ stepCount: 3,
183
+ slowestStep: 'Process (2000ms)',
184
+ },
185
+ issueCount: 0,
186
+ recommendationCount: 1,
187
+ // Only include top recommendation
188
+ topRecommendation: 'Consider caching step-2 results',
189
+ }));
190
+ };
191
+ //# sourceMappingURL=trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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C;QACtB,kCAAkC;QAClC,iBAAiB,EAAE,iCAAiC;KACrD,CACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { MCPTool, ToolHandler } from '../types.js';
2
+ /**
3
+ * Workflow run tool definition
4
+ */
5
+ export declare const workflowRunTool: MCPTool;
6
+ /**
7
+ * Workflow list tool definition
8
+ */
9
+ export declare const workflowListTool: MCPTool;
10
+ /**
11
+ * Workflow describe tool definition
12
+ */
13
+ export declare const workflowDescribeTool: MCPTool;
14
+ /**
15
+ * Handler for workflow_run tool
16
+ */
17
+ export declare const handleWorkflowRun: ToolHandler;
18
+ /**
19
+ * Handler for workflow_list tool
20
+ */
21
+ export declare const handleWorkflowList: ToolHandler;
22
+ /**
23
+ * Handler for workflow_describe tool
24
+ */
25
+ export declare const handleWorkflowDescribe: ToolHandler;
26
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/tools/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AA4CvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAiB7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAkB9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,OAalC,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAqE/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAiDhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAyDpC,CAAC"}
@@ -0,0 +1,269 @@
1
+ import { createWorkflowRunner, createWorkflowLoader, findWorkflowDir, defaultStepExecutor, } from '@defai.digital/workflow-engine';
2
+ import { LIMIT_WORKFLOWS } from '@defai.digital/contracts';
3
+ import { getStepExecutor } from '../bootstrap.js';
4
+ // Check if we're in test environment
5
+ const isTestEnv = process.env.VITEST === 'true' || process.env.NODE_ENV === 'test';
6
+ // ============================================================================
7
+ // Workflow Loader Singleton
8
+ // ============================================================================
9
+ let _workflowLoader = null;
10
+ function getWorkflowLoader() {
11
+ if (_workflowLoader === null) {
12
+ const workflowDir = findWorkflowDir(process.cwd()) ?? 'examples/workflows';
13
+ _workflowLoader = createWorkflowLoader({ workflowsDir: workflowDir });
14
+ }
15
+ return _workflowLoader;
16
+ }
17
+ /**
18
+ * Get the appropriate step executor based on environment
19
+ * Uses placeholder in tests, production executor otherwise
20
+ */
21
+ function getWorkflowStepExecutor() {
22
+ if (isTestEnv) {
23
+ return defaultStepExecutor;
24
+ }
25
+ return getStepExecutor();
26
+ }
27
+ // ============================================================================
28
+ // Tool Definitions
29
+ // ============================================================================
30
+ /**
31
+ * Workflow run tool definition
32
+ */
33
+ export const workflowRunTool = {
34
+ name: 'workflow_run',
35
+ description: 'Execute a workflow by ID with optional input parameters',
36
+ inputSchema: {
37
+ type: 'object',
38
+ properties: {
39
+ workflowId: {
40
+ type: 'string',
41
+ description: 'The ID of the workflow to execute',
42
+ },
43
+ input: {
44
+ type: 'object',
45
+ description: 'Optional input parameters for the workflow',
46
+ },
47
+ },
48
+ required: ['workflowId'],
49
+ },
50
+ };
51
+ /**
52
+ * Workflow list tool definition
53
+ */
54
+ export const workflowListTool = {
55
+ name: 'workflow_list',
56
+ description: 'List all available workflows',
57
+ inputSchema: {
58
+ type: 'object',
59
+ properties: {
60
+ status: {
61
+ type: 'string',
62
+ description: 'Filter by status (active, inactive, draft)',
63
+ enum: ['active', 'inactive', 'draft'],
64
+ },
65
+ limit: {
66
+ type: 'number',
67
+ description: 'Maximum number of workflows to return',
68
+ default: LIMIT_WORKFLOWS,
69
+ },
70
+ },
71
+ },
72
+ };
73
+ /**
74
+ * Workflow describe tool definition
75
+ */
76
+ export const workflowDescribeTool = {
77
+ name: 'workflow_describe',
78
+ description: 'Get detailed information about a specific workflow',
79
+ inputSchema: {
80
+ type: 'object',
81
+ properties: {
82
+ workflowId: {
83
+ type: 'string',
84
+ description: 'The ID of the workflow to describe',
85
+ },
86
+ },
87
+ required: ['workflowId'],
88
+ },
89
+ };
90
+ // ============================================================================
91
+ // Tool Handlers
92
+ // ============================================================================
93
+ /**
94
+ * Handler for workflow_run tool
95
+ */
96
+ export const handleWorkflowRun = async (args) => {
97
+ const workflowId = args.workflowId;
98
+ const input = args.input ?? {};
99
+ try {
100
+ // Load workflow from file
101
+ const loader = getWorkflowLoader();
102
+ const workflow = await loader.load(workflowId);
103
+ if (!workflow) {
104
+ const available = await loader.loadAll();
105
+ const ids = available.map(w => w.workflowId).slice(0, 5).join(', ');
106
+ return {
107
+ content: [
108
+ {
109
+ type: 'text',
110
+ text: JSON.stringify({
111
+ error: `Workflow "${workflowId}" not found`,
112
+ availableWorkflows: ids,
113
+ hint: 'Use workflow_list to see all available workflows',
114
+ }, null, 2),
115
+ },
116
+ ],
117
+ isError: true,
118
+ };
119
+ }
120
+ // Create workflow runner with production step executor
121
+ // Uses placeholder executor in test environment to avoid real LLM calls
122
+ const runner = createWorkflowRunner({
123
+ stepExecutor: getWorkflowStepExecutor(),
124
+ });
125
+ // Execute workflow
126
+ const result = await runner.run(workflow, input);
127
+ return {
128
+ content: [
129
+ {
130
+ type: 'text',
131
+ text: JSON.stringify({
132
+ success: result.success,
133
+ workflowId: workflow.workflowId,
134
+ name: workflow.name,
135
+ version: workflow.version,
136
+ stepsCompleted: result.stepResults.map((s) => ({
137
+ stepId: s.stepId,
138
+ success: s.success,
139
+ durationMs: s.durationMs,
140
+ })),
141
+ output: result.output,
142
+ totalDurationMs: result.totalDurationMs,
143
+ error: result.error,
144
+ }, null, 2),
145
+ },
146
+ ],
147
+ isError: !result.success,
148
+ };
149
+ }
150
+ catch (error) {
151
+ return {
152
+ content: [
153
+ {
154
+ type: 'text',
155
+ text: `Error executing workflow: ${error instanceof Error ? error.message : 'Unknown error'}`,
156
+ },
157
+ ],
158
+ isError: true,
159
+ };
160
+ }
161
+ };
162
+ /**
163
+ * Handler for workflow_list tool
164
+ */
165
+ export const handleWorkflowList = async (args) => {
166
+ const status = args.status;
167
+ const limit = args.limit ?? LIMIT_WORKFLOWS;
168
+ try {
169
+ const loader = getWorkflowLoader();
170
+ const allWorkflows = await loader.listAll();
171
+ // Filter by status if specified
172
+ const filtered = status !== undefined
173
+ ? allWorkflows.filter((w) => w.status === status)
174
+ : allWorkflows;
175
+ // Apply limit
176
+ const limited = filtered.slice(0, limit);
177
+ // Format for output
178
+ const workflows = limited.map((w) => ({
179
+ id: w.id,
180
+ name: w.name,
181
+ version: w.version,
182
+ description: w.description,
183
+ stepCount: w.stepCount,
184
+ status: w.status,
185
+ }));
186
+ return {
187
+ content: [
188
+ {
189
+ type: 'text',
190
+ text: JSON.stringify({
191
+ count: workflows.length,
192
+ total: allWorkflows.length,
193
+ workflows,
194
+ }, null, 2),
195
+ },
196
+ ],
197
+ };
198
+ }
199
+ catch (error) {
200
+ return {
201
+ content: [
202
+ {
203
+ type: 'text',
204
+ text: `Error listing workflows: ${error instanceof Error ? error.message : 'Unknown error'}`,
205
+ },
206
+ ],
207
+ isError: true,
208
+ };
209
+ }
210
+ };
211
+ /**
212
+ * Handler for workflow_describe tool
213
+ */
214
+ export const handleWorkflowDescribe = async (args) => {
215
+ const workflowId = args.workflowId;
216
+ try {
217
+ const loader = getWorkflowLoader();
218
+ const workflow = await loader.load(workflowId);
219
+ if (!workflow) {
220
+ return {
221
+ content: [
222
+ {
223
+ type: 'text',
224
+ text: JSON.stringify({
225
+ error: `Workflow "${workflowId}" not found`,
226
+ hint: 'Use workflow_list to see all available workflows',
227
+ }, null, 2),
228
+ },
229
+ ],
230
+ isError: true,
231
+ };
232
+ }
233
+ // Format workflow for output
234
+ const description = {
235
+ workflowId: workflow.workflowId,
236
+ name: workflow.name,
237
+ version: workflow.version,
238
+ description: workflow.description,
239
+ steps: workflow.steps.map((step) => ({
240
+ stepId: step.stepId,
241
+ name: step.name,
242
+ type: step.type,
243
+ timeout: step.timeout,
244
+ config: step.config,
245
+ })),
246
+ metadata: workflow.metadata,
247
+ };
248
+ return {
249
+ content: [
250
+ {
251
+ type: 'text',
252
+ text: JSON.stringify(description, null, 2),
253
+ },
254
+ ],
255
+ };
256
+ }
257
+ catch (error) {
258
+ return {
259
+ content: [
260
+ {
261
+ type: 'text',
262
+ text: `Error describing workflow: ${error instanceof Error ? error.message : 'Unknown error'}`,
263
+ },
264
+ ],
265
+ isError: true,
266
+ };
267
+ }
268
+ };
269
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/tools/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,GAGpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,qCAAqC;AACrC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC;AAEnF,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,IAAI,eAAe,GAAmD,IAAI,CAAC;AAE3E,SAAS,iBAAiB;IACxB,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC;QAC3E,eAAe,GAAG,oBAAoB,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,uBAAuB;IAC9B,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,m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ACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE;iBAC/F;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * MCP Tool Trace Wrapper
3
+ *
4
+ * Wraps tool handlers with tracing for observability.
5
+ *
6
+ * Invariants:
7
+ * - INV-MCP-007: Every tool call produces exactly one trace
8
+ * - INV-MCP-008: Trace includes input/output/duration/success
9
+ */
10
+ import type { ToolHandler } from './types.js';
11
+ import { type ToolTraceEvent } from '@defai.digital/contracts';
12
+ /**
13
+ * Collects trace events for analysis and persistence
14
+ */
15
+ export interface TraceCollector {
16
+ /**
17
+ * Records a tool trace event
18
+ */
19
+ record(event: ToolTraceEvent): void;
20
+ /**
21
+ * Gets all recorded events
22
+ */
23
+ getEvents(): ToolTraceEvent[];
24
+ /**
25
+ * Clears recorded events
26
+ */
27
+ clear(): void;
28
+ }
29
+ /**
30
+ * In-memory trace collector implementation
31
+ */
32
+ export declare class InMemoryTraceCollector implements TraceCollector {
33
+ private events;
34
+ private readonly maxEvents;
35
+ constructor(maxEvents?: number);
36
+ record(event: ToolTraceEvent): void;
37
+ getEvents(): ToolTraceEvent[];
38
+ clear(): void;
39
+ /**
40
+ * Gets summary statistics
41
+ */
42
+ getSummary(): {
43
+ totalInvocations: number;
44
+ successCount: number;
45
+ failureCount: number;
46
+ avgDurationMs: number;
47
+ byTool: Record<string, number>;
48
+ };
49
+ }
50
+ /**
51
+ * Sets the global trace collector
52
+ */
53
+ export declare function setTraceCollector(collector: TraceCollector): void;
54
+ /**
55
+ * Gets the global trace collector
56
+ */
57
+ export declare function getTraceCollector(): TraceCollector | undefined;
58
+ /**
59
+ * Wraps a single tool handler with tracing
60
+ *
61
+ * INV-MCP-007: Every tool call produces exactly one trace event
62
+ * INV-MCP-008: Trace includes input/output/duration/success
63
+ */
64
+ export declare function withTracing(toolName: string, handler: ToolHandler, collector?: TraceCollector): ToolHandler;
65
+ /**
66
+ * Wraps all handlers in a registry with tracing
67
+ */
68
+ export declare function wrapHandlersWithTracing(handlers: Record<string, ToolHandler>, collector?: TraceCollector): Record<string, ToolHandler>;
69
+ /**
70
+ * Initializes default trace collector if not already set
71
+ * Returns the collector, which may be InMemoryTraceCollector or a custom implementation
72
+ */
73
+ export declare function initializeDefaultTracing(): TraceCollector;
74
+ /**
75
+ * Gets the trace collector as InMemoryTraceCollector if it is one
76
+ * Returns undefined if no collector is set or if it's a different implementation
77
+ */
78
+ export declare function getInMemoryTraceCollector(): InMemoryTraceCollector | undefined;
79
+ //# sourceMappingURL=trace-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-wrapper.d.ts","sourceRoot":"","sources":["../src/trace-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAMrF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,SAAS,IAAI,cAAc,EAAE,CAAC;IAE9B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,SAAS,SAAO;IAI5B,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAQnC,SAAS,IAAI,cAAc,EAAE;IAI7B,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,UAAU,IAAI;QACZ,g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