| @@ -159,6 +159,14 @@ function parseMcpContext(url: URL): McpWorkspaceContext | undefined { · 158 unmodified lines |
| 159 | 159 | return { workspaceId, actorId, clientId }; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | +// ── MCP handler ── |
| 163 | + |
| 164 | +const handleMcp = async ({ request }: { request: Request }) => { |
| 165 | + const url = new URL(request.url); |
| 166 | + const context = parseMcpContext(url); |
| 167 | + return await handleMcpRequest(service, request, context); |
| 168 | +}; |
| 169 | + |
| 162 | 170 | // ── Elysia app ── |
| 163 | 171 | |
| 164 | 172 | const app = new Elysia() |
| @@ -173,21 +181,9 @@ const app = new Elysia() · 8 unmodified lines |
| 173 | 181 | // ── MCP (raw protocol passthrough) ── |
| 174 | 182 | // Optional query params: ?workspaceId=...&actorId=... to bind workspace context. |
| 175 | 183 | // When bound, run_code description includes sandbox tool inventory and input is simplified. |
| 176 | | − .post("/mcp", async ({ request }) => { |
| 177 | | − const url = new URL(request.url); |
| 178 | | − const context = parseMcpContext(url); |
| 179 | | − return await handleMcpRequest(service, request, context); |
| 180 | | − }) |
| 181 | | − .get("/mcp", async ({ request }) => { |
| 182 | | − const url = new URL(request.url); |
| 183 | | − const context = parseMcpContext(url); |
| 184 | | − return await handleMcpRequest(service, request, context); |
| 185 | | − }) |
| 186 | | − .delete("/mcp", async ({ request }) => { |
| 187 | | − const url = new URL(request.url); |
| 188 | | − const context = parseMcpContext(url); |
| 189 | | − return await handleMcpRequest(service, request, context); |
| 190 | | − }) |
| 184 | + .post("/mcp", handleMcp) |
| 185 | + .get("/mcp", handleMcp) |
| 186 | + .delete("/mcp", handleMcp) |
| 191 | 187 | |
| 192 | 188 | // ── Health ── |
| 193 | 189 | .get("/api/health", () => ({ |
| @@ -208,11 +204,7 @@ const app = new Elysia() · 14 unmodified lines |
| 208 | 204 | .get("/api/runtime-targets", () => service.listRuntimes()) |
| 209 | 205 | |
| 210 | 206 | // ── Tools ── |
| 211 | | − .get("/api/tools", async ({ query, set }) => { |
| 212 | | − if (!query.workspaceId) { |
| 213 | | − set.status = 400; |
| 214 | | − return { error: "workspaceId is required" }; |
| 215 | | − } |
| 207 | + .get("/api/tools", async ({ query }) => { |
| 216 | 208 | return await service.listTools({ |
| 217 | 209 | workspaceId: query.workspaceId, |
| 218 | 210 | actorId: query.actorId, |
| @@ -227,11 +219,7 @@ const app = new Elysia() · 8 unmodified lines |
| 227 | 219 | }) |
| 228 | 220 | |
| 229 | 221 | // ── Tool Sources ── |
| 230 | | − .get("/api/tool-sources", async ({ query, set }) => { |
| 231 | | − if (!query.workspaceId) { |
| 232 | | − set.status = 400; |
| 233 | | − return { error: "workspaceId is required" }; |
| 234 | | − } |
| 222 | + .get("/api/tool-sources", async ({ query }) => { |
| 235 | 223 | return await service.listToolSources(query.workspaceId); |
| 236 | 224 | }, { |
| 237 | 225 | query: t.Object({ |
| @@ -240,10 +228,6 @@ const app = new Elysia() · 2 unmodified lines |
| 240 | 228 | }) |
| 241 | 229 | |
| 242 | 230 | .post("/api/tool-sources", async ({ body, set }) => { |
| 243 | | − if (!body.workspaceId || !body.name || !body.type || !body.config) { |
| 244 | | − set.status = 400; |
| 245 | | − return { error: "workspaceId, name, type, and config are required" }; |
| 246 | | − } |
| 247 | 231 | try { |
| 248 | 232 | return await service.upsertToolSource({ |
| 249 | 233 | id: body.id, |
| @@ -269,10 +253,6 @@ const app = new Elysia() · 19 unmodified lines |
| 269 | 253 | }) |
| 270 | 254 | |
| 271 | 255 | .delete("/api/tool-sources/:sourceId", async ({ params, query, set }) => { |
| 272 | | − if (!query.workspaceId) { |
| 273 | | − set.status = 400; |
| 274 | | − return { error: "workspaceId is required" }; |
| 275 | | − } |
| 276 | 256 | const deleted = await service.deleteToolSource(query.workspaceId, params.sourceId); |
| 277 | 257 | if (!deleted) { |
| 278 | 258 | set.status = 404; |
| @@ -285,11 +265,7 @@ const app = new Elysia() · 6 unmodified lines |
| 285 | 265 | }) |
| 286 | 266 | |
| 287 | 267 | // ── Tasks ── |
| 288 | | − .get("/api/tasks", async ({ query, set }) => { |
| 289 | | − if (!query.workspaceId) { |
| 290 | | − set.status = 400; |
| 291 | | − return { error: "workspaceId is required" }; |
| 292 | | − } |
| 268 | + .get("/api/tasks", async ({ query }) => { |
| 293 | 269 | return await service.listTasks(query.workspaceId); |
| 294 | 270 | }, { |
| 295 | 271 | query: t.Object({ workspaceId: t.String() }), |
| @@ -316,10 +292,6 @@ const app = new Elysia() · 20 unmodified lines |
| 316 | 292 | }) |
| 317 | 293 | |
| 318 | 294 | .get("/api/tasks/:taskId", async ({ params, query, set }) => { |
| 319 | | − if (!query.workspaceId) { |
| 320 | | − set.status = 400; |
| 321 | | − return { error: "workspaceId is required" }; |
| 322 | | − } |
| 323 | 295 | const task = await service.getTask(params.taskId, query.workspaceId); |
| 324 | 296 | if (!task) { |
| 325 | 297 | set.status = 404; |
| @@ -332,10 +304,6 @@ const app = new Elysia() · 6 unmodified lines |
| 332 | 304 | }) |
| 333 | 305 | |
| 334 | 306 | .get("/api/tasks/:taskId/events", async ({ params, query, set }) => { |
| 335 | | − if (!query.workspaceId) { |
| 336 | | − set.status = 400; |
| 337 | | − return { error: "workspaceId is required" }; |
| 338 | | − } |
| 339 | 307 | const task = await service.getTask(params.taskId, query.workspaceId); |
| 340 | 308 | if (!task) { |
| 341 | 309 | set.status = 404; |
| @@ -349,10 +317,6 @@ const app = new Elysia() · 7 unmodified lines |
| 349 | 317 | |
| 350 | 318 | // ── Approvals ── |
| 351 | 319 | .get("/api/approvals", async ({ query, set }) => { |
| 352 | | − if (!query.workspaceId) { |
| 353 | | − set.status = 400; |
| 354 | | − return { error: "workspaceId is required" }; |
| 355 | | − } |
| 356 | 320 | const status = query.status as ApprovalStatus | undefined; |
| 357 | 321 | |
| 358 | 322 | if (status === "pending") { |
| @@ -373,11 +337,6 @@ const app = new Elysia() · 14 unmodified lines |
| 373 | 337 | }) |
| 374 | 338 | |
| 375 | 339 | .post("/api/approvals/:approvalId", async ({ params, body, set }) => { |
| 376 | | − if (!body.workspaceId || (body.decision !== "approved" && body.decision !== "denied")) { |
| 377 | | − set.status = 400; |
| 378 | | − return { error: "workspaceId and decision are required" }; |
| 379 | | − } |
| 380 | | − |
| 381 | 340 | const resolved = await service.resolveApproval( |
| 382 | 341 | body.workspaceId, |
| 383 | 342 | params.approvalId, |
| @@ -402,21 +361,13 @@ const app = new Elysia() · 18 unmodified lines |
| 402 | 361 | }) |
| 403 | 362 | |
| 404 | 363 | // ── Policies ── |
| 405 | | − .get("/api/policies", async ({ query, set }) => { |
| 406 | | − if (!query.workspaceId) { |
| 407 | | − set.status = 400; |
| 408 | | − return { error: "workspaceId is required" }; |
| 409 | | − } |
| 364 | + .get("/api/policies", async ({ query }) => { |
| 410 | 365 | return await service.listAccessPolicies(query.workspaceId); |
| 411 | 366 | }, { |
| 412 | 367 | query: t.Object({ workspaceId: t.String() }), |
| 413 | 368 | }) |
| 414 | 369 | |
| 415 | | − .post("/api/policies", async ({ body, set }) => { |
| 416 | | − if (!body.workspaceId || !body.toolPathPattern || !body.decision) { |
| 417 | | − set.status = 400; |
| 418 | | − return { error: "workspaceId, toolPathPattern, and decision are required" }; |
| 419 | | − } |
| 370 | + .post("/api/policies", async ({ body }) => { |
| 420 | 371 | return await service.upsertAccessPolicy({ |
| 421 | 372 | id: body.id, |
| 422 | 373 | workspaceId: body.workspaceId, |
| @@ -439,21 +390,13 @@ const app = new Elysia() · 16 unmodified lines |
| 439 | 390 | }) |
| 440 | 391 | |
| 441 | 392 | // ── Credentials ── |
| 442 | | − .get("/api/credentials", async ({ query, set }) => { |
| 443 | | − if (!query.workspaceId) { |
| 444 | | − set.status = 400; |
| 445 | | − return { error: "workspaceId is required" }; |
| 446 | | − } |
| 393 | + .get("/api/credentials", async ({ query }) => { |
| 447 | 394 | return await service.listCredentials(query.workspaceId); |
| 448 | 395 | }, { |
| 449 | 396 | query: t.Object({ workspaceId: t.String() }), |
| 450 | 397 | }) |
| 451 | 398 | |
| 452 | 399 | .post("/api/credentials", async ({ body, set }) => { |
| 453 | | − if (!body.workspaceId || !body.sourceKey || !body.scope || !body.secretJson) { |
| 454 | | − set.status = 400; |
| 455 | | − return { error: "workspaceId, sourceKey, scope, and secretJson are required" }; |
| 456 | | − } |
| 457 | 400 | if (body.scope === "actor" && (!body.actorId || body.actorId.trim().length === 0)) { |
| 458 | 401 | set.status = 400; |
| 459 | 402 | return { error: "actorId is required for actor-scoped credential" }; |
| @@ -493,10 +436,6 @@ const app = new Elysia() · 33 unmodified lines |
| 493 | 436 | set.status = 401; |
| 494 | 437 | return { error: "Unauthorized internal call" }; |
| 495 | 438 | } |
| 496 | | − if (!body.callId || !body.toolPath) { |
| 497 | | − set.status = 400; |
| 498 | | − return { error: "callId and toolPath are required" }; |
| 499 | | − } |
| 500 | 439 | |
| 501 | 440 | const call: ToolCallRequest = { |
| 502 | 441 | runId: params.runId, |