@wowok/agent-mcp 2.4.3 → 2.5.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 (317) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.js +21 -0
  6. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  7. package/dist/knowledge/allocation-confirm.js +534 -0
  8. package/dist/knowledge/allocation-context.d.ts +58 -0
  9. package/dist/knowledge/allocation-context.js +249 -0
  10. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  11. package/dist/knowledge/allocation-ledger.js +463 -0
  12. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  13. package/dist/knowledge/allocation-puzzle.js +298 -0
  14. package/dist/knowledge/allocation-risk.d.ts +78 -0
  15. package/dist/knowledge/allocation-risk.js +568 -0
  16. package/dist/knowledge/allocation-templates.d.ts +38 -0
  17. package/dist/knowledge/allocation-templates.js +970 -0
  18. package/dist/knowledge/allocation-translation.d.ts +72 -0
  19. package/dist/knowledge/allocation-translation.js +585 -0
  20. package/dist/knowledge/arb-risk.d.ts +37 -0
  21. package/dist/knowledge/arb-risk.js +210 -0
  22. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  23. package/dist/knowledge/arbitration-confirm.js +559 -0
  24. package/dist/knowledge/arbitration-context.d.ts +81 -0
  25. package/dist/knowledge/arbitration-context.js +505 -0
  26. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  27. package/dist/knowledge/arbitration-ledger.js +521 -0
  28. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  29. package/dist/knowledge/arbitration-puzzle.js +304 -0
  30. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  31. package/dist/knowledge/arbitration-risk.js +433 -0
  32. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  33. package/dist/knowledge/arbitration-templates.js +276 -0
  34. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  35. package/dist/knowledge/arbitration-translation.js +487 -0
  36. package/dist/knowledge/bridge-risk.d.ts +36 -0
  37. package/dist/knowledge/bridge-risk.js +263 -0
  38. package/dist/knowledge/contact-risk.d.ts +32 -0
  39. package/dist/knowledge/contact-risk.js +200 -0
  40. package/dist/knowledge/demand-confirm.d.ts +32 -0
  41. package/dist/knowledge/demand-confirm.js +206 -0
  42. package/dist/knowledge/demand-risk.d.ts +30 -0
  43. package/dist/knowledge/demand-risk.js +240 -0
  44. package/dist/knowledge/demand-translation.d.ts +55 -0
  45. package/dist/knowledge/demand-translation.js +354 -0
  46. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  47. package/dist/knowledge/deployment-scanner.js +762 -0
  48. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  49. package/dist/knowledge/examples-scanner-cli.js +26 -0
  50. package/dist/knowledge/examples-scanner.d.ts +121 -0
  51. package/dist/knowledge/examples-scanner.js +825 -0
  52. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  53. package/dist/knowledge/flywheel-loop.js +32 -3
  54. package/dist/knowledge/glossary.js +3 -1
  55. package/dist/knowledge/guard-confirm.d.ts +86 -0
  56. package/dist/knowledge/guard-confirm.js +406 -0
  57. package/dist/knowledge/guard-context.d.ts +56 -0
  58. package/dist/knowledge/guard-context.js +287 -0
  59. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  60. package/dist/knowledge/guard-design-patterns.js +257 -0
  61. package/dist/knowledge/guard-puzzle.js +3 -2
  62. package/dist/knowledge/guard-risk.d.ts +1 -1
  63. package/dist/knowledge/guard-risk.js +12 -14
  64. package/dist/knowledge/guard-templates.js +1 -1
  65. package/dist/knowledge/guard-translation.js +6 -5
  66. package/dist/knowledge/index.d.ts +342 -0
  67. package/dist/knowledge/index.js +344 -0
  68. package/dist/knowledge/machine-confirm.d.ts +102 -0
  69. package/dist/knowledge/machine-confirm.js +559 -0
  70. package/dist/knowledge/machine-context.d.ts +160 -0
  71. package/dist/knowledge/machine-context.js +812 -0
  72. package/dist/knowledge/machine-ledger.d.ts +41 -0
  73. package/dist/knowledge/machine-ledger.js +315 -0
  74. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  75. package/dist/knowledge/machine-puzzle.js +494 -0
  76. package/dist/knowledge/machine-risk.d.ts +75 -0
  77. package/dist/knowledge/machine-risk.js +644 -0
  78. package/dist/knowledge/machine-templates.d.ts +92 -0
  79. package/dist/knowledge/machine-templates.js +1592 -0
  80. package/dist/knowledge/machine-topology.d.ts +57 -0
  81. package/dist/knowledge/machine-topology.js +234 -0
  82. package/dist/knowledge/machine-translation.d.ts +96 -0
  83. package/dist/knowledge/machine-translation.js +513 -0
  84. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  85. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  86. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  87. package/dist/knowledge/mcp-schema-audit.js +772 -0
  88. package/dist/knowledge/onchain-constants.d.ts +4 -0
  89. package/dist/knowledge/onchain-constants.js +35 -0
  90. package/dist/knowledge/order-confirm.d.ts +115 -0
  91. package/dist/knowledge/order-confirm.js +573 -0
  92. package/dist/knowledge/order-context.d.ts +66 -0
  93. package/dist/knowledge/order-context.js +390 -0
  94. package/dist/knowledge/order-ledger.d.ts +69 -0
  95. package/dist/knowledge/order-ledger.js +341 -0
  96. package/dist/knowledge/order-puzzle.d.ts +159 -0
  97. package/dist/knowledge/order-puzzle.js +255 -0
  98. package/dist/knowledge/order-risk.d.ts +66 -0
  99. package/dist/knowledge/order-risk.js +653 -0
  100. package/dist/knowledge/order-templates.d.ts +50 -0
  101. package/dist/knowledge/order-templates.js +368 -0
  102. package/dist/knowledge/order-translation.d.ts +78 -0
  103. package/dist/knowledge/order-translation.js +550 -0
  104. package/dist/knowledge/passport-confirm.d.ts +130 -0
  105. package/dist/knowledge/passport-confirm.js +531 -0
  106. package/dist/knowledge/passport-context.d.ts +59 -0
  107. package/dist/knowledge/passport-context.js +306 -0
  108. package/dist/knowledge/passport-ledger.d.ts +48 -0
  109. package/dist/knowledge/passport-ledger.js +282 -0
  110. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  111. package/dist/knowledge/passport-puzzle.js +333 -0
  112. package/dist/knowledge/passport-risk.d.ts +70 -0
  113. package/dist/knowledge/passport-risk.js +450 -0
  114. package/dist/knowledge/passport-templates.d.ts +40 -0
  115. package/dist/knowledge/passport-templates.js +568 -0
  116. package/dist/knowledge/passport-translation.d.ts +68 -0
  117. package/dist/knowledge/passport-translation.js +516 -0
  118. package/dist/knowledge/payment-risk.d.ts +33 -0
  119. package/dist/knowledge/payment-risk.js +182 -0
  120. package/dist/knowledge/permission-confirm.d.ts +110 -0
  121. package/dist/knowledge/permission-confirm.js +426 -0
  122. package/dist/knowledge/permission-context.d.ts +58 -0
  123. package/dist/knowledge/permission-context.js +224 -0
  124. package/dist/knowledge/permission-ledger.d.ts +38 -0
  125. package/dist/knowledge/permission-ledger.js +403 -0
  126. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  127. package/dist/knowledge/permission-puzzle.js +173 -0
  128. package/dist/knowledge/permission-risk.d.ts +76 -0
  129. package/dist/knowledge/permission-risk.js +411 -0
  130. package/dist/knowledge/permission-templates.d.ts +38 -0
  131. package/dist/knowledge/permission-templates.js +234 -0
  132. package/dist/knowledge/permission-translation.d.ts +57 -0
  133. package/dist/knowledge/permission-translation.js +350 -0
  134. package/dist/knowledge/personal-risk.d.ts +36 -0
  135. package/dist/knowledge/personal-risk.js +212 -0
  136. package/dist/knowledge/progress-confirm.d.ts +108 -0
  137. package/dist/knowledge/progress-confirm.js +456 -0
  138. package/dist/knowledge/progress-context.d.ts +123 -0
  139. package/dist/knowledge/progress-context.js +452 -0
  140. package/dist/knowledge/progress-ledger.d.ts +63 -0
  141. package/dist/knowledge/progress-ledger.js +327 -0
  142. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  143. package/dist/knowledge/progress-puzzle.js +219 -0
  144. package/dist/knowledge/progress-risk.d.ts +74 -0
  145. package/dist/knowledge/progress-risk.js +461 -0
  146. package/dist/knowledge/progress-templates.d.ts +38 -0
  147. package/dist/knowledge/progress-templates.js +228 -0
  148. package/dist/knowledge/progress-translation.d.ts +52 -0
  149. package/dist/knowledge/progress-translation.js +401 -0
  150. package/dist/knowledge/proof-confirm.d.ts +31 -0
  151. package/dist/knowledge/proof-confirm.js +187 -0
  152. package/dist/knowledge/proof-risk.d.ts +33 -0
  153. package/dist/knowledge/proof-risk.js +207 -0
  154. package/dist/knowledge/proof-translation.d.ts +52 -0
  155. package/dist/knowledge/proof-translation.js +283 -0
  156. package/dist/knowledge/registrar-risk.d.ts +34 -0
  157. package/dist/knowledge/registrar-risk.js +217 -0
  158. package/dist/knowledge/repository-confirm.d.ts +36 -0
  159. package/dist/knowledge/repository-confirm.js +242 -0
  160. package/dist/knowledge/repository-risk.d.ts +40 -0
  161. package/dist/knowledge/repository-risk.js +312 -0
  162. package/dist/knowledge/repository-translation.d.ts +58 -0
  163. package/dist/knowledge/repository-translation.js +422 -0
  164. package/dist/knowledge/resource-risk.d.ts +32 -0
  165. package/dist/knowledge/resource-risk.js +157 -0
  166. package/dist/knowledge/reward-confirm.d.ts +113 -0
  167. package/dist/knowledge/reward-confirm.js +496 -0
  168. package/dist/knowledge/reward-context.d.ts +127 -0
  169. package/dist/knowledge/reward-context.js +504 -0
  170. package/dist/knowledge/reward-ledger.d.ts +96 -0
  171. package/dist/knowledge/reward-ledger.js +502 -0
  172. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  173. package/dist/knowledge/reward-puzzle.js +288 -0
  174. package/dist/knowledge/reward-risk.d.ts +84 -0
  175. package/dist/knowledge/reward-risk.js +545 -0
  176. package/dist/knowledge/reward-translation.d.ts +58 -0
  177. package/dist/knowledge/reward-translation.js +501 -0
  178. package/dist/knowledge/safety-rules.js +11 -3
  179. package/dist/knowledge/scenario-modes.d.ts +53 -0
  180. package/dist/knowledge/scenario-modes.js +302 -0
  181. package/dist/knowledge/service-confirm.d.ts +152 -0
  182. package/dist/knowledge/service-confirm.js +699 -0
  183. package/dist/knowledge/service-context.d.ts +66 -0
  184. package/dist/knowledge/service-context.js +403 -0
  185. package/dist/knowledge/service-ledger.d.ts +71 -0
  186. package/dist/knowledge/service-ledger.js +609 -0
  187. package/dist/knowledge/service-puzzle.d.ts +158 -0
  188. package/dist/knowledge/service-puzzle.js +236 -0
  189. package/dist/knowledge/service-risk.d.ts +108 -0
  190. package/dist/knowledge/service-risk.js +615 -0
  191. package/dist/knowledge/service-templates.d.ts +39 -0
  192. package/dist/knowledge/service-templates.js +418 -0
  193. package/dist/knowledge/service-translation.d.ts +103 -0
  194. package/dist/knowledge/service-translation.js +622 -0
  195. package/dist/knowledge/tools-reference.d.ts +17 -0
  196. package/dist/knowledge/tools-reference.js +151 -0
  197. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  198. package/dist/knowledge/treasury-confirm.js +512 -0
  199. package/dist/knowledge/treasury-context.d.ts +64 -0
  200. package/dist/knowledge/treasury-context.js +363 -0
  201. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  202. package/dist/knowledge/treasury-ledger.js +300 -0
  203. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  204. package/dist/knowledge/treasury-puzzle.js +216 -0
  205. package/dist/knowledge/treasury-risk.d.ts +86 -0
  206. package/dist/knowledge/treasury-risk.js +440 -0
  207. package/dist/knowledge/treasury-templates.d.ts +38 -0
  208. package/dist/knowledge/treasury-templates.js +316 -0
  209. package/dist/knowledge/treasury-translation.d.ts +78 -0
  210. package/dist/knowledge/treasury-translation.js +498 -0
  211. package/dist/knowledge/util-risk.d.ts +30 -0
  212. package/dist/knowledge/util-risk.js +135 -0
  213. package/dist/project/business-puzzle.d.ts +47 -0
  214. package/dist/project/business-puzzle.js +372 -0
  215. package/dist/project/deployment-doc.d.ts +61 -0
  216. package/dist/project/deployment-doc.js +432 -0
  217. package/dist/project/risk-aggregator.d.ts +50 -0
  218. package/dist/project/risk-aggregator.js +280 -0
  219. package/dist/project/substep-trace.d.ts +130 -0
  220. package/dist/project/substep-trace.js +332 -0
  221. package/dist/schema/call/allocation.d.ts +34 -34
  222. package/dist/schema/call/arbitration.d.ts +141 -141
  223. package/dist/schema/call/base.d.ts +386 -386
  224. package/dist/schema/call/base.js +3 -3
  225. package/dist/schema/call/bridge-handler.d.ts +5 -2
  226. package/dist/schema/call/bridge.d.ts +159 -159
  227. package/dist/schema/call/contact.d.ts +110 -110
  228. package/dist/schema/call/demand.d.ts +76 -76
  229. package/dist/schema/call/handler.d.ts +2 -3
  230. package/dist/schema/call/handler.js +1 -1
  231. package/dist/schema/call/machine.d.ts +58 -58
  232. package/dist/schema/call/order.d.ts +98 -110
  233. package/dist/schema/call/permission-handler.d.ts +5 -0
  234. package/dist/schema/call/permission-handler.js +54 -0
  235. package/dist/schema/call/permission.d.ts +108 -108
  236. package/dist/schema/call/personal.d.ts +14 -14
  237. package/dist/schema/call/progress.d.ts +57 -72
  238. package/dist/schema/call/progress.js +7 -4
  239. package/dist/schema/call/proof.d.ts +18 -18
  240. package/dist/schema/call/proof.js +12 -7
  241. package/dist/schema/call/repository.d.ts +154 -154
  242. package/dist/schema/call/reward.d.ts +55 -55
  243. package/dist/schema/call/service.d.ts +231 -231
  244. package/dist/schema/call/treasury.d.ts +93 -93
  245. package/dist/schema/config/index.d.ts +178 -5
  246. package/dist/schema/config/index.js +52 -1
  247. package/dist/schema/local/index.d.ts +3554 -836
  248. package/dist/schema/local/index.js +2 -1
  249. package/dist/schema/messenger/index.d.ts +162 -162
  250. package/dist/schema/operations.d.ts +1058 -1074
  251. package/dist/schema/operations.js +7 -1
  252. package/dist/schema/project/index.d.ts +1412 -6
  253. package/dist/schema/project/index.js +441 -3
  254. package/dist/schema/query/index.d.ts +672 -672
  255. package/dist/schema/schema-query/index.d.ts +23 -3
  256. package/dist/schema/schema-query/index.js +13 -2
  257. package/dist/schema/sync-layer4.d.ts +21 -0
  258. package/dist/schema/sync-layer4.js +261 -0
  259. package/dist/schema/trust/index.d.ts +26 -26
  260. package/dist/schemas/account_operation.output.json +718 -0
  261. package/dist/schemas/config_operation.output.json +173 -0
  262. package/dist/schemas/index.json +9 -1
  263. package/dist/schemas/local_info_operation.output.json +718 -0
  264. package/dist/schemas/local_mark_operation.output.json +718 -0
  265. package/dist/schemas/onchain_operations.output.json +3 -2
  266. package/dist/schemas/onchain_operations.schema.json +1809 -336
  267. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  268. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  269. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  270. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  271. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  272. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  273. package/dist/schemas/onchain_operations_guard.schema.json +578 -579
  274. package/dist/schemas/onchain_operations_machine.schema.json +2 -1
  275. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  276. package/dist/schemas/onchain_operations_payment.schema.json +0 -514
  277. package/dist/schemas/onchain_operations_permission.schema.json +0 -514
  278. package/dist/schemas/onchain_operations_personal.schema.json +0 -514
  279. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  280. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  281. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  282. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  283. package/dist/schemas/onchain_operations_service.schema.json +2 -1
  284. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  285. package/dist/schemas/onchain_table_data.schema.json +32 -1
  286. package/dist/schemas/project_operation.output.json +918 -0
  287. package/dist/schemas/project_operation.schema.json +474 -3
  288. package/dist/schemas/query_toolkit.output.json +14906 -6
  289. package/dist/schemas/schema_query.output.json +38 -1
  290. package/dist/telemetry/index.d.ts +1 -1
  291. package/dist/tools/handlers/config.d.ts +1 -1
  292. package/dist/tools/handlers/config.js +21 -18
  293. package/dist/tools/handlers/file-export.d.ts +2 -2
  294. package/dist/tools/handlers/local.d.ts +3 -30
  295. package/dist/tools/handlers/local.js +14 -3
  296. package/dist/tools/handlers/messenger.d.ts +1 -1
  297. package/dist/tools/handlers/messenger.js +2 -1
  298. package/dist/tools/handlers/onchain.d.ts +1 -1
  299. package/dist/tools/handlers/onchain.js +24 -22
  300. package/dist/tools/handlers/project.d.ts +1 -1
  301. package/dist/tools/handlers/project.js +262 -18
  302. package/dist/tools/handlers/query.d.ts +4 -4
  303. package/dist/tools/handlers/schema-query.d.ts +1 -1
  304. package/dist/tools/handlers/schema-query.js +21 -20
  305. package/dist/tools/handlers/trust.d.ts +1 -1
  306. package/dist/tools/handlers/trust.js +2 -2
  307. package/dist/tools/handlers/wip.d.ts +1 -1
  308. package/dist/tools/handlers/wip.js +1 -1
  309. package/dist/tools/index.d.ts +1 -1
  310. package/dist/tools/index.js +96 -25
  311. package/dist/tools/rules-hook.d.ts +1 -1
  312. package/dist/tools/rules-hook.js +3 -2
  313. package/dist/tools/shared.d.ts +13 -22
  314. package/dist/tools/types.d.ts +5 -5
  315. package/dist/tools/wrap.d.ts +10 -2
  316. package/dist/tools/wrap.js +212 -0
  317. package/package.json +3 -3
@@ -0,0 +1,772 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ export const DEPLOYED_TOOLS_DIR = 'c:\\Users\\zhou\\.trae-cn\\mcps\\s_wowok-7838e181\\solo_agent\\mcp_wagent\\tools';
4
+ export const GENERATED_SCHEMAS_DIR = 'd:\\wowok\\agent\\mcp\\dist\\schemas';
5
+ export const MCP_SRC_SCHEMA_DIR = 'd:\\wowok\\agent\\mcp\\src\\schema';
6
+ export const MCP_SRC_TOOLS_DIR = 'd:\\wowok\\agent\\mcp\\src\\tools';
7
+ export const GENERATION_SCRIPT = 'd:\\wowok\\agent\\mcp\\scripts\\generate-json-schemas.ts';
8
+ export const TOOLS_INDEX_FILE = 'd:\\wowok\\agent\\mcp\\src\\tools\\index.ts';
9
+ export const MCP_SCHEMA_AUDIT_VERSION = '1.0.0';
10
+ export const TOOLS_17 = [
11
+ { name: 'onchain_operations', input_schema_export: 'OnchainOperationsSchema', output_schema_export: 'CallOutputSchema' },
12
+ { name: 'account_operation', input_schema_export: 'AccountOperationSchema', output_schema_export: 'AccountOperationOutputWrappedSchema' },
13
+ { name: 'local_mark_operation', input_schema_export: 'LocalMarkOperationSchema', output_schema_export: 'LocalMarkOperationOutputWrappedSchema' },
14
+ { name: 'local_info_operation', input_schema_export: 'LocalInfoOperationSchema', output_schema_export: 'LocalInfoOperationOutputWrappedSchema' },
15
+ { name: 'wip_file', input_schema_export: 'WipOperationsSchema', output_schema_export: 'WipOperationOutputSchema' },
16
+ { name: 'messenger_operation', input_schema_export: 'MessengerOperationInputSchema', output_schema_export: 'MessengerOperationOutputSchema' },
17
+ { name: 'guard2file', input_schema_export: 'Guard2File_InputSchema', output_schema_export: 'Guard2File_OutputWrappedSchema' },
18
+ { name: 'machineNode2file', input_schema_export: 'MachineNode2File_InputSchema', output_schema_export: 'MachineNode2File_OutputWrappedSchema' },
19
+ { name: 'query_toolkit', input_schema_export: 'WatchQueryOperationsSchema', output_schema_export: 'WatchQueryOperationsResultSchema' },
20
+ { name: 'onchain_table_data', input_schema_export: 'OnchainTableDataSchema', output_schema_export: 'OnchainTableDataResultSchema' },
21
+ { name: 'onchain_events', input_schema_export: 'OnchainEventsInputSchema', output_schema_export: 'OnchainEventsResultSchema' },
22
+ { name: 'wowok_buildin_info', input_schema_export: 'ProtocolInfoQuerySchema', output_schema_export: 'ProtocolInfoResultSchema' },
23
+ { name: 'schema_query', input_schema_export: 'SchemaQueryInputSchema', output_schema_export: 'SchemaQueryOutputSchema' },
24
+ { name: 'bridge_operation', input_schema_export: 'BridgeOperationsSchema', output_schema_export: 'BridgeCallOutputSchema' },
25
+ { name: 'project_operation', input_schema_export: 'ProjectOperationInputSchema', output_schema_export: 'ProjectOperationOutputSchema' },
26
+ { name: 'config_operation', input_schema_export: 'ConfigOperationInputSchema', output_schema_export: 'ConfigOperationOutputSchema' },
27
+ { name: 'trust_score', input_schema_export: 'TrustScoreInputSchema', output_schema_export: 'TrustScoreOutputSchema' },
28
+ ];
29
+ export function loadLayer4Deployed(toolName) {
30
+ const filePath = path.join(DEPLOYED_TOOLS_DIR, `${toolName}.json`);
31
+ const fallback = {
32
+ tool_descriptor_file: filePath,
33
+ file_exists: false,
34
+ is_stub: true,
35
+ properties_count: 0,
36
+ required_count: 0,
37
+ has_schema_hint: false,
38
+ has_additional_properties_false: false,
39
+ has_dollar_schema: false,
40
+ has_oneof: false,
41
+ has_anyof: false,
42
+ has_allof: false,
43
+ union_count: 0,
44
+ };
45
+ if (!fs.existsSync(filePath))
46
+ return fallback;
47
+ try {
48
+ const raw = fs.readFileSync(filePath, 'utf-8');
49
+ const data = JSON.parse(raw);
50
+ const args = data.arguments ?? {};
51
+ const props = args.properties ?? {};
52
+ const required = args.required ?? [];
53
+ const propKeys = Object.keys(props);
54
+ const oneOfArr = args.oneOf ?? [];
55
+ const anyOfArr = args.anyOf ?? [];
56
+ const allOfArr = args.allOf ?? [];
57
+ const hasOneOf = oneOfArr.length > 0;
58
+ const hasAnyOf = anyOfArr.length > 0;
59
+ const hasAllOf = allOfArr.length > 0;
60
+ const unionCount = oneOfArr.length + anyOfArr.length + allOfArr.length;
61
+ const isStub = propKeys.length === 0 && unionCount === 0;
62
+ const description = data.description ?? '';
63
+ const hasSchemaHint = description.includes('schema_query');
64
+ return {
65
+ tool_descriptor_file: filePath,
66
+ file_exists: true,
67
+ is_stub: isStub,
68
+ properties_count: propKeys.length,
69
+ required_count: required.length,
70
+ has_schema_hint: hasSchemaHint,
71
+ has_additional_properties_false: args.additionalProperties === false,
72
+ has_dollar_schema: !!args.$schema,
73
+ has_oneof: hasOneOf,
74
+ has_anyof: hasAnyOf,
75
+ has_allof: hasAllOf,
76
+ union_count: unionCount,
77
+ };
78
+ }
79
+ catch {
80
+ return fallback;
81
+ }
82
+ }
83
+ export function loadLayer3Generated(toolName) {
84
+ const inputPath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.schema.json`);
85
+ const outputPath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.output.json`);
86
+ const inputExists = fs.existsSync(inputPath);
87
+ const outputExists = fs.existsSync(outputPath);
88
+ const inputSize = inputExists ? fs.statSync(inputPath).size : 0;
89
+ const outputSize = outputExists ? fs.statSync(outputPath).size : 0;
90
+ return {
91
+ input_schema_file: inputPath,
92
+ output_schema_file: outputPath,
93
+ input_exists: inputExists,
94
+ output_exists: outputExists,
95
+ input_size_bytes: inputSize,
96
+ output_size_bytes: outputSize,
97
+ };
98
+ }
99
+ export function analyzeLayerCensus() {
100
+ const census = [];
101
+ for (const tool of TOOLS_17) {
102
+ census.push({
103
+ name: tool.name,
104
+ layer2_zod: {
105
+ input_schema_export: tool.input_schema_export,
106
+ output_schema_export: tool.output_schema_export,
107
+ schema_dir: MCP_SRC_SCHEMA_DIR,
108
+ },
109
+ layer3_generated: loadLayer3Generated(tool.name),
110
+ layer4_deployed: loadLayer4Deployed(tool.name) ?? {},
111
+ });
112
+ }
113
+ return census;
114
+ }
115
+ export function analyzeDeployedStubInconsistency(census) {
116
+ const findings = [];
117
+ const stubs = [];
118
+ const fullSchemas = [];
119
+ for (const c of census) {
120
+ if (!c.layer4_deployed.file_exists) {
121
+ findings.push({
122
+ rule_id: 'MCP-DEPLOY-001',
123
+ severity: 'critical',
124
+ category: 'stub_inconsistency',
125
+ tool_name: c.name,
126
+ description: `Layer 4 deployed file does not exist: ${c.layer4_deployed.tool_descriptor_file}`,
127
+ location: c.layer4_deployed.tool_descriptor_file,
128
+ fix: `Create ${c.name}.json in DEPLOYED_TOOLS_DIR matching the Layer 3 generated schema.`,
129
+ });
130
+ continue;
131
+ }
132
+ if (c.layer4_deployed.is_stub) {
133
+ stubs.push(c);
134
+ }
135
+ else {
136
+ fullSchemas.push(c);
137
+ }
138
+ }
139
+ for (const c of stubs) {
140
+ findings.push({
141
+ rule_id: 'MCP-STUB-001',
142
+ severity: 'high',
143
+ category: 'stub_inconsistency',
144
+ tool_name: c.name,
145
+ description: `Layer 4 deployed file is a STUB (empty properties:{}) — LLM must call schema_query(action='get', name='${c.name}') to learn the parameter structure. This is inconsistent with the ${fullSchemas.length} tools that embed full schemas.`,
146
+ location: c.layer4_deployed.tool_descriptor_file,
147
+ fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json (resolve $ref, inline definitions, wrap as {name, description, arguments}).`,
148
+ });
149
+ if (!c.layer4_deployed.has_schema_hint) {
150
+ findings.push({
151
+ rule_id: 'MCP-STUB-003',
152
+ severity: 'high',
153
+ category: 'stub_inconsistency',
154
+ tool_name: c.name,
155
+ description: `Stub file is missing schema_query hint in description — the LLM has no way to discover the parameter structure. Description should mention schema_query(action='get', name='${c.name}').`,
156
+ location: c.layer4_deployed.tool_descriptor_file,
157
+ fix: `Add "💡 Schema hint: Use schema_query with action='get' and name='${c.name}' to retrieve the exact parameter schema before calling." to the description.`,
158
+ });
159
+ }
160
+ }
161
+ if (stubs.length > 0 && fullSchemas.length > 0) {
162
+ findings.push({
163
+ rule_id: 'MCP-STUB-002',
164
+ severity: 'info',
165
+ category: 'stub_inconsistency',
166
+ tool_name: '(all)',
167
+ description: `Layer 4 deployed files are INCONSISTENT: ${stubs.length} stubs + ${fullSchemas.length} full schemas. Stubs: ${stubs.map(s => s.name).join(', ')}. Full: ${fullSchemas.map(s => s.name).join(', ')}.`,
168
+ fix: `Make all 17 files consistent — either (a) embed full schemas in all 17 (RECOMMENDED — gives LLM immediate access), or (b) keep all stubs and rely on schema_query (increases token cost + latency).`,
169
+ });
170
+ }
171
+ return findings;
172
+ }
173
+ export function analyzeLayerParity(census) {
174
+ const findings = [];
175
+ for (const c of census) {
176
+ if (!c.layer4_deployed.file_exists || c.layer4_deployed.is_stub)
177
+ continue;
178
+ if (!c.layer3_generated.input_exists) {
179
+ findings.push({
180
+ rule_id: 'MCP-PARITY-001',
181
+ severity: 'critical',
182
+ category: 'layer_parity',
183
+ tool_name: c.name,
184
+ description: `Layer 4 has full schema but Layer 3 generated file is missing: ${c.layer3_generated.input_schema_file}`,
185
+ fix: `Run pnpm generate:schemas to regenerate Layer 3 from Zod source.`,
186
+ });
187
+ continue;
188
+ }
189
+ const l4 = readLayer4Arguments(c.name);
190
+ const l3 = readLayer3ResolvedSchema(c.name);
191
+ if (!l4 || !l3)
192
+ continue;
193
+ const l4Props = new Set(Object.keys(l4.properties ?? {}));
194
+ const l3Props = new Set(Object.keys(l3.properties ?? {}));
195
+ const missingInL4 = [...l3Props].filter(p => !l4Props.has(p));
196
+ const extraInL4 = [...l4Props].filter(p => !l3Props.has(p));
197
+ if (missingInL4.length > 0) {
198
+ findings.push({
199
+ rule_id: 'MCP-PARITY-002',
200
+ severity: 'high',
201
+ category: 'layer_parity',
202
+ tool_name: c.name,
203
+ description: `Layer 4 deployed schema is missing ${missingInL4.length} properties present in Layer 3 generated schema: ${missingInL4.join(', ')}`,
204
+ location: c.layer4_deployed.tool_descriptor_file,
205
+ fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json.`,
206
+ });
207
+ }
208
+ if (extraInL4.length > 0) {
209
+ findings.push({
210
+ rule_id: 'MCP-PARITY-003',
211
+ severity: 'medium',
212
+ category: 'layer_parity',
213
+ tool_name: c.name,
214
+ description: `Layer 4 deployed schema has ${extraInL4.length} extra properties not in Layer 3: ${extraInL4.join(', ')}`,
215
+ location: c.layer4_deployed.tool_descriptor_file,
216
+ fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json.`,
217
+ });
218
+ }
219
+ const l4Req = new Set(l4.required ?? []);
220
+ const l3Req = new Set(l3.required ?? []);
221
+ const reqMissing = [...l3Req].filter(r => !l4Req.has(r));
222
+ const reqExtra = [...l4Req].filter(r => !l3Req.has(r));
223
+ if (reqMissing.length > 0 || reqExtra.length > 0) {
224
+ findings.push({
225
+ rule_id: 'MCP-PARITY-004',
226
+ severity: 'high',
227
+ category: 'layer_parity',
228
+ tool_name: c.name,
229
+ description: `Layer 4 'required' array differs from Layer 3. Missing in L4: [${reqMissing.join(', ')}]. Extra in L4: [${reqExtra.join(', ')}].`,
230
+ location: c.layer4_deployed.tool_descriptor_file,
231
+ fix: `Sync 'required' array from Layer 3 to Layer 4.`,
232
+ });
233
+ }
234
+ const l4AP = l4.additionalProperties;
235
+ const l3AP = l3.additionalProperties;
236
+ if (l4AP !== l3AP) {
237
+ findings.push({
238
+ rule_id: 'MCP-PARITY-005',
239
+ severity: 'medium',
240
+ category: 'layer_parity',
241
+ tool_name: c.name,
242
+ description: `Layer 4 'additionalProperties' (${JSON.stringify(l4AP)}) differs from Layer 3 (${JSON.stringify(l3AP)}).`,
243
+ location: c.layer4_deployed.tool_descriptor_file,
244
+ fix: `Sync 'additionalProperties' value.`,
245
+ });
246
+ }
247
+ }
248
+ return findings;
249
+ }
250
+ function readLayer4Arguments(toolName) {
251
+ const filePath = path.join(DEPLOYED_TOOLS_DIR, `${toolName}.json`);
252
+ try {
253
+ const raw = fs.readFileSync(filePath, 'utf-8');
254
+ const data = JSON.parse(raw);
255
+ return data.arguments ?? null;
256
+ }
257
+ catch {
258
+ return null;
259
+ }
260
+ }
261
+ function readLayer3ResolvedSchema(toolName) {
262
+ const filePath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.schema.json`);
263
+ try {
264
+ const raw = fs.readFileSync(filePath, 'utf-8');
265
+ const data = JSON.parse(raw);
266
+ if (data.$ref && data.$ref.startsWith('#/definitions/')) {
267
+ const defName = data.$ref.slice('#/definitions/'.length);
268
+ const def = data.definitions?.[defName];
269
+ if (def && typeof def === 'object') {
270
+ return def;
271
+ }
272
+ }
273
+ return data;
274
+ }
275
+ catch {
276
+ return null;
277
+ }
278
+ }
279
+ export function analyzeAnyUnknownCensus() {
280
+ const instances = [];
281
+ const scanDirs = [MCP_SRC_SCHEMA_DIR, MCP_SRC_TOOLS_DIR];
282
+ for (const dir of scanDirs) {
283
+ const files = listTypeScriptFiles(dir);
284
+ for (const file of files) {
285
+ const lines = fs.readFileSync(file, 'utf-8').split('\n');
286
+ for (let i = 0; i < lines.length; i++) {
287
+ const line = lines[i];
288
+ const trimmed = line.trim();
289
+ if (trimmed.startsWith('//') || trimmed.startsWith('*'))
290
+ continue;
291
+ const patterns = [
292
+ { regex: /z\.any\(\)/g, pattern: 'z.any()' },
293
+ { regex: /z\.unknown\(\)/g, pattern: 'z.unknown()' },
294
+ { regex: /args\s*:\s*any\b/g, pattern: 'args: any' },
295
+ { regex: /Promise\s*<\s*any\s*>/g, pattern: 'Promise<any>' },
296
+ { regex: /Record\s*<\s*string\s*,\s*any\s*>/g, pattern: 'Record<string, any>' },
297
+ { regex: /\bas\s+any\b/g, pattern: 'as any' },
298
+ ];
299
+ for (const { regex, pattern } of patterns) {
300
+ regex.lastIndex = 0;
301
+ let m;
302
+ while ((m = regex.exec(line)) !== null) {
303
+ const category = categorizeAnyInstance(file, i + 1, line, pattern);
304
+ instances.push({
305
+ file,
306
+ line: i + 1,
307
+ code: trimmed.length > 120 ? trimmed.slice(0, 117) + '...' : trimmed,
308
+ pattern,
309
+ category: category.category,
310
+ reason: category.reason,
311
+ fix_suggestion: category.fix,
312
+ });
313
+ }
314
+ }
315
+ }
316
+ }
317
+ }
318
+ return instances;
319
+ }
320
+ function listTypeScriptFiles(dir) {
321
+ const result = [];
322
+ if (!fs.existsSync(dir))
323
+ return result;
324
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
325
+ for (const entry of entries) {
326
+ const fullPath = path.join(dir, entry.name);
327
+ if (entry.isDirectory()) {
328
+ if (entry.name === '__tests__' || entry.name === 'node_modules')
329
+ continue;
330
+ result.push(...listTypeScriptFiles(fullPath));
331
+ }
332
+ else if (entry.isFile() && entry.name.endsWith('.ts')) {
333
+ result.push(fullPath);
334
+ }
335
+ }
336
+ return result;
337
+ }
338
+ function categorizeAnyInstance(file, lineNum, line, pattern) {
339
+ const fileName = path.basename(file);
340
+ const trimmed = line.trim();
341
+ if (pattern === 'z.any()' && /SemanticSummarySchema\s*=\s*z\.any\(\)/.test(trimmed)) {
342
+ return {
343
+ category: 'fixable',
344
+ reason: 'Circular-dependency workaround for SemanticSummarySchema — can use z.lazy() or refactor to break the cycle.',
345
+ fix: 'Define SemanticSummarySchema with z.lazy(() => SemanticSummarySchemaReal) or restructure imports to break the cycle.',
346
+ };
347
+ }
348
+ if (pattern === 'z.any()' && /result\s*:\s*z\.any\(\)/.test(trimmed) && /[\\/]config[\\/]|[\\/]project[\\/]/.test(file)) {
349
+ return {
350
+ category: 'fixable',
351
+ reason: `Result shape depends on action — can use z.discriminatedUnion('action', [...]) to type each action's result.`,
352
+ fix: `Define discriminated union: z.discriminatedUnion('action', [z.object({action: z.literal('list'), result: ...}), ...]).`,
353
+ };
354
+ }
355
+ if (pattern === 'z.unknown()' && /result\s*:\s*z\.unknown\(\)/.test(trimmed) && /index\.ts/.test(fileName)) {
356
+ return {
357
+ category: 'fixable',
358
+ reason: 'query_toolkit output result depends on query_type — can use z.discriminatedUnion(\'query_type\', [...]).',
359
+ fix: 'Define discriminated union: z.discriminatedUnion(\'query_type\', [z.object({query_type: z.literal(\'local_mark_list\'), result: z.array(MarkDataSchema)}), ...]).',
360
+ };
361
+ }
362
+ if (pattern === 'z.any()' && /data\s*:\s*z\.any\(\)/.test(trimmed) && /[\\/]schema-query[\\/]/.test(file)) {
363
+ return {
364
+ category: 'fixable',
365
+ reason: 'SchemaQuery output data depends on action — can use discriminated union by action.',
366
+ fix: 'Define discriminated union: action=\'get\' returns JSON Schema, action=\'list\' returns array of items.',
367
+ };
368
+ }
369
+ if (pattern === 'args: any' && /handlers[\\/]/.test(file)) {
370
+ return {
371
+ category: 'fixable',
372
+ reason: 'Handler args can use `unknown` (forces runtime validation) or a typed input schema.',
373
+ fix: 'Replace `args: any` with `args: unknown` and use strictParse(schema, args) at the top of the handler.',
374
+ };
375
+ }
376
+ if (pattern === 'args: any' && /tools[\\/]index\.ts/.test(file)) {
377
+ return {
378
+ category: 'fixable',
379
+ reason: 'dispatchToolCall args is `any` — can be `unknown` since each tool parses with its own schema.',
380
+ fix: 'Change `args: any` to `args: unknown` in dispatchToolCall signature.',
381
+ };
382
+ }
383
+ if (pattern === 'args: any' && /types\.ts/.test(fileName) && /handler/.test(trimmed)) {
384
+ return {
385
+ category: 'fixable',
386
+ reason: 'ToolEntry.handler args is `any` — can be `unknown` (each handler parses with its own schema).',
387
+ fix: 'Change `handler: (args: any) => ...` to `handler: (args: unknown) => ...`.',
388
+ };
389
+ }
390
+ if (pattern === 'z.any()' && /claimReceipt|ethReceipt|wowReceipt/.test(trimmed)) {
391
+ return {
392
+ category: 'legitimate',
393
+ reason: 'EVM transaction receipts have an externally-defined shape from viem/ethers — z.any() is acceptable (receipt is informational, not validated).',
394
+ };
395
+ }
396
+ if (pattern === 'z.any()' && /content_raw/.test(trimmed)) {
397
+ return {
398
+ category: 'legitimate',
399
+ reason: 'content_raw holds raw content for unknown object types — by definition untyped. z.any() is acceptable here.',
400
+ };
401
+ }
402
+ if ((pattern === 'z.unknown()' || pattern === 'z.any()') && /parsedJson/.test(trimmed)) {
403
+ return {
404
+ category: 'legitimate',
405
+ reason: 'Event parsedJson is arbitrary on-chain event data — z.record(z.string(), z.unknown()) is appropriate.',
406
+ };
407
+ }
408
+ if (pattern === 'z.any()' && /key_value/.test(trimmed)) {
409
+ return {
410
+ category: 'fixable',
411
+ reason: 'Repository key_value depends on key_type — could use discriminated union by key_type (string→z.string(), u64→z.bigint()/number, etc.).',
412
+ fix: 'Define z.discriminatedUnion(\'key_type\', [...]) with each variant typed.',
413
+ };
414
+ }
415
+ if (pattern === 'z.unknown()' && /data\s*:\s*z\.unknown\(\)/.test(trimmed) && /[\\/]bridge/.test(file)) {
416
+ return {
417
+ category: 'legitimate',
418
+ reason: 'Bridge operation result data varies by operation_type — currently 9 different shapes. Discriminated union would be ideal but high refactor cost.',
419
+ };
420
+ }
421
+ if (pattern === 'z.unknown()' && /adjusted_params/.test(trimmed)) {
422
+ return {
423
+ category: 'legitimate',
424
+ reason: 'adjusted_params are free-form key-value pairs suggested by AI — z.record(z.string(), z.unknown()) is appropriate.',
425
+ };
426
+ }
427
+ if (pattern === 'z.any()' && /object\s*:\s*z\.union.*z\.record\(z\.any\(\)/.test(trimmed)) {
428
+ return {
429
+ category: 'fixable',
430
+ reason: 'Creation vs reference object union — z.record(z.any()) should be replaced with NamedObjectSchema (structured creation input).',
431
+ fix: 'Replace z.record(z.any()) with NamedObjectSchema (already defined in base.ts).',
432
+ };
433
+ }
434
+ if (pattern === 'z.any()' && /result\s*:\s*z\.any\(\)\.optional\(\)/.test(trimmed) && /[\\/]bridge/.test(file)) {
435
+ return {
436
+ category: 'legitimate',
437
+ reason: 'Bridge result is operation-specific (manage_evm_rpc has different result per operation) — z.any().optional() is acceptable here.',
438
+ };
439
+ }
440
+ if (pattern === 'Promise<any>' && /[\\/](wrap|shared)\.ts/.test(file)) {
441
+ return {
442
+ category: 'fixable',
443
+ reason: 'Generic wrappers in wrap.ts/shared.ts use Promise<any> — could be made generic <T>.',
444
+ fix: 'Replace `Promise<any>` with `Promise<ToolDispatchResult>` (the actual return shape).',
445
+ };
446
+ }
447
+ if (pattern === 'Record<string, any>' && /types\.ts/.test(fileName) && /_meta|structuredContent/.test(trimmed)) {
448
+ return {
449
+ category: 'fixable',
450
+ reason: 'ToolConfig._meta and ToolDispatchResult.structuredContent could use structured types.',
451
+ fix: 'Define ToolMeta interface (category, tags) and replace structuredContent: any with structured type.',
452
+ };
453
+ }
454
+ if (pattern === 'as any') {
455
+ return {
456
+ category: 'legitimate',
457
+ reason: '`as any` cast — usually for third-party type mismatches (MCP SDK). Acceptable if isolated.',
458
+ };
459
+ }
460
+ return {
461
+ category: 'legitimate',
462
+ reason: 'Unclassified any/unknown usage — review manually. Defaulting to legitimate (no auto-fix).',
463
+ };
464
+ }
465
+ export function analyzeHandlerTypeSafety(instances) {
466
+ const findings = [];
467
+ for (const inst of instances) {
468
+ if (inst.pattern !== 'args: any')
469
+ continue;
470
+ if (!/tools[\\/]/.test(inst.file))
471
+ continue;
472
+ findings.push({
473
+ rule_id: 'MCP-HANDLER-001',
474
+ severity: 'medium',
475
+ category: 'handler_types',
476
+ tool_name: path.basename(inst.file, '.ts'),
477
+ description: `Handler uses \`args: any\` — bypasses TypeScript type checking. ${inst.reason}`,
478
+ location: `${inst.file}:${inst.line}`,
479
+ fix: inst.fix_suggestion,
480
+ });
481
+ }
482
+ return findings;
483
+ }
484
+ export function analyzeOutputSchemaCoverage(census) {
485
+ const findings = [];
486
+ for (const c of census) {
487
+ if (!c.layer3_generated.output_exists) {
488
+ findings.push({
489
+ rule_id: 'MCP-OUTPUT-001',
490
+ severity: 'high',
491
+ category: 'output_coverage',
492
+ tool_name: c.name,
493
+ description: `Layer 3 output schema file does not exist: ${c.layer3_generated.output_schema_file}`,
494
+ fix: `Add outputSchema to ${c.name}'s tool definition and regenerate schemas.`,
495
+ });
496
+ }
497
+ if (c.layer2_zod.output_schema_export === null) {
498
+ findings.push({
499
+ rule_id: 'MCP-OUTPUT-002',
500
+ severity: 'medium',
501
+ category: 'output_coverage',
502
+ tool_name: c.name,
503
+ description: `Layer 2 outputSchema is defined inline (not exported with a stable name). This makes it harder to reference from tests.`,
504
+ fix: `Export the outputSchema with a stable name (e.g., ${c.name}OutputSchema).`,
505
+ });
506
+ }
507
+ }
508
+ return findings;
509
+ }
510
+ export function analyzeGenerationScriptSync() {
511
+ const findings = [];
512
+ if (!fs.existsSync(GENERATION_SCRIPT)) {
513
+ findings.push({
514
+ rule_id: 'MCP-GENSYNC-001',
515
+ severity: 'critical',
516
+ category: 'generation_sync',
517
+ tool_name: '(all)',
518
+ description: `Generation script not found: ${GENERATION_SCRIPT}`,
519
+ });
520
+ return findings;
521
+ }
522
+ const src = fs.readFileSync(GENERATION_SCRIPT, 'utf-8');
523
+ const nameRegex = /name:\s*["']([^"']+)["']/g;
524
+ const scriptNames = new Set();
525
+ let m;
526
+ while ((m = nameRegex.exec(src)) !== null) {
527
+ if (TOOLS_17.some(t => t.name === m[1])) {
528
+ scriptNames.add(m[1]);
529
+ }
530
+ }
531
+ for (const tool of TOOLS_17) {
532
+ if (!scriptNames.has(tool.name)) {
533
+ findings.push({
534
+ rule_id: 'MCP-GENSYNC-002',
535
+ severity: 'high',
536
+ category: 'generation_sync',
537
+ tool_name: tool.name,
538
+ description: `Tool "${tool.name}" is in TOOL_REGISTRY but missing from generate-json-schemas.ts. Layer 3 schemas will not be generated.`,
539
+ location: GENERATION_SCRIPT,
540
+ fix: `Add a get${toPascalCase(tool.name)}Tool() function and add it to the tools array.`,
541
+ });
542
+ }
543
+ }
544
+ return findings;
545
+ }
546
+ function toPascalCase(s) {
547
+ return s.split('_').map(p => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join('');
548
+ }
549
+ export function analyzeSchemaQueryReflection(census) {
550
+ const findings = [];
551
+ for (const c of census) {
552
+ if (!c.layer3_generated.input_exists) {
553
+ findings.push({
554
+ rule_id: 'MCP-REFLECT-001',
555
+ severity: 'high',
556
+ category: 'reflection',
557
+ tool_name: c.name,
558
+ description: `schema_query(action='get', name='${c.name}') would fail — Layer 3 input schema missing.`,
559
+ fix: `Run pnpm generate:schemas.`,
560
+ });
561
+ }
562
+ if (!c.layer3_generated.output_exists) {
563
+ findings.push({
564
+ rule_id: 'MCP-REFLECT-002',
565
+ severity: 'medium',
566
+ category: 'reflection',
567
+ tool_name: c.name,
568
+ description: `schema_query(action='get_output', name='${c.name}') would fail — Layer 3 output schema missing.`,
569
+ fix: `Run pnpm generate:schemas.`,
570
+ });
571
+ }
572
+ }
573
+ const onchainOps = [
574
+ 'permission', 'service', 'machine', 'progress', 'guard',
575
+ 'arbitration', 'repository', 'contact', 'treasury', 'reward',
576
+ 'allocation', 'personal', 'payment', 'demand', 'order', 'gen_passport',
577
+ ];
578
+ for (const op of onchainOps) {
579
+ const opFile = path.join(GENERATED_SCHEMAS_DIR, `onchain_operations_${op}.schema.json`);
580
+ if (!fs.existsSync(opFile)) {
581
+ findings.push({
582
+ rule_id: 'MCP-REFLECT-003',
583
+ severity: 'medium',
584
+ category: 'reflection',
585
+ tool_name: `onchain_operations_${op}`,
586
+ description: `Individual operation schema missing: ${opFile}. schema_query(action='get', name='onchain_operations_${op}') would fail.`,
587
+ fix: `Run pnpm generate:schemas.`,
588
+ });
589
+ }
590
+ }
591
+ return findings;
592
+ }
593
+ export function scanAllMcpSchemas() {
594
+ const census = analyzeLayerCensus();
595
+ const anyInstances = analyzeAnyUnknownCensus();
596
+ const findings = [
597
+ ...analyzeDeployedStubInconsistency(census),
598
+ ...analyzeLayerParity(census),
599
+ ...analyzeHandlerTypeSafety(anyInstances),
600
+ ...analyzeOutputSchemaCoverage(census),
601
+ ...analyzeGenerationScriptSync(),
602
+ ...analyzeSchemaQueryReflection(census),
603
+ ];
604
+ const bySev = new Map();
605
+ const byCat = new Map();
606
+ for (const f of findings) {
607
+ if (!bySev.has(f.severity))
608
+ bySev.set(f.severity, []);
609
+ bySev.get(f.severity).push(f);
610
+ if (!byCat.has(f.category))
611
+ byCat.set(f.category, []);
612
+ byCat.get(f.category).push(f);
613
+ }
614
+ const fixable = anyInstances.filter(i => i.category === 'fixable').length;
615
+ const legit = anyInstances.filter(i => i.category === 'legitimate').length;
616
+ const external = anyInstances.filter(i => i.category === 'external').length;
617
+ const stubCount = census.filter(c => c.layer4_deployed.is_stub).length;
618
+ const fullCount = census.filter(c => !c.layer4_deployed.is_stub && c.layer4_deployed.file_exists).length;
619
+ return {
620
+ census,
621
+ findings,
622
+ any_unknown_instances: anyInstances,
623
+ findings_by_severity: bySev,
624
+ findings_by_category: byCat,
625
+ total_findings: findings.length,
626
+ fixable_any_count: fixable,
627
+ legitimate_any_count: legit,
628
+ external_any_count: external,
629
+ stub_count: stubCount,
630
+ full_schema_count: fullCount,
631
+ };
632
+ }
633
+ export function formatAuditReport(result) {
634
+ const lines = [];
635
+ lines.push(`# MCP Schema Audit Report — 17 WoWok Tools`);
636
+ lines.push('');
637
+ lines.push(`> Auto-generated by \`mcp-schema-audit.ts\` v${MCP_SCHEMA_AUDIT_VERSION} — comprehensive`);
638
+ lines.push(`> 4-layer audit of schema consistency, any/unknown usage, and I/O coverage.`);
639
+ lines.push('');
640
+ lines.push(`## Summary`);
641
+ lines.push('');
642
+ lines.push(`- **Tools audited**: ${result.census.length}`);
643
+ lines.push(`- **Total findings**: ${result.total_findings}`);
644
+ lines.push(`- **Stub files**: ${result.stub_count} / ${result.census.length}`);
645
+ lines.push(`- **Full schema files**: ${result.full_schema_count} / ${result.census.length}`);
646
+ lines.push(`- **any/unknown instances**: ${result.any_unknown_instances.length} total`);
647
+ lines.push(` - Fixable: ${result.fixable_any_count}`);
648
+ lines.push(` - Legitimate: ${result.legitimate_any_count}`);
649
+ lines.push(` - External: ${result.external_any_count}`);
650
+ lines.push('');
651
+ lines.push(`### Findings by Severity`);
652
+ lines.push('');
653
+ lines.push(`| Severity | Count |`);
654
+ lines.push(`|----------|-------|`);
655
+ for (const sev of ['critical', 'high', 'medium', 'low', 'info']) {
656
+ const arr = result.findings_by_severity.get(sev) ?? [];
657
+ lines.push(`| ${sev} | ${arr.length} |`);
658
+ }
659
+ lines.push('');
660
+ lines.push(`### Findings by Category`);
661
+ lines.push('');
662
+ lines.push(`| Category | Count |`);
663
+ lines.push(`|----------|-------|`);
664
+ for (const cat of ['stub_inconsistency', 'layer_parity', 'handler_types', 'output_coverage', 'generation_sync', 'reflection']) {
665
+ const arr = result.findings_by_category.get(cat) ?? [];
666
+ lines.push(`| ${cat} | ${arr.length} |`);
667
+ }
668
+ lines.push('');
669
+ lines.push(`## Layer Census — All 17 Tools`);
670
+ lines.push('');
671
+ lines.push(`| Tool | L3 Input | L3 Output | L4 Status | L4 Properties | L4 Required |`);
672
+ lines.push(`|------|----------|-----------|-----------|---------------|-------------|`);
673
+ for (const c of result.census) {
674
+ const l3i = c.layer3_generated.input_exists ? `✓ ${(c.layer3_generated.input_size_bytes / 1024).toFixed(1)}KB` : '✗ MISSING';
675
+ const l3o = c.layer3_generated.output_exists ? `✓ ${(c.layer3_generated.output_size_bytes / 1024).toFixed(1)}KB` : '✗ MISSING';
676
+ const l4s = !c.layer4_deployed.file_exists ? '✗ MISSING' : c.layer4_deployed.is_stub ? '⚠ STUB' : '✓ FULL';
677
+ const l4p = c.layer4_deployed.properties_count;
678
+ const l4r = c.layer4_deployed.required_count;
679
+ lines.push(`| ${c.name} | ${l3i} | ${l3o} | ${l4s} | ${l4p} | ${l4r} |`);
680
+ }
681
+ lines.push('');
682
+ lines.push(`## Findings Detail`);
683
+ lines.push('');
684
+ const orderedSeverities = ['critical', 'high', 'medium', 'low', 'info'];
685
+ for (const sev of orderedSeverities) {
686
+ const sevFindings = result.findings_by_severity.get(sev) ?? [];
687
+ if (sevFindings.length === 0)
688
+ continue;
689
+ const title = sev.toUpperCase();
690
+ lines.push(`### ${title} (${sevFindings.length})`);
691
+ lines.push('');
692
+ for (const f of sevFindings) {
693
+ lines.push(`- **[${f.rule_id}] ${f.description}`);
694
+ if (f.location)
695
+ lines.push(` - Location: \`${f.location}\``);
696
+ if (f.fix)
697
+ lines.push(` - Fix: ${f.fix}`);
698
+ lines.push('');
699
+ }
700
+ }
701
+ lines.push(`## any/unknown Census Detail`);
702
+ lines.push('');
703
+ lines.push(`Total instances: ${result.any_unknown_instances.length}`);
704
+ lines.push('');
705
+ lines.push(`### By Pattern`);
706
+ lines.push('');
707
+ lines.push(`| Pattern | Total | Fixable | Legitimate | External |`);
708
+ lines.push(`|---------|-------|---------|------------|----------|`);
709
+ const patternGroups = new Map();
710
+ for (const inst of result.any_unknown_instances) {
711
+ if (!patternGroups.has(inst.pattern))
712
+ patternGroups.set(inst.pattern, []);
713
+ patternGroups.get(inst.pattern).push(inst);
714
+ }
715
+ for (const [pattern, arr] of [...patternGroups.entries()].sort((a, b) => b[1].length - a[1].length)) {
716
+ const fixable = arr.filter(i => i.category === 'fixable').length;
717
+ const legit = arr.filter(i => i.category === 'legitimate').length;
718
+ const ext = arr.filter(i => i.category === 'external').length;
719
+ lines.push(`| \`${pattern}\` | ${arr.length} | ${fixable} | ${legit} | ${ext} |`);
720
+ }
721
+ lines.push('');
722
+ const fixable = result.any_unknown_instances.filter(i => i.category === 'fixable');
723
+ if (fixable.length > 0) {
724
+ lines.push(`### Fixable Instances (Priority List)`);
725
+ lines.push('');
726
+ for (const inst of fixable) {
727
+ lines.push(`- **${path.basename(inst.file)}:${inst.line}** [\`${inst.pattern}\`]`);
728
+ lines.push(` - Code: \`${inst.code}\``);
729
+ lines.push(` - Reason: ${inst.reason}`);
730
+ if (inst.fix_suggestion)
731
+ lines.push(` - Fix: ${inst.fix_suggestion}`);
732
+ lines.push('');
733
+ }
734
+ }
735
+ lines.push(`## Recommended Action Plan`);
736
+ lines.push('');
737
+ lines.push(`### Phase 1: Fix Layer 4 Stub Inconsistency (CRITICAL UX)`);
738
+ lines.push('');
739
+ lines.push(`The ${result.stub_count} stub files force the LLM to call \`schema_query\` first, creating an extra round-trip. Fix by regenerating all 17 Layer 4 files from Layer 3 schemas:`);
740
+ lines.push('');
741
+ lines.push(`\`\`\`bash`);
742
+ lines.push(`# 1. Generate Layer 3 schemas from Zod source`);
743
+ lines.push(`cd d:/wowok/agent/mcp && pnpm generate:schemas`);
744
+ lines.push('');
745
+ lines.push(`# 2. Generate Layer 4 deployed files from Layer 3`);
746
+ lines.push(`# (Run the new sync-deployed-tools.ts script — see E2.4)`);
747
+ lines.push(`npx tsx scripts/sync-deployed-tools.ts`);
748
+ lines.push(`\`\`\``);
749
+ lines.push('');
750
+ lines.push(`### Phase 2: Type the ${result.fixable_any_count} fixable any/unknown instances`);
751
+ lines.push('');
752
+ lines.push(`Priority order:`);
753
+ lines.push('');
754
+ lines.push(`1. **SemanticSummarySchema** (src/schema/local/index.ts:6) — use \`z.lazy()\``);
755
+ lines.push(`2. **ConfigOperationOutputSchema.result** (src/schema/config/index.ts:17) — discriminated union by action`);
756
+ lines.push(`3. **ProjectOperationOutputSchema.result** (src/schema/project/index.ts:34) — discriminated union by action`);
757
+ lines.push(`4. **query_toolkit output result** (src/tools/index.ts:250) — discriminated union by query_type`);
758
+ lines.push(`5. **SchemaQueryOutputSchema.data** (src/schema/schema-query/index.ts:34) — discriminated union by action`);
759
+ lines.push(`6. **RepositoryKeyValueSchema.key_value** (src/schema/operations.ts:331) — discriminated union by key_type`);
760
+ lines.push(`7. **Handler args: any** — replace with \`unknown\` (forces strictParse at top of handler)`);
761
+ lines.push(`8. **dispatchToolCall(name, args: any)** — replace with \`unknown\``);
762
+ lines.push('');
763
+ lines.push(`### Phase 3: Verify I/O Schema Match`);
764
+ lines.push('');
765
+ lines.push(`For each tool, write a parity test that:`);
766
+ lines.push(`1. Calls the handler with a minimal valid input`);
767
+ lines.push(`2. Captures the structuredContent`);
768
+ lines.push(`3. Validates structuredContent against outputSchema`);
769
+ lines.push(`4. Reports any mismatch`);
770
+ lines.push('');
771
+ return lines.join('\n');
772
+ }