@tonyclaw/agent-inspector 4.0.1 → 4.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 (373) hide show
  1. package/.output/backend/nitro.json +1 -1
  2. package/.output/cli.js +193 -110
  3. package/.output/server/_ssr/index.mjs +1 -1
  4. package/.output/server/_ssr/{router-CTHqmroT.mjs → router-ChILzhmz.mjs} +92 -4
  5. package/.output/server/index.mjs +1 -1
  6. package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-Co3cUF_I.js} +1 -1
  7. package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-jFcrL37X.js} +1 -1
  8. package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-BPzt_VpM.js} +4 -4
  9. package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-C6O_zuwI.js} +1 -1
  10. package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-Ca6NvB7L.js} +1 -1
  11. package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BzqKcveJ.js} +1 -1
  12. package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-9pCZIsS_.js} +1 -1
  13. package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-BMP3KVGR.js} +1 -1
  14. package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-y4eRoT1H.js} +1 -1
  15. package/.output/ui/assets/{index-Ea-c8hPg.js → index-CH5w-haG.js} +1 -1
  16. package/.output/ui/assets/{index-zVVS53Hd.js → index-CmocEhyU.js} +1 -1
  17. package/.output/ui/assets/{index-Du4qNOOt.js → index-DT8sMJ_n.js} +2 -2
  18. package/.output/ui/assets/{index-gvFj_9K6.js → index-bfsbIRZa.js} +1 -1
  19. package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-BfFOSDG5.js} +1 -1
  20. package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkbVkOsp.js} +1 -1
  21. package/.output/ui/index.html +1 -1
  22. package/package.json +5 -10
  23. package/src/assets/IDE/claudecode-color.svg +0 -1
  24. package/src/assets/IDE/codex-color.svg +0 -1
  25. package/src/assets/IDE/opencode.svg +0 -1
  26. package/src/assets/IDE/xiaomimimo.svg +0 -1
  27. package/src/assets/favicon.svg +0 -21
  28. package/src/assets/logos/alibaba.svg +0 -1
  29. package/src/assets/logos/anthropic.svg +0 -1
  30. package/src/assets/logos/claude-code.svg +0 -4
  31. package/src/assets/logos/deepseek.svg +0 -1
  32. package/src/assets/logos/minimax.jpeg +0 -0
  33. package/src/assets/logos/openai.svg +0 -1
  34. package/src/assets/logos/opencode.svg +0 -4
  35. package/src/assets/logos/qwen.webp +0 -0
  36. package/src/assets/logos/zhipuai.svg +0 -219
  37. package/src/backend/router.tsx +0 -36
  38. package/src/backend/routes/$.ts +0 -26
  39. package/src/backend/routes/__root.ts +0 -4
  40. package/src/backend/routes/api/-instances.ts +0 -7
  41. package/src/backend/routes/api/alerts.summary.ts +0 -28
  42. package/src/backend/routes/api/alerts.ts +0 -70
  43. package/src/backend/routes/api/config.paths.ts +0 -14
  44. package/src/backend/routes/api/config.ts +0 -73
  45. package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
  46. package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
  47. package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
  48. package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
  49. package/src/backend/routes/api/ecosystem.packages.ts +0 -21
  50. package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
  51. package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
  52. package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
  53. package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
  54. package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
  55. package/src/backend/routes/api/groups.$groupId.ts +0 -93
  56. package/src/backend/routes/api/groups.ts +0 -79
  57. package/src/backend/routes/api/health.ts +0 -22
  58. package/src/backend/routes/api/instances.$name.connection.ts +0 -12
  59. package/src/backend/routes/api/instances.$name.restart.ts +0 -23
  60. package/src/backend/routes/api/instances.$name.start.ts +0 -18
  61. package/src/backend/routes/api/instances.$name.stop.ts +0 -23
  62. package/src/backend/routes/api/instances.$name.ts +0 -12
  63. package/src/backend/routes/api/instances.ts +0 -16
  64. package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
  65. package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
  66. package/src/backend/routes/api/knowledge.candidates.ts +0 -10
  67. package/src/backend/routes/api/knowledge.project-context.ts +0 -29
  68. package/src/backend/routes/api/knowledge.search.ts +0 -62
  69. package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
  70. package/src/backend/routes/api/logs.$id.body.ts +0 -58
  71. package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
  72. package/src/backend/routes/api/logs.$id.replay.ts +0 -297
  73. package/src/backend/routes/api/logs.$id.ts +0 -23
  74. package/src/backend/routes/api/logs.import.ts +0 -39
  75. package/src/backend/routes/api/logs.stream.ts +0 -174
  76. package/src/backend/routes/api/logs.ts +0 -214
  77. package/src/backend/routes/api/mcp.ts +0 -25
  78. package/src/backend/routes/api/models.ts +0 -10
  79. package/src/backend/routes/api/pi-agent.ts +0 -29
  80. package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
  81. package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
  82. package/src/backend/routes/api/providers.$providerId.ts +0 -111
  83. package/src/backend/routes/api/providers.export.ts +0 -44
  84. package/src/backend/routes/api/providers.import.ts +0 -81
  85. package/src/backend/routes/api/providers.scan.ts +0 -28
  86. package/src/backend/routes/api/providers.ts +0 -102
  87. package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
  88. package/src/backend/routes/api/runs.$runId.ts +0 -50
  89. package/src/backend/routes/api/runs.ts +0 -62
  90. package/src/backend/routes/api/runtime.ts +0 -46
  91. package/src/backend/routes/api/sessions.ts +0 -51
  92. package/src/backend/routes/api/storage.ts +0 -56
  93. package/src/backend/routes/livez.ts +0 -13
  94. package/src/backend/routes/metrics.ts +0 -14
  95. package/src/backend/routes/proxy/$.ts +0 -15
  96. package/src/backend/routes/readyz.ts +0 -18
  97. package/src/backend/start.ts +0 -10
  98. package/src/cli/alias.ts +0 -431
  99. package/src/cli/detect-tools.ts +0 -123
  100. package/src/cli/doctor.ts +0 -836
  101. package/src/cli/instance.ts +0 -1071
  102. package/src/cli/instanceApi.ts +0 -213
  103. package/src/cli/instanceArgs.ts +0 -301
  104. package/src/cli/instanceControl.ts +0 -191
  105. package/src/cli/instanceModel.ts +0 -276
  106. package/src/cli/instanceRegistry.ts +0 -731
  107. package/src/cli/networkHints.ts +0 -170
  108. package/src/cli/onboard.ts +0 -1668
  109. package/src/cli/onboardTarget.ts +0 -228
  110. package/src/cli/rustBackendPackage.ts +0 -458
  111. package/src/cli/startupOutput.ts +0 -16
  112. package/src/cli/templates/codex-skill-onboard.ts +0 -320
  113. package/src/cli/templates/command-onboard.ts +0 -25
  114. package/src/cli/templates/skill-onboard.ts +0 -625
  115. package/src/cli.ts +0 -1433
  116. package/src/components/OnboardingBanner.tsx +0 -115
  117. package/src/components/ProxyViewer.tsx +0 -2259
  118. package/src/components/ProxyViewerContainer.tsx +0 -1076
  119. package/src/components/alerts/AlertsDialog.tsx +0 -615
  120. package/src/components/clients/ClientLogo.tsx +0 -175
  121. package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
  122. package/src/components/errors/SafeErrorBoundary.tsx +0 -201
  123. package/src/components/groups/GroupsDialog.tsx +0 -1304
  124. package/src/components/inspector-pet/InspectorPet.tsx +0 -398
  125. package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
  126. package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
  127. package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
  128. package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
  129. package/src/components/providers/ImportWizardDialog.tsx +0 -281
  130. package/src/components/providers/ProviderCard.tsx +0 -347
  131. package/src/components/providers/ProviderForm.tsx +0 -1183
  132. package/src/components/providers/ProviderLogo.tsx +0 -122
  133. package/src/components/providers/ProviderTestResultsView.tsx +0 -734
  134. package/src/components/providers/ProvidersPanel.tsx +0 -714
  135. package/src/components/providers/SettingsDialog.tsx +0 -1042
  136. package/src/components/providers/providerFormCapabilities.ts +0 -36
  137. package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
  138. package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
  139. package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
  140. package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
  141. package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
  142. package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
  143. package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
  144. package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
  145. package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
  146. package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
  147. package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
  148. package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
  149. package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
  150. package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
  151. package/src/components/proxy-viewer/ResponseView.tsx +0 -202
  152. package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
  153. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
  154. package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
  155. package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
  156. package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
  157. package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
  158. package/src/components/proxy-viewer/accessibility.ts +0 -8
  159. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
  160. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
  161. package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
  162. package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
  163. package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
  164. package/src/components/proxy-viewer/anatomy/types.ts +0 -41
  165. package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
  166. package/src/components/proxy-viewer/bodyHydration.ts +0 -123
  167. package/src/components/proxy-viewer/cacheTrend.ts +0 -50
  168. package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
  169. package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
  170. package/src/components/proxy-viewer/diff/index.ts +0 -3
  171. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
  172. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
  173. package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
  174. package/src/components/proxy-viewer/formats/index.tsx +0 -47
  175. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
  176. package/src/components/proxy-viewer/index.ts +0 -9
  177. package/src/components/proxy-viewer/lazy.ts +0 -41
  178. package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
  179. package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
  180. package/src/components/proxy-viewer/log-formats/index.ts +0 -23
  181. package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
  182. package/src/components/proxy-viewer/log-formats/types.ts +0 -40
  183. package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
  184. package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
  185. package/src/components/proxy-viewer/logFocus.ts +0 -54
  186. package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
  187. package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
  188. package/src/components/proxy-viewer/replayComparison.ts +0 -131
  189. package/src/components/proxy-viewer/requestDiff.ts +0 -277
  190. package/src/components/proxy-viewer/requestTools.ts +0 -220
  191. package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
  192. package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
  193. package/src/components/proxy-viewer/viewerState.ts +0 -176
  194. package/src/components/ui/badge.tsx +0 -47
  195. package/src/components/ui/button.tsx +0 -47
  196. package/src/components/ui/collapsible.tsx +0 -21
  197. package/src/components/ui/confirm-dialog.tsx +0 -51
  198. package/src/components/ui/crab-logo.tsx +0 -45
  199. package/src/components/ui/crab-variants.tsx +0 -467
  200. package/src/components/ui/dialog.tsx +0 -130
  201. package/src/components/ui/icon-trigger.ts +0 -2
  202. package/src/components/ui/json-viewer-bulk.ts +0 -132
  203. package/src/components/ui/json-viewer.tsx +0 -508
  204. package/src/components/ui/scroll-area.tsx +0 -54
  205. package/src/components/ui/select.tsx +0 -178
  206. package/src/components/ui/separator.tsx +0 -28
  207. package/src/components/ui/tabs.tsx +0 -88
  208. package/src/components/ui/tooltip.tsx +0 -51
  209. package/src/components/ui/transient-toast.tsx +0 -105
  210. package/src/contracts/anthropic.ts +0 -230
  211. package/src/contracts/index.ts +0 -59
  212. package/src/contracts/json.ts +0 -37
  213. package/src/contracts/log.ts +0 -139
  214. package/src/contracts/openai.ts +0 -267
  215. package/src/index.css +0 -11
  216. package/src/knowledge/candidateStore.ts +0 -94
  217. package/src/knowledge/distiller.ts +0 -98
  218. package/src/knowledge/openclawClient.ts +0 -161
  219. package/src/knowledge/openclawGatewayClient.ts +0 -249
  220. package/src/knowledge/openclawMarkdown.ts +0 -146
  221. package/src/knowledge/redactor.ts +0 -80
  222. package/src/knowledge/types.ts +0 -83
  223. package/src/lib/alertContract.ts +0 -76
  224. package/src/lib/apiClient.ts +0 -166
  225. package/src/lib/apiFormat.ts +0 -29
  226. package/src/lib/backendImplementation.ts +0 -16
  227. package/src/lib/basePath.ts +0 -107
  228. package/src/lib/browserRuntimeContract.ts +0 -124
  229. package/src/lib/browserRuntimeResolver.ts +0 -333
  230. package/src/lib/chunkLoadRecovery.ts +0 -83
  231. package/src/lib/claudeCodeStrip.ts +0 -98
  232. package/src/lib/clipboard.ts +0 -67
  233. package/src/lib/codingAgentEndpoints.ts +0 -54
  234. package/src/lib/ecosystemContract.ts +0 -130
  235. package/src/lib/export-logs.ts +0 -287
  236. package/src/lib/groupContract.ts +0 -166
  237. package/src/lib/instanceContract.ts +0 -239
  238. package/src/lib/jsonFile.ts +0 -46
  239. package/src/lib/logImportContract.ts +0 -12
  240. package/src/lib/managedInstance.ts +0 -112
  241. package/src/lib/mask.ts +0 -4
  242. package/src/lib/objectUtils.ts +0 -22
  243. package/src/lib/piAgentContract.ts +0 -102
  244. package/src/lib/providerContract.ts +0 -125
  245. package/src/lib/providerImportContract.ts +0 -27
  246. package/src/lib/providerModelMetadata.ts +0 -458
  247. package/src/lib/providerTestContract.ts +0 -170
  248. package/src/lib/providerTestPrompt.ts +0 -100
  249. package/src/lib/publicBasePathContext.ts +0 -137
  250. package/src/lib/resourceLimits.ts +0 -345
  251. package/src/lib/runContract.ts +0 -164
  252. package/src/lib/runtimeConfig.ts +0 -43
  253. package/src/lib/safeDiagnostic.ts +0 -38
  254. package/src/lib/safeFetch.ts +0 -508
  255. package/src/lib/serverPort.ts +0 -47
  256. package/src/lib/sessionInfoContract.ts +0 -78
  257. package/src/lib/sessionUrl.ts +0 -46
  258. package/src/lib/ssrfGuard.ts +0 -133
  259. package/src/lib/stopReason.ts +0 -130
  260. package/src/lib/themeMode.ts +0 -41
  261. package/src/lib/timeDisplay.ts +0 -22
  262. package/src/lib/toolTrace.ts +0 -290
  263. package/src/lib/uiScale.ts +0 -117
  264. package/src/lib/unknown.ts +0 -27
  265. package/src/lib/upstreamUrl.ts +0 -150
  266. package/src/lib/useAlerts.ts +0 -82
  267. package/src/lib/useGroupEvidence.ts +0 -37
  268. package/src/lib/useGroups.ts +0 -32
  269. package/src/lib/useOnboarding.ts +0 -93
  270. package/src/lib/useProviders.ts +0 -30
  271. package/src/lib/useStripConfig.ts +0 -154
  272. package/src/lib/useThemeMode.ts +0 -40
  273. package/src/lib/useUiScale.ts +0 -52
  274. package/src/lib/utils.ts +0 -78
  275. package/src/mcp/currentContext.ts +0 -65
  276. package/src/mcp/instanceHandlers.ts +0 -151
  277. package/src/mcp/loopback.ts +0 -88
  278. package/src/mcp/mode.ts +0 -75
  279. package/src/mcp/previewExtractor.ts +0 -233
  280. package/src/mcp/server.ts +0 -2274
  281. package/src/mcp/toolHandlers.ts +0 -1533
  282. package/src/proxy/alerts.ts +0 -664
  283. package/src/proxy/chunkStorage.ts +0 -123
  284. package/src/proxy/config.ts +0 -218
  285. package/src/proxy/constants.ts +0 -66
  286. package/src/proxy/dataDir.ts +0 -147
  287. package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
  288. package/src/proxy/ecosystemExecutionRoute.ts +0 -116
  289. package/src/proxy/ecosystemRegistry.ts +0 -296
  290. package/src/proxy/ecosystemTasks.ts +0 -415
  291. package/src/proxy/evidenceAnalysis.ts +0 -526
  292. package/src/proxy/evidenceExporter.ts +0 -235
  293. package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
  294. package/src/proxy/formats/anthropic/handler.ts +0 -75
  295. package/src/proxy/formats/anthropic/index.ts +0 -13
  296. package/src/proxy/formats/anthropic/register.ts +0 -4
  297. package/src/proxy/formats/anthropic/schemas.ts +0 -6
  298. package/src/proxy/formats/anthropic/stream.ts +0 -205
  299. package/src/proxy/formats/handler.ts +0 -46
  300. package/src/proxy/formats/index.ts +0 -13
  301. package/src/proxy/formats/jsonSchema.ts +0 -2
  302. package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
  303. package/src/proxy/formats/openai/codexMetadata.ts +0 -61
  304. package/src/proxy/formats/openai/handler.ts +0 -133
  305. package/src/proxy/formats/openai/index.ts +0 -33
  306. package/src/proxy/formats/openai/provider.ts +0 -50
  307. package/src/proxy/formats/openai/register.ts +0 -4
  308. package/src/proxy/formats/openai/schemas.ts +0 -25
  309. package/src/proxy/formats/openai/stream.ts +0 -600
  310. package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
  311. package/src/proxy/formats/providerAdapter.ts +0 -50
  312. package/src/proxy/formats/providerRegistry.ts +0 -51
  313. package/src/proxy/formats/providers/index.ts +0 -3
  314. package/src/proxy/formats/registry.ts +0 -65
  315. package/src/proxy/groupEvidenceExporter.ts +0 -371
  316. package/src/proxy/groupStore.ts +0 -336
  317. package/src/proxy/handler.ts +0 -729
  318. package/src/proxy/identityProxy.ts +0 -1842
  319. package/src/proxy/jsonlRecovery.ts +0 -554
  320. package/src/proxy/logBodyChunks.ts +0 -91
  321. package/src/proxy/logFinalizer.ts +0 -777
  322. package/src/proxy/logFinalizer.worker.ts +0 -24
  323. package/src/proxy/logImportUpload.ts +0 -128
  324. package/src/proxy/logImporter.ts +0 -813
  325. package/src/proxy/logIndex.ts +0 -663
  326. package/src/proxy/logSearch.ts +0 -122
  327. package/src/proxy/logger.ts +0 -537
  328. package/src/proxy/openaiOrphanToolStrip.ts +0 -142
  329. package/src/proxy/platformCommands.ts +0 -258
  330. package/src/proxy/privateDataPath.ts +0 -419
  331. package/src/proxy/providerImporters.ts +0 -578
  332. package/src/proxy/providerScanStore.ts +0 -87
  333. package/src/proxy/providerSecretStore.ts +0 -216
  334. package/src/proxy/providers.ts +0 -998
  335. package/src/proxy/rawStreamCapture.ts +0 -342
  336. package/src/proxy/runFailures.ts +0 -94
  337. package/src/proxy/runStore.ts +0 -214
  338. package/src/proxy/runtimeAdmission.ts +0 -55
  339. package/src/proxy/runtimeHealth.ts +0 -221
  340. package/src/proxy/runtimeMetrics.ts +0 -149
  341. package/src/proxy/runtimeShutdown.ts +0 -157
  342. package/src/proxy/schemas.ts +0 -112
  343. package/src/proxy/sessionArchive.ts +0 -479
  344. package/src/proxy/sessionInfo.ts +0 -266
  345. package/src/proxy/sessionProcess.ts +0 -194
  346. package/src/proxy/sessionRuntime.ts +0 -121
  347. package/src/proxy/sessionSupervisor.ts +0 -305
  348. package/src/proxy/sessionWorkerEntry.ts +0 -26
  349. package/src/proxy/shutdownCoordinator.ts +0 -90
  350. package/src/proxy/socketTracker.ts +0 -639
  351. package/src/proxy/sqliteLogIndex.ts +0 -733
  352. package/src/proxy/storageLifecycle.ts +0 -432
  353. package/src/proxy/store.ts +0 -1773
  354. package/src/proxy/streamTiming.ts +0 -31
  355. package/src/proxy/toolSchemaWarnings.ts +0 -529
  356. package/src/proxy/uiAssetServer.ts +0 -106
  357. package/src/proxy/upstream.ts +0 -127
  358. package/src/services/alerts.ts +0 -12
  359. package/src/services/groups.ts +0 -119
  360. package/src/services/piAgent.ts +0 -421
  361. package/src/services/piAgentRetrieval.ts +0 -1180
  362. package/src/services/result.ts +0 -17
  363. package/src/services/runs.ts +0 -76
  364. package/src/ui/bootstrap.ts +0 -167
  365. package/src/ui/index.html +0 -38
  366. package/src/ui/logsStreamClient.ts +0 -20
  367. package/src/ui/main.tsx +0 -13
  368. package/src/ui/public/runtime-config.js +0 -2
  369. package/src/ui/router.tsx +0 -13
  370. package/src/ui/routes/__root.tsx +0 -69
  371. package/src/ui/routes/index.tsx +0 -35
  372. package/src/ui/routes/session/$sessionId.tsx +0 -50
  373. package/src/ui/runtimeDiscovery.ts +0 -50
