@evref-bl/plexus 0.15.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/README.md +8 -12
  2. package/dist/answers/index.d.ts +97 -0
  3. package/dist/answers/index.d.ts.map +1 -0
  4. package/dist/answers/index.js +352 -0
  5. package/dist/answers/index.js.map +1 -0
  6. package/dist/answers/texts.d.ts +83 -0
  7. package/dist/answers/texts.d.ts.map +1 -0
  8. package/dist/answers/texts.js +216 -0
  9. package/dist/answers/texts.js.map +1 -0
  10. package/dist/cli.js +21 -182
  11. package/dist/cli.js.map +1 -1
  12. package/dist/commandLine.d.ts +13 -0
  13. package/dist/commandLine.d.ts.map +1 -0
  14. package/dist/commandLine.js +259 -0
  15. package/dist/commandLine.js.map +1 -0
  16. package/dist/config/pharoMcpVersion.d.ts +6 -7
  17. package/dist/config/pharoMcpVersion.d.ts.map +1 -1
  18. package/dist/config/pharoMcpVersion.js +6 -7
  19. package/dist/config/pharoMcpVersion.js.map +1 -1
  20. package/dist/errors.d.ts +11 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +17 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/forward/endpointHandoffFormat.d.ts +23 -0
  25. package/dist/forward/endpointHandoffFormat.d.ts.map +1 -0
  26. package/dist/forward/endpointHandoffFormat.js.map +1 -0
  27. package/dist/forward/index.d.ts +61 -0
  28. package/dist/forward/index.d.ts.map +1 -0
  29. package/dist/forward/index.js +133 -0
  30. package/dist/forward/index.js.map +1 -0
  31. package/dist/forward/jsonRpc.d.ts +58 -0
  32. package/dist/forward/jsonRpc.d.ts.map +1 -0
  33. package/dist/forward/jsonRpc.js +259 -0
  34. package/dist/forward/jsonRpc.js.map +1 -0
  35. package/dist/home.d.ts +15 -0
  36. package/dist/home.d.ts.map +1 -0
  37. package/dist/home.js +30 -0
  38. package/dist/home.js.map +1 -0
  39. package/dist/images/bases.d.ts +41 -0
  40. package/dist/images/bases.d.ts.map +1 -0
  41. package/dist/images/bases.js +194 -0
  42. package/dist/images/bases.js.map +1 -0
  43. package/dist/images/claims.d.ts +34 -0
  44. package/dist/images/claims.d.ts.map +1 -0
  45. package/dist/images/claims.js +119 -0
  46. package/dist/images/claims.js.map +1 -0
  47. package/dist/images/context.d.ts +37 -0
  48. package/dist/images/context.d.ts.map +1 -0
  49. package/dist/images/context.js +40 -0
  50. package/dist/images/context.js.map +1 -0
  51. package/dist/images/create.d.ts +19 -0
  52. package/dist/images/create.d.ts.map +1 -0
  53. package/dist/images/create.js +122 -0
  54. package/dist/images/create.js.map +1 -0
  55. package/dist/images/delete.d.ts +10 -0
  56. package/dist/images/delete.d.ts.map +1 -0
  57. package/dist/images/delete.js +32 -0
  58. package/dist/images/delete.js.map +1 -0
  59. package/dist/images/endpoint.d.ts +29 -0
  60. package/dist/images/endpoint.d.ts.map +1 -0
  61. package/dist/images/endpoint.js +86 -0
  62. package/dist/images/endpoint.js.map +1 -0
  63. package/dist/images/index.d.ts +32 -0
  64. package/dist/images/index.d.ts.map +1 -0
  65. package/dist/images/index.js +56 -0
  66. package/dist/images/index.js.map +1 -0
  67. package/dist/images/leftovers.d.ts +9 -0
  68. package/dist/images/leftovers.d.ts.map +1 -0
  69. package/dist/images/leftovers.js +38 -0
  70. package/dist/images/leftovers.js.map +1 -0
  71. package/dist/images/list.d.ts +12 -0
  72. package/dist/images/list.d.ts.map +1 -0
  73. package/dist/images/list.js +74 -0
  74. package/dist/images/list.js.map +1 -0
  75. package/dist/images/names.d.ts +15 -0
  76. package/dist/images/names.d.ts.map +1 -0
  77. package/dist/images/names.js +53 -0
  78. package/dist/images/names.js.map +1 -0
  79. package/dist/images/prepare.d.ts +18 -0
  80. package/dist/images/prepare.d.ts.map +1 -0
  81. package/dist/images/prepare.js +58 -0
  82. package/dist/images/prepare.js.map +1 -0
  83. package/dist/images/processes.d.ts +21 -0
  84. package/dist/images/processes.d.ts.map +1 -0
  85. package/dist/images/processes.js +83 -0
  86. package/dist/images/processes.js.map +1 -0
  87. package/dist/images/scripts.d.ts +48 -0
  88. package/dist/images/scripts.d.ts.map +1 -0
  89. package/dist/images/scripts.js +149 -0
  90. package/dist/images/scripts.js.map +1 -0
  91. package/dist/images/start.d.ts +23 -0
  92. package/dist/images/start.d.ts.map +1 -0
  93. package/dist/images/start.js +179 -0
  94. package/dist/images/start.js.map +1 -0
  95. package/dist/images/stop.d.ts +17 -0
  96. package/dist/images/stop.d.ts.map +1 -0
  97. package/dist/images/stop.js +171 -0
  98. package/dist/images/stop.js.map +1 -0
  99. package/dist/images/store.d.ts +62 -0
  100. package/dist/images/store.d.ts.map +1 -0
  101. package/dist/images/store.js +181 -0
  102. package/dist/images/store.js.map +1 -0
  103. package/dist/images/templates.d.ts +14 -0
  104. package/dist/images/templates.d.ts.map +1 -0
  105. package/dist/images/templates.js +85 -0
  106. package/dist/images/templates.js.map +1 -0
  107. package/dist/index.d.ts +16 -22
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +9 -22
  110. package/dist/index.js.map +1 -1
  111. package/dist/launcher/pharoLauncherMcpClient.d.ts +22 -59
  112. package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -1
  113. package/dist/launcher/pharoLauncherMcpClient.js +121 -98
  114. package/dist/launcher/pharoLauncherMcpClient.js.map +1 -1
  115. package/dist/launcher/pharoLauncherProfile.d.ts +5 -32
  116. package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -1
  117. package/dist/launcher/pharoLauncherProfile.js +17 -115
  118. package/dist/launcher/pharoLauncherProfile.js.map +1 -1
  119. package/dist/mcp/server.d.ts +27 -0
  120. package/dist/mcp/server.d.ts.map +1 -0
  121. package/dist/mcp/server.js +269 -0
  122. package/dist/mcp/server.js.map +1 -0
  123. package/dist/telemetry/reachability.d.ts +59 -0
  124. package/dist/telemetry/reachability.d.ts.map +1 -0
  125. package/dist/telemetry/reachability.js +183 -0
  126. package/dist/telemetry/reachability.js.map +1 -0
  127. package/dist/telemetry/sdk.d.ts +54 -0
  128. package/dist/telemetry/sdk.d.ts.map +1 -0
  129. package/dist/telemetry/sdk.js +167 -0
  130. package/dist/telemetry/sdk.js.map +1 -0
  131. package/dist/telemetry/settings.d.ts +16 -0
  132. package/dist/telemetry/settings.d.ts.map +1 -0
  133. package/dist/telemetry/settings.js +67 -0
  134. package/dist/telemetry/settings.js.map +1 -0
  135. package/dist/telemetry/trace.d.ts +32 -0
  136. package/dist/telemetry/trace.d.ts.map +1 -0
  137. package/dist/telemetry/trace.js +79 -0
  138. package/dist/telemetry/trace.js.map +1 -0
  139. package/dist/types.d.ts +82 -0
  140. package/dist/types.d.ts.map +1 -0
  141. package/dist/types.js +2 -0
  142. package/dist/types.js.map +1 -0
  143. package/dist/version.d.ts +2 -0
  144. package/dist/version.d.ts.map +1 -0
  145. package/dist/version.js +5 -0
  146. package/dist/version.js.map +1 -0
  147. package/package.json +15 -15
  148. package/dist/config/config.d.ts +0 -15
  149. package/dist/config/config.d.ts.map +0 -1
  150. package/dist/config/config.js +0 -74
  151. package/dist/config/config.js.map +0 -1
  152. package/dist/config/plexusHome.d.ts +0 -17
  153. package/dist/config/plexusHome.d.ts.map +0 -1
  154. package/dist/config/plexusHome.js +0 -30
  155. package/dist/config/plexusHome.js.map +0 -1
  156. package/dist/config/projectConfig.d.ts +0 -141
  157. package/dist/config/projectConfig.d.ts.map +0 -1
  158. package/dist/config/projectConfig.js +0 -722
  159. package/dist/config/projectConfig.js.map +0 -1
  160. package/dist/config/projectConfigAuthoring.d.ts +0 -53
  161. package/dist/config/projectConfigAuthoring.d.ts.map +0 -1
  162. package/dist/config/projectConfigAuthoring.js +0 -159
  163. package/dist/config/projectConfigAuthoring.js.map +0 -1
  164. package/dist/gateway/projectImageMcpEndpoint.d.ts +0 -23
  165. package/dist/gateway/projectImageMcpEndpoint.d.ts.map +0 -1
  166. package/dist/gateway/projectImageMcpEndpoint.js +0 -40
  167. package/dist/gateway/projectImageMcpEndpoint.js.map +0 -1
  168. package/dist/gateway/server/index.d.ts +0 -8
  169. package/dist/gateway/server/index.d.ts.map +0 -1
  170. package/dist/gateway/server/index.js +0 -34
  171. package/dist/gateway/server/index.js.map +0 -1
  172. package/dist/gateway/server/mcp/server.d.ts +0 -66
  173. package/dist/gateway/server/mcp/server.d.ts.map +0 -1
  174. package/dist/gateway/server/mcp/server.js +0 -458
  175. package/dist/gateway/server/mcp/server.js.map +0 -1
  176. package/dist/gateway/server/routing/endpointHandoffFormat.d.ts +0 -26
  177. package/dist/gateway/server/routing/endpointHandoffFormat.d.ts.map +0 -1
  178. package/dist/gateway/server/routing/endpointHandoffFormat.js.map +0 -1
  179. package/dist/gateway/server/routing/gateway.d.ts +0 -167
  180. package/dist/gateway/server/routing/gateway.d.ts.map +0 -1
  181. package/dist/gateway/server/routing/gateway.js +0 -863
  182. package/dist/gateway/server/routing/gateway.js.map +0 -1
  183. package/dist/gateway/server/routing/imageMcpRouter.d.ts +0 -59
  184. package/dist/gateway/server/routing/imageMcpRouter.d.ts.map +0 -1
  185. package/dist/gateway/server/routing/imageMcpRouter.js +0 -253
  186. package/dist/gateway/server/routing/imageMcpRouter.js.map +0 -1
  187. package/dist/gateway/server/routing/pharoFacade.d.ts +0 -12
  188. package/dist/gateway/server/routing/pharoFacade.d.ts.map +0 -1
  189. package/dist/gateway/server/routing/pharoFacade.js +0 -67
  190. package/dist/gateway/server/routing/pharoFacade.js.map +0 -1
  191. package/dist/gateway/server/routing/routeDiscovery.d.ts +0 -26
  192. package/dist/gateway/server/routing/routeDiscovery.d.ts.map +0 -1
  193. package/dist/gateway/server/routing/routeDiscovery.js +0 -46
  194. package/dist/gateway/server/routing/routeDiscovery.js.map +0 -1
  195. package/dist/gateway/server/routing/routingTable.d.ts +0 -120
  196. package/dist/gateway/server/routing/routingTable.d.ts.map +0 -1
  197. package/dist/gateway/server/routing/routingTable.js +0 -215
  198. package/dist/gateway/server/routing/routingTable.js.map +0 -1
  199. package/dist/gateway/server/support/processLiveness.d.ts +0 -10
  200. package/dist/gateway/server/support/processLiveness.d.ts.map +0 -1
  201. package/dist/gateway/server/support/processLiveness.js +0 -25
  202. package/dist/gateway/server/support/processLiveness.js.map +0 -1
  203. package/dist/gateway/server/support/sourceBuildPreflight.d.ts +0 -15
  204. package/dist/gateway/server/support/sourceBuildPreflight.d.ts.map +0 -1
  205. package/dist/gateway/server/support/sourceBuildPreflight.js +0 -88
  206. package/dist/gateway/server/support/sourceBuildPreflight.js.map +0 -1
  207. package/dist/gateway/server/support/toolResultFormatting.d.ts +0 -8
  208. package/dist/gateway/server/support/toolResultFormatting.d.ts.map +0 -1
  209. package/dist/gateway/server/support/toolResultFormatting.js +0 -74
  210. package/dist/gateway/server/support/toolResultFormatting.js.map +0 -1
  211. package/dist/images/homeImageCache.d.ts +0 -302
  212. package/dist/images/homeImageCache.d.ts.map +0 -1
  213. package/dist/images/homeImageCache.js +0 -1031
  214. package/dist/images/homeImageCache.js.map +0 -1
  215. package/dist/images/imageRescue.d.ts +0 -151
  216. package/dist/images/imageRescue.d.ts.map +0 -1
  217. package/dist/images/imageRescue.js +0 -748
  218. package/dist/images/imageRescue.js.map +0 -1
  219. package/dist/images/imageRuntime.d.ts +0 -60
  220. package/dist/images/imageRuntime.d.ts.map +0 -1
  221. package/dist/images/imageRuntime.js +0 -90
  222. package/dist/images/imageRuntime.js.map +0 -1
  223. package/dist/images/preparedImageCache.d.ts +0 -86
  224. package/dist/images/preparedImageCache.d.ts.map +0 -1
  225. package/dist/images/preparedImageCache.js +0 -229
  226. package/dist/images/preparedImageCache.js.map +0 -1
  227. package/dist/images/scopedTemplateCatalog.d.ts +0 -33
  228. package/dist/images/scopedTemplateCatalog.d.ts.map +0 -1
  229. package/dist/images/scopedTemplateCatalog.js +0 -363
  230. package/dist/images/scopedTemplateCatalog.js.map +0 -1
  231. package/dist/internal.d.ts +0 -20
  232. package/dist/internal.d.ts.map +0 -1
  233. package/dist/internal.js +0 -20
  234. package/dist/internal.js.map +0 -1
  235. package/dist/launcher/scopedPharoLauncherServer.d.ts +0 -349
  236. package/dist/launcher/scopedPharoLauncherServer.d.ts.map +0 -1
  237. package/dist/launcher/scopedPharoLauncherServer.js +0 -1307
  238. package/dist/launcher/scopedPharoLauncherServer.js.map +0 -1
  239. package/dist/lifecycle/startProjectImage.d.ts +0 -94
  240. package/dist/lifecycle/startProjectImage.d.ts.map +0 -1
  241. package/dist/lifecycle/startProjectImage.js +0 -1054
  242. package/dist/lifecycle/startProjectImage.js.map +0 -1
  243. package/dist/lifecycle/stopProjectImage.d.ts +0 -31
  244. package/dist/lifecycle/stopProjectImage.d.ts.map +0 -1
  245. package/dist/lifecycle/stopProjectImage.js +0 -201
  246. package/dist/lifecycle/stopProjectImage.js.map +0 -1
  247. package/dist/mcp/agentServer.d.ts +0 -15
  248. package/dist/mcp/agentServer.d.ts.map +0 -1
  249. package/dist/mcp/agentServer.js +0 -67
  250. package/dist/mcp/agentServer.js.map +0 -1
  251. package/dist/mcp/imageOperations.d.ts +0 -54
  252. package/dist/mcp/imageOperations.d.ts.map +0 -1
  253. package/dist/mcp/imageOperations.js +0 -223
  254. package/dist/mcp/imageOperations.js.map +0 -1
  255. package/dist/mcp/pharoMcpHealth.d.ts +0 -26
  256. package/dist/mcp/pharoMcpHealth.d.ts.map +0 -1
  257. package/dist/mcp/pharoMcpHealth.js +0 -97
  258. package/dist/mcp/pharoMcpHealth.js.map +0 -1
  259. package/dist/support/pathStyle.d.ts +0 -11
  260. package/dist/support/pathStyle.d.ts.map +0 -1
  261. package/dist/support/pathStyle.js +0 -61
  262. package/dist/support/pathStyle.js.map +0 -1
  263. package/dist/support/toolResultFormatting.d.ts +0 -8
  264. package/dist/support/toolResultFormatting.d.ts.map +0 -1
  265. package/dist/support/toolResultFormatting.js +0 -74
  266. package/dist/support/toolResultFormatting.js.map +0 -1
  267. package/dist/workspace/projectStartupScript.d.ts +0 -73
  268. package/dist/workspace/projectStartupScript.d.ts.map +0 -1
  269. package/dist/workspace/projectStartupScript.js +0 -607
  270. package/dist/workspace/projectStartupScript.js.map +0 -1
  271. package/dist/workspace/projectState.d.ts +0 -216
  272. package/dist/workspace/projectState.d.ts.map +0 -1
  273. package/dist/workspace/projectState.js +0 -172
  274. package/dist/workspace/projectState.js.map +0 -1
  275. /package/dist/{gateway/server/routing → forward}/endpointHandoffFormat.js +0 -0
@@ -1,863 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { StreamableHttpImageMcpToolRouter, } from "./imageMcpRouter.js";
3
- import { buildPharoFacadeTools, parsePharoFacadeArguments, } from "./pharoFacade.js";
4
- import { PlexusRoutingTable, } from "./routingTable.js";
5
- export class HttpGatewayImageHealthClient {
6
- host;
7
- paths;
8
- mcpPath;
9
- probeMethods;
10
- timeoutMs;
11
- constructor(options = {}) {
12
- this.host = options.host ?? "127.0.0.1";
13
- this.paths = options.paths ?? ["/health"];
14
- this.mcpPath = options.mcpPath ?? "/";
15
- this.probeMethods = options.probeMethods ?? ["ping"];
16
- this.timeoutMs = options.timeoutMs ?? 1_000;
17
- }
18
- async check(port) {
19
- for (const method of this.probeMethods) {
20
- try {
21
- const response = await this.fetchWithTimeout(`http://${this.host}:${port}${this.mcpPath}`, {
22
- method: "POST",
23
- headers: {
24
- accept: "application/json, text/event-stream",
25
- "content-type": "application/json",
26
- },
27
- body: JSON.stringify({
28
- jsonrpc: "2.0",
29
- id: "plexus-gateway-health-check",
30
- method,
31
- }),
32
- });
33
- if (await this.isJsonRpcResponse(response)) {
34
- return true;
35
- }
36
- }
37
- catch {
38
- // Route health is best-effort and should not hide route status.
39
- }
40
- }
41
- for (const pathname of this.paths) {
42
- try {
43
- const response = await this.fetchWithTimeout(`http://${this.host}:${port}${pathname}`);
44
- if (response.ok) {
45
- return true;
46
- }
47
- }
48
- catch {
49
- // Route health is best-effort and should not hide route status.
50
- }
51
- }
52
- return false;
53
- }
54
- async fetchWithTimeout(input, init = {}) {
55
- const controller = new AbortController();
56
- const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
57
- try {
58
- const response = await fetch(input, {
59
- ...init,
60
- signal: controller.signal,
61
- });
62
- return response;
63
- }
64
- finally {
65
- clearTimeout(timeout);
66
- }
67
- }
68
- async isJsonRpcResponse(response) {
69
- let payload;
70
- try {
71
- payload = await response.json();
72
- }
73
- catch {
74
- return false;
75
- }
76
- if (!isObject(payload)) {
77
- return false;
78
- }
79
- return (payload.jsonrpc === "2.0" &&
80
- ("result" in payload || "error" in payload));
81
- }
82
- }
83
- class GatewayInputError extends Error {
84
- constructor(message) {
85
- super(message);
86
- this.name = "GatewayInputError";
87
- }
88
- }
89
- function isObject(value) {
90
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
91
- }
92
- function requireString(input, key) {
93
- const value = input[key];
94
- if (typeof value !== "string" || value.length === 0) {
95
- throw new GatewayInputError(`${key} is required`);
96
- }
97
- return value;
98
- }
99
- function optionalString(input, key) {
100
- const value = input[key];
101
- if (value === undefined) {
102
- return undefined;
103
- }
104
- if (typeof value !== "string" || value.length === 0) {
105
- throw new GatewayInputError(`${key} must be a non-empty string`);
106
- }
107
- return value;
108
- }
109
- function optionalBoolean(input, key) {
110
- const value = input[key];
111
- if (value === undefined) {
112
- return false;
113
- }
114
- if (typeof value !== "boolean") {
115
- throw new GatewayInputError(`${key} must be a boolean`);
116
- }
117
- return value;
118
- }
119
- function optionalObject(input, key) {
120
- const value = input[key];
121
- if (value === undefined) {
122
- return {};
123
- }
124
- if (!isObject(value)) {
125
- throw new GatewayInputError(`${key} must be an object`);
126
- }
127
- return value;
128
- }
129
- function objectInput(input) {
130
- if (!isObject(input)) {
131
- return {};
132
- }
133
- return input;
134
- }
135
- function mcpServersInput(image, index) {
136
- const value = image.mcpServers;
137
- if (value === undefined) {
138
- return undefined;
139
- }
140
- if (!Array.isArray(value)) {
141
- throw new GatewayInputError(`state.images[${index}].mcpServers must be an array`);
142
- }
143
- return value.map((server, serverIndex) => {
144
- const pathLabel = `state.images[${index}].mcpServers[${serverIndex}]`;
145
- if (!isObject(server)) {
146
- throw new GatewayInputError(`${pathLabel} must be an object`);
147
- }
148
- return {
149
- id: requireString(server, "id"),
150
- endpoint: endpointValueInput(server.endpoint, `${pathLabel}.endpoint`),
151
- };
152
- });
153
- }
154
- function endpointValueInput(value, pathLabel) {
155
- if (!isObject(value)) {
156
- throw new GatewayInputError(`${pathLabel} must be an object`);
157
- }
158
- if (value.transport !== "http") {
159
- throw new GatewayInputError(`${pathLabel}.transport must be http`);
160
- }
161
- if (typeof value.host !== "string" || value.host.length === 0) {
162
- throw new GatewayInputError(`${pathLabel}.host must be a non-empty string`);
163
- }
164
- if (typeof value.port !== "number" || !Number.isInteger(value.port)) {
165
- throw new GatewayInputError(`${pathLabel}.port must be an integer`);
166
- }
167
- if (typeof value.path !== "string" || value.path.length === 0) {
168
- throw new GatewayInputError(`${pathLabel}.path must be a non-empty string`);
169
- }
170
- return {
171
- transport: "http",
172
- host: value.host,
173
- port: value.port,
174
- path: value.path,
175
- };
176
- }
177
- function remoteGatewayInput(state) {
178
- const value = state.remoteGateway;
179
- if (value === undefined) {
180
- return undefined;
181
- }
182
- if (!isObject(value)) {
183
- throw new GatewayInputError("state.remoteGateway must be an object");
184
- }
185
- const endpoint = value.endpoint;
186
- if (endpoint === undefined) {
187
- throw new GatewayInputError("state.remoteGateway.endpoint is required");
188
- }
189
- const projectId = optionalString(value, "projectId");
190
- const workspaceId = optionalString(value, "workspaceId");
191
- return {
192
- remoteNodeId: requireString(value, "remoteNodeId"),
193
- endpoint: endpointValueInput(endpoint, "state.remoteGateway.endpoint"),
194
- ...(projectId ? { projectId } : {}),
195
- ...(workspaceId ? { workspaceId } : {}),
196
- };
197
- }
198
- function gatewayImageStatusInput(image, index) {
199
- const status = requireString(image, "status");
200
- if (status !== "starting" &&
201
- status !== "running" &&
202
- status !== "stopped" &&
203
- status !== "failed") {
204
- throw new GatewayInputError(`state.images[${index}].status must be starting, running, stopped, or failed`);
205
- }
206
- return status;
207
- }
208
- function imageRouteInput(image, index, remoteGateway) {
209
- if (!isObject(image)) {
210
- throw new GatewayInputError(`state.images[${index}] must be an object`);
211
- }
212
- if ("mcpEndpoint" in image) {
213
- throw new GatewayInputError(`state.images[${index}].mcpEndpoint is not supported; use mcpServers`);
214
- }
215
- const mcpServers = mcpServersInput(image, index);
216
- const pharoMcpContract = isObject(image.pharoMcpContract)
217
- ? image.pharoMcpContract
218
- : undefined;
219
- const unsupportedPharoMcp = pharoMcpContract?.status === "unsupported";
220
- const status = gatewayImageStatusInput(image, index);
221
- // Only a running image owes us an endpoint. A declared image that is
222
- // stopped, starting or failed has none yet, and refusing it would refuse the
223
- // whole registration, taking its running siblings down with it.
224
- if (mcpServers === undefined &&
225
- status === "running" &&
226
- !unsupportedPharoMcp &&
227
- !remoteGateway) {
228
- throw new GatewayInputError(`state.images[${index}] is running but has no mcpServers`);
229
- }
230
- return {
231
- id: requireString(image, "id"),
232
- imageName: requireString(image, "imageName"),
233
- ...(mcpServers ? { mcpServers } : {}),
234
- status,
235
- ...(pharoMcpContract ? { pharoMcpContract } : {}),
236
- };
237
- }
238
- function stateInput(input) {
239
- const value = input.state;
240
- if (!isObject(value)) {
241
- throw new GatewayInputError("state is required");
242
- }
243
- const images = value.images;
244
- if (!Array.isArray(images)) {
245
- throw new GatewayInputError("state.images must be an array");
246
- }
247
- const remoteGateway = remoteGatewayInput(value);
248
- return {
249
- projectId: requireString(value, "projectId"),
250
- projectName: requireString(value, "projectName"),
251
- workspaceId: requireString(value, "workspaceId"),
252
- updatedAt: requireString(value, "updatedAt"),
253
- ...(remoteGateway ? { remoteGateway } : {}),
254
- ...(isObject(value.pharoMcpContract)
255
- ? { pharoMcpContract: value.pharoMcpContract }
256
- : {}),
257
- images: images.map((image, index) => imageRouteInput(image, index, remoteGateway)),
258
- };
259
- }
260
- function assertProjectRoute(route, identity) {
261
- if (!route) {
262
- throw new GatewayInputError(`No route is registered for: ${identity}`);
263
- }
264
- return route;
265
- }
266
- function result(data) {
267
- return { ok: true, data };
268
- }
269
- function failure(error) {
270
- return {
271
- ok: false,
272
- error: error instanceof Error ? error.message : String(error),
273
- };
274
- }
275
- function canonicalJson(value) {
276
- if (Array.isArray(value)) {
277
- return `[${value.map((item) => canonicalJson(item)).join(",")}]`;
278
- }
279
- if (isObject(value)) {
280
- const entries = Object.entries(value).sort(([left], [right]) => left.localeCompare(right));
281
- return `{${entries
282
- .map(([key, item]) => `${JSON.stringify(key)}:${canonicalJson(item)}`)
283
- .join(",")}}`;
284
- }
285
- return JSON.stringify(value);
286
- }
287
- function hostForUrl(host) {
288
- return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
289
- }
290
- function endpointUrl(endpoint) {
291
- return `http://${hostForUrl(endpoint.host)}:${endpoint.port}${endpoint.path}`;
292
- }
293
- function toolSchemaFingerprint(tools) {
294
- const canonicalTools = [...tools].sort((left, right) => left.name.localeCompare(right.name));
295
- const hash = crypto
296
- .createHash("sha256")
297
- .update(canonicalJson(canonicalTools))
298
- .digest("hex");
299
- return `sha256:${hash}`;
300
- }
301
- function schemaSourceConnectionFields(connectionInfo) {
302
- if (!connectionInfo) {
303
- return {};
304
- }
305
- return {
306
- lifecycle: connectionInfo.lifecycle,
307
- ...(connectionInfo.protocolVersion
308
- ? { protocolVersion: connectionInfo.protocolVersion }
309
- : {}),
310
- ...(connectionInfo.capabilities
311
- ? { capabilities: connectionInfo.capabilities }
312
- : {}),
313
- ...(connectionInfo.serverInfo ? { serverInfo: connectionInfo.serverInfo } : {}),
314
- };
315
- }
316
- function schemaSourceActiveVersion(source) {
317
- return {
318
- fingerprint: source.fingerprint,
319
- workspaceId: source.workspaceId,
320
- imageId: source.imageId,
321
- mcpServerId: source.mcpServerId,
322
- ...(source.toolCount !== undefined ? { toolCount: source.toolCount } : {}),
323
- ...(source.protocolVersion ? { protocolVersion: source.protocolVersion } : {}),
324
- ...(source.serverInfo ? { serverInfo: source.serverInfo } : {}),
325
- };
326
- }
327
- function sourceHasFingerprint(success) {
328
- return success.source.fingerprint !== undefined;
329
- }
330
- function markSchemaSourceCompatibility(source, active) {
331
- if (!source.fingerprint) {
332
- return {
333
- ...source,
334
- compatibility: "unavailable",
335
- };
336
- }
337
- if (source.fingerprint !== active.fingerprint) {
338
- return {
339
- ...source,
340
- compatibility: "incompatible",
341
- };
342
- }
343
- return {
344
- ...source,
345
- compatibility: source.workspaceId === active.workspaceId &&
346
- source.mcpServerId === active.mcpServerId
347
- ? "active"
348
- : "compatible",
349
- };
350
- }
351
- export class PlexusGateway {
352
- routingTable;
353
- imageRouter;
354
- healthClient;
355
- pharoTools;
356
- pharoToolNames;
357
- pharoScope;
358
- pharoToolSchemaMcpServerId;
359
- remoteGatewayFetch;
360
- pharoToolSchemaStatus = {
361
- state: "unknown",
362
- sourceCount: 0,
363
- sources: [],
364
- };
365
- constructor(options = {}) {
366
- this.routingTable =
367
- options.routingTable ?? new PlexusRoutingTable(options.routeSources ?? []);
368
- this.imageRouter =
369
- options.imageRouter ?? new StreamableHttpImageMcpToolRouter();
370
- this.healthClient =
371
- options.healthClient ?? new HttpGatewayImageHealthClient();
372
- this.pharoTools = [];
373
- this.pharoToolNames = new Set();
374
- this.pharoScope = options.pharoScope ?? {};
375
- this.pharoToolSchemaMcpServerId = options.pharoToolSchemaMcpServerId;
376
- this.remoteGatewayFetch = options.remoteGatewayFetch ?? fetch;
377
- this.setPharoTools(options.pharoTools ?? []);
378
- }
379
- listPharoTools() {
380
- return this.pharoTools.map((tool) => ({ ...tool }));
381
- }
382
- async refreshPharoTools() {
383
- let tools;
384
- try {
385
- tools = await this.refreshPharoToolsForScope(this.pharoScope, {
386
- toolSchemaMcpServerId: this.pharoToolSchemaMcpServerId,
387
- });
388
- }
389
- catch (error) {
390
- if (this.pharoTools.length === 0 || this.pharoToolSchemaMcpServerId) {
391
- throw error;
392
- }
393
- return this.listPharoTools();
394
- }
395
- if (tools !== undefined) {
396
- this.setPharoTools(tools);
397
- }
398
- return this.listPharoTools();
399
- }
400
- isPharoTool(name) {
401
- return this.pharoToolNames.has(name);
402
- }
403
- /** Serve another project's images; the directory is the route. */
404
- addRouteSource(source) {
405
- this.routingTable.addSource(source);
406
- }
407
- async status(input) {
408
- try {
409
- if (input.refreshTools) {
410
- await this.refreshPharoToolsForScope(input, {
411
- toolSchemaMcpServerId: input.toolSchemaMcpServerId,
412
- });
413
- }
414
- let routes = await this.resolveProjectRoutes(input);
415
- if (input.refreshHealth) {
416
- for (const route of routes) {
417
- await this.refreshProjectHealth(route);
418
- }
419
- // Routes are built from disk each time, so the health just observed is
420
- // only visible on a fresh resolve.
421
- routes = await this.resolveProjectRoutes(input);
422
- }
423
- const routesWithSchema = routes.map((route) => this.routeWithPharoToolSchema(route));
424
- return result(routesWithSchema.length === 1 ? routesWithSchema[0] : routesWithSchema);
425
- }
426
- catch (error) {
427
- return failure(error);
428
- }
429
- }
430
- async getRouteStatus(input) {
431
- return this.status(input);
432
- }
433
- async routeToImage(input) {
434
- try {
435
- const routed = await this.callRoutedImageTool(input, input.mcpServerId, input.toolName, input.arguments ?? {});
436
- return {
437
- ok: true,
438
- data: routed.result,
439
- route: routed.route,
440
- };
441
- }
442
- catch (error) {
443
- return failure(error);
444
- }
445
- }
446
- async callImageTool(reference, imageId, toolName, argumentsValue) {
447
- const routed = await this.routeToImage({
448
- ...reference,
449
- mcpServerId: imageId,
450
- toolName,
451
- arguments: argumentsValue,
452
- });
453
- if (!routed.ok) {
454
- throw new GatewayInputError(routed.error ?? "Image route failed");
455
- }
456
- return routed.data;
457
- }
458
- async callPharoTool(toolName, inputValue) {
459
- try {
460
- if (!this.isPharoTool(toolName)) {
461
- throw new GatewayInputError(`Unknown Pharo tool: ${toolName}`);
462
- }
463
- const parsed = parsePharoFacadeArguments(inputValue);
464
- const routed = await this.callRoutedImageTool(this.pharoScope, parsed.mcpServerId, toolName, parsed.argumentsValue, {
465
- requireActivePharoSchema: true,
466
- });
467
- return result(routed.result);
468
- }
469
- catch (error) {
470
- return failure(error);
471
- }
472
- }
473
- async handleTool(name, inputValue) {
474
- try {
475
- const input = objectInput(inputValue);
476
- switch (name) {
477
- case "plexus_gateway_status":
478
- return this.status({
479
- projectId: optionalString(input, "projectId"),
480
- workspaceId: optionalString(input, "workspaceId"),
481
- refreshTools: optionalBoolean(input, "refreshTools"),
482
- refreshHealth: optionalBoolean(input, "refreshHealth"),
483
- toolSchemaMcpServerId: optionalString(input, "toolSchemaMcpServerId"),
484
- });
485
- case "plexus_route_to_image":
486
- return this.routeToImage({
487
- projectId: optionalString(input, "projectId"),
488
- workspaceId: optionalString(input, "workspaceId"),
489
- mcpServerId: requireString(input, "mcpServerId"),
490
- toolName: requireString(input, "toolName"),
491
- arguments: optionalObject(input, "arguments"),
492
- });
493
- default:
494
- return {
495
- ok: false,
496
- error: `Unknown tool: ${name}`,
497
- };
498
- }
499
- }
500
- catch (error) {
501
- return failure(error);
502
- }
503
- }
504
- findRegisteredRoute(input) {
505
- if (input.projectId && input.workspaceId) {
506
- return this.routingTable.getProjectWorkspace(input.projectId, input.workspaceId);
507
- }
508
- throw new GatewayInputError("projectId with workspaceId is required");
509
- }
510
- async resolveProjectRoutes(input) {
511
- if (input.projectId && input.workspaceId) {
512
- return [
513
- assertProjectRoute(this.routingTable.getProjectWorkspace(input.projectId, input.workspaceId), `${input.projectId}/${input.workspaceId}`),
514
- ];
515
- }
516
- if (input.projectId) {
517
- return this.routingTable.listProjectTargets(input.projectId);
518
- }
519
- return this.routingTable.listTargets();
520
- }
521
- async resolveSingleProjectRoute(input) {
522
- const routes = await this.resolveProjectRoutes(input);
523
- if (routes.length === 0) {
524
- throw new GatewayInputError("projectId with workspaceId is required");
525
- }
526
- if (routes.length > 1) {
527
- throw new GatewayInputError("Multiple routes match; provide projectId with workspaceId");
528
- }
529
- return routes[0];
530
- }
531
- async callRoutedImageTool(projectReference, mcpServerId, toolName, argumentsValue, options = {}) {
532
- const project = await this.resolveSingleProjectRoute(projectReference);
533
- const image = this.resolveMcpServerRoute(project, mcpServerId);
534
- if (!image.routable.ok) {
535
- throw new GatewayInputError(image.routable.message);
536
- }
537
- const route = {
538
- projectId: project.projectId,
539
- workspaceId: project.workspaceId,
540
- imageId: image.id,
541
- mcpServerId: image.mcpServerId,
542
- imageName: image.imageName,
543
- ...(image.port !== undefined ? { port: image.port } : {}),
544
- endpoint: image.endpoint,
545
- ...(project.remoteGateway ? { remoteGateway: project.remoteGateway } : {}),
546
- };
547
- if (options.requireActivePharoSchema) {
548
- this.assertActivePharoSchemaForRoute(route, mcpServerId);
549
- }
550
- const toolResult = project.remoteGateway
551
- ? await this.callRemoteGatewayTool(project.remoteGateway, image.mcpServerId, toolName, argumentsValue)
552
- : await this.imageRouter.callTool(route, toolName, argumentsValue);
553
- return {
554
- route,
555
- result: toolResult,
556
- };
557
- }
558
- async callRemoteGatewayTool(remoteGateway, mcpServerId, toolName, argumentsValue) {
559
- const response = await this.remoteGatewayFetch(endpointUrl(remoteGateway.endpoint), {
560
- method: "POST",
561
- headers: {
562
- accept: "application/json, text/event-stream",
563
- "content-type": "application/json",
564
- },
565
- body: JSON.stringify({
566
- jsonrpc: "2.0",
567
- id: `plexus-remote-${remoteGateway.remoteNodeId}-${Date.now()}`,
568
- method: "tools/call",
569
- params: {
570
- name: toolName,
571
- arguments: {
572
- ...argumentsValue,
573
- mcpServerId,
574
- },
575
- },
576
- }),
577
- });
578
- if (!response.ok) {
579
- throw new GatewayInputError(`Remote gateway MCP request failed with HTTP ${response.status}`);
580
- }
581
- const payload = (await response.json());
582
- if (!isObject(payload)) {
583
- throw new GatewayInputError("Remote gateway MCP response was not a JSON object");
584
- }
585
- if ("error" in payload) {
586
- throw new GatewayInputError(JSON.stringify(payload.error));
587
- }
588
- if (!("result" in payload)) {
589
- throw new GatewayInputError("Remote gateway MCP response did not include a result");
590
- }
591
- return payload.result;
592
- }
593
- async listRemoteGatewayTools(remoteGateway) {
594
- const response = await this.remoteGatewayFetch(endpointUrl(remoteGateway.endpoint), {
595
- method: "POST",
596
- headers: {
597
- accept: "application/json, text/event-stream",
598
- "content-type": "application/json",
599
- },
600
- body: JSON.stringify({
601
- jsonrpc: "2.0",
602
- id: `plexus-remote-${remoteGateway.remoteNodeId}-tools-${Date.now()}`,
603
- method: "tools/list",
604
- }),
605
- });
606
- if (!response.ok) {
607
- throw new GatewayInputError(`Remote gateway MCP tools/list failed with HTTP ${response.status}`);
608
- }
609
- const payload = (await response.json());
610
- if (!isObject(payload)) {
611
- throw new GatewayInputError("Remote gateway MCP tools/list response was not a JSON object");
612
- }
613
- if ("error" in payload) {
614
- throw new GatewayInputError(JSON.stringify(payload.error));
615
- }
616
- const resultValue = payload.result;
617
- if (!isObject(resultValue) || !Array.isArray(resultValue.tools)) {
618
- throw new GatewayInputError("Remote gateway MCP tools/list response did not include result.tools");
619
- }
620
- return resultValue.tools.map((tool, index) => {
621
- if (!isObject(tool) || typeof tool.name !== "string") {
622
- throw new GatewayInputError(`Remote gateway MCP tools/list returned an invalid tool at index ${index}`);
623
- }
624
- return tool;
625
- });
626
- }
627
- assertActivePharoSchemaForRoute(route, mcpServerId) {
628
- const activeFingerprint = this.pharoToolSchemaStatus.fingerprint;
629
- if (!activeFingerprint) {
630
- return;
631
- }
632
- const source = this.pharoToolSchemaStatus.sources.find((candidate) => candidate.workspaceId === route.workspaceId &&
633
- candidate.mcpServerId === mcpServerId);
634
- if (!source) {
635
- throw new GatewayInputError(`Image ${route.imageId} has no refreshed Pharo MCP schema for the active gateway schema`);
636
- }
637
- if (!source.fingerprint || source.error) {
638
- throw new GatewayInputError(`Image ${route.imageId} Pharo MCP schema is unavailable`);
639
- }
640
- if (source.fingerprint !== activeFingerprint) {
641
- throw new GatewayInputError(`Image ${route.imageId} Pharo MCP schema is incompatible with active gateway schema`);
642
- }
643
- }
644
- setPharoTools(tools) {
645
- this.pharoTools = buildPharoFacadeTools(tools);
646
- this.pharoToolNames = new Set(this.pharoTools.map((tool) => tool.name));
647
- }
648
- routeWithPharoToolSchema(route) {
649
- return {
650
- ...route,
651
- images: route.images.map((image) => ({
652
- ...image,
653
- pharoToolSchema: this.imagePharoToolSchemaStatus(route, image),
654
- })),
655
- pharoToolSchema: this.pharoToolSchemaStatus,
656
- };
657
- }
658
- imagePharoToolSchemaStatus(route, image) {
659
- const source = this.pharoToolSchemaStatus.sources.find((candidate) => candidate.workspaceId === route.workspaceId &&
660
- candidate.mcpServerId === image.mcpServerId);
661
- if (!source) {
662
- if (this.pharoToolSchemaStatus.state === "unknown") {
663
- return { state: "unknown" };
664
- }
665
- return {
666
- state: "unavailable",
667
- compatibility: "unavailable",
668
- error: image.routable.ok
669
- ? `Image ${image.id} has no refreshed Pharo MCP schema`
670
- : image.routable.message,
671
- };
672
- }
673
- const compatibility = source.compatibility ?? "unavailable";
674
- return {
675
- state: compatibility,
676
- ...(source.fingerprint ? { fingerprint: source.fingerprint } : {}),
677
- compatibility,
678
- ...(source.toolCount !== undefined ? { toolCount: source.toolCount } : {}),
679
- ...(source.lifecycle ? { lifecycle: source.lifecycle } : {}),
680
- ...(source.protocolVersion
681
- ? { protocolVersion: source.protocolVersion }
682
- : {}),
683
- ...(source.capabilities ? { capabilities: source.capabilities } : {}),
684
- ...(source.serverInfo ? { serverInfo: source.serverInfo } : {}),
685
- ...(source.error ? { error: source.error } : {}),
686
- };
687
- }
688
- imageRouteReference(project, image) {
689
- return {
690
- projectId: project.projectId,
691
- workspaceId: project.workspaceId,
692
- imageId: image.id,
693
- mcpServerId: image.mcpServerId,
694
- imageName: image.imageName,
695
- ...(image.port !== undefined ? { port: image.port } : {}),
696
- endpoint: image.endpoint,
697
- };
698
- }
699
- async probePharoToolSchemaSource(project, image, listTools) {
700
- const route = this.imageRouteReference(project, image);
701
- try {
702
- const tools = project.remoteGateway
703
- ? await this.listRemoteGatewayTools(project.remoteGateway)
704
- : await listTools(route);
705
- const connectionInfo = project.remoteGateway
706
- ? undefined
707
- : this.imageRouter.connectionInfo?.(route);
708
- if (tools.length > 0) {
709
- return {
710
- source: {
711
- workspaceId: project.workspaceId,
712
- imageId: image.id,
713
- mcpServerId: image.mcpServerId,
714
- fingerprint: toolSchemaFingerprint(tools),
715
- toolCount: tools.length,
716
- ...schemaSourceConnectionFields(connectionInfo),
717
- },
718
- tools,
719
- };
720
- }
721
- const error = "MCP tools/list returned no tools";
722
- return {
723
- source: {
724
- workspaceId: project.workspaceId,
725
- imageId: image.id,
726
- mcpServerId: image.mcpServerId,
727
- ...schemaSourceConnectionFields(connectionInfo),
728
- error,
729
- },
730
- tools: [],
731
- };
732
- }
733
- catch (error) {
734
- const message = error instanceof Error ? error.message : String(error);
735
- const connectionInfo = this.imageRouter.connectionInfo?.(route);
736
- return {
737
- source: {
738
- workspaceId: project.workspaceId,
739
- imageId: image.id,
740
- mcpServerId: image.mcpServerId,
741
- ...schemaSourceConnectionFields(connectionInfo),
742
- error: message,
743
- },
744
- tools: [],
745
- };
746
- }
747
- }
748
- async refreshPharoToolsForScope(scope, options = {}) {
749
- if (!this.imageRouter.listTools) {
750
- return undefined;
751
- }
752
- const listTools = this.imageRouter.listTools.bind(this.imageRouter);
753
- let routes;
754
- try {
755
- routes = await this.resolveProjectRoutes(scope);
756
- }
757
- catch {
758
- return undefined;
759
- }
760
- const errors = [];
761
- const successes = [];
762
- let attempted = false;
763
- for (const project of routes) {
764
- for (const image of project.images) {
765
- if (!image.routable.ok) {
766
- continue;
767
- }
768
- attempted = true;
769
- const probe = await this.probePharoToolSchemaSource(project, image, listTools);
770
- if (probe.source.error) {
771
- errors.push(`${project.workspaceId}/${image.mcpServerId}: ${probe.source.error}`);
772
- }
773
- successes.push(probe);
774
- }
775
- }
776
- const refreshedAt = new Date().toISOString();
777
- const sources = successes.map((success) => success.source);
778
- const validSources = successes.filter(sourceHasFingerprint);
779
- if (validSources.length > 0) {
780
- return this.applyAvailablePharoToolSchemaRefresh(sources, validSources, errors, refreshedAt, options.toolSchemaMcpServerId);
781
- }
782
- if (attempted) {
783
- this.applyUnavailablePharoToolSchemaRefresh(sources, errors, refreshedAt);
784
- }
785
- return undefined;
786
- }
787
- applyAvailablePharoToolSchemaRefresh(sources, validSources, errors, refreshedAt, requestedToolSchemaMcpServerId) {
788
- const currentFingerprint = this.pharoToolSchemaStatus.fingerprint;
789
- const active = (requestedToolSchemaMcpServerId
790
- ? this.requestedPharoToolSchemaSource(validSources, requestedToolSchemaMcpServerId)
791
- : undefined) ??
792
- validSources.find((success) => success.source.fingerprint === currentFingerprint) ??
793
- validSources[0];
794
- const compatibleSources = sources.map((source) => markSchemaSourceCompatibility(source, active.source));
795
- const hasExcludedSources = compatibleSources.some((source) => source.compatibility === "incompatible" ||
796
- source.compatibility === "unavailable");
797
- const statusErrors = [
798
- ...(hasExcludedSources
799
- ? [
800
- "Some registered image routes are not compatible with the active Pharo MCP schema",
801
- ]
802
- : []),
803
- ...(errors.length > 0 ? [errors.join("; ")] : []),
804
- ];
805
- this.pharoToolSchemaStatus = {
806
- state: hasExcludedSources ? "mismatched" : "matching",
807
- refreshedAt,
808
- fingerprint: active.source.fingerprint,
809
- activeVersion: schemaSourceActiveVersion(active.source),
810
- sourceCount: sources.length,
811
- sources: compatibleSources,
812
- ...(statusErrors.length > 0 ? { error: statusErrors.join("; ") } : {}),
813
- };
814
- this.setPharoTools(active.tools);
815
- return this.listPharoTools();
816
- }
817
- applyUnavailablePharoToolSchemaRefresh(sources, errors, refreshedAt) {
818
- this.pharoToolSchemaStatus = {
819
- state: "unavailable",
820
- refreshedAt,
821
- sourceCount: sources.length,
822
- sources,
823
- error: errors.join("; "),
824
- };
825
- throw new GatewayInputError(`Unable to refresh Pharo tool schemas from registered image routes: ${errors.join("; ")}`);
826
- }
827
- requestedPharoToolSchemaSource(validSources, mcpServerId) {
828
- const matches = validSources.filter((success) => success.source.mcpServerId === mcpServerId);
829
- if (matches.length === 0) {
830
- throw new GatewayInputError(`No routable MCP server ${mcpServerId} provided an available Pharo MCP schema`);
831
- }
832
- if (matches.length > 1) {
833
- throw new GatewayInputError(`Multiple routable MCP servers named ${mcpServerId} provided Pharo MCP schemas; provide projectId with workspaceId`);
834
- }
835
- return matches[0];
836
- }
837
- resolveMcpServerRoute(project, mcpServerId) {
838
- const image = project.images.find((candidate) => candidate.mcpServerId === mcpServerId);
839
- if (image) {
840
- return image;
841
- }
842
- const otherWorkspace = this.routingTable.findMcpServerOutsideWorkspace(project.projectId, project.workspaceId, mcpServerId);
843
- if (otherWorkspace) {
844
- throw new GatewayInputError(`MCP server ${mcpServerId} is registered in workspace ${otherWorkspace.workspaceId}, not ${project.workspaceId}`);
845
- }
846
- throw new GatewayInputError(`No route is registered for MCP server ${mcpServerId} in project ${project.projectId}`);
847
- }
848
- async refreshProjectHealth(route) {
849
- for (const image of route.images) {
850
- if (image.status !== "running") {
851
- this.routingTable.updateImageHealth(route.projectId, route.workspaceId, image.mcpServerId, "unknown");
852
- continue;
853
- }
854
- if (image.port === undefined) {
855
- this.routingTable.updateImageHealth(route.projectId, route.workspaceId, image.mcpServerId, image.routable.code === "unsupported" ? "unknown" : "unhealthy");
856
- continue;
857
- }
858
- const healthy = await this.healthClient.check(image.port);
859
- this.routingTable.updateImageHealth(route.projectId, route.workspaceId, image.mcpServerId, healthy ? "healthy" : "unhealthy");
860
- }
861
- }
862
- }
863
- //# sourceMappingURL=gateway.js.map