windows-exe-decompiler-mcp-server 0.1.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.
Files changed (190) hide show
  1. package/CODEX_INSTALLATION.md +69 -0
  2. package/COPILOT_INSTALLATION.md +77 -0
  3. package/LICENSE +21 -0
  4. package/README.md +314 -0
  5. package/bin/windows-exe-decompiler-mcp-server.js +3 -0
  6. package/dist/analysis-provenance.d.ts +184 -0
  7. package/dist/analysis-provenance.js +74 -0
  8. package/dist/analysis-task-runner.d.ts +31 -0
  9. package/dist/analysis-task-runner.js +160 -0
  10. package/dist/artifact-inventory.d.ts +23 -0
  11. package/dist/artifact-inventory.js +175 -0
  12. package/dist/cache-manager.d.ts +128 -0
  13. package/dist/cache-manager.js +454 -0
  14. package/dist/confidence-semantics.d.ts +66 -0
  15. package/dist/confidence-semantics.js +122 -0
  16. package/dist/config.d.ts +335 -0
  17. package/dist/config.js +193 -0
  18. package/dist/database.d.ts +227 -0
  19. package/dist/database.js +601 -0
  20. package/dist/decompiler-worker.d.ts +441 -0
  21. package/dist/decompiler-worker.js +1962 -0
  22. package/dist/dynamic-trace.d.ts +95 -0
  23. package/dist/dynamic-trace.js +629 -0
  24. package/dist/env-validator.d.ts +15 -0
  25. package/dist/env-validator.js +249 -0
  26. package/dist/error-handler.d.ts +28 -0
  27. package/dist/error-handler.example.d.ts +22 -0
  28. package/dist/error-handler.example.js +141 -0
  29. package/dist/error-handler.js +139 -0
  30. package/dist/ghidra-analysis-status.d.ts +49 -0
  31. package/dist/ghidra-analysis-status.js +178 -0
  32. package/dist/ghidra-config.d.ts +134 -0
  33. package/dist/ghidra-config.js +464 -0
  34. package/dist/index.d.ts +9 -0
  35. package/dist/index.js +200 -0
  36. package/dist/job-queue.d.ts +169 -0
  37. package/dist/job-queue.js +407 -0
  38. package/dist/logger.d.ts +106 -0
  39. package/dist/logger.js +176 -0
  40. package/dist/policy-guard.d.ts +115 -0
  41. package/dist/policy-guard.js +243 -0
  42. package/dist/process-output.d.ts +15 -0
  43. package/dist/process-output.js +90 -0
  44. package/dist/prompts/function-explanation-review.d.ts +5 -0
  45. package/dist/prompts/function-explanation-review.js +64 -0
  46. package/dist/prompts/semantic-name-review.d.ts +5 -0
  47. package/dist/prompts/semantic-name-review.js +63 -0
  48. package/dist/runtime-correlation.d.ts +34 -0
  49. package/dist/runtime-correlation.js +279 -0
  50. package/dist/runtime-paths.d.ts +3 -0
  51. package/dist/runtime-paths.js +11 -0
  52. package/dist/selection-diff.d.ts +667 -0
  53. package/dist/selection-diff.js +53 -0
  54. package/dist/semantic-name-suggestion-artifacts.d.ts +116 -0
  55. package/dist/semantic-name-suggestion-artifacts.js +314 -0
  56. package/dist/server.d.ts +129 -0
  57. package/dist/server.js +578 -0
  58. package/dist/tools/artifact-read.d.ts +235 -0
  59. package/dist/tools/artifact-read.js +317 -0
  60. package/dist/tools/artifacts-diff.d.ts +728 -0
  61. package/dist/tools/artifacts-diff.js +304 -0
  62. package/dist/tools/artifacts-list.d.ts +515 -0
  63. package/dist/tools/artifacts-list.js +389 -0
  64. package/dist/tools/attack-map.d.ts +290 -0
  65. package/dist/tools/attack-map.js +519 -0
  66. package/dist/tools/cache-observability.d.ts +4 -0
  67. package/dist/tools/cache-observability.js +36 -0
  68. package/dist/tools/code-function-cfg.d.ts +50 -0
  69. package/dist/tools/code-function-cfg.js +102 -0
  70. package/dist/tools/code-function-decompile.d.ts +55 -0
  71. package/dist/tools/code-function-decompile.js +103 -0
  72. package/dist/tools/code-function-disassemble.d.ts +43 -0
  73. package/dist/tools/code-function-disassemble.js +185 -0
  74. package/dist/tools/code-function-explain-apply.d.ts +255 -0
  75. package/dist/tools/code-function-explain-apply.js +225 -0
  76. package/dist/tools/code-function-explain-prepare.d.ts +535 -0
  77. package/dist/tools/code-function-explain-prepare.js +276 -0
  78. package/dist/tools/code-function-explain-review.d.ts +397 -0
  79. package/dist/tools/code-function-explain-review.js +589 -0
  80. package/dist/tools/code-function-rename-apply.d.ts +248 -0
  81. package/dist/tools/code-function-rename-apply.js +220 -0
  82. package/dist/tools/code-function-rename-prepare.d.ts +506 -0
  83. package/dist/tools/code-function-rename-prepare.js +279 -0
  84. package/dist/tools/code-function-rename-review.d.ts +574 -0
  85. package/dist/tools/code-function-rename-review.js +761 -0
  86. package/dist/tools/code-functions-list.d.ts +37 -0
  87. package/dist/tools/code-functions-list.js +91 -0
  88. package/dist/tools/code-functions-rank.d.ts +34 -0
  89. package/dist/tools/code-functions-rank.js +90 -0
  90. package/dist/tools/code-functions-reconstruct.d.ts +2725 -0
  91. package/dist/tools/code-functions-reconstruct.js +2807 -0
  92. package/dist/tools/code-functions-search.d.ts +39 -0
  93. package/dist/tools/code-functions-search.js +90 -0
  94. package/dist/tools/code-reconstruct-export.d.ts +1212 -0
  95. package/dist/tools/code-reconstruct-export.js +4002 -0
  96. package/dist/tools/code-reconstruct-plan.d.ts +274 -0
  97. package/dist/tools/code-reconstruct-plan.js +342 -0
  98. package/dist/tools/dotnet-metadata-extract.d.ts +541 -0
  99. package/dist/tools/dotnet-metadata-extract.js +355 -0
  100. package/dist/tools/dotnet-reconstruct-export.d.ts +567 -0
  101. package/dist/tools/dotnet-reconstruct-export.js +1151 -0
  102. package/dist/tools/dotnet-types-list.d.ts +325 -0
  103. package/dist/tools/dotnet-types-list.js +201 -0
  104. package/dist/tools/dynamic-dependencies.d.ts +115 -0
  105. package/dist/tools/dynamic-dependencies.js +213 -0
  106. package/dist/tools/dynamic-memory-import.d.ts +10 -0
  107. package/dist/tools/dynamic-memory-import.js +567 -0
  108. package/dist/tools/dynamic-trace-import.d.ts +10 -0
  109. package/dist/tools/dynamic-trace-import.js +235 -0
  110. package/dist/tools/entrypoint-fallback-disasm.d.ts +30 -0
  111. package/dist/tools/entrypoint-fallback-disasm.js +89 -0
  112. package/dist/tools/ghidra-analyze.d.ts +88 -0
  113. package/dist/tools/ghidra-analyze.js +208 -0
  114. package/dist/tools/ghidra-health.d.ts +37 -0
  115. package/dist/tools/ghidra-health.js +212 -0
  116. package/dist/tools/ioc-export.d.ts +209 -0
  117. package/dist/tools/ioc-export.js +542 -0
  118. package/dist/tools/packer-detect.d.ts +165 -0
  119. package/dist/tools/packer-detect.js +284 -0
  120. package/dist/tools/pe-exports-extract.d.ts +175 -0
  121. package/dist/tools/pe-exports-extract.js +253 -0
  122. package/dist/tools/pe-fingerprint.d.ts +234 -0
  123. package/dist/tools/pe-fingerprint.js +269 -0
  124. package/dist/tools/pe-imports-extract.d.ts +105 -0
  125. package/dist/tools/pe-imports-extract.js +245 -0
  126. package/dist/tools/report-generate.d.ts +157 -0
  127. package/dist/tools/report-generate.js +457 -0
  128. package/dist/tools/report-summarize.d.ts +2131 -0
  129. package/dist/tools/report-summarize.js +596 -0
  130. package/dist/tools/runtime-detect.d.ts +135 -0
  131. package/dist/tools/runtime-detect.js +247 -0
  132. package/dist/tools/sample-ingest.d.ts +94 -0
  133. package/dist/tools/sample-ingest.js +327 -0
  134. package/dist/tools/sample-profile-get.d.ts +183 -0
  135. package/dist/tools/sample-profile-get.js +121 -0
  136. package/dist/tools/sandbox-execute.d.ts +441 -0
  137. package/dist/tools/sandbox-execute.js +392 -0
  138. package/dist/tools/strings-extract.d.ts +375 -0
  139. package/dist/tools/strings-extract.js +314 -0
  140. package/dist/tools/strings-floss-decode.d.ts +143 -0
  141. package/dist/tools/strings-floss-decode.js +259 -0
  142. package/dist/tools/system-health.d.ts +434 -0
  143. package/dist/tools/system-health.js +446 -0
  144. package/dist/tools/task-cancel.d.ts +21 -0
  145. package/dist/tools/task-cancel.js +70 -0
  146. package/dist/tools/task-status.d.ts +27 -0
  147. package/dist/tools/task-status.js +106 -0
  148. package/dist/tools/task-sweep.d.ts +22 -0
  149. package/dist/tools/task-sweep.js +77 -0
  150. package/dist/tools/tool-help.d.ts +340 -0
  151. package/dist/tools/tool-help.js +261 -0
  152. package/dist/tools/yara-scan.d.ts +554 -0
  153. package/dist/tools/yara-scan.js +313 -0
  154. package/dist/types.d.ts +266 -0
  155. package/dist/types.js +41 -0
  156. package/dist/worker-pool.d.ts +204 -0
  157. package/dist/worker-pool.js +650 -0
  158. package/dist/workflows/deep-static.d.ts +104 -0
  159. package/dist/workflows/deep-static.js +276 -0
  160. package/dist/workflows/function-explanation-review.d.ts +655 -0
  161. package/dist/workflows/function-explanation-review.js +440 -0
  162. package/dist/workflows/reconstruct.d.ts +2053 -0
  163. package/dist/workflows/reconstruct.js +666 -0
  164. package/dist/workflows/semantic-name-review.d.ts +2418 -0
  165. package/dist/workflows/semantic-name-review.js +521 -0
  166. package/dist/workflows/triage.d.ts +659 -0
  167. package/dist/workflows/triage.js +1374 -0
  168. package/dist/workspace-manager.d.ts +150 -0
  169. package/dist/workspace-manager.js +411 -0
  170. package/ghidra_scripts/DecompileFunction.java +487 -0
  171. package/ghidra_scripts/DecompileFunction.py +150 -0
  172. package/ghidra_scripts/ExtractCFG.java +256 -0
  173. package/ghidra_scripts/ExtractCFG.py +233 -0
  174. package/ghidra_scripts/ExtractFunctions.java +442 -0
  175. package/ghidra_scripts/ExtractFunctions.py +101 -0
  176. package/ghidra_scripts/README.md +125 -0
  177. package/ghidra_scripts/SearchFunctionReferences.java +380 -0
  178. package/helpers/DotNetMetadataProbe/DotNetMetadataProbe.csproj +9 -0
  179. package/helpers/DotNetMetadataProbe/Program.cs +566 -0
  180. package/install-to-codex.ps1 +178 -0
  181. package/install-to-copilot.ps1 +303 -0
  182. package/package.json +101 -0
  183. package/requirements.txt +9 -0
  184. package/workers/requirements-dynamic.txt +11 -0
  185. package/workers/requirements.txt +8 -0
  186. package/workers/speakeasy_compat.py +175 -0
  187. package/workers/static_worker.py +5183 -0
  188. package/workers/yara_rules/default.yar +33 -0
  189. package/workers/yara_rules/malware_families.yar +93 -0
  190. package/workers/yara_rules/packers.yar +80 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * task.sweep MCP tool
3
+ * Reap stale running tasks and clear old finished records.
4
+ */
5
+ import { z } from 'zod';
6
+ import type { ToolDefinition, ToolHandler } from '../types.js';
7
+ import type { JobQueue } from '../job-queue.js';
8
+ import type { DatabaseManager } from '../database.js';
9
+ export declare const taskSweepInputSchema: z.ZodObject<{
10
+ stale_running_ms: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
11
+ clear_finished_older_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ clear_finished_older_ms: number;
14
+ stale_running_ms?: number | null | undefined;
15
+ }, {
16
+ stale_running_ms?: number | null | undefined;
17
+ clear_finished_older_ms?: number | undefined;
18
+ }>;
19
+ export type TaskSweepInput = z.infer<typeof taskSweepInputSchema>;
20
+ export declare const taskSweepToolDefinition: ToolDefinition;
21
+ export declare function createTaskSweepHandler(jobQueue: JobQueue, database?: DatabaseManager): ToolHandler;
22
+ //# sourceMappingURL=task-sweep.d.ts.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * task.sweep MCP tool
3
+ * Reap stale running tasks and clear old finished records.
4
+ */
5
+ import { z } from 'zod';
6
+ const TOOL_NAME = 'task.sweep';
7
+ export const taskSweepInputSchema = z.object({
8
+ stale_running_ms: z
9
+ .number()
10
+ .int()
11
+ .min(1000)
12
+ .nullable()
13
+ .optional()
14
+ .describe('Optional stale-running threshold in milliseconds. Omit or null to disable automatic reaping.'),
15
+ clear_finished_older_ms: z
16
+ .number()
17
+ .int()
18
+ .min(60 * 1000)
19
+ .optional()
20
+ .default(24 * 60 * 60 * 1000)
21
+ .describe('Clear completed/failed/cancelled jobs older than this threshold (default: 24 hours)'),
22
+ });
23
+ export const taskSweepToolDefinition = {
24
+ name: TOOL_NAME,
25
+ description: 'Sweep stale running tasks and clear old finished task records.',
26
+ inputSchema: taskSweepInputSchema,
27
+ };
28
+ export function createTaskSweepHandler(jobQueue, database) {
29
+ return async (args) => {
30
+ try {
31
+ const input = taskSweepInputSchema.parse(args);
32
+ const reaper = jobQueue;
33
+ const reaped = typeof input.stale_running_ms === 'number' && typeof reaper.reapStaleRunningJobs === 'function'
34
+ ? reaper.reapStaleRunningJobs(input.stale_running_ms)
35
+ : [];
36
+ const reapedAnalyses = database
37
+ ? typeof input.stale_running_ms === 'number'
38
+ ? database.reapStaleAnalyses(input.stale_running_ms)
39
+ : []
40
+ : [];
41
+ const cleared = jobQueue.clearOldJobs(input.clear_finished_older_ms);
42
+ return {
43
+ content: [
44
+ {
45
+ type: 'text',
46
+ text: JSON.stringify({
47
+ ok: true,
48
+ data: {
49
+ reaped_running_jobs: reaped,
50
+ reaped_count: reaped.length,
51
+ reaped_persisted_analyses: reapedAnalyses.map((item) => item.id),
52
+ reaped_persisted_analysis_count: reapedAnalyses.length,
53
+ cleared_finished_count: cleared,
54
+ },
55
+ }, null, 2),
56
+ },
57
+ ],
58
+ };
59
+ }
60
+ catch (error) {
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ return {
63
+ content: [
64
+ {
65
+ type: 'text',
66
+ text: JSON.stringify({
67
+ ok: false,
68
+ errors: [message],
69
+ }, null, 2),
70
+ },
71
+ ],
72
+ isError: true,
73
+ };
74
+ }
75
+ };
76
+ }
77
+ //# sourceMappingURL=task-sweep.js.map
@@ -0,0 +1,340 @@
1
+ import { z } from 'zod';
2
+ import type { ToolArgs, ToolDefinition, WorkerResult } from '../types.js';
3
+ export declare const toolHelpInputSchema: z.ZodObject<{
4
+ tool_name: z.ZodOptional<z.ZodString>;
5
+ include_output_schema: z.ZodDefault<z.ZodBoolean>;
6
+ include_fields: z.ZodDefault<z.ZodBoolean>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ include_output_schema: boolean;
9
+ include_fields: boolean;
10
+ tool_name?: string | undefined;
11
+ }, {
12
+ tool_name?: string | undefined;
13
+ include_output_schema?: boolean | undefined;
14
+ include_fields?: boolean | undefined;
15
+ }>;
16
+ export declare const toolHelpOutputSchema: z.ZodObject<{
17
+ ok: z.ZodBoolean;
18
+ data: z.ZodObject<{
19
+ count: z.ZodNumber;
20
+ tools: z.ZodArray<z.ZodObject<{
21
+ name: z.ZodString;
22
+ description: z.ZodString;
23
+ usage_notes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
24
+ input: z.ZodOptional<z.ZodObject<{
25
+ field_count: z.ZodNumber;
26
+ fields: z.ZodArray<z.ZodObject<{
27
+ path: z.ZodString;
28
+ type: z.ZodString;
29
+ required: z.ZodBoolean;
30
+ nullable: z.ZodBoolean;
31
+ description: z.ZodNullable<z.ZodString>;
32
+ help_hint: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ default_value: z.ZodOptional<z.ZodAny>;
34
+ enum_values: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ path: string;
37
+ type: string;
38
+ description: string | null;
39
+ required: boolean;
40
+ nullable: boolean;
41
+ help_hint?: string | null | undefined;
42
+ default_value?: any;
43
+ enum_values?: string[] | undefined;
44
+ }, {
45
+ path: string;
46
+ type: string;
47
+ description: string | null;
48
+ required: boolean;
49
+ nullable: boolean;
50
+ help_hint?: string | null | undefined;
51
+ default_value?: any;
52
+ enum_values?: string[] | undefined;
53
+ }>, "many">;
54
+ }, "strip", z.ZodTypeAny, {
55
+ field_count: number;
56
+ fields: {
57
+ path: string;
58
+ type: string;
59
+ description: string | null;
60
+ required: boolean;
61
+ nullable: boolean;
62
+ help_hint?: string | null | undefined;
63
+ default_value?: any;
64
+ enum_values?: string[] | undefined;
65
+ }[];
66
+ }, {
67
+ field_count: number;
68
+ fields: {
69
+ path: string;
70
+ type: string;
71
+ description: string | null;
72
+ required: boolean;
73
+ nullable: boolean;
74
+ help_hint?: string | null | undefined;
75
+ default_value?: any;
76
+ enum_values?: string[] | undefined;
77
+ }[];
78
+ }>>;
79
+ output: z.ZodOptional<z.ZodObject<{
80
+ field_count: z.ZodNumber;
81
+ fields: z.ZodArray<z.ZodObject<{
82
+ path: z.ZodString;
83
+ type: z.ZodString;
84
+ required: z.ZodBoolean;
85
+ nullable: z.ZodBoolean;
86
+ description: z.ZodNullable<z.ZodString>;
87
+ help_hint: z.ZodOptional<z.ZodNullable<z.ZodString>>;
88
+ default_value: z.ZodOptional<z.ZodAny>;
89
+ enum_values: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
90
+ }, "strip", z.ZodTypeAny, {
91
+ path: string;
92
+ type: string;
93
+ description: string | null;
94
+ required: boolean;
95
+ nullable: boolean;
96
+ help_hint?: string | null | undefined;
97
+ default_value?: any;
98
+ enum_values?: string[] | undefined;
99
+ }, {
100
+ path: string;
101
+ type: string;
102
+ description: string | null;
103
+ required: boolean;
104
+ nullable: boolean;
105
+ help_hint?: string | null | undefined;
106
+ default_value?: any;
107
+ enum_values?: string[] | undefined;
108
+ }>, "many">;
109
+ }, "strip", z.ZodTypeAny, {
110
+ field_count: number;
111
+ fields: {
112
+ path: string;
113
+ type: string;
114
+ description: string | null;
115
+ required: boolean;
116
+ nullable: boolean;
117
+ help_hint?: string | null | undefined;
118
+ default_value?: any;
119
+ enum_values?: string[] | undefined;
120
+ }[];
121
+ }, {
122
+ field_count: number;
123
+ fields: {
124
+ path: string;
125
+ type: string;
126
+ description: string | null;
127
+ required: boolean;
128
+ nullable: boolean;
129
+ help_hint?: string | null | undefined;
130
+ default_value?: any;
131
+ enum_values?: string[] | undefined;
132
+ }[];
133
+ }>>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ name: string;
136
+ description: string;
137
+ output?: {
138
+ field_count: number;
139
+ fields: {
140
+ path: string;
141
+ type: string;
142
+ description: string | null;
143
+ required: boolean;
144
+ nullable: boolean;
145
+ help_hint?: string | null | undefined;
146
+ default_value?: any;
147
+ enum_values?: string[] | undefined;
148
+ }[];
149
+ } | undefined;
150
+ input?: {
151
+ field_count: number;
152
+ fields: {
153
+ path: string;
154
+ type: string;
155
+ description: string | null;
156
+ required: boolean;
157
+ nullable: boolean;
158
+ help_hint?: string | null | undefined;
159
+ default_value?: any;
160
+ enum_values?: string[] | undefined;
161
+ }[];
162
+ } | undefined;
163
+ usage_notes?: string[] | undefined;
164
+ }, {
165
+ name: string;
166
+ description: string;
167
+ output?: {
168
+ field_count: number;
169
+ fields: {
170
+ path: string;
171
+ type: string;
172
+ description: string | null;
173
+ required: boolean;
174
+ nullable: boolean;
175
+ help_hint?: string | null | undefined;
176
+ default_value?: any;
177
+ enum_values?: string[] | undefined;
178
+ }[];
179
+ } | undefined;
180
+ input?: {
181
+ field_count: number;
182
+ fields: {
183
+ path: string;
184
+ type: string;
185
+ description: string | null;
186
+ required: boolean;
187
+ nullable: boolean;
188
+ help_hint?: string | null | undefined;
189
+ default_value?: any;
190
+ enum_values?: string[] | undefined;
191
+ }[];
192
+ } | undefined;
193
+ usage_notes?: string[] | undefined;
194
+ }>, "many">;
195
+ }, "strip", z.ZodTypeAny, {
196
+ count: number;
197
+ tools: {
198
+ name: string;
199
+ description: string;
200
+ output?: {
201
+ field_count: number;
202
+ fields: {
203
+ path: string;
204
+ type: string;
205
+ description: string | null;
206
+ required: boolean;
207
+ nullable: boolean;
208
+ help_hint?: string | null | undefined;
209
+ default_value?: any;
210
+ enum_values?: string[] | undefined;
211
+ }[];
212
+ } | undefined;
213
+ input?: {
214
+ field_count: number;
215
+ fields: {
216
+ path: string;
217
+ type: string;
218
+ description: string | null;
219
+ required: boolean;
220
+ nullable: boolean;
221
+ help_hint?: string | null | undefined;
222
+ default_value?: any;
223
+ enum_values?: string[] | undefined;
224
+ }[];
225
+ } | undefined;
226
+ usage_notes?: string[] | undefined;
227
+ }[];
228
+ }, {
229
+ count: number;
230
+ tools: {
231
+ name: string;
232
+ description: string;
233
+ output?: {
234
+ field_count: number;
235
+ fields: {
236
+ path: string;
237
+ type: string;
238
+ description: string | null;
239
+ required: boolean;
240
+ nullable: boolean;
241
+ help_hint?: string | null | undefined;
242
+ default_value?: any;
243
+ enum_values?: string[] | undefined;
244
+ }[];
245
+ } | undefined;
246
+ input?: {
247
+ field_count: number;
248
+ fields: {
249
+ path: string;
250
+ type: string;
251
+ description: string | null;
252
+ required: boolean;
253
+ nullable: boolean;
254
+ help_hint?: string | null | undefined;
255
+ default_value?: any;
256
+ enum_values?: string[] | undefined;
257
+ }[];
258
+ } | undefined;
259
+ usage_notes?: string[] | undefined;
260
+ }[];
261
+ }>;
262
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
263
+ }, "strip", z.ZodTypeAny, {
264
+ data: {
265
+ count: number;
266
+ tools: {
267
+ name: string;
268
+ description: string;
269
+ output?: {
270
+ field_count: number;
271
+ fields: {
272
+ path: string;
273
+ type: string;
274
+ description: string | null;
275
+ required: boolean;
276
+ nullable: boolean;
277
+ help_hint?: string | null | undefined;
278
+ default_value?: any;
279
+ enum_values?: string[] | undefined;
280
+ }[];
281
+ } | undefined;
282
+ input?: {
283
+ field_count: number;
284
+ fields: {
285
+ path: string;
286
+ type: string;
287
+ description: string | null;
288
+ required: boolean;
289
+ nullable: boolean;
290
+ help_hint?: string | null | undefined;
291
+ default_value?: any;
292
+ enum_values?: string[] | undefined;
293
+ }[];
294
+ } | undefined;
295
+ usage_notes?: string[] | undefined;
296
+ }[];
297
+ };
298
+ ok: boolean;
299
+ errors?: string[] | undefined;
300
+ }, {
301
+ data: {
302
+ count: number;
303
+ tools: {
304
+ name: string;
305
+ description: string;
306
+ output?: {
307
+ field_count: number;
308
+ fields: {
309
+ path: string;
310
+ type: string;
311
+ description: string | null;
312
+ required: boolean;
313
+ nullable: boolean;
314
+ help_hint?: string | null | undefined;
315
+ default_value?: any;
316
+ enum_values?: string[] | undefined;
317
+ }[];
318
+ } | undefined;
319
+ input?: {
320
+ field_count: number;
321
+ fields: {
322
+ path: string;
323
+ type: string;
324
+ description: string | null;
325
+ required: boolean;
326
+ nullable: boolean;
327
+ help_hint?: string | null | undefined;
328
+ default_value?: any;
329
+ enum_values?: string[] | undefined;
330
+ }[];
331
+ } | undefined;
332
+ usage_notes?: string[] | undefined;
333
+ }[];
334
+ };
335
+ ok: boolean;
336
+ errors?: string[] | undefined;
337
+ }>;
338
+ export declare const toolHelpToolDefinition: ToolDefinition;
339
+ export declare function createToolHelpHandler(getDefinitions: () => ToolDefinition[]): (args: ToolArgs) => Promise<WorkerResult>;
340
+ //# sourceMappingURL=tool-help.d.ts.map
@@ -0,0 +1,261 @@
1
+ import { z } from 'zod';
2
+ const TOOL_NAME = 'tool.help';
3
+ const ToolFieldSchema = z.object({
4
+ path: z.string(),
5
+ type: z.string(),
6
+ required: z.boolean(),
7
+ nullable: z.boolean(),
8
+ description: z.string().nullable(),
9
+ help_hint: z.string().nullable().optional(),
10
+ default_value: z.any().optional(),
11
+ enum_values: z.array(z.string()).optional(),
12
+ });
13
+ const ToolSchemaSummarySchema = z.object({
14
+ field_count: z.number().int().nonnegative(),
15
+ fields: z.array(ToolFieldSchema),
16
+ });
17
+ export const toolHelpInputSchema = z.object({
18
+ tool_name: z.string().optional().describe('Optional exact tool name for a detailed schema/help lookup'),
19
+ include_output_schema: z
20
+ .boolean()
21
+ .default(true)
22
+ .describe('Include output schema field help when the tool defines one'),
23
+ include_fields: z
24
+ .boolean()
25
+ .default(true)
26
+ .describe('When false, only return name/description counts without flattened field help'),
27
+ });
28
+ export const toolHelpOutputSchema = z.object({
29
+ ok: z.boolean(),
30
+ data: z.object({
31
+ count: z.number().int().nonnegative(),
32
+ tools: z.array(z.object({
33
+ name: z.string(),
34
+ description: z.string(),
35
+ usage_notes: z.array(z.string()).optional(),
36
+ input: ToolSchemaSummarySchema.optional(),
37
+ output: ToolSchemaSummarySchema.optional(),
38
+ })),
39
+ }),
40
+ errors: z.array(z.string()).optional(),
41
+ });
42
+ export const toolHelpToolDefinition = {
43
+ name: TOOL_NAME,
44
+ description: 'Query normalized schema/help for registered MCP tools, including enum values, defaults, and field descriptions.',
45
+ inputSchema: toolHelpInputSchema,
46
+ outputSchema: toolHelpOutputSchema,
47
+ };
48
+ function unwrapSchema(schema) {
49
+ let current = schema;
50
+ let required = true;
51
+ let nullable = false;
52
+ let defaultValue;
53
+ while (true) {
54
+ if (current instanceof z.ZodOptional) {
55
+ required = false;
56
+ current = current._def.innerType;
57
+ continue;
58
+ }
59
+ if (current instanceof z.ZodDefault) {
60
+ required = false;
61
+ try {
62
+ defaultValue = current._def.defaultValue();
63
+ }
64
+ catch {
65
+ defaultValue = undefined;
66
+ }
67
+ current = current._def.innerType;
68
+ continue;
69
+ }
70
+ if (current instanceof z.ZodNullable) {
71
+ nullable = true;
72
+ current = current._def.innerType;
73
+ continue;
74
+ }
75
+ if (current instanceof z.ZodCatch) {
76
+ current = current._def.innerType;
77
+ continue;
78
+ }
79
+ if (current instanceof z.ZodEffects) {
80
+ current = current._def.schema;
81
+ continue;
82
+ }
83
+ if (current instanceof z.ZodBranded) {
84
+ current = current._def.type;
85
+ continue;
86
+ }
87
+ if (current instanceof z.ZodReadonly) {
88
+ current = current._def.innerType;
89
+ continue;
90
+ }
91
+ break;
92
+ }
93
+ return {
94
+ schema: current,
95
+ required,
96
+ nullable,
97
+ defaultValue,
98
+ };
99
+ }
100
+ function describeSchemaType(schema) {
101
+ if (schema instanceof z.ZodString)
102
+ return 'string';
103
+ if (schema instanceof z.ZodNumber)
104
+ return 'number';
105
+ if (schema instanceof z.ZodBoolean)
106
+ return 'boolean';
107
+ if (schema instanceof z.ZodEnum)
108
+ return 'enum';
109
+ if (schema instanceof z.ZodLiteral)
110
+ return 'literal';
111
+ if (schema instanceof z.ZodObject)
112
+ return 'object';
113
+ if (schema instanceof z.ZodArray) {
114
+ const itemInfo = unwrapSchema(schema._def.type);
115
+ return `array<${describeSchemaType(itemInfo.schema)}>`;
116
+ }
117
+ if (schema instanceof z.ZodUnion)
118
+ return 'union';
119
+ if (schema instanceof z.ZodTuple)
120
+ return 'tuple';
121
+ return 'unknown';
122
+ }
123
+ function collectSchemaFields(schema, prefix = '', toolName) {
124
+ const info = unwrapSchema(schema);
125
+ const current = info.schema;
126
+ if (current instanceof z.ZodObject) {
127
+ const shape = current.shape;
128
+ return Object.entries(shape).flatMap(([key, value]) => collectSchemaFields(value, prefix ? `${prefix}.${key}` : key, toolName));
129
+ }
130
+ const field = {
131
+ path: prefix || '$',
132
+ type: describeSchemaType(current),
133
+ required: info.required,
134
+ nullable: info.nullable,
135
+ description: schema.description || current.description || null,
136
+ help_hint: buildFieldHelpHint(prefix || '$', toolName),
137
+ };
138
+ if (info.defaultValue !== undefined) {
139
+ field.default_value = info.defaultValue;
140
+ }
141
+ if (current instanceof z.ZodEnum) {
142
+ field.enum_values = [...current._def.values];
143
+ }
144
+ else if (current instanceof z.ZodLiteral) {
145
+ field.enum_values = [String(current._def.value)];
146
+ }
147
+ return [field];
148
+ }
149
+ function buildFieldHelpHint(path, toolName) {
150
+ if (toolName === 'sample.ingest') {
151
+ if (path === 'path') {
152
+ return 'Preferred for local files. Pass an absolute path when the MCP client can read the same filesystem as the MCP server.';
153
+ }
154
+ if (path === 'bytes_b64') {
155
+ return 'Fallback only. Use this when the MCP client cannot read the local file path directly, such as remote or browser-hosted clients.';
156
+ }
157
+ if (path === 'filename') {
158
+ return 'Optional display/original filename. Useful when ingesting from bytes_b64 because there is no source path-derived filename.';
159
+ }
160
+ }
161
+ if (path === 'evidence_scope') {
162
+ return 'Controls runtime evidence selection only. Use session for one runtime import/replay lineage, latest for the newest artifact window, all to aggregate historical runtime evidence.';
163
+ }
164
+ if (path === 'evidence_session_tag') {
165
+ return 'Required when evidence_scope=session. You can also pass it with all/latest to narrow runtime evidence to one named session.';
166
+ }
167
+ if (path === 'semantic_scope') {
168
+ return 'Controls semantic naming/explanation artifact selection only. Use session to consume one naming or explanation review pass, latest for the newest semantic artifact window, all to aggregate historical semantic artifacts.';
169
+ }
170
+ if (path === 'semantic_session_tag') {
171
+ return 'Required when semantic_scope=session. Usually set this to the naming or explanation review session_tag you want reconstruct/export/report to consume.';
172
+ }
173
+ if (path === 'session_tag') {
174
+ return 'Session tag groups newly created artifacts so later MCP calls can select this exact review/export/import session.';
175
+ }
176
+ if (path === 'path_prefix') {
177
+ return 'Use this to narrow artifact tools to one export directory such as reports/reconstruct/<session>.';
178
+ }
179
+ return null;
180
+ }
181
+ function buildUsageNotes(definition) {
182
+ const notes = [];
183
+ const inputFields = buildSchemaSummary(definition.inputSchema, definition.name).fields.map((item) => item.path);
184
+ const hasEvidenceScope = inputFields.includes('evidence_scope');
185
+ const hasSemanticScope = inputFields.includes('semantic_scope');
186
+ const hasSessionTag = inputFields.includes('session_tag');
187
+ if (hasEvidenceScope && hasSemanticScope) {
188
+ notes.push('This tool separates runtime evidence scope from semantic artifact scope. Set both when you need fully reproducible session-only results.');
189
+ }
190
+ else if (hasEvidenceScope) {
191
+ notes.push('This tool consumes runtime evidence artifacts. Prefer evidence_scope=session plus evidence_session_tag for one replay/import session.');
192
+ }
193
+ if (hasSemanticScope) {
194
+ notes.push('This tool consumes naming/explanation artifacts. Prefer semantic_scope=session plus semantic_session_tag to avoid mixing historical LLM outputs.');
195
+ }
196
+ if (hasSessionTag) {
197
+ notes.push('session_tag labels newly created artifacts. Reuse that tag in later semantic_scope=session or artifacts.diff calls.');
198
+ }
199
+ if (definition.name === 'artifacts.list') {
200
+ notes.push('Use session_tag, path_prefix, or latest_only to narrow artifact views before reading or diffing files.');
201
+ }
202
+ if (definition.name === 'artifacts.diff') {
203
+ notes.push('Diff two session_tag values after export, naming review, explanation review, or runtime import to see what changed between analysis rounds.');
204
+ }
205
+ if (definition.name === 'tool.help') {
206
+ notes.push('Query this tool first when an MCP client needs exact enum values, defaults, or scope/session usage guidance before calling another tool.');
207
+ }
208
+ if (definition.name === 'sample.ingest') {
209
+ notes.push('Prefer path for local files. Use bytes_b64 only when the MCP client cannot access the same local filesystem as the MCP server.');
210
+ notes.push('When both path and bytes_b64 are provided, path wins. Passing an absolute file path is the most reliable option for local VS Code/Copilot clients.');
211
+ }
212
+ return notes;
213
+ }
214
+ function buildSchemaSummary(schema, toolName) {
215
+ const fields = collectSchemaFields(schema, '', toolName);
216
+ return {
217
+ field_count: fields.length,
218
+ fields,
219
+ };
220
+ }
221
+ export function createToolHelpHandler(getDefinitions) {
222
+ return async (args) => {
223
+ try {
224
+ const input = toolHelpInputSchema.parse(args);
225
+ const definitions = getDefinitions();
226
+ const filtered = input.tool_name
227
+ ? definitions.filter((item) => item.name === input.tool_name)
228
+ : definitions;
229
+ if (input.tool_name && filtered.length === 0) {
230
+ return {
231
+ ok: false,
232
+ errors: [`Tool not found: ${input.tool_name}`],
233
+ };
234
+ }
235
+ return {
236
+ ok: true,
237
+ data: {
238
+ count: filtered.length,
239
+ tools: filtered.map((definition) => ({
240
+ name: definition.name,
241
+ description: definition.description,
242
+ usage_notes: buildUsageNotes(definition),
243
+ input: input.include_fields
244
+ ? buildSchemaSummary(definition.inputSchema, definition.name)
245
+ : undefined,
246
+ output: input.include_fields && input.include_output_schema && definition.outputSchema
247
+ ? buildSchemaSummary(definition.outputSchema, definition.name)
248
+ : undefined,
249
+ })),
250
+ },
251
+ };
252
+ }
253
+ catch (error) {
254
+ return {
255
+ ok: false,
256
+ errors: [error instanceof Error ? error.message : String(error)],
257
+ };
258
+ }
259
+ };
260
+ }
261
+ //# sourceMappingURL=tool-help.js.map