package/src/mcp/server.ts DELETED
@@ -1,2274 +0,0 @@
1
- /**
2
- * MCP (Model Context Protocol) server for agent-inspector.
3
- *
4
- * Exposes `inspector_*` tools and resources. Mounted
5
- * at `POST /api/mcp` in the existing TanStack Start process using HTTP Streamable
6
- * transport. localhost-only, no auth in v1 — see
7
- * `openspec/changes/add-mcp-server/design.md` decisions D1, D2, D9.
8
- *
9
- * The `McpServer` + `WebStandardStreamableHTTPServerTransport` pair is
10
- * instantiated once per process on first request and reused for all
11
- * subsequent requests (stateless mode — no `sessionIdGenerator`).
12
- *
13
- * Tool implementations live in `./toolHandlers.ts`; this file wires them to
14
- * the SDK and exposes MCP resources/prompts.
15
- */
16
-
17
- import { z } from "zod";
18
- import packageJson from "../../package.json";
19
- import {
20
- type GetPromptResult,
21
- type ListResourcesResult,
22
- McpServer,
23
- type ReadResourceResult,
24
- ResourceTemplate,
25
- type Variables,
26
- WebStandardStreamableHTTPServerTransport,
27
- } from "@modelcontextprotocol/server";
28
- import {
29
- AddInspectorGroupSessionInputSchema,
30
- DeleteInspectorGroupOptionsSchema,
31
- GroupEvidenceExportOptionsSchema,
32
- InspectorGroupStatusSchema,
33
- UpdateInspectorGroupInputSchema,
34
- } from "../lib/groupContract";
35
- import { InspectorRunStatusSchema, UpdateInspectorRunInputSchema } from "../lib/runContract";
36
- import { withBasePath } from "../lib/basePath";
37
- import {
38
- getPublicBasePath,
39
- getPublicOrigin,
40
- runWithRequestPublicBasePath,
41
- } from "../lib/publicBasePathContext";
42
- import { JsonValueSchema, LogIdSchema, parseLogId } from "../contracts";
43
- import { InstanceListOutputSchema } from "../lib/instanceContract";
44
- import {
45
- MAX_PROVIDER_MODEL_NAME_CHARS,
46
- MAX_PROVIDER_MODELS,
47
- MAX_SEARCH_PROJECT_CHARS,
48
- MAX_SEARCH_QUERY_CHARS,
49
- } from "../lib/resourceLimits";
50
- import { getCurrentContext } from "./currentContext";
51
- import {
52
- getMcpInstanceModeInfo,
53
- getMcpModeInfo,
54
- isMcpInstanceWriteEnabled,
55
- isMcpWriteEnabled,
56
- } from "./mode";
57
- import {
58
- getInstanceConnectionImpl,
59
- getInstanceImpl,
60
- InstanceLifecycleToolInputSchema,
61
- InstanceNameToolInputSchema,
62
- listInstancesImpl,
63
- restartInstanceImpl,
64
- startInstanceImpl,
65
- stopInstanceImpl,
66
- } from "./instanceHandlers";
67
- import {
68
- getInspectorGroup,
69
- listInspectorGroups,
70
- readInspectorGroupEvidence,
71
- readInspectorGroupSessions,
72
- } from "../services/groups";
73
- import {
74
- getInspectorRun,
75
- listInspectorRecentFailures,
76
- listInspectorRuns,
77
- readInspectorRunEvidence,
78
- } from "../services/runs";
79
- import { callApi } from "./loopback";
80
- import {
81
- addGroupSessionImpl,
82
- addGroupProcessImpl,
83
- addProviderImpl,
84
- diagnoseCaptureImpl,
85
- diagnoseProviderTestImpl,
86
- exportEvidenceBundleImpl,
87
- createGroupImpl,
88
- createRunImpl,
89
- createSessionKnowledgeImpl,
90
- deleteGroupImpl,
91
- exportEvidenceImpl,
92
- getCurrentContextImpl,
93
- getEvidenceFilesImpl,
94
- exportGroupEvidenceImpl,
95
- exportGroupEvidenceBundleImpl,
96
- getGroupEvidenceFilesImpl,
97
- getGroupImpl,
98
- getLogHeadersImpl,
99
- getRecentFailuresImpl,
100
- getProcessImpl,
101
- getProcessTimelineImpl,
102
- getProjectContextImpl,
103
- getRuntimeConfigImpl,
104
- getRunImpl,
105
- getSessionImpl,
106
- getSessionTimelineImpl,
107
- getLogChunksImpl,
108
- getLogImpl,
109
- getProviderImpl,
110
- listGroupsImpl,
111
- LIMIT_HARD_CAP,
112
- listKnowledgeCandidatesImpl,
113
- listLogsImpl,
114
- listModelsImpl,
115
- listProcessesImpl,
116
- listProvidersImpl,
117
- listSessionsImpl,
118
- promoteKnowledgeCandidateImpl,
119
- replayLogImpl,
120
- safeCall,
121
- searchLogsImpl,
122
- searchKnowledgeImpl,
123
- setCurrentContextImpl,
124
- testProviderImpl,
125
- updateGroupImpl,
126
- updateRunImpl,
127
- updateProviderImpl,
128
- type ToolResult,
129
- } from "./toolHandlers";
130
- import { logger } from "../proxy/logger";
131
-
132
- // ---------------------------------------------------------------------------
133
- // Lazy singleton: build the McpServer + transport on first use.
134
- // ---------------------------------------------------------------------------
135
-
136
- type ServerPair = { server: McpServer; transport: WebStandardStreamableHTTPServerTransport };
137
-
138
- export const MCP_SERVER_VERSION = packageJson.version;
139
-
140
- let initialized: ServerPair | null = null;
141
- let initPromise: Promise<ServerPair> | null = null;
142
-
143
- function buildServer(): ServerPair {
144
- const server = new McpServer(
145
- { name: "agent-inspector", version: MCP_SERVER_VERSION },
146
- { capabilities: { tools: {}, resources: {}, prompts: {} } },
147
- );
148
- registerTools(server);
149
- registerResources(server);
150
- registerPrompts(server);
151
- const transport = new WebStandardStreamableHTTPServerTransport({
152
- sessionIdGenerator: undefined, // stateless — see module docstring
153
- });
154
- // The connect() call is async — handle rejection so a failed transport
155
- // setup doesn't leave a broken singleton that silently fails all requests.
156
- void server.connect(transport).then(
157
- () => {},
158
- (err) => {
159
- logger.error(
160
- "[mcp] server.connect failed:",
161
- err instanceof Error ? err.message : String(err),
162
- );
163
- },
164
- );
165
- return { server, transport };
166
- }
167
-
168
- async function getServer(): Promise<ServerPair> {
169
- if (initialized !== null) return initialized;
170
- if (initPromise === null) {
171
- initPromise = Promise.resolve(buildServer()).then((pair) => {
172
- initialized = pair;
173
- return pair;
174
- });
175
- }
176
- return initPromise;
177
- }
178
-
179
- /** Reset for tests. */
180
- export async function _resetForTests(): Promise<void> {
181
- if (initialized !== null) {
182
- try {
183
- await initialized.server.close();
184
- } catch {
185
- // ignore
186
- }
187
- }
188
- initialized = null;
189
- initPromise = null;
190
- }
191
-
192
- // ---------------------------------------------------------------------------
193
- // Public entry point for the route handler.
194
- // ---------------------------------------------------------------------------
195
-
196
- /**
197
- * Handle an incoming MCP HTTP request. Suitable as a TanStack Start route
198
- * handler — accepts a Web `Request`, returns a `Promise<Response>`.
199
- */
200
- export async function handleMcpRequest(request: Request): Promise<Response> {
201
- return runWithRequestPublicBasePath(request, async () => {
202
- const { transport } = await getServer();
203
- return transport.handleRequest(request);
204
- });
205
- }
206
-
207
- // ---------------------------------------------------------------------------
208
- // Tool descriptions (kept here, not in toolHandlers.ts, because they are
209
- // only relevant to the wire-level MCP registration).
210
- // ---------------------------------------------------------------------------
211
-
212
- const TOOL_LIST_LOGS_DESC = `List recent captured agent/model proxy logs in reverse-chronological order with parsed previews. Useful for "what did I just send?" discovery.
213
-
214
- REFLEXIVE-LOOP WARNING: this list includes the agent's own recent /proxy calls. If results appear to be the agent's own tool calls (e.g., the agent called inspector_list_logs and now sees itself in the results), filter by clientPid (your own PID) or by timestamp on the client side.
215
-
216
- Parameters:
217
- - offset (number, default 0): skip this many entries from the start of the filtered list
218
- - limit (number, default 3, hard-clamped to 5): how many summaries to return
219
- - sessionId (string, optional): filter by session/affinity id
220
- - model (string, optional): filter by model name
221
-
222
- Returns: array of "thick summary" objects, each containing:
223
- - id, timestamp, provider, model, apiFormat, method, path, status, isStreaming,
224
- hasError, latencyMs, tokens { input, output, cacheCreate, cacheRead },
225
- sessionId, userAgent, clientPid, clientCwd, clientProjectFolder,
226
- - lastUserMessagePreview (string|null, ≤500 chars) — first text block of the last user message, parsed via the format-specific schema (NOT a raw body slice)
227
- - responsePreview (string|null, ≤500 chars) — first text block of the assistant response
228
- - hasChunks, hasRawRequestBody (booleans)
229
-
230
- Either preview field is null when the body is unknown format, unparseable, or the relevant content is non-text (e.g., image-only).`;
231
-
232
- const PROVIDER_WRITE_WARNING =
233
- "⚠ This tool mutates provider configuration. Confirm with the user before invoking.";
234
-
235
- const INSTANCE_LIFECYCLE_WRITE_WARNING =
236
- "This tool changes a local Agent Inspector process. Obtain explicit user approval before invoking it.";
237
-
238
- const INSTANCE_READ_TOOL_NAMES = [
239
- "inspector_list_instances",
240
- "inspector_get_instance",
241
- "inspector_get_instance_connection",
242
- ] as const;
243
-
244
- const INSTANCE_WRITE_TOOL_NAMES = [
245
- "inspector_start_instance",
246
- "inspector_stop_instance",
247
- "inspector_restart_instance",
248
- ] as const;
249
-
250
- const INSTANCE_RESOURCE_URIS = [
251
- "inspector://instances",
252
- "inspector://instances/{name}",
253
- "inspector://instances/{name}/connection",
254
- ] as const;
255
-
256
- const AddProviderInputSchema = z
257
- .object({
258
- name: z.string().min(1).describe("Provider display name."),
259
- apiKey: z.string().min(1).describe("Plaintext provider API key."),
260
- format: z
261
- .enum(["anthropic", "openai"])
262
- .optional()
263
- .describe("Primary API family. Use openai for Chat Completions or Responses providers."),
264
- model: z
265
- .string()
266
- .min(1)
267
- .max(MAX_PROVIDER_MODEL_NAME_CHARS)
268
- .optional()
269
- .describe("Legacy single-model input. Prefer models for new clients."),
270
- models: z
271
- .array(z.string().min(1).max(MAX_PROVIDER_MODEL_NAME_CHARS))
272
- .min(1)
273
- .max(MAX_PROVIDER_MODELS)
274
- .optional()
275
- .describe("Provider model names."),
276
- anthropicBaseUrl: z
277
- .string()
278
- .optional()
279
- .describe("Anthropic-compatible base or exact /v1/messages endpoint."),
280
- openaiBaseUrl: z
281
- .string()
282
- .optional()
283
- .describe("OpenAI Chat Completions base or exact /v1/chat/completions endpoint."),
284
- openaiResponsesBaseUrl: z
285
- .string()
286
- .optional()
287
- .describe(
288
- "OpenAI Responses base or exact /v1/responses endpoint. MiniMax default endpoint is https://api.minimaxi.com/v1/responses.",
289
- ),
290
- authHeader: z.enum(["bearer", "x-api-key"]).optional(),
291
- apiDocsUrl: z.string().optional(),
292
- })
293
- .refine(
294
- (input) => input.model !== undefined || (input.models !== undefined && input.models.length > 0),
295
- { message: "Provide models or legacy model." },
296
- );
297
-
298
- const UpdateProviderInputSchema = z.object({
299
- id: z.string().describe("The provider id to update."),
300
- name: z.string().min(1).optional(),
301
- apiKey: z.string().min(1).optional(),
302
- format: z.enum(["anthropic", "openai"]).optional(),
303
- model: z
304
- .string()
305
- .min(1)
306
- .max(MAX_PROVIDER_MODEL_NAME_CHARS)
307
- .optional()
308
- .describe("Legacy single-model input. Prefer models."),
309
- models: z
310
- .array(z.string().min(1).max(MAX_PROVIDER_MODEL_NAME_CHARS))
311
- .max(MAX_PROVIDER_MODELS)
312
- .optional()
313
- .describe("Replace provider model names."),
314
- baseUrl: z
315
- .string()
316
- .min(1)
317
- .optional()
318
- .describe("Legacy route URL retained for old configs; prefer format-specific URL fields."),
319
- authHeader: z.enum(["bearer", "x-api-key"]).optional(),
320
- anthropicBaseUrl: z
321
- .string()
322
- .optional()
323
- .describe("Anthropic-compatible base or exact /v1/messages endpoint."),
324
- openaiBaseUrl: z
325
- .string()
326
- .optional()
327
- .describe("OpenAI Chat Completions base or exact /v1/chat/completions endpoint."),
328
- openaiResponsesBaseUrl: z
329
- .string()
330
- .optional()
331
- .describe(
332
- "OpenAI Responses base or exact /v1/responses endpoint. MiniMax default endpoint is https://api.minimaxi.com/v1/responses.",
333
- ),
334
- apiDocsUrl: z.string().optional(),
335
- });
336
-
337
- const LogResourceListResponseSchema = z.object({
338
- logs: z.array(z.object({ id: LogIdSchema })),
339
- });
340
-
341
- export const McpLogIdInputSchema = z.object({
342
- id: LogIdSchema.describe("The log id."),
343
- });
344
-
345
- export const McpOptionalLogIdInputSchema = z.object({
346
- id: LogIdSchema.optional().describe("Optional log id to inspect."),
347
- });
348
-
349
- const ProcessResourceListResponseSchema = z.object({
350
- logs: z.array(z.object({ clientPid: z.number().int().positive().nullable().optional() })),
351
- });
352
-
353
- type ResourceDescriptor = {
354
- uri: string;
355
- name: string;
356
- title?: string;
357
- mimeType?: string;
358
- description?: string;
359
- };
360
-
361
- function textResource(uri: URL, mimeType: string, text: string): ReadResourceResult {
362
- return {
363
- contents: [{ uri: uri.href, mimeType, text }],
364
- };
365
- }
366
-
367
- function jsonResource(uri: URL, data: unknown): ReadResourceResult {
368
- return textResource(uri, "application/json", JSON.stringify(data, null, 2));
369
- }
370
-
371
- function mcpEndpointUrl(): string {
372
- return `${getPublicOrigin()}${withBasePath("/api/mcp", getPublicBasePath())}`;
373
- }
374
-
375
- function mcpHealth(): Record<string, unknown> {
376
- return {
377
- status: "ok",
378
- serverInfo: {
379
- name: "agent-inspector",
380
- version: MCP_SERVER_VERSION,
381
- },
382
- transport: {
383
- primary: "streamable-http",
384
- endpoint: mcpEndpointUrl(),
385
- stateless: true,
386
- },
387
- mode: getMcpModeInfo(),
388
- catalog: {
389
- tools: TOOL_NAMES.length,
390
- resources: RESOURCE_NAMES.length,
391
- prompts: PROMPT_NAMES.length,
392
- },
393
- };
394
- }
395
-
396
- const WRITE_TOOL_NAMES = new Set<string>([
397
- ...INSTANCE_WRITE_TOOL_NAMES,
398
- "inspector_create_run",
399
- "inspector_update_run",
400
- "inspector_export_evidence",
401
- "inspector_export_evidence_bundle",
402
- "inspector_create_group",
403
- "inspector_update_group",
404
- "inspector_delete_group",
405
- "inspector_add_group_session",
406
- "inspector_add_group_process",
407
- "inspector_export_group_evidence",
408
- "inspector_export_group_evidence_bundle",
409
- "inspector_set_current_context",
410
- "inspector_replay_log",
411
- "inspector_add_provider",
412
- "inspector_update_provider",
413
- "inspector_test_provider",
414
- "inspector_diagnose_provider_test",
415
- "inspector_create_session_knowledge",
416
- "inspector_promote_knowledge_candidate",
417
- ]);
418
-
419
- function mcpCapabilities(): Record<string, unknown> {
420
- const readTools = TOOL_NAMES.filter((name) => !WRITE_TOOL_NAMES.has(name));
421
- const writeTools = TOOL_NAMES.filter((name) => WRITE_TOOL_NAMES.has(name));
422
- const generalWriteMode = getMcpModeInfo();
423
- const instanceWriteMode = getMcpInstanceModeInfo();
424
- return {
425
- serverInfo: {
426
- name: "agent-inspector",
427
- version: MCP_SERVER_VERSION,
428
- },
429
- mode: generalWriteMode,
430
- tools: {
431
- read: readTools,
432
- writeOrAction: writeTools,
433
- },
434
- resources: RESOURCE_NAMES,
435
- prompts: PROMPT_NAMES,
436
- instanceControl: {
437
- tools: {
438
- read: INSTANCE_READ_TOOL_NAMES,
439
- writeOrAction: INSTANCE_WRITE_TOOL_NAMES,
440
- },
441
- resources: INSTANCE_RESOURCE_URIS,
442
- writeGates: {
443
- general: generalWriteMode,
444
- instance: instanceWriteMode,
445
- lifecycleWritesEnabled: generalWriteMode.writesEnabled && instanceWriteMode.writesEnabled,
446
- },
447
- limitations: {
448
- selfStopOrRestart:
449
- "The serving managed instance cannot stop or restart itself over REST or MCP. Use the CLI or a sibling controller instance.",
450
- },
451
- },
452
- };
453
- }
454
-
455
- function mcpConfig(): Record<string, unknown> {
456
- const endpoint = mcpEndpointUrl();
457
- return {
458
- streamableHttp: {
459
- endpoint,
460
- config: {
461
- mcpServers: {
462
- "agent-inspector": {
463
- type: "streamableHttp",
464
- url: endpoint,
465
- },
466
- },
467
- },
468
- },
469
- stdioBridge: {
470
- command: "agent-inspector-mcp",
471
- args: ["stdio", "--url", endpoint],
472
- config: {
473
- mcpServers: {
474
- "agent-inspector": {
475
- command: "agent-inspector-mcp",
476
- args: ["stdio", "--url", endpoint],
477
- },
478
- },
479
- },
480
- },
481
- opencodeLocal: {
482
- mcp: {
483
- "agent-inspector": {
484
- type: "local",
485
- command: ["agent-inspector-mcp", "stdio", "--url", endpoint],
486
- enabled: true,
487
- },
488
- },
489
- },
490
- mimoCodeLocal: {
491
- mcp: {
492
- "agent-inspector": {
493
- type: "local",
494
- command: ["agent-inspector-mcp", "stdio", "--url", endpoint],
495
- enabled: true,
496
- },
497
- },
498
- },
499
- networkNote:
500
- "If the MCP client runs in another container or host, replace localhost with an address reachable from that client. Configure only one transport for the same Inspector instance.",
501
- };
502
- }
503
-
504
- function disabledWriteTool(toolName: string): ToolResult {
505
- return {
506
- content: [
507
- {
508
- type: "text",
509
- text: JSON.stringify(
510
- {
511
- error: "mcp-write-disabled",
512
- tool: toolName,
513
- mode: getMcpModeInfo(),
514
- },
515
- null,
516
- 2,
517
- ),
518
- },
519
- ],
520
- isError: true,
521
- };
522
- }
523
-
524
- function safeWriteCall(
525
- toolName: string,
526
- fn: () => ToolResult | Promise<ToolResult>,
527
- ): Promise<ToolResult> {
528
- return safeCall(() => {
529
- if (!isMcpWriteEnabled()) return disabledWriteTool(toolName);
530
- return fn();
531
- });
532
- }
533
-
534
- function disabledInstanceWriteTool(toolName: string): ToolResult {
535
- return {
536
- content: [
537
- {
538
- type: "text",
539
- text: JSON.stringify(
540
- {
541
- error: "mcp-instance-write-disabled",
542
- tool: toolName,
543
- generalMode: getMcpModeInfo(),
544
- instanceMode: getMcpInstanceModeInfo(),
545
- },
546
- null,
547
- 2,
548
- ),
549
- },
550
- ],
551
- isError: true,
552
- };
553
- }
554
-
555
- function safeInstanceWriteCall(
556
- toolName: string,
557
- fn: () => ToolResult | Promise<ToolResult>,
558
- ): Promise<ToolResult> {
559
- return safeWriteCall(toolName, () =>
560
- isMcpInstanceWriteEnabled() ? fn() : disabledInstanceWriteTool(toolName),
561
- );
562
- }
563
-
564
- function variableString(variables: Variables, name: string): string | null {
565
- const value = variables[name];
566
- if (Array.isArray(value)) return value[0] ?? null;
567
- return value ?? null;
568
- }
569
-
570
- function listResult(resources: ResourceDescriptor[]): ListResourcesResult {
571
- return { resources };
572
- }
573
-
574
- async function readApiJsonResource(uri: URL, path: string): Promise<ReadResourceResult> {
575
- try {
576
- const response = await callApi(path);
577
- if (!response.ok) {
578
- return textResource(uri, "text/plain", `GET ${path} returned ${response.status}`);
579
- }
580
- return jsonResource(uri, await response.json());
581
- } catch (err) {
582
- const message = err instanceof Error ? err.message : String(err);
583
- return textResource(uri, "text/plain", `Resource read failed: ${message}`);
584
- }
585
- }
586
-
587
- function readServiceJsonResource<T>(
588
- uri: URL,
589
- result: { ok: true; value: T } | { ok: false; message: string },
590
- ): ReadResourceResult {
591
- if (!result.ok) return textResource(uri, "text/plain", result.message);
592
- return jsonResource(uri, result.value);
593
- }
594
-
595
- async function readInstanceToolResource(
596
- uri: URL,
597
- resultPromise: Promise<ToolResult>,
598
- ): Promise<ReadResourceResult> {
599
- const result = await resultPromise;
600
- const text = result.content[0]?.text ?? "";
601
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
602
- }
603
-
604
- async function listInstanceTemplateResources(connection: boolean): Promise<ListResourcesResult> {
605
- try {
606
- const response = await callApi("/api/instances", {
607
- headers: { accept: "application/json" },
608
- });
609
- if (!response.ok) return listResult([]);
610
- const parsed = InstanceListOutputSchema.safeParse(await response.json());
611
- if (!parsed.success) return listResult([]);
612
- return listResult(
613
- parsed.data.instances.map((instance) => ({
614
- uri: connection
615
- ? `inspector://instances/${encodeURIComponent(instance.name)}/connection`
616
- : `inspector://instances/${encodeURIComponent(instance.name)}`,
617
- name: connection ? `instance-connection:${instance.name}` : `instance:${instance.name}`,
618
- title: connection
619
- ? `Agent Inspector connection for ${instance.name}`
620
- : `Agent Inspector instance ${instance.name}`,
621
- mimeType: "application/json",
622
- description: `${instance.state} at ${instance.urls.ui}`,
623
- })),
624
- );
625
- } catch {
626
- return listResult([]);
627
- }
628
- }
629
-
630
- async function listSessionResources(): Promise<ListResourcesResult> {
631
- try {
632
- const response = await callApi("/api/sessions");
633
- if (!response.ok) return listResult([]);
634
- const parsed = z.array(z.string()).safeParse(await response.json());
635
- if (!parsed.success) return listResult([]);
636
- return listResult(
637
- parsed.data.map((sessionId) => ({
638
- uri: `inspector://sessions/${encodeURIComponent(sessionId)}`,
639
- name: `session:${sessionId}`,
640
- title: `Inspector session ${sessionId}`,
641
- mimeType: "application/json",
642
- })),
643
- );
644
- } catch {
645
- return listResult([]);
646
- }
647
- }
648
-
649
- async function listSessionTimelineResources(): Promise<ListResourcesResult> {
650
- try {
651
- const response = await callApi("/api/sessions");
652
- if (!response.ok) return listResult([]);
653
- const parsed = z.array(z.string()).safeParse(await response.json());
654
- if (!parsed.success) return listResult([]);
655
- return listResult(
656
- parsed.data.map((sessionId) => ({
657
- uri: `inspector://sessions/${encodeURIComponent(sessionId)}/timeline`,
658
- name: `session-timeline:${sessionId}`,
659
- title: `Inspector session ${sessionId} timeline`,
660
- mimeType: "application/json",
661
- })),
662
- );
663
- } catch {
664
- return listResult([]);
665
- }
666
- }
667
-
668
- async function listLogResources(): Promise<ListResourcesResult> {
669
- try {
670
- const response = await callApi("/api/logs?offset=0&limit=5&compact=1");
671
- if (!response.ok) return listResult([]);
672
- const parsed = LogResourceListResponseSchema.safeParse(await response.json());
673
- if (!parsed.success) return listResult([]);
674
- return listResult(
675
- parsed.data.logs.map((log) => ({
676
- uri: `inspector://logs/${String(log.id)}`,
677
- name: `log:${String(log.id)}`,
678
- title: `Inspector log ${String(log.id)}`,
679
- mimeType: "application/json",
680
- })),
681
- );
682
- } catch {
683
- return listResult([]);
684
- }
685
- }
686
-
687
- async function listProcessResources(): Promise<ListResourcesResult> {
688
- try {
689
- const response = await callApi("/api/logs?q=&offset=0&limit=50&scanLimit=200");
690
- if (!response.ok) return listResult([]);
691
- const parsed = ProcessResourceListResponseSchema.safeParse(await response.json());
692
- if (!parsed.success) return listResult([]);
693
- const pids = [
694
- ...new Set(
695
- parsed.data.logs
696
- .map((log) => log.clientPid ?? null)
697
- .filter((pid): pid is number => pid !== null),
698
- ),
699
- ].sort((left, right) => left - right);
700
- return listResult(
701
- pids.map((pid) => ({
702
- uri: `inspector://processes/${String(pid)}`,
703
- name: `process:${String(pid)}`,
704
- title: `Inspector process ${String(pid)}`,
705
- mimeType: "application/json",
706
- })),
707
- );
708
- } catch {
709
- return listResult([]);
710
- }
711
- }
712
-
713
- async function listProcessTimelineResources(): Promise<ListResourcesResult> {
714
- const processResources = await listProcessResources();
715
- return listResult(
716
- processResources.resources.map((resource) => ({
717
- uri: `${resource.uri}/timeline`,
718
- name: `${resource.name}:timeline`,
719
- title: `${resource.title ?? resource.name} timeline`,
720
- mimeType: "application/json",
721
- })),
722
- );
723
- }
724
-
725
- function listRunResources(): ListResourcesResult {
726
- return listResult(
727
- listInspectorRuns().runs.map((run) => ({
728
- uri: `inspector://runs/${encodeURIComponent(run.id)}`,
729
- name: `run:${run.id}`,
730
- title: run.title,
731
- mimeType: "application/json",
732
- })),
733
- );
734
- }
735
-
736
- function listGroupResources(): ListResourcesResult {
737
- return listResult(
738
- listInspectorGroups().groups.map((group) => ({
739
- uri: `inspector://groups/${encodeURIComponent(group.id)}`,
740
- name: `group:${group.id}`,
741
- title: group.title,
742
- mimeType: "application/json",
743
- })),
744
- );
745
- }
746
-
747
- function listGroupSessionResources(): ListResourcesResult {
748
- return listResult(
749
- listInspectorGroups().groups.map((group) => ({
750
- uri: `inspector://groups/${encodeURIComponent(group.id)}/sessions`,
751
- name: `group-sessions:${group.id}`,
752
- title: `${group.title} sessions`,
753
- mimeType: "application/json",
754
- })),
755
- );
756
- }
757
-
758
- function listGroupEvidenceResources(): ListResourcesResult {
759
- return listResult(
760
- listInspectorGroups()
761
- .groups.filter((group) => group.evidence !== null)
762
- .map((group) => ({
763
- uri: `inspector://groups/${encodeURIComponent(group.id)}/evidence`,
764
- name: `group-evidence:${group.id}`,
765
- title: `${group.title} evidence pack`,
766
- mimeType: "text/markdown",
767
- description: group.evidence?.markdownPath,
768
- })),
769
- );
770
- }
771
-
772
- function listGroupEvidenceFileResources(): ListResourcesResult {
773
- return listResult(
774
- listInspectorGroups()
775
- .groups.filter((group) => group.evidence !== null)
776
- .map((group) => ({
777
- uri: `inspector://groups/${encodeURIComponent(group.id)}/evidence/files`,
778
- name: `group-evidence-files:${group.id}`,
779
- title: `${group.title} evidence files`,
780
- mimeType: "application/json",
781
- description: group.evidence?.jsonPath,
782
- })),
783
- );
784
- }
785
-
786
- function listEvidenceResources(): ListResourcesResult {
787
- return listResult(
788
- listInspectorRuns()
789
- .runs.filter((run) => run.evidence !== null)
790
- .map((run) => ({
791
- uri: `inspector://evidence/${encodeURIComponent(run.id)}`,
792
- name: `evidence:${run.id}`,
793
- title: `${run.title} evidence pack`,
794
- mimeType: "text/markdown",
795
- description: run.evidence?.markdownPath,
796
- })),
797
- );
798
- }
799
-
800
- function listEvidenceFileResources(): ListResourcesResult {
801
- return listResult(
802
- listInspectorRuns()
803
- .runs.filter((run) => run.evidence !== null)
804
- .map((run) => ({
805
- uri: `inspector://evidence/${encodeURIComponent(run.id)}/files`,
806
- name: `evidence-files:${run.id}`,
807
- title: `${run.title} evidence files`,
808
- mimeType: "application/json",
809
- description: run.evidence?.jsonPath,
810
- })),
811
- );
812
- }
813
-
814
- function userPrompt(text: string): GetPromptResult {
815
- return {
816
- messages: [
817
- {
818
- role: "user",
819
- content: {
820
- type: "text",
821
- text,
822
- },
823
- },
824
- ],
825
- };
826
- }
827
-
828
- // ---------------------------------------------------------------------------
829
- // Tool registration (thin wiring of impls to the SDK)
830
- // ---------------------------------------------------------------------------
831
-
832
- function registerTools(server: McpServer): void {
833
- // ----- Named instance discovery and lifecycle -----
834
-
835
- server.registerTool(
836
- "inspector_list_instances",
837
- {
838
- title: "List named Agent Inspector instances",
839
- description:
840
- "Returns the versioned, token-free REST instance list with live state, saved configuration, and public URLs. Available in readonly mode.",
841
- inputSchema: z.object({}).strict(),
842
- },
843
- () => safeCall(() => listInstancesImpl(callApi)),
844
- );
845
-
846
- server.registerTool(
847
- "inspector_get_instance",
848
- {
849
- title: "Get a named Agent Inspector instance",
850
- description:
851
- "Returns one versioned, token-free named-instance status document from the REST control plane. Available in readonly mode.",
852
- inputSchema: InstanceNameToolInputSchema,
853
- },
854
- ({ name }) => safeCall(() => getInstanceImpl(callApi, name)),
855
- );
856
-
857
- server.registerTool(
858
- "inspector_get_instance_connection",
859
- {
860
- title: "Get coding-agent connection settings for an instance",
861
- description:
862
- "Returns the REST connection descriptor for one named instance, including protocol-correct proxy, OpenAI /v1, MCP, health, environment, and Codex values. It never includes credentials.",
863
- inputSchema: InstanceNameToolInputSchema,
864
- },
865
- ({ name }) => safeCall(() => getInstanceConnectionImpl(callApi, name)),
866
- );
867
-
868
- server.registerTool(
869
- "inspector_start_instance",
870
- {
871
- title: "Start or create a named Agent Inspector instance",
872
- description: `${INSTANCE_LIFECYCLE_WRITE_WARNING} Starts, creates, or idempotently reuses a named sibling instance through the REST lifecycle API. Requires both AGENT_INSPECTOR_MCP_WRITES=1 and AGENT_INSPECTOR_MCP_INSTANCE_WRITES=1.`,
873
- inputSchema: InstanceLifecycleToolInputSchema,
874
- },
875
- (args) =>
876
- safeInstanceWriteCall("inspector_start_instance", () => startInstanceImpl(callApi, args)),
877
- );
878
-
879
- server.registerTool(
880
- "inspector_stop_instance",
881
- {
882
- title: "Stop a named Agent Inspector instance",
883
- description: `${INSTANCE_LIFECYCLE_WRITE_WARNING} Gracefully stops a sibling instance after authenticated ownership checks. The instance serving this MCP connection cannot stop itself. Requires both MCP write gates.`,
884
- inputSchema: InstanceNameToolInputSchema,
885
- },
886
- ({ name }) =>
887
- safeInstanceWriteCall("inspector_stop_instance", () => stopInstanceImpl(callApi, name)),
888
- );
889
-
890
- server.registerTool(
891
- "inspector_restart_instance",
892
- {
893
- title: "Restart a named Agent Inspector instance",
894
- description: `${INSTANCE_LIFECYCLE_WRITE_WARNING} Validates and restarts a sibling instance through the bounded REST lifecycle path. The instance serving this MCP connection cannot restart itself. Requires both MCP write gates.`,
895
- inputSchema: InstanceLifecycleToolInputSchema,
896
- },
897
- (args) =>
898
- safeInstanceWriteCall("inspector_restart_instance", () => restartInstanceImpl(callApi, args)),
899
- );
900
-
901
- // ----- Read tools -----
902
-
903
- server.registerTool(
904
- "inspector_list_logs",
905
- {
906
- title: "List captured agent/model logs",
907
- description: TOOL_LIST_LOGS_DESC,
908
- inputSchema: z.object({
909
- offset: z.number().int().nonnegative().optional().describe("Skip this many entries."),
910
- limit: z
911
- .number()
912
- .int()
913
- .positive()
914
- .max(LIMIT_HARD_CAP)
915
- .optional()
916
- .describe("How many summaries to return. Hard-capped at 5."),
917
- sessionId: z.string().optional().describe("Filter by session/affinity id."),
918
- model: z.string().optional().describe("Filter by model name."),
919
- clientPid: z
920
- .number()
921
- .int()
922
- .positive()
923
- .optional()
924
- .describe("Filter by originating client process PID."),
925
- }),
926
- },
927
- (args) => safeCall(() => listLogsImpl(callApi, args)),
928
- );
929
-
930
- server.registerTool(
931
- "inspector_search_logs",
932
- {
933
- title: "Search captured logs",
934
- description:
935
- "Searches recent compact proxy logs by id, session, model, provider, API path, status, error text, and client context. Results are bounded summaries; call inspector_get_log for full details after locating a candidate id.",
936
- inputSchema: z.object({
937
- query: z
938
- .string()
939
- .max(MAX_SEARCH_QUERY_CHARS)
940
- .optional()
941
- .describe("Search terms. Empty or omitted returns the newest scanned logs."),
942
- offset: z.number().int().nonnegative().optional().describe("Skip this many matches."),
943
- limit: z
944
- .number()
945
- .int()
946
- .positive()
947
- .max(LIMIT_HARD_CAP)
948
- .optional()
949
- .describe("How many summaries to return. Hard-capped at 5 by the MCP handler."),
950
- scanLimit: z
951
- .number()
952
- .int()
953
- .positive()
954
- .max(1000)
955
- .optional()
956
- .describe("How many recent compact logs to scan before filtering. Default 200."),
957
- sessionId: z.string().optional().describe("Optional session/affinity id filter."),
958
- model: z.string().optional().describe("Optional model name filter."),
959
- clientPid: z
960
- .number()
961
- .int()
962
- .positive()
963
- .optional()
964
- .describe("Optional originating client process PID filter."),
965
- }),
966
- },
967
- (args) => safeCall(() => searchLogsImpl(callApi, args)),
968
- );
969
-
970
- server.registerTool(
971
- "inspector_get_log",
972
- {
973
- title: "Get a single captured log by id",
974
- description:
975
- "Returns the full CapturedLog for the given id, including rawRequestBody and responseText with no truncation. SSE streaming chunks are NOT included — use inspector_get_log_chunks for those. Returns an error if the id does not exist.",
976
- inputSchema: McpLogIdInputSchema,
977
- },
978
- ({ id }) => safeCall(() => getLogImpl(callApi, id)),
979
- );
980
-
981
- server.registerTool(
982
- "inspector_get_log_chunks",
983
- {
984
- title: "Get SSE streaming chunks for a captured log",
985
- description:
986
- "Returns the SSE chunks array for a streaming log, in the order they were received. Returns an error if the log has no chunks (i.e. was non-streaming or the log id is unknown).",
987
- inputSchema: McpLogIdInputSchema,
988
- },
989
- ({ id }) => safeCall(() => getLogChunksImpl(callApi, id)),
990
- );
991
-
992
- server.registerTool(
993
- "inspector_get_log_headers",
994
- {
995
- title: "Get captured log headers",
996
- description:
997
- "Returns header-focused evidence for one log without large request/response bodies: raw headers, upstream headers, user-agent, origin, client PID/port, session id, model, and API path.",
998
- inputSchema: McpLogIdInputSchema,
999
- },
1000
- ({ id }) => safeCall(() => getLogHeadersImpl(callApi, id)),
1001
- );
1002
-
1003
- server.registerTool(
1004
- "inspector_list_processes",
1005
- {
1006
- title: "List observed client processes",
1007
- description:
1008
- "Groups recent compact logs by originating client PID and returns sessions, agents, user-agents, models, providers, ports, error counts, and latest logs. Useful for IDE -> process -> session navigation.",
1009
- inputSchema: z.object({
1010
- scanLimit: z
1011
- .number()
1012
- .int()
1013
- .positive()
1014
- .max(200)
1015
- .optional()
1016
- .describe("How many recent logs to scan. Default 50, max 200."),
1017
- limit: z
1018
- .number()
1019
- .int()
1020
- .positive()
1021
- .max(200)
1022
- .optional()
1023
- .describe("Alias for scanLimit for simpler MCP clients."),
1024
- }),
1025
- },
1026
- (args) => safeCall(() => listProcessesImpl(callApi, args)),
1027
- );
1028
-
1029
- server.registerTool(
1030
- "inspector_get_process",
1031
- {
1032
- title: "Get process summary",
1033
- description:
1034
- "Returns a bounded summary for one originating client PID across sessions, including user-agents, ports, models, providers, errors, and latest compact logs.",
1035
- inputSchema: z.object({
1036
- clientPid: z.number().int().positive().describe("Originating client process PID."),
1037
- offset: z.number().int().nonnegative().optional().describe("Skip this many matching logs."),
1038
- limit: z
1039
- .number()
1040
- .int()
1041
- .positive()
1042
- .max(200)
1043
- .optional()
1044
- .describe("Maximum logs to summarize. Default 50, max 200."),
1045
- }),
1046
- },
1047
- (args) => safeCall(() => getProcessImpl(callApi, args)),
1048
- );
1049
-
1050
- server.registerTool(
1051
- "inspector_get_process_timeline",
1052
- {
1053
- title: "Get process timeline",
1054
- description:
1055
- "Returns a bounded chronological timeline for one originating client PID, spanning all sessions observed for that process.",
1056
- inputSchema: z.object({
1057
- clientPid: z.number().int().positive().describe("Originating client process PID."),
1058
- offset: z.number().int().nonnegative().optional().describe("Skip this many matching logs."),
1059
- limit: z
1060
- .number()
1061
- .int()
1062
- .positive()
1063
- .max(50)
1064
- .optional()
1065
- .describe("Maximum timeline events to return. Default 20, max 50."),
1066
- }),
1067
- },
1068
- (args) => safeCall(() => getProcessTimelineImpl(callApi, args)),
1069
- );
1070
-
1071
- server.registerTool(
1072
- "inspector_list_sessions",
1073
- {
1074
- title: "List known session ids",
1075
- description:
1076
- "Returns the array of session ids that have been observed in captured logs. Useful for discovering what sessionId values to pass to inspector_list_logs.",
1077
- inputSchema: z.object({}),
1078
- },
1079
- () => safeCall(() => listSessionsImpl(callApi)),
1080
- );
1081
-
1082
- server.registerTool(
1083
- "inspector_get_session",
1084
- {
1085
- title: "Get Inspector session info",
1086
- description:
1087
- "Returns a lightweight, evidence-friendly summary for one Inspector session: clickable inspectorUrl, compact logs URL, status, request/error counts, token totals, models/providers, and the latest compact log summaries. Defaults to recent in-memory/cache data for speed; set includeHistory=true only when you explicitly want to scan persisted jsonl history. It avoids raw request/response bodies so it is safe to use in evaluation artifacts.",
1088
- inputSchema: z.object({
1089
- sessionId: z.string().min(1).describe("The Inspector session id."),
1090
- includeHistory: z
1091
- .boolean()
1092
- .optional()
1093
- .describe("Scan persisted jsonl history for this session. Slower; default false."),
1094
- latestLogLimit: z
1095
- .number()
1096
- .int()
1097
- .positive()
1098
- .max(50)
1099
- .optional()
1100
- .describe("How many latest compact log summaries to include. Max 50, default 10."),
1101
- }),
1102
- },
1103
- (args) => safeCall(() => getSessionImpl(callApi, args)),
1104
- );
1105
-
1106
- server.registerTool(
1107
- "inspector_get_session_timeline",
1108
- {
1109
- title: "Get Inspector session timeline",
1110
- description:
1111
- "Returns a bounded chronological request timeline for one session with log ids, provider/model labels, statuses, latency, streaming timing, token usage, and previews. Use this when an agent needs the shape of a session before opening large logs.",
1112
- inputSchema: z.object({
1113
- sessionId: z.string().min(1).describe("The Inspector session id."),
1114
- offset: z.number().int().nonnegative().optional().describe("Skip this many matching logs."),
1115
- limit: z
1116
- .number()
1117
- .int()
1118
- .positive()
1119
- .max(50)
1120
- .optional()
1121
- .describe("Maximum timeline events to return. Default 20, max 50."),
1122
- }),
1123
- },
1124
- (args) => safeCall(() => getSessionTimelineImpl(callApi, args)),
1125
- );
1126
-
1127
- server.registerTool(
1128
- "inspector_get_current_context",
1129
- {
1130
- title: "Get current Inspector MCP context",
1131
- description:
1132
- "Returns the current MCP context that an evaluator or coding agent can set to bind subsequent work to a group, run, session, model, provider, project, or task.",
1133
- inputSchema: z.object({}),
1134
- },
1135
- () => safeCall(() => getCurrentContextImpl()),
1136
- );
1137
-
1138
- server.registerTool(
1139
- "inspector_set_current_context",
1140
- {
1141
- title: "Set current Inspector MCP context",
1142
- description:
1143
- "Updates the current MCP context for this local Inspector process. Use this at the start of a benchmark/eval turn so later tools can discover the active group/run/session labels.",
1144
- inputSchema: z.object({
1145
- groupId: z.string().min(1).nullable().optional(),
1146
- runId: z.string().min(1).nullable().optional(),
1147
- sessionId: z.string().min(1).nullable().optional(),
1148
- model: z.string().min(1).nullable().optional(),
1149
- provider: z.string().min(1).nullable().optional(),
1150
- agent: z.string().min(1).nullable().optional(),
1151
- project: z.string().min(1).nullable().optional(),
1152
- task: z.string().min(1).nullable().optional(),
1153
- metadata: z.record(z.string(), JsonValueSchema).optional(),
1154
- }),
1155
- },
1156
- (args) => safeWriteCall("inspector_set_current_context", () => setCurrentContextImpl(args)),
1157
- );
1158
-
1159
- server.registerTool(
1160
- "inspector_get_runtime_config",
1161
- {
1162
- title: "Get Inspector runtime config",
1163
- description:
1164
- "Read-only runtime diagnostics: current proxy config plus log storage stats, including captureMode and log/chunk directories. Does not expose provider secrets.",
1165
- inputSchema: z.object({}),
1166
- },
1167
- () => safeCall(() => getRuntimeConfigImpl(callApi)),
1168
- );
1169
-
1170
- server.registerTool(
1171
- "inspector_diagnose_capture",
1172
- {
1173
- title: "Diagnose capture detail availability",
1174
- description:
1175
- "Explains why headers or bodies may be missing for the current runtime or a specific log, including captureMode, compact body mode, rawHeaders presence, and next-step recommendations.",
1176
- inputSchema: McpOptionalLogIdInputSchema,
1177
- },
1178
- (args) => safeCall(() => diagnoseCaptureImpl(callApi, args)),
1179
- );
1180
-
1181
- server.registerTool(
1182
- "inspector_create_run",
1183
- {
1184
- title: "Create or declare an Inspector run",
1185
- description:
1186
- "Creates an evaluation-friendly run record before a coding-agent task starts. Use this when a benchmark or Jenkins job wants a stable runId/sessionId pair instead of inferring a task after the fact from logs.",
1187
- inputSchema: z.object({
1188
- runId: z.string().min(1).optional().describe("Stable run id. Generated when omitted."),
1189
- sessionId: z
1190
- .string()
1191
- .min(1)
1192
- .optional()
1193
- .describe("Inspector session id to attach. Defaults to the run id."),
1194
- groupId: z
1195
- .string()
1196
- .min(1)
1197
- .nullable()
1198
- .optional()
1199
- .describe(
1200
- "Optional group id. When set with a real sessionId, the run is auto-attached to that group.",
1201
- ),
1202
- title: z.string().min(1).optional().describe("Human-readable run title."),
1203
- task: z.string().nullable().optional().describe("Task statement or benchmark case."),
1204
- project: z.string().nullable().optional().describe("Project or repository under test."),
1205
- agent: z
1206
- .string()
1207
- .nullable()
1208
- .optional()
1209
- .describe("Coding agent name, e.g. Codex/OpenCode/MiMo Code."),
1210
- status: InspectorRunStatusSchema.optional().describe("Initial run status."),
1211
- tags: z.array(z.string()).optional().describe("Free-form run labels."),
1212
- metadata: z.record(z.string(), JsonValueSchema).optional().describe("JSON metadata."),
1213
- }),
1214
- },
1215
- (args) => safeWriteCall("inspector_create_run", () => createRunImpl(args)),
1216
- );
1217
-
1218
- server.registerTool(
1219
- "inspector_get_run",
1220
- {
1221
- title: "Get an Inspector run",
1222
- description:
1223
- "Returns one declared Inspector run, including its session binding and exported evidence paths when available.",
1224
- inputSchema: z.object({
1225
- runId: z.string().min(1).describe("The Inspector run id."),
1226
- }),
1227
- },
1228
- (args) => safeCall(() => getRunImpl(args)),
1229
- );
1230
-
1231
- server.registerTool(
1232
- "inspector_update_run",
1233
- {
1234
- title: "Update an Inspector run",
1235
- description:
1236
- "PATCH-style update for a declared run. Use this during a coding-agent task to mark status transitions such as running, failed, completed, or to attach refined task metadata. Supplied metadata keys are merged into existing metadata.",
1237
- inputSchema: UpdateInspectorRunInputSchema.extend({
1238
- runId: z.string().min(1).describe("The Inspector run id."),
1239
- }),
1240
- },
1241
- (args) => safeWriteCall("inspector_update_run", () => updateRunImpl(args)),
1242
- );
1243
-
1244
- server.registerTool(
1245
- "inspector_export_evidence",
1246
- {
1247
- title: "Export an Inspector evidence pack",
1248
- description:
1249
- "Exports one run's evidence pack to local JSON, Markdown, and HTML files under <dataDir>/evidence/<runId> and returns the paths plus session summary.",
1250
- inputSchema: z.object({
1251
- runId: z.string().min(1).describe("The Inspector run id."),
1252
- includeHistory: z
1253
- .boolean()
1254
- .optional()
1255
- .describe("Scan persisted jsonl history for the bound session. Slower; default false."),
1256
- latestLogLimit: z
1257
- .number()
1258
- .int()
1259
- .positive()
1260
- .max(50)
1261
- .optional()
1262
- .describe("How many compact log summaries to include in the evidence pack. Max 50."),
1263
- }),
1264
- },
1265
- (args) => safeWriteCall("inspector_export_evidence", () => exportEvidenceImpl(args)),
1266
- );
1267
-
1268
- server.registerTool(
1269
- "inspector_get_evidence_files",
1270
- {
1271
- title: "Get run evidence file paths",
1272
- description:
1273
- "Returns the local JSON, Markdown, HTML, and byte-size status for an already exported run evidence pack. It does not create new files.",
1274
- inputSchema: z.object({
1275
- runId: z.string().min(1).describe("The Inspector run id."),
1276
- }),
1277
- },
1278
- (args) => safeCall(() => getEvidenceFilesImpl(args)),
1279
- );
1280
-
1281
- server.registerTool(
1282
- "inspector_export_evidence_bundle",
1283
- {
1284
- title: "Export run evidence ZIP bundle",
1285
- description:
1286
- "Creates evidence.zip next to an already exported run evidence pack, bundling evidence.json, evidence.md, evidence.html, and a manifest.",
1287
- inputSchema: z.object({
1288
- runId: z.string().min(1).describe("The Inspector run id."),
1289
- }),
1290
- },
1291
- (args) =>
1292
- safeWriteCall("inspector_export_evidence_bundle", () => exportEvidenceBundleImpl(args)),
1293
- );
1294
-
1295
- server.registerTool(
1296
- "inspector_get_recent_failures",
1297
- {
1298
- title: "Get recent Inspector failures",
1299
- description:
1300
- "Returns recent declared runs that are failed/cancelled or have non-success exported evidence, including classification, Jenkins summary, Inspector link, and evidence paths when available.",
1301
- inputSchema: z.object({
1302
- limit: z
1303
- .number()
1304
- .int()
1305
- .positive()
1306
- .max(20)
1307
- .optional()
1308
- .describe("Maximum failures to return. Default 5, max 20."),
1309
- }),
1310
- },
1311
- (args) => safeCall(() => getRecentFailuresImpl(args)),
1312
- );
1313
-
1314
- server.registerTool(
1315
- "inspector_list_groups",
1316
- {
1317
- title: "List Inspector groups",
1318
- description:
1319
- "Lists declared Inspector groups. Groups aggregate multiple sessions/runs, commonly one evaluation matrix spanning several providers or models.",
1320
- inputSchema: z.object({}),
1321
- },
1322
- () => safeCall(() => listGroupsImpl()),
1323
- );
1324
-
1325
- server.registerTool(
1326
- "inspector_create_group",
1327
- {
1328
- title: "Create or declare an Inspector group",
1329
- description:
1330
- "Creates an evaluation/batch group that external systems can use to aggregate multiple Codex, OpenCode, or MiMo Code sessions across models such as MiniMax, DeepSeek, or GLM.",
1331
- inputSchema: z.object({
1332
- groupId: z.string().min(1).optional().describe("Stable group id. Generated when omitted."),
1333
- title: z.string().min(1).optional().describe("Human-readable group title."),
1334
- kind: z
1335
- .enum(["evaluation", "batch", "manual"])
1336
- .optional()
1337
- .describe("Group kind. Defaults to evaluation."),
1338
- task: z.string().nullable().optional().describe("Task, benchmark, or evaluation goal."),
1339
- project: z.string().nullable().optional().describe("Project or repository under test."),
1340
- status: InspectorGroupStatusSchema.optional().describe("Initial group status."),
1341
- tags: z.array(z.string()).optional().describe("Free-form group labels."),
1342
- metadata: z.record(z.string(), JsonValueSchema).optional().describe("JSON metadata."),
1343
- }),
1344
- },
1345
- (args) => safeWriteCall("inspector_create_group", () => createGroupImpl(args)),
1346
- );
1347
-
1348
- server.registerTool(
1349
- "inspector_get_group",
1350
- {
1351
- title: "Get an Inspector group",
1352
- description:
1353
- "Returns one declared Inspector group with its attached session/run members and exported evidence paths when available.",
1354
- inputSchema: z.object({
1355
- groupId: z.string().min(1).describe("The Inspector group id."),
1356
- }),
1357
- },
1358
- (args) => safeCall(() => getGroupImpl(args)),
1359
- );
1360
-
1361
- server.registerTool(
1362
- "inspector_update_group",
1363
- {
1364
- title: "Update an Inspector group",
1365
- description:
1366
- "PATCH-style update for a declared group. Use this to mark a whole evaluation running, failed, completed, or to merge CI metadata.",
1367
- inputSchema: UpdateInspectorGroupInputSchema.extend({
1368
- groupId: z.string().min(1).describe("The Inspector group id."),
1369
- }),
1370
- },
1371
- (args) => safeWriteCall("inspector_update_group", () => updateGroupImpl(args)),
1372
- );
1373
-
1374
- server.registerTool(
1375
- "inspector_delete_group",
1376
- {
1377
- title: "Delete an Inspector group",
1378
- description:
1379
- "Deletes one declared Inspector group from <dataDir>/groups.json. By default this keeps exported evidence files; set deleteEvidence=true only when the local evidence pack should also be removed.",
1380
- inputSchema: DeleteInspectorGroupOptionsSchema.extend({
1381
- groupId: z.string().min(1).describe("The Inspector group id."),
1382
- }),
1383
- },
1384
- (args) => safeWriteCall("inspector_delete_group", () => deleteGroupImpl(args)),
1385
- );
1386
-
1387
- server.registerTool(
1388
- "inspector_add_group_session",
1389
- {
1390
- title: "Attach a session to an Inspector group",
1391
- description:
1392
- "Adds or updates one group member. Use it after each coding-agent process discovers its session id, or while an evaluation matrix is running to attach model/provider labels.",
1393
- inputSchema: AddInspectorGroupSessionInputSchema.extend({
1394
- groupId: z.string().min(1).describe("The Inspector group id."),
1395
- }),
1396
- },
1397
- (args) => safeWriteCall("inspector_add_group_session", () => addGroupSessionImpl(args)),
1398
- );
1399
-
1400
- server.registerTool(
1401
- "inspector_add_group_process",
1402
- {
1403
- title: "Attach a process to an Inspector group",
1404
- description:
1405
- "Finds sessions observed for one client PID and attaches each session to a group with inferred agent/model/provider metadata. Useful when a process has both process fallback and explicit sessions.",
1406
- inputSchema: z.object({
1407
- groupId: z.string().min(1).describe("The Inspector group id."),
1408
- clientPid: z.number().int().positive().describe("Originating client process PID."),
1409
- labelPrefix: z
1410
- .string()
1411
- .min(1)
1412
- .optional()
1413
- .describe("Optional label prefix. Defaults to PID <clientPid>."),
1414
- }),
1415
- },
1416
- (args) =>
1417
- safeWriteCall("inspector_add_group_process", () => addGroupProcessImpl(callApi, args)),
1418
- );
1419
-
1420
- server.registerTool(
1421
- "inspector_export_group_evidence",
1422
- {
1423
- title: "Export an Inspector group evidence pack",
1424
- description:
1425
- "Exports a whole group's evidence pack to local JSON, Markdown, and HTML files under <dataDir>/evidence/groups/<groupId>. The export contains a provider/model matrix and compact session summaries.",
1426
- inputSchema: GroupEvidenceExportOptionsSchema.unwrap().extend({
1427
- groupId: z.string().min(1).describe("The Inspector group id."),
1428
- }),
1429
- },
1430
- (args) => safeWriteCall("inspector_export_group_evidence", () => exportGroupEvidenceImpl(args)),
1431
- );
1432
-
1433
- server.registerTool(
1434
- "inspector_get_group_evidence_files",
1435
- {
1436
- title: "Get group evidence file paths",
1437
- description:
1438
- "Returns the local JSON, Markdown, HTML, and byte-size status for an already exported group evidence pack. It does not create new files.",
1439
- inputSchema: z.object({
1440
- groupId: z.string().min(1).describe("The Inspector group id."),
1441
- }),
1442
- },
1443
- (args) => safeCall(() => getGroupEvidenceFilesImpl(args)),
1444
- );
1445
-
1446
- server.registerTool(
1447
- "inspector_export_group_evidence_bundle",
1448
- {
1449
- title: "Export group evidence ZIP bundle",
1450
- description:
1451
- "Creates group-evidence.zip next to an already exported group evidence pack, bundling evidence.json, evidence.md, evidence.html, and a manifest.",
1452
- inputSchema: z.object({
1453
- groupId: z.string().min(1).describe("The Inspector group id."),
1454
- }),
1455
- },
1456
- (args) =>
1457
- safeWriteCall("inspector_export_group_evidence_bundle", () =>
1458
- exportGroupEvidenceBundleImpl(args),
1459
- ),
1460
- );
1461
-
1462
- server.registerTool(
1463
- "inspector_list_models",
1464
- {
1465
- title: "List distinct model names seen in captured logs",
1466
- description: "Returns the array of distinct model names observed across all captured logs.",
1467
- inputSchema: z.object({}),
1468
- },
1469
- () => safeCall(() => listModelsImpl(callApi)),
1470
- );
1471
-
1472
- server.registerTool(
1473
- "inspector_list_providers",
1474
- {
1475
- title: "List configured LLM providers",
1476
- description:
1477
- "Returns the configured ProviderConfig array with write-only API keys represented as configured.",
1478
- inputSchema: z.object({}),
1479
- },
1480
- () => safeCall(() => listProvidersImpl(callApi)),
1481
- );
1482
-
1483
- // ----- Action tools -----
1484
-
1485
- server.registerTool(
1486
- "inspector_get_provider",
1487
- {
1488
- title: "Get a single provider by id",
1489
- description:
1490
- "Returns one ProviderConfig. API keys are write-only and represented as configured.",
1491
- inputSchema: z.object({
1492
- id: z.string().describe("The provider id."),
1493
- }),
1494
- },
1495
- ({ id }) => safeCall(() => getProviderImpl(callApi, id)),
1496
- );
1497
-
1498
- server.registerTool(
1499
- "inspector_replay_log",
1500
- {
1501
- title: "Replay a captured log against its provider",
1502
- description:
1503
- "Re-sends the captured request body to the upstream LLM and returns the response summary: success flag, status, responseText, input/output token counts, elapsedMs, and whether the response was streaming. Useful for re-running a request after a fix or a transient failure. Returns an error if the log id is unknown or the upstream call fails.",
1504
- inputSchema: McpLogIdInputSchema,
1505
- },
1506
- (args) => safeWriteCall("inspector_replay_log", () => replayLogImpl(callApi, args)),
1507
- );
1508
-
1509
- // ----- Provider write tools -----
1510
-
1511
- server.registerTool(
1512
- "inspector_add_provider",
1513
- {
1514
- title: "Add a new LLM provider",
1515
- description: `${PROVIDER_WRITE_WARNING}\n\nPersists a new provider to <dataDir>/providers.json. Required fields: name, apiKey, and models (or legacy model). Chat Completions and Responses can use different upstream URLs: set openaiBaseUrl for /v1/chat/completions and openaiResponsesBaseUrl for /v1/responses. The URL builder accepts either a base URL such as https://api.minimaxi.com or an exact endpoint such as https://api.minimaxi.com/v1/responses.`,
1516
- inputSchema: AddProviderInputSchema,
1517
- },
1518
- (provider) => safeWriteCall("inspector_add_provider", () => addProviderImpl(callApi, provider)),
1519
- );
1520
-
1521
- server.registerTool(
1522
- "inspector_update_provider",
1523
- {
1524
- title: "Update an existing provider",
1525
- description: `${PROVIDER_WRITE_WARNING} Updating with nonsense values effectively soft-deletes a provider. Confirm with the user before invoking.
1526
-
1527
- PATCH-style update: only the fields you supply are changed. Use models to update the configured model list. For OpenAI-compatible providers, openaiBaseUrl targets /v1/chat/completions and openaiResponsesBaseUrl targets /v1/responses, and those endpoints may be different.`,
1528
- inputSchema: UpdateProviderInputSchema,
1529
- },
1530
- (input) => safeWriteCall("inspector_update_provider", () => updateProviderImpl(callApi, input)),
1531
- );
1532
-
1533
- server.registerTool(
1534
- "inspector_test_provider",
1535
- {
1536
- title: "Test a provider's connectivity",
1537
- description:
1538
- "Runs the same connectivity test the UI's 'Test' button does, against both Anthropic and OpenAI endpoints if configured. Returns the per-endpoint success/failure result. Returns an error if the provider id is unknown.",
1539
- inputSchema: z.object({
1540
- id: z.string().describe("The provider id to test."),
1541
- }),
1542
- },
1543
- ({ id }) => safeWriteCall("inspector_test_provider", () => testProviderImpl(callApi, id)),
1544
- );
1545
-
1546
- server.registerTool(
1547
- "inspector_diagnose_provider_test",
1548
- {
1549
- title: "Run provider test with diagnostics",
1550
- description:
1551
- "Runs Provider Test and returns the raw result plus MCP-friendly diagnostic issues and hints for timeout, auth, base URL, container networking, and non-streaming/streaming mismatches.",
1552
- inputSchema: z.object({
1553
- id: z.string().describe("The provider id to test."),
1554
- }),
1555
- },
1556
- ({ id }) =>
1557
- safeWriteCall("inspector_diagnose_provider_test", () =>
1558
- diagnoseProviderTestImpl(callApi, id),
1559
- ),
1560
- );
1561
-
1562
- // ----- Knowledge bridge tools -----
1563
-
1564
- server.registerTool(
1565
- "inspector_create_session_knowledge",
1566
- {
1567
- title: "Create knowledge candidates for a session",
1568
- description:
1569
- "Generates sanitized draft knowledge candidates from a captured Inspector session. This does not write to OpenClaw; use inspector_promote_knowledge_candidate after review.",
1570
- inputSchema: z.object({
1571
- sessionId: z.string().min(1).describe("The Inspector session id to distill."),
1572
- }),
1573
- },
1574
- (args) =>
1575
- safeWriteCall("inspector_create_session_knowledge", () =>
1576
- createSessionKnowledgeImpl(callApi, args),
1577
- ),
1578
- );
1579
-
1580
- server.registerTool(
1581
- "inspector_list_knowledge_candidates",
1582
- {
1583
- title: "List knowledge candidates",
1584
- description:
1585
- "Lists locally stored Inspector knowledge candidates and their draft/promoted/failed status.",
1586
- inputSchema: z.object({}),
1587
- },
1588
- () => safeCall(() => listKnowledgeCandidatesImpl(callApi)),
1589
- );
1590
-
1591
- server.registerTool(
1592
- "inspector_promote_knowledge_candidate",
1593
- {
1594
- title: "Promote a knowledge candidate",
1595
- description:
1596
- "Writes a sanitized Inspector knowledge candidate to the configured OpenClaw memory backend. Confirm the candidate is safe before invoking.",
1597
- inputSchema: z.object({
1598
- candidateId: z.string().min(1).describe("The candidate id to promote."),
1599
- }),
1600
- },
1601
- (args) =>
1602
- safeWriteCall("inspector_promote_knowledge_candidate", () =>
1603
- promoteKnowledgeCandidateImpl(callApi, args),
1604
- ),
1605
- );
1606
-
1607
- server.registerTool(
1608
- "inspector_search_knowledge",
1609
- {
1610
- title: "Search Inspector knowledge",
1611
- description:
1612
- "Searches knowledge through Inspector. OpenClaw backend details are hidden from the agent.",
1613
- inputSchema: z.object({
1614
- query: z.string().min(1).max(MAX_SEARCH_QUERY_CHARS).describe("Knowledge search query."),
1615
- project: z
1616
- .string()
1617
- .max(MAX_SEARCH_PROJECT_CHARS)
1618
- .optional()
1619
- .describe("Optional project filter."),
1620
- }),
1621
- },
1622
- (args) => safeCall(() => searchKnowledgeImpl(callApi, args)),
1623
- );
1624
-
1625
- server.registerTool(
1626
- "inspector_get_project_context",
1627
- {
1628
- title: "Get project context",
1629
- description:
1630
- "Returns relevant Inspector knowledge for a project so an agent can seed task context without calling OpenClaw directly.",
1631
- inputSchema: z.object({
1632
- project: z
1633
- .string()
1634
- .min(1)
1635
- .max(MAX_SEARCH_PROJECT_CHARS)
1636
- .describe("Project name or folder."),
1637
- }),
1638
- },
1639
- (args) => safeCall(() => getProjectContextImpl(callApi, args)),
1640
- );
1641
- }
1642
-
1643
- function registerResources(server: McpServer): void {
1644
- server.registerResource(
1645
- "inspector_instances",
1646
- "inspector://instances",
1647
- {
1648
- title: "Named Agent Inspector instances",
1649
- description: "Versioned, token-free named-instance list backed by GET /api/instances.",
1650
- mimeType: "application/json",
1651
- },
1652
- (uri) => readInstanceToolResource(uri, listInstancesImpl(callApi)),
1653
- );
1654
-
1655
- server.registerResource(
1656
- "inspector_instance",
1657
- new ResourceTemplate("inspector://instances/{name}", {
1658
- list: async () => await listInstanceTemplateResources(false),
1659
- }),
1660
- {
1661
- title: "Named Agent Inspector instance",
1662
- description:
1663
- "Versioned, token-free status for one named instance backed by GET /api/instances/{name}.",
1664
- mimeType: "application/json",
1665
- },
1666
- (uri, variables) => {
1667
- const name = variableString(variables, "name");
1668
- return name === null
1669
- ? textResource(uri, "text/plain", "Missing instance name")
1670
- : readInstanceToolResource(uri, getInstanceImpl(callApi, name));
1671
- },
1672
- );
1673
-
1674
- server.registerResource(
1675
- "inspector_instance_connection",
1676
- new ResourceTemplate("inspector://instances/{name}/connection", {
1677
- list: async () => await listInstanceTemplateResources(true),
1678
- }),
1679
- {
1680
- title: "Named instance coding-agent connection",
1681
- description:
1682
- "Token-free connection descriptor backed by GET /api/instances/{name}/connection.",
1683
- mimeType: "application/json",
1684
- },
1685
- (uri, variables) => {
1686
- const name = variableString(variables, "name");
1687
- return name === null
1688
- ? textResource(uri, "text/plain", "Missing instance name")
1689
- : readInstanceToolResource(uri, getInstanceConnectionImpl(callApi, name));
1690
- },
1691
- );
1692
-
1693
- server.registerResource(
1694
- "inspector_mcp_health",
1695
- "inspector://mcp/health",
1696
- {
1697
- title: "Inspector MCP health",
1698
- description: "MCP server version, transport, mode, and catalog counts.",
1699
- mimeType: "application/json",
1700
- },
1701
- (uri) => jsonResource(uri, mcpHealth()),
1702
- );
1703
-
1704
- server.registerResource(
1705
- "inspector_mcp_capabilities",
1706
- "inspector://mcp/capabilities",
1707
- {
1708
- title: "Inspector MCP capabilities",
1709
- description: "Machine-readable Inspector MCP tools, resources, prompts, and write mode.",
1710
- mimeType: "application/json",
1711
- },
1712
- (uri) => jsonResource(uri, mcpCapabilities()),
1713
- );
1714
-
1715
- server.registerResource(
1716
- "inspector_mcp_config",
1717
- "inspector://mcp/config",
1718
- {
1719
- title: "Inspector MCP client config",
1720
- description:
1721
- "Streamable HTTP, stdio bridge, OpenCode, and MiMo Code MCP configuration snippets.",
1722
- mimeType: "application/json",
1723
- },
1724
- (uri) => jsonResource(uri, mcpConfig()),
1725
- );
1726
-
1727
- server.registerResource(
1728
- "inspector_current_context",
1729
- "inspector://context/current",
1730
- {
1731
- title: "Inspector current context",
1732
- description: "Current group/run/session/model/provider context set through MCP.",
1733
- mimeType: "application/json",
1734
- },
1735
- (uri) => jsonResource(uri, getCurrentContext()),
1736
- );
1737
-
1738
- server.registerResource(
1739
- "inspector_runtime_config",
1740
- "inspector://runtime/config",
1741
- {
1742
- title: "Inspector runtime config",
1743
- description: "Read-only runtime config and log storage stats.",
1744
- mimeType: "application/json",
1745
- },
1746
- async (uri) => {
1747
- const result = await getRuntimeConfigImpl(callApi);
1748
- const first = result.content[0];
1749
- const text = first?.text ?? "";
1750
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1751
- },
1752
- );
1753
-
1754
- server.registerResource(
1755
- "inspector_sessions",
1756
- "inspector://sessions",
1757
- {
1758
- title: "Inspector sessions",
1759
- description: "Observed Inspector session ids.",
1760
- mimeType: "application/json",
1761
- },
1762
- (uri) => readApiJsonResource(uri, "/api/sessions"),
1763
- );
1764
-
1765
- server.registerResource(
1766
- "inspector_session",
1767
- new ResourceTemplate("inspector://sessions/{sessionId}", { list: listSessionResources }),
1768
- {
1769
- title: "Inspector session",
1770
- description:
1771
- "Evidence-friendly session summary with Inspector URL, compact logs URL, counts, models, providers, token totals, and recent compact logs.",
1772
- mimeType: "application/json",
1773
- },
1774
- (uri, variables) => {
1775
- const sessionId = variableString(variables, "sessionId");
1776
- if (sessionId === null) return textResource(uri, "text/plain", "Missing sessionId");
1777
- const params = new URLSearchParams({ sessionId, limit: "10" });
1778
- return readApiJsonResource(uri, `/api/sessions?${params.toString()}`);
1779
- },
1780
- );
1781
-
1782
- server.registerResource(
1783
- "inspector_session_timeline",
1784
- new ResourceTemplate("inspector://sessions/{sessionId}/timeline", {
1785
- list: listSessionTimelineResources,
1786
- }),
1787
- {
1788
- title: "Inspector session timeline",
1789
- description:
1790
- "Bounded chronological request timeline for a session with log ids, timings, status, tokens, and previews.",
1791
- mimeType: "application/json",
1792
- },
1793
- async (uri, variables) => {
1794
- const sessionId = variableString(variables, "sessionId");
1795
- if (sessionId === null) return textResource(uri, "text/plain", "Missing sessionId");
1796
- const result = await getSessionTimelineImpl(callApi, { sessionId, limit: 50 });
1797
- const first = result.content[0];
1798
- const text = first?.text ?? "";
1799
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1800
- },
1801
- );
1802
-
1803
- server.registerResource(
1804
- "inspector_log",
1805
- new ResourceTemplate("inspector://logs/{id}", { list: listLogResources }),
1806
- {
1807
- title: "Inspector log",
1808
- description: "Single captured proxy log by numeric id.",
1809
- mimeType: "application/json",
1810
- },
1811
- async (uri, variables) => {
1812
- const id = variableString(variables, "id");
1813
- const parsed = id === null ? null : parseLogId(id);
1814
- if (parsed === null) {
1815
- return textResource(uri, "text/plain", "Invalid log id");
1816
- }
1817
- const result = await getLogImpl(callApi, parsed);
1818
- const first = result.content[0];
1819
- const text = first?.text ?? "";
1820
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1821
- },
1822
- );
1823
-
1824
- server.registerResource(
1825
- "inspector_processes",
1826
- "inspector://processes",
1827
- {
1828
- title: "Inspector client processes",
1829
- description: "Observed originating client process PIDs grouped from recent logs.",
1830
- mimeType: "application/json",
1831
- },
1832
- async (uri) => {
1833
- const result = await listProcessesImpl(callApi, { scanLimit: 200 });
1834
- const first = result.content[0];
1835
- const text = first?.text ?? "";
1836
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1837
- },
1838
- );
1839
-
1840
- server.registerResource(
1841
- "inspector_process",
1842
- new ResourceTemplate("inspector://processes/{clientPid}", { list: listProcessResources }),
1843
- {
1844
- title: "Inspector process",
1845
- description:
1846
- "One originating client process summary with sessions, agents, user-agents, ports, models, providers, errors, and latest logs.",
1847
- mimeType: "application/json",
1848
- },
1849
- async (uri, variables) => {
1850
- const clientPid = variableString(variables, "clientPid");
1851
- const parsed = clientPid === null ? Number.NaN : Number(clientPid);
1852
- if (!Number.isInteger(parsed) || parsed <= 0) {
1853
- return textResource(uri, "text/plain", "Invalid clientPid");
1854
- }
1855
- const result = await getProcessImpl(callApi, { clientPid: parsed });
1856
- const first = result.content[0];
1857
- const text = first?.text ?? "";
1858
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1859
- },
1860
- );
1861
-
1862
- server.registerResource(
1863
- "inspector_process_timeline",
1864
- new ResourceTemplate("inspector://processes/{clientPid}/timeline", {
1865
- list: listProcessTimelineResources,
1866
- }),
1867
- {
1868
- title: "Inspector process timeline",
1869
- description: "Bounded chronological timeline for one originating client process PID.",
1870
- mimeType: "application/json",
1871
- },
1872
- async (uri, variables) => {
1873
- const clientPid = variableString(variables, "clientPid");
1874
- const parsed = clientPid === null ? Number.NaN : Number(clientPid);
1875
- if (!Number.isInteger(parsed) || parsed <= 0) {
1876
- return textResource(uri, "text/plain", "Invalid clientPid");
1877
- }
1878
- const result = await getProcessTimelineImpl(callApi, { clientPid: parsed, limit: 50 });
1879
- const first = result.content[0];
1880
- const text = first?.text ?? "";
1881
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
1882
- },
1883
- );
1884
-
1885
- server.registerResource(
1886
- "inspector_runs",
1887
- "inspector://runs",
1888
- {
1889
- title: "Inspector runs",
1890
- description: "Declared Inspector evaluation runs.",
1891
- mimeType: "application/json",
1892
- },
1893
- (uri) => jsonResource(uri, listInspectorRuns()),
1894
- );
1895
-
1896
- server.registerResource(
1897
- "inspector_groups",
1898
- "inspector://groups",
1899
- {
1900
- title: "Inspector groups",
1901
- description: "Declared Inspector groups aggregating multiple sessions or runs.",
1902
- mimeType: "application/json",
1903
- },
1904
- (uri) => jsonResource(uri, listInspectorGroups()),
1905
- );
1906
-
1907
- server.registerResource(
1908
- "inspector_group",
1909
- new ResourceTemplate("inspector://groups/{groupId}", { list: listGroupResources }),
1910
- {
1911
- title: "Inspector group",
1912
- description: "One declared Inspector group with attached session/run members.",
1913
- mimeType: "application/json",
1914
- },
1915
- (uri, variables) => {
1916
- const groupId = variableString(variables, "groupId");
1917
- if (groupId === null) return textResource(uri, "text/plain", "Missing groupId");
1918
- return readServiceJsonResource(uri, getInspectorGroup(groupId));
1919
- },
1920
- );
1921
-
1922
- server.registerResource(
1923
- "inspector_group_sessions",
1924
- new ResourceTemplate("inspector://groups/{groupId}/sessions", {
1925
- list: listGroupSessionResources,
1926
- }),
1927
- {
1928
- title: "Inspector group sessions",
1929
- description: "Attached session/run members for one Inspector group.",
1930
- mimeType: "application/json",
1931
- },
1932
- (uri, variables) => {
1933
- const groupId = variableString(variables, "groupId");
1934
- if (groupId === null) return textResource(uri, "text/plain", "Missing groupId");
1935
- return readServiceJsonResource(uri, readInspectorGroupSessions(groupId));
1936
- },
1937
- );
1938
-
1939
- server.registerResource(
1940
- "inspector_recent_failures",
1941
- "inspector://failures/recent",
1942
- {
1943
- title: "Recent Inspector failures",
1944
- description:
1945
- "Recent declared runs with failed/cancelled status or non-success exported evidence.",
1946
- mimeType: "application/json",
1947
- },
1948
- (uri) => jsonResource(uri, listInspectorRecentFailures(10)),
1949
- );
1950
-
1951
- server.registerResource(
1952
- "inspector_run",
1953
- new ResourceTemplate("inspector://runs/{runId}", { list: listRunResources }),
1954
- {
1955
- title: "Inspector run",
1956
- description: "One declared Inspector run, including session binding and evidence paths.",
1957
- mimeType: "application/json",
1958
- },
1959
- (uri, variables) => {
1960
- const runId = variableString(variables, "runId");
1961
- if (runId === null) return textResource(uri, "text/plain", "Missing runId");
1962
- return readServiceJsonResource(uri, getInspectorRun(runId));
1963
- },
1964
- );
1965
-
1966
- server.registerResource(
1967
- "inspector_evidence",
1968
- new ResourceTemplate("inspector://evidence/{runId}", { list: listEvidenceResources }),
1969
- {
1970
- title: "Inspector evidence pack",
1971
- description:
1972
- "Markdown evidence pack for a declared Inspector run. Generate it first with inspector_export_evidence.",
1973
- mimeType: "text/markdown",
1974
- },
1975
- (uri, variables) => {
1976
- const runId = variableString(variables, "runId");
1977
- if (runId === null) return textResource(uri, "text/plain", "Missing runId");
1978
- const evidence = readInspectorRunEvidence(runId);
1979
- if (!evidence.ok) return textResource(uri, "text/plain", evidence.message);
1980
- return textResource(uri, "text/markdown", evidence.value.markdown);
1981
- },
1982
- );
1983
-
1984
- server.registerResource(
1985
- "inspector_evidence_files",
1986
- new ResourceTemplate("inspector://evidence/{runId}/files", {
1987
- list: listEvidenceFileResources,
1988
- }),
1989
- {
1990
- title: "Inspector evidence files",
1991
- description: "Local file paths and byte sizes for a run evidence pack.",
1992
- mimeType: "application/json",
1993
- },
1994
- (uri, variables) => {
1995
- const runId = variableString(variables, "runId");
1996
- if (runId === null) return textResource(uri, "text/plain", "Missing runId");
1997
- const result = getEvidenceFilesImpl({ runId });
1998
- const first = result.content[0];
1999
- const text = first?.text ?? "";
2000
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
2001
- },
2002
- );
2003
-
2004
- server.registerResource(
2005
- "inspector_group_evidence",
2006
- new ResourceTemplate("inspector://groups/{groupId}/evidence", {
2007
- list: listGroupEvidenceResources,
2008
- }),
2009
- {
2010
- title: "Inspector group evidence pack",
2011
- description:
2012
- "Markdown evidence pack for an Inspector group. Generate it first with inspector_export_group_evidence.",
2013
- mimeType: "text/markdown",
2014
- },
2015
- (uri, variables) => {
2016
- const groupId = variableString(variables, "groupId");
2017
- if (groupId === null) return textResource(uri, "text/plain", "Missing groupId");
2018
- const evidence = readInspectorGroupEvidence(groupId);
2019
- if (!evidence.ok) return textResource(uri, "text/plain", evidence.message);
2020
- return textResource(uri, "text/markdown", evidence.value.markdown);
2021
- },
2022
- );
2023
-
2024
- server.registerResource(
2025
- "inspector_group_evidence_files",
2026
- new ResourceTemplate("inspector://groups/{groupId}/evidence/files", {
2027
- list: listGroupEvidenceFileResources,
2028
- }),
2029
- {
2030
- title: "Inspector group evidence files",
2031
- description: "Local file paths and byte sizes for a group evidence pack.",
2032
- mimeType: "application/json",
2033
- },
2034
- (uri, variables) => {
2035
- const groupId = variableString(variables, "groupId");
2036
- if (groupId === null) return textResource(uri, "text/plain", "Missing groupId");
2037
- const result = getGroupEvidenceFilesImpl({ groupId });
2038
- const first = result.content[0];
2039
- const text = first?.text ?? "";
2040
- return textResource(uri, result.isError === true ? "text/plain" : "application/json", text);
2041
- },
2042
- );
2043
- }
2044
-
2045
- function registerPrompts(server: McpServer): void {
2046
- server.registerPrompt(
2047
- "inspector_analyze_session_failure",
2048
- {
2049
- title: "Analyze session failure",
2050
- description:
2051
- "Use Inspector session/log resources to explain why a coding-agent session failed.",
2052
- argsSchema: z.object({
2053
- sessionId: z.string().min(1).describe("The Inspector session id."),
2054
- includeHistory: z
2055
- .boolean()
2056
- .optional()
2057
- .describe("When true, call inspector_get_session with includeHistory=true if needed."),
2058
- }),
2059
- },
2060
- ({ sessionId, includeHistory }) =>
2061
- userPrompt(`Analyze this Agent Inspector session and explain why it failed.
2062
-
2063
- Evidence to read:
2064
- - Session resource: inspector://sessions/${encodeURIComponent(sessionId)}
2065
- - Relevant log resources: inspector://logs/{id} for the failing or suspicious log ids
2066
-
2067
- If includeHistory is ${includeHistory === true ? "true" : "false"} or the session summary looks incomplete, call inspector_get_session with includeHistory=true and latestLogLimit=50.
2068
-
2069
- Return:
2070
- 1. Outcome and severity
2071
- 2. Most likely root cause
2072
- 3. Evidence bullets with log ids, models, providers, status codes, and error text
2073
- 4. Concrete fix or next diagnostic step
2074
- 5. Confidence and what evidence is still missing`),
2075
- );
2076
-
2077
- server.registerPrompt(
2078
- "inspector_triage_recent_failures",
2079
- {
2080
- title: "Triage recent failures",
2081
- description:
2082
- "Use the recent failures resource and log search tool to prioritize coding-agent failures.",
2083
- argsSchema: z.object({
2084
- limit: z
2085
- .number()
2086
- .int()
2087
- .positive()
2088
- .max(20)
2089
- .optional()
2090
- .describe("How many failures to triage."),
2091
- }),
2092
- },
2093
- ({ limit }) =>
2094
- userPrompt(`Triage recent Agent Inspector failures.
2095
-
2096
- Evidence to read:
2097
- - Recent failures resource: inspector://failures/recent
2098
- - For missing details, call inspector_get_recent_failures with limit=${String(limit ?? 5)}
2099
- - For suspicious sessions/models/providers, call inspector_search_logs and then inspector_get_log for cited ids
2100
-
2101
- Return:
2102
- 1. Highest-priority failure first
2103
- 2. Run id, session id, category, severity, and evidence links
2104
- 3. Likely root cause and concrete next action
2105
- 4. Whether evidence is sufficient or inspector_export_evidence should be run again`),
2106
- );
2107
-
2108
- server.registerPrompt(
2109
- "inspector_generate_jenkins_report",
2110
- {
2111
- title: "Generate Jenkins report",
2112
- description:
2113
- "Generate a Jenkins-friendly Markdown report from an Inspector run and evidence pack.",
2114
- argsSchema: z.object({
2115
- runId: z.string().min(1).describe("The Inspector run id."),
2116
- }),
2117
- },
2118
- ({ runId }) =>
2119
- userPrompt(`Generate a Jenkins-ready Markdown report for this Inspector run.
2120
-
2121
- Evidence to read:
2122
- - Run resource: inspector://runs/${encodeURIComponent(runId)}
2123
- - Evidence pack resource: inspector://evidence/${encodeURIComponent(runId)}
2124
-
2125
- If the evidence pack resource says it has not been exported, call inspector_export_evidence for this run first.
2126
-
2127
- The report should include:
2128
- 1. Build/run status summary
2129
- 2. Run id, session id, Inspector URLs, and artifact paths
2130
- 3. Models/providers used, token totals, request counts, and error counts
2131
- 4. Failure analysis or success evidence
2132
- 5. Reproducible next action for a developer`),
2133
- );
2134
-
2135
- server.registerPrompt(
2136
- "inspector_generate_group_report",
2137
- {
2138
- title: "Generate group report",
2139
- description:
2140
- "Generate a model/provider evaluation report from an Inspector group and group evidence pack.",
2141
- argsSchema: z.object({
2142
- groupId: z.string().min(1).describe("The Inspector group id."),
2143
- }),
2144
- },
2145
- ({ groupId }) =>
2146
- userPrompt(`Generate a model/provider evaluation report for this Inspector group.
2147
-
2148
- Evidence to read:
2149
- - Group resource: inspector://groups/${encodeURIComponent(groupId)}
2150
- - Group session members: inspector://groups/${encodeURIComponent(groupId)}/sessions
2151
- - Group evidence pack: inspector://groups/${encodeURIComponent(groupId)}/evidence
2152
-
2153
- If the evidence pack resource says it has not been exported, call inspector_export_group_evidence for this group first.
2154
-
2155
- The report should include:
2156
- 1. Evaluation status summary
2157
- 2. Provider/model matrix with session links
2158
- 3. Request counts, token totals, streaming timing, and error counts
2159
- 4. Winner/loser observations when the evidence supports them
2160
- 5. Concrete next actions for failed or missing sessions`),
2161
- );
2162
-
2163
- server.registerPrompt(
2164
- "inspector_extract_repro_steps",
2165
- {
2166
- title: "Extract reproducible steps",
2167
- description:
2168
- "Turn an Inspector session into concise repro steps for a developer or evaluator.",
2169
- argsSchema: z.object({
2170
- sessionId: z.string().min(1).describe("The Inspector session id."),
2171
- }),
2172
- },
2173
- ({ sessionId }) =>
2174
- userPrompt(`Extract reproducible steps from this Agent Inspector session.
2175
-
2176
- Evidence to read:
2177
- - Session resource: inspector://sessions/${encodeURIComponent(sessionId)}
2178
- - Relevant log resources: inspector://logs/{id}
2179
-
2180
- Return:
2181
- 1. Preconditions and environment assumptions
2182
- 2. Ordered user/agent actions that led to the behavior
2183
- 3. Exact model/provider/API path details needed to reproduce
2184
- 4. Expected vs actual result
2185
- 5. Minimal verification command or UI check`),
2186
- );
2187
- }
2188
-
2189
- // Surface the tool catalog for tests that assert on the tool name set.
2190
- export const TOOL_NAMES = [
2191
- ...INSTANCE_READ_TOOL_NAMES,
2192
- ...INSTANCE_WRITE_TOOL_NAMES,
2193
- "inspector_list_logs",
2194
- "inspector_search_logs",
2195
- "inspector_get_log",
2196
- "inspector_get_log_chunks",
2197
- "inspector_get_log_headers",
2198
- "inspector_list_processes",
2199
- "inspector_get_process",
2200
- "inspector_get_process_timeline",
2201
- "inspector_list_sessions",
2202
- "inspector_get_session",
2203
- "inspector_get_session_timeline",
2204
- "inspector_get_current_context",
2205
- "inspector_set_current_context",
2206
- "inspector_get_runtime_config",
2207
- "inspector_diagnose_capture",
2208
- "inspector_create_run",
2209
- "inspector_get_run",
2210
- "inspector_update_run",
2211
- "inspector_export_evidence",
2212
- "inspector_get_evidence_files",
2213
- "inspector_export_evidence_bundle",
2214
- "inspector_get_recent_failures",
2215
- "inspector_list_groups",
2216
- "inspector_create_group",
2217
- "inspector_get_group",
2218
- "inspector_update_group",
2219
- "inspector_delete_group",
2220
- "inspector_add_group_session",
2221
- "inspector_add_group_process",
2222
- "inspector_export_group_evidence",
2223
- "inspector_get_group_evidence_files",
2224
- "inspector_export_group_evidence_bundle",
2225
- "inspector_list_models",
2226
- "inspector_list_providers",
2227
- "inspector_get_provider",
2228
- "inspector_replay_log",
2229
- "inspector_add_provider",
2230
- "inspector_update_provider",
2231
- "inspector_test_provider",
2232
- "inspector_diagnose_provider_test",
2233
- "inspector_create_session_knowledge",
2234
- "inspector_list_knowledge_candidates",
2235
- "inspector_promote_knowledge_candidate",
2236
- "inspector_search_knowledge",
2237
- "inspector_get_project_context",
2238
- ] as const;
2239
-
2240
- export const RESOURCE_NAMES = [
2241
- "inspector_instances",
2242
- "inspector_instance",
2243
- "inspector_instance_connection",
2244
- "inspector_mcp_health",
2245
- "inspector_mcp_capabilities",
2246
- "inspector_mcp_config",
2247
- "inspector_current_context",
2248
- "inspector_runtime_config",
2249
- "inspector_sessions",
2250
- "inspector_session",
2251
- "inspector_session_timeline",
2252
- "inspector_log",
2253
- "inspector_processes",
2254
- "inspector_process",
2255
- "inspector_process_timeline",
2256
- "inspector_runs",
2257
- "inspector_recent_failures",
2258
- "inspector_run",
2259
- "inspector_evidence",
2260
- "inspector_evidence_files",
2261
- "inspector_groups",
2262
- "inspector_group",
2263
- "inspector_group_sessions",
2264
- "inspector_group_evidence",
2265
- "inspector_group_evidence_files",
2266
- ] as const;
2267
-
2268
- export const PROMPT_NAMES = [
2269
- "inspector_analyze_session_failure",
2270
- "inspector_triage_recent_failures",
2271
- "inspector_generate_jenkins_report",
2272
- "inspector_generate_group_report",
2273
- "inspector_extract_repro_steps",
2274
- ] as const;