@orgsdk/cli 0.1.0 → 0.2.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.
- package/README.md +21 -7
- package/bin/orgsdk.mjs +1 -1
- package/dist/THIRD_PARTY_NOTICES.txt +278 -0
- package/dist/runtime/README.md +9 -7
- package/dist/runtime/cli.js +12 -13
- package/dist/runtime/client.js +79 -17
- package/dist/runtime/contract.js +39 -6
- package/dist/runtime/executor-configuration.js +1 -1
- package/dist/runtime/isolated-actions.js +4 -5
- package/dist/runtime/isolated-worker.js +5 -0
- package/dist/runtime/mcp/aliases.js +29 -0
- package/dist/runtime/mcp/client.js +239 -0
- package/dist/runtime/mcp/contract.js +57 -0
- package/dist/runtime/mcp/functions.js +40 -0
- package/dist/runtime/mcp/network.js +61 -0
- package/dist/runtime/mcp/schema-types.js +35 -0
- package/dist/runtime/mcp/transport.js +18 -0
- package/dist/runtime/project-data.js +1 -1
- package/dist/runtime/register-executor.js +23 -0
- package/dist/runtime/runner.js +30 -24
- package/dist/runtime/sdk-declarations.js +8 -1
- package/dist/runtime/session-job-contract.js +29 -0
- package/dist/runtime/session-job.js +256 -0
- package/dist/runtime/session-plugin-call.js +33 -0
- package/dist/runtime/sessions/manager.js +5 -3
- package/dist/runtime/sessions/process.js +3 -3
- package/dist/runtime/sessions/session-runtime.js +7 -3
- package/dist/runtime/sessions/worker-guard.js +20 -0
- package/dist/runtime/spawn-job.js +69 -0
- package/dist/runtime/supervisor.js +102 -146
- package/dist/runtime/worker.js +48 -45
- package/dist/server/{bun-driver-JKOGHIVX.js → bun-driver-DTZUUCI3.js} +1 -1
- package/dist/server/{chunk-WCVBLUNL.js → chunk-S5SFX3JM.js} +24 -0
- package/dist/server/index.js +2628 -1230
- package/dist/server/migrations/0003_remote-mcp.sql +17 -0
- package/dist/server/migrations/meta/0003_snapshot.json +3395 -0
- package/dist/server/migrations/meta/_journal.json +7 -0
- package/dist/server/{node-driver-FRDSYDBU.js → node-driver-HDJKKWXQ.js} +1 -1
- package/dist/server/out/404/index.html +1 -1
- package/dist/server/out/404.html +1 -1
- package/dist/server/out/__next.!KHdvcmtzcGFjZSk.__PAGE__.txt +10 -10
- package/dist/server/out/__next._full.txt +10 -10
- package/dist/server/out/__next._tree.txt +2 -2
- package/dist/server/out/_next/static/chunks/0ay0b1lpy734z.js +1 -0
- package/dist/server/out/_next/static/chunks/0c-3k17txbh0-.js +1 -0
- package/dist/server/out/_next/static/chunks/0cwfl2xanfapu.js +1 -0
- package/dist/server/out/_next/static/chunks/0e7s8ie0wlk66.js +1 -0
- package/dist/server/out/_next/static/chunks/0ey-6hb0za4r_.js +1 -0
- package/dist/server/out/_next/static/chunks/0huhp5j8dlai8.js +1 -0
- package/dist/server/out/_next/static/chunks/0khjy8qh1ll42.js +1 -0
- package/dist/server/out/_next/static/chunks/0r0572w1rwpcv.js +1 -0
- package/dist/server/out/_next/static/chunks/0rlc9tihf4po6.css +1 -0
- package/dist/server/out/_next/static/chunks/0u_9k8f7709np.js +1 -0
- package/dist/server/out/_next/static/chunks/0w34iczo7r1v5.js +1 -0
- package/dist/server/out/_next/static/chunks/{280w168xxgtwt.js → 0y5lgqdwpeabb.js} +4 -4
- package/dist/server/out/_next/static/chunks/0zfiikazg0_ga.js +1 -0
- package/dist/server/out/_next/static/chunks/1-75euysc3lin.js +22 -0
- package/dist/server/out/_next/static/chunks/10aam78qxauw0.js +1 -0
- package/dist/server/out/_next/static/chunks/12ro_nqb83zku.js +1 -0
- package/dist/server/out/_next/static/chunks/19ue6x5c3f_38.js +3 -0
- package/dist/server/out/_next/static/chunks/1c1ayx3fqtub5.js +31 -0
- package/dist/server/out/_next/static/chunks/1c2xcwifk3vhh.js +1 -0
- package/dist/server/out/_next/static/chunks/1dwr62uuyceq-.js +1 -0
- package/dist/server/out/_next/static/chunks/1fweh1ttncdlv.js +1 -0
- package/dist/server/out/_next/static/chunks/1iklteprcoims.js +1 -0
- package/dist/server/out/_next/static/chunks/1qaow7bdy3oid.js +1 -0
- package/dist/server/out/_next/static/chunks/1tnzhqkfwk7l8.js +1 -0
- package/dist/server/out/_next/static/chunks/1wn9ohqcnx8y8.js +3 -0
- package/dist/server/out/_next/static/chunks/1zieh-zxgxmcp.js +1 -0
- package/dist/server/out/_next/static/chunks/25qsan0t-_of0.js +1 -0
- package/dist/server/out/_next/static/chunks/26yareaaj1kyr.js +1 -0
- package/dist/server/out/_next/static/chunks/2bkkmnhngpacd.js +1 -0
- package/dist/server/out/_next/static/chunks/2e39uy7huhczu.js +1 -0
- package/dist/server/out/_next/static/chunks/2lxgam-nk-e9a.js +3 -0
- package/dist/server/out/_next/static/chunks/{3dx108d0g6032.js → 2navy2mx7--vk.js} +1 -1
- package/dist/server/out/_next/static/chunks/2ngzwwqeitkk7.js +1 -0
- package/dist/server/out/_next/static/chunks/2rp65hq6bmpxv.js +1 -0
- package/dist/server/out/_next/static/chunks/2z60o39-yshg2.js +1 -0
- package/dist/server/out/_next/static/chunks/3_d6w25_b15kx.js +1 -0
- package/dist/server/out/_next/static/chunks/3d8gkwu9nszjk.js +1 -0
- package/dist/server/out/_next/static/chunks/3l-16g1y6k5rs.js +1 -0
- package/dist/server/out/_next/static/chunks/3obu_9-ka7u_h.js +1 -0
- package/dist/server/out/_next/static/chunks/3xs2ji0dgkbmc.js +1 -0
- package/dist/server/out/_next/static/chunks/{turbopack-3-ry682tkyiqk.js → turbopack-2u1d16houkiyo.js} +1 -1
- package/dist/server/out/_not-found/__next._full.txt +3 -3
- package/dist/server/out/_not-found/__next._not-found.__PAGE__.txt +3 -3
- package/dist/server/out/_not-found/__next._tree.txt +2 -2
- package/dist/server/out/_not-found/index.html +1 -1
- package/dist/server/out/_not-found/index.txt +3 -3
- package/dist/server/out/accounts/2fa/__next._full.txt +8 -8
- package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
- package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +8 -8
- package/dist/server/out/accounts/2fa/index.html +1 -1
- package/dist/server/out/accounts/2fa/index.txt +8 -8
- package/dist/server/out/accounts/email/__next._full.txt +7 -7
- package/dist/server/out/accounts/email/__next._tree.txt +2 -2
- package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +7 -7
- package/dist/server/out/accounts/email/index.html +1 -1
- package/dist/server/out/accounts/email/index.txt +7 -7
- package/dist/server/out/accounts/login/__next._full.txt +7 -7
- package/dist/server/out/accounts/login/__next._tree.txt +2 -2
- package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +7 -7
- package/dist/server/out/accounts/login/index.html +1 -1
- package/dist/server/out/accounts/login/index.txt +7 -7
- package/dist/server/out/accounts/logout/__next._full.txt +7 -7
- package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
- package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +7 -7
- package/dist/server/out/accounts/logout/index.html +1 -1
- package/dist/server/out/accounts/logout/index.txt +7 -7
- package/dist/server/out/accounts/password/change/__next._full.txt +7 -7
- package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
- package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +7 -7
- package/dist/server/out/accounts/password/change/index.html +1 -1
- package/dist/server/out/accounts/password/change/index.txt +7 -7
- package/dist/server/out/accounts/password/reset/__next._full.txt +5 -5
- package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
- package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +5 -5
- package/dist/server/out/accounts/password/reset/index.html +1 -1
- package/dist/server/out/accounts/password/reset/index.txt +5 -5
- package/dist/server/out/accounts/signup/__next._full.txt +7 -7
- package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
- package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +7 -7
- package/dist/server/out/accounts/signup/index.html +1 -1
- package/dist/server/out/accounts/signup/index.txt +7 -7
- package/dist/server/out/actions/__next.!KHdvcmtzcGFjZSk.actions.__PAGE__.txt +15 -15
- package/dist/server/out/actions/__next._full.txt +15 -15
- package/dist/server/out/actions/__next._tree.txt +2 -2
- package/dist/server/out/actions/index.html +1 -1
- package/dist/server/out/actions/index.txt +15 -15
- package/dist/server/out/agents/__next.!KHdvcmtzcGFjZSk.agents.__PAGE__.txt +8 -8
- package/dist/server/out/agents/__next._full.txt +8 -8
- package/dist/server/out/agents/__next._tree.txt +2 -2
- package/dist/server/out/agents/index.html +1 -1
- package/dist/server/out/agents/index.txt +8 -8
- package/dist/server/out/approvals/__next.!KHdvcmtzcGFjZSk.approvals.__PAGE__.txt +10 -10
- package/dist/server/out/approvals/__next._full.txt +10 -10
- package/dist/server/out/approvals/__next._tree.txt +2 -2
- package/dist/server/out/approvals/index.html +1 -1
- package/dist/server/out/approvals/index.txt +10 -10
- package/dist/server/out/artifacts/__next.!KHdvcmtzcGFjZSk.artifacts.__PAGE__.txt +12 -12
- package/dist/server/out/artifacts/__next._full.txt +12 -12
- package/dist/server/out/artifacts/__next._tree.txt +2 -2
- package/dist/server/out/artifacts/index.html +1 -1
- package/dist/server/out/artifacts/index.txt +12 -12
- package/dist/server/out/audit/__next.!KHdvcmtzcGFjZSk.audit.__PAGE__.txt +10 -10
- package/dist/server/out/audit/__next._full.txt +10 -10
- package/dist/server/out/audit/__next._tree.txt +2 -2
- package/dist/server/out/audit/index.html +1 -1
- package/dist/server/out/audit/index.txt +10 -10
- package/dist/server/out/chat/__next.!KHdvcmtzcGFjZSk.chat.__PAGE__.txt +8 -8
- package/dist/server/out/chat/__next._full.txt +8 -8
- package/dist/server/out/chat/__next._tree.txt +2 -2
- package/dist/server/out/chat/index.html +1 -1
- package/dist/server/out/chat/index.txt +8 -8
- package/dist/server/out/connections/__next.!KHdvcmtzcGFjZSk.connections.__PAGE__.txt +10 -10
- package/dist/server/out/connections/__next._full.txt +10 -10
- package/dist/server/out/connections/__next._tree.txt +2 -2
- package/dist/server/out/connections/index.html +1 -1
- package/dist/server/out/connections/index.txt +10 -10
- package/dist/server/out/credentials/__next.!KHdvcmtzcGFjZSk.credentials.__PAGE__.txt +11 -11
- package/dist/server/out/credentials/__next._full.txt +11 -11
- package/dist/server/out/credentials/__next._tree.txt +2 -2
- package/dist/server/out/credentials/index.html +1 -1
- package/dist/server/out/credentials/index.txt +11 -11
- package/dist/server/out/documents/__next.!KHdvcmtzcGFjZSk.documents.__PAGE__.txt +10 -10
- package/dist/server/out/documents/__next._full.txt +10 -10
- package/dist/server/out/documents/__next._tree.txt +2 -2
- package/dist/server/out/documents/index.html +1 -1
- package/dist/server/out/documents/index.txt +10 -10
- package/dist/server/out/index.html +1 -1
- package/dist/server/out/index.txt +10 -10
- package/dist/server/out/people/__next.!KHdvcmtzcGFjZSk.people.__PAGE__.txt +10 -10
- package/dist/server/out/people/__next._full.txt +10 -10
- package/dist/server/out/people/__next._tree.txt +2 -2
- package/dist/server/out/people/index.html +1 -1
- package/dist/server/out/people/index.txt +10 -10
- package/dist/server/out/plugins/__next.!KHdvcmtzcGFjZSk.plugins.__PAGE__.txt +13 -13
- package/dist/server/out/plugins/__next._full.txt +13 -13
- package/dist/server/out/plugins/__next._tree.txt +2 -2
- package/dist/server/out/plugins/index.html +1 -1
- package/dist/server/out/plugins/index.txt +13 -13
- package/dist/server/out/projects/__next.!KHdvcmtzcGFjZSk.projects.__PAGE__.txt +10 -10
- package/dist/server/out/projects/__next._full.txt +10 -10
- package/dist/server/out/projects/__next._tree.txt +2 -2
- package/dist/server/out/projects/index.html +1 -1
- package/dist/server/out/projects/index.txt +10 -10
- package/dist/server/out/runs/__next.!KHdvcmtzcGFjZSk.runs.__PAGE__.txt +12 -12
- package/dist/server/out/runs/__next._full.txt +12 -12
- package/dist/server/out/runs/__next._tree.txt +2 -2
- package/dist/server/out/runs/index.html +1 -1
- package/dist/server/out/runs/index.txt +12 -12
- package/dist/server/out/schedules/__next.!KHdvcmtzcGFjZSk.schedules.__PAGE__.txt +12 -12
- package/dist/server/out/schedules/__next._full.txt +12 -12
- package/dist/server/out/schedules/__next._tree.txt +2 -2
- package/dist/server/out/schedules/index.html +1 -1
- package/dist/server/out/schedules/index.txt +12 -12
- package/dist/server/out/settings/__next.!KHdvcmtzcGFjZSk.settings.__PAGE__.txt +10 -10
- package/dist/server/out/settings/__next._full.txt +10 -10
- package/dist/server/out/settings/__next._tree.txt +2 -2
- package/dist/server/out/settings/index.html +1 -1
- package/dist/server/out/settings/index.txt +10 -10
- package/dist/server/out/setup/__next._full.txt +7 -7
- package/dist/server/out/setup/__next._tree.txt +2 -2
- package/dist/server/out/setup/__next.setup.__PAGE__.txt +7 -7
- package/dist/server/out/setup/index.html +1 -1
- package/dist/server/out/setup/index.txt +7 -7
- package/dist/server/out/tables/__next.!KHdvcmtzcGFjZSk.tables.__PAGE__.txt +10 -10
- package/dist/server/out/tables/__next._full.txt +10 -10
- package/dist/server/out/tables/__next._tree.txt +2 -2
- package/dist/server/out/tables/index.html +1 -1
- package/dist/server/out/tables/index.txt +10 -10
- package/dist/server/out/webhooks/__next.!KHdvcmtzcGFjZSk.webhooks.__PAGE__.txt +10 -10
- package/dist/server/out/webhooks/__next._full.txt +10 -10
- package/dist/server/out/webhooks/__next._tree.txt +2 -2
- package/dist/server/out/webhooks/index.html +1 -1
- package/dist/server/out/webhooks/index.txt +10 -10
- package/dist/server/out/workspaces/invite/__next._full.txt +6 -6
- package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
- package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +6 -6
- package/dist/server/out/workspaces/invite/index.html +1 -1
- package/dist/server/out/workspaces/invite/index.txt +6 -6
- package/docs/browser-sessions.md +85 -0
- package/docs/npm-distribution.md +13 -11
- package/docs/remote-mcp.md +51 -0
- package/package.json +53 -20
- package/runtime/README.md +9 -7
- package/dist/runtime/generated/schema.d.ts +0 -6443
- package/dist/server/out/THIRD_PARTY_NOTICES.md +0 -13
- package/dist/server/out/_next/static/chunks/016glzdsa3q5_.js +0 -1
- package/dist/server/out/_next/static/chunks/05i1qq0mw887k.js +0 -1
- package/dist/server/out/_next/static/chunks/06tt8wiyre1ez.js +0 -1
- package/dist/server/out/_next/static/chunks/0cm9i2msjsy--.js +0 -1
- package/dist/server/out/_next/static/chunks/0hq5dvj7fy64b.js +0 -1
- package/dist/server/out/_next/static/chunks/0ma4vl-fj0tmu.js +0 -1
- package/dist/server/out/_next/static/chunks/0noal-jqjivtf.js +0 -1
- package/dist/server/out/_next/static/chunks/0spckmsiek0gd.js +0 -1
- package/dist/server/out/_next/static/chunks/103sekujf0rxr.js +0 -1
- package/dist/server/out/_next/static/chunks/10h8kpcnjfe_v.js +0 -1
- package/dist/server/out/_next/static/chunks/16_aurf9162_6.js +0 -1
- package/dist/server/out/_next/static/chunks/1c48yx15nlt6w.js +0 -1
- package/dist/server/out/_next/static/chunks/1jp827_2p_wkf.js +0 -1
- package/dist/server/out/_next/static/chunks/1kdk-viqnjs3j.js +0 -1
- package/dist/server/out/_next/static/chunks/1mlfee105fhl7.js +0 -1
- package/dist/server/out/_next/static/chunks/1q9jpzm9b6zy9.js +0 -1
- package/dist/server/out/_next/static/chunks/1v0-a7pehktp9.js +0 -22
- package/dist/server/out/_next/static/chunks/24qxhh2dqvhaa.js +0 -1
- package/dist/server/out/_next/static/chunks/253gnn8ai3i89.js +0 -1
- package/dist/server/out/_next/static/chunks/27umf0z4povug.js +0 -1
- package/dist/server/out/_next/static/chunks/2a_c2xcjy62fq.css +0 -1
- package/dist/server/out/_next/static/chunks/2mvlvogrl6o0u.js +0 -1
- package/dist/server/out/_next/static/chunks/2xzrcwr9q6195.js +0 -1
- package/dist/server/out/_next/static/chunks/2yi6lq56xoijl.js +0 -31
- package/dist/server/out/_next/static/chunks/30g0jo299pr8e.js +0 -1
- package/dist/server/out/_next/static/chunks/36tf56rgybjz0.js +0 -3
- package/dist/server/out/_next/static/chunks/39dofrhzg_uju.js +0 -1
- package/dist/server/out/_next/static/chunks/3a8aanmz3kfof.js +0 -1
- package/dist/server/out/_next/static/chunks/3bd3k15tx3lj1.js +0 -1
- package/dist/server/out/_next/static/chunks/3d34pxerfr389.js +0 -1
- package/dist/server/out/_next/static/chunks/3elab9vgx7_ok.js +0 -1
- package/dist/server/out/_next/static/chunks/3gvae9c-5pi5z.js +0 -1
- package/dist/server/out/_next/static/chunks/3hzia782sc9pf.js +0 -1
- package/dist/server/out/_next/static/chunks/3jl4k-15i8847.js +0 -1
- package/dist/server/out/_next/static/chunks/3lb23el6qno6s.js +0 -1
- package/dist/server/out/_next/static/chunks/3prum3lr5470i.js +0 -3
- package/dist/server/out/_next/static/chunks/3prwkrciuqwjg.js +0 -1
- package/dist/server/out/_next/static/chunks/3txmqtuo5xgfd.js +0 -3
- package/dist/server/out/third-party-licenses/monaco-editor.txt +0 -21
- package/dist/server/out/third-party-licenses/zod.txt +0 -21
- /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_buildManifest.js +0 -0
- /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_clientMiddlewareManifest.js +0 -0
- /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_ssgManifest.js +0 -0
package/dist/runtime/contract.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// src/contract.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
sessionCommandSchema,
|
|
5
|
+
sessionScopeSchema
|
|
6
|
+
} from "./session-job-contract.js";
|
|
7
|
+
import { connectionSchema } from "./mcp/contract.js";
|
|
3
8
|
var pluginSchema = z.object({
|
|
4
|
-
distribution: z.enum(["inline", "external"]).optional(),
|
|
9
|
+
distribution: z.enum(["inline", "external", "mcp"]).optional(),
|
|
10
|
+
mcp: connectionSchema.optional(),
|
|
5
11
|
package_url: z.string().optional(),
|
|
6
12
|
configuration: z.record(z.string(), z.unknown()).optional(),
|
|
7
13
|
credential_provider: z.string().nullable().optional(),
|
|
@@ -28,16 +34,32 @@ var agentSchema = z.object({
|
|
|
28
34
|
}).optional()
|
|
29
35
|
});
|
|
30
36
|
var jobSchema = z.object({
|
|
31
|
-
protocol_version: z.union([
|
|
37
|
+
protocol_version: z.union([
|
|
38
|
+
z.literal(1),
|
|
39
|
+
z.literal(2),
|
|
40
|
+
z.literal(3),
|
|
41
|
+
z.literal(4)
|
|
42
|
+
]),
|
|
32
43
|
run_id: z.string().uuid(),
|
|
33
44
|
workspace_id: z.number(),
|
|
34
45
|
actor_id: z.number(),
|
|
35
|
-
operation: z.enum([
|
|
46
|
+
operation: z.enum([
|
|
47
|
+
"action",
|
|
48
|
+
"chat",
|
|
49
|
+
"code",
|
|
50
|
+
"validate",
|
|
51
|
+
"test",
|
|
52
|
+
"mcp_discover",
|
|
53
|
+
"session"
|
|
54
|
+
]),
|
|
36
55
|
capability: z.string(),
|
|
37
56
|
inputs: z.record(z.string(), z.unknown()),
|
|
38
57
|
deadline: z.string(),
|
|
39
58
|
lease_seconds: z.number(),
|
|
40
59
|
snapshot: z.object({
|
|
60
|
+
mcp_discovery: connectionSchema.optional(),
|
|
61
|
+
session: sessionCommandSchema.optional(),
|
|
62
|
+
session_scope: sessionScopeSchema.optional(),
|
|
41
63
|
agents: z.array(agentSchema),
|
|
42
64
|
root_agent_id: z.string(),
|
|
43
65
|
validation_mode: z.enum(["legacy", "semantic"]).optional(),
|
|
@@ -56,11 +78,22 @@ var jobSchema = z.object({
|
|
|
56
78
|
sdk_revision: z.number().int().optional(),
|
|
57
79
|
configuration_revision: z.string().optional()
|
|
58
80
|
})
|
|
59
|
-
}).refine((job) => job.operation !== "code" || job.protocol_version === 2, {
|
|
60
|
-
message: "Code execution requires protocol version 2"
|
|
61
81
|
}).refine(
|
|
62
|
-
(job) =>
|
|
82
|
+
(job) => job.protocol_version === 4 || job.operation !== "mcp_discover" && !job.snapshot.mcp_discovery && !job.snapshot.agents.some(
|
|
83
|
+
(agent) => agent.plugins.some((plugin) => plugin.distribution === "mcp")
|
|
84
|
+
),
|
|
85
|
+
{ message: "MCP connections require protocol version 4" }
|
|
86
|
+
).refine(
|
|
87
|
+
(job) => job.operation !== "code" || [2, 4].includes(job.protocol_version),
|
|
88
|
+
{
|
|
89
|
+
message: "Code execution requires protocol version 2"
|
|
90
|
+
}
|
|
91
|
+
).refine(
|
|
92
|
+
(job) => !["validate", "test"].includes(job.operation) && job.snapshot.validation_mode !== "semantic" || [3, 4].includes(job.protocol_version),
|
|
63
93
|
{ message: "Semantic validation and tests require protocol version 3" }
|
|
94
|
+
).refine(
|
|
95
|
+
(job) => job.operation !== "session" || job.protocol_version === 4 && job.snapshot.session !== void 0 && job.snapshot.session_scope?.projectId === job.snapshot.root_agent_id && job.snapshot.session_scope.workspaceId === String(job.workspace_id) && (job.snapshot.session.operation !== "execute" || typeof job.snapshot.source === "string"),
|
|
96
|
+
{ message: "Invalid execution session job" }
|
|
64
97
|
);
|
|
65
98
|
export {
|
|
66
99
|
agentSchema,
|
|
@@ -56,7 +56,6 @@ async function boundedText(stream, kill) {
|
|
|
56
56
|
}
|
|
57
57
|
async function runIsolatedJob(job, base, sourceArguments, signal, mode = "docker") {
|
|
58
58
|
const control = new Client(base, job.capability);
|
|
59
|
-
const path = `/internal/execution/v1/runs/${job.run_id}/`;
|
|
60
59
|
let timer;
|
|
61
60
|
let deadline;
|
|
62
61
|
let cancelled = false;
|
|
@@ -123,7 +122,7 @@ async function runIsolatedJob(job, base, sourceArguments, signal, mode = "docker
|
|
|
123
122
|
timer = setInterval(() => {
|
|
124
123
|
void (async () => {
|
|
125
124
|
try {
|
|
126
|
-
const state = z.object({ cancel_requested: z.boolean(), status: z.string() }).parse(await control.
|
|
125
|
+
const state = z.object({ cancel_requested: z.boolean(), status: z.string() }).parse(await control.heartbeat(job.run_id));
|
|
127
126
|
if (state.cancel_requested || ["failed", "interrupted", "cancelled"].includes(state.status))
|
|
128
127
|
kill();
|
|
129
128
|
} catch {
|
|
@@ -155,7 +154,7 @@ async function runIsolatedJob(job, base, sourceArguments, signal, mode = "docker
|
|
|
155
154
|
} : void 0
|
|
156
155
|
}
|
|
157
156
|
};
|
|
158
|
-
await control.
|
|
157
|
+
await control.publishEvent(job.run_id, {
|
|
159
158
|
sequence: 1,
|
|
160
159
|
kind: job.operation === "validate" ? "validation.result" : "test.result",
|
|
161
160
|
data: {
|
|
@@ -164,13 +163,13 @@ async function runIsolatedJob(job, base, sourceArguments, signal, mode = "docker
|
|
|
164
163
|
diagnostics: Array.isArray(result.diagnostics) ? result.diagnostics.slice(0, 10) : []
|
|
165
164
|
}
|
|
166
165
|
});
|
|
167
|
-
await control.
|
|
166
|
+
await control.complete(job.run_id, {
|
|
168
167
|
status: passed ? "succeeded" : "failed",
|
|
169
168
|
output,
|
|
170
169
|
...passed ? {} : { error: "Validation or tests failed" }
|
|
171
170
|
});
|
|
172
171
|
} catch (error) {
|
|
173
|
-
await control.
|
|
172
|
+
await control.complete(job.run_id, {
|
|
174
173
|
status: cancelled ? "cancelled" : "failed",
|
|
175
174
|
error: error instanceof Error ? error.message.slice(0, 2e3) : "Isolated execution failed"
|
|
176
175
|
}).catch(() => void 0);
|
|
@@ -25,14 +25,19 @@ var isolatedInputSchema = z.object({
|
|
|
25
25
|
sdk: z.object({
|
|
26
26
|
plugins: z.array(
|
|
27
27
|
z.object({
|
|
28
|
+
kind: z.string().optional(),
|
|
28
29
|
namespace: z.string().nullable(),
|
|
29
30
|
available: z.boolean(),
|
|
30
31
|
metadata_complete: z.boolean().optional(),
|
|
31
32
|
tools: z.array(
|
|
32
33
|
z.object({
|
|
34
|
+
inputSchema: z.record(z.string(), z.json()).optional(),
|
|
35
|
+
outputSchema: z.record(z.string(), z.json()).nullable().optional(),
|
|
33
36
|
name: z.string(),
|
|
34
37
|
parameters: z.array(
|
|
35
38
|
z.object({
|
|
39
|
+
inputSchema: z.record(z.string(), z.json()).optional(),
|
|
40
|
+
outputSchema: z.record(z.string(), z.json()).nullable().optional(),
|
|
36
41
|
name: z.string(),
|
|
37
42
|
type: z.string(),
|
|
38
43
|
optional: z.boolean().optional()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/mcp/aliases.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { RESERVED_FUNCTION_KEYS } from "../engine/plugins/namespace.js";
|
|
4
|
+
function approveTools(tools, previous) {
|
|
5
|
+
const existing = new Map(previous.map((tool) => [tool.name, tool.alias]));
|
|
6
|
+
const claimed = new Set(previous.map((tool) => tool.alias));
|
|
7
|
+
return [...tools].sort((left, right) => {
|
|
8
|
+
if (left.name === right.name) return 0;
|
|
9
|
+
return left.name < right.name ? -1 : 1;
|
|
10
|
+
}).map((tool) => {
|
|
11
|
+
const old = existing.get(tool.name);
|
|
12
|
+
if (old) return { ...tool, alias: old };
|
|
13
|
+
const words = tool.name.replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/);
|
|
14
|
+
let alias = words.map(
|
|
15
|
+
(word, index) => index ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toLowerCase() + word.slice(1)
|
|
16
|
+
).join("").slice(0, 60);
|
|
17
|
+
if (!/^[a-z]/.test(alias)) alias = `tool${alias}`;
|
|
18
|
+
if (RESERVED_FUNCTION_KEYS.has(alias) || claimed.has(alias)) {
|
|
19
|
+
alias += createHash("sha256").update(tool.name).digest("hex").slice(0, 16);
|
|
20
|
+
}
|
|
21
|
+
if (claimed.has(alias))
|
|
22
|
+
throw new Error("Tool alias collision; rename the remote tool");
|
|
23
|
+
claimed.add(alias);
|
|
24
|
+
return { ...tool, alias };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
approveTools
|
|
29
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// src/mcp/client.ts
|
|
2
|
+
import { httpTransport } from "./transport.js";
|
|
3
|
+
import {
|
|
4
|
+
Client,
|
|
5
|
+
discoverOAuthProtectedResourceMetadata
|
|
6
|
+
} from "@modelcontextprotocol/client";
|
|
7
|
+
import Ajv from "ajv/dist/2020.js";
|
|
8
|
+
import AjvDraft7 from "ajv";
|
|
9
|
+
import Ajv2019 from "ajv/dist/2019.js";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import {
|
|
12
|
+
connectionSchema,
|
|
13
|
+
discoverySchema,
|
|
14
|
+
remoteToolSchema
|
|
15
|
+
} from "./contract.js";
|
|
16
|
+
import { endpointFetch, redactMcp } from "./network.js";
|
|
17
|
+
var argumentsSchema = z.record(z.string(), z.unknown());
|
|
18
|
+
var McpRuntime = class {
|
|
19
|
+
constructor(connection, credentials, signal, transportFactory = httpTransport) {
|
|
20
|
+
this.credentials = credentials;
|
|
21
|
+
this.transportFactory = transportFactory;
|
|
22
|
+
this.connection = connectionSchema.parse(connection);
|
|
23
|
+
this.signal = AbortSignal.any([signal, this.controller.signal]);
|
|
24
|
+
this.signal.addEventListener("abort", this.onAbort, { once: true });
|
|
25
|
+
}
|
|
26
|
+
credentials;
|
|
27
|
+
transportFactory;
|
|
28
|
+
client;
|
|
29
|
+
opening;
|
|
30
|
+
closing;
|
|
31
|
+
onAbort = () => {
|
|
32
|
+
void this.close();
|
|
33
|
+
};
|
|
34
|
+
headers = {};
|
|
35
|
+
secrets = /* @__PURE__ */ new Set();
|
|
36
|
+
lastStatus = 0;
|
|
37
|
+
challenge;
|
|
38
|
+
selected = "streamable-http";
|
|
39
|
+
controller = new AbortController();
|
|
40
|
+
validators = /* @__PURE__ */ new Map();
|
|
41
|
+
signal;
|
|
42
|
+
connection;
|
|
43
|
+
async open() {
|
|
44
|
+
this.signal.throwIfAborted();
|
|
45
|
+
this.headers = await this.credentials();
|
|
46
|
+
for (const value of Object.values(this.headers)) this.secrets.add(value);
|
|
47
|
+
this.signal.throwIfAborted();
|
|
48
|
+
const fetcher = async (input, init) => {
|
|
49
|
+
this.headers = await this.credentials();
|
|
50
|
+
for (const value of Object.values(this.headers)) this.secrets.add(value);
|
|
51
|
+
const response = await endpointFetch(
|
|
52
|
+
this.connection.endpoint,
|
|
53
|
+
this.signal,
|
|
54
|
+
this.headers
|
|
55
|
+
)(input, init);
|
|
56
|
+
this.lastStatus = response.status;
|
|
57
|
+
if ([401, 403].includes(response.status))
|
|
58
|
+
this.challenge = response.headers.get("www-authenticate") ?? void 0;
|
|
59
|
+
return response;
|
|
60
|
+
};
|
|
61
|
+
const connect = async (transport) => {
|
|
62
|
+
this.selected = transport;
|
|
63
|
+
this.lastStatus = 0;
|
|
64
|
+
this.client = new Client(
|
|
65
|
+
{ name: "orgsdk-executor", version: "0.1.1" },
|
|
66
|
+
{
|
|
67
|
+
versionNegotiation: { mode: transport === "sse" ? "legacy" : "auto" }
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
await this.client.connect(
|
|
71
|
+
this.transportFactory(this.connection.endpoint, transport, fetcher),
|
|
72
|
+
{ timeout: 15e3, signal: this.signal }
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
await connect(
|
|
77
|
+
this.connection.transport === "sse" ? "sse" : "streamable-http"
|
|
78
|
+
);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const fallback = this.connection.transport === "auto" && [404, 405].includes(this.lastStatus);
|
|
81
|
+
await this.client?.close();
|
|
82
|
+
if (!fallback) throw error;
|
|
83
|
+
await connect("sse");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async ready() {
|
|
87
|
+
this.opening ??= this.open();
|
|
88
|
+
await this.opening;
|
|
89
|
+
this.signal.throwIfAborted();
|
|
90
|
+
if (!this.client) throw new Error("MCP connection unavailable");
|
|
91
|
+
return this.client;
|
|
92
|
+
}
|
|
93
|
+
async connect() {
|
|
94
|
+
await this.ready();
|
|
95
|
+
}
|
|
96
|
+
async discover() {
|
|
97
|
+
const timer = setTimeout(
|
|
98
|
+
() => this.controller.abort(new Error("MCP discovery timed out")),
|
|
99
|
+
6e4
|
|
100
|
+
);
|
|
101
|
+
try {
|
|
102
|
+
const client = await this.ready();
|
|
103
|
+
const tools = [];
|
|
104
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
105
|
+
const names = /* @__PURE__ */ new Set();
|
|
106
|
+
let cursor;
|
|
107
|
+
do {
|
|
108
|
+
const page = await client.request(
|
|
109
|
+
{
|
|
110
|
+
method: "tools/list",
|
|
111
|
+
params: cursor !== void 0 ? { cursor } : {}
|
|
112
|
+
},
|
|
113
|
+
{ signal: this.signal, timeout: 15e3 }
|
|
114
|
+
);
|
|
115
|
+
for (const value of page.tools) {
|
|
116
|
+
const tool = remoteToolSchema.parse(value);
|
|
117
|
+
if (names.has(tool.name))
|
|
118
|
+
throw new Error("MCP server returned duplicate tool names");
|
|
119
|
+
names.add(tool.name);
|
|
120
|
+
tools.push(tool);
|
|
121
|
+
}
|
|
122
|
+
if (tools.length > 1e3 || JSON.stringify(tools).length > 5e5)
|
|
123
|
+
throw new Error("MCP tool catalogue exceeds the supported size");
|
|
124
|
+
cursor = page.nextCursor;
|
|
125
|
+
if (cursor !== void 0 && cursors.has(cursor))
|
|
126
|
+
throw new Error("MCP server repeated a discovery cursor");
|
|
127
|
+
if (cursor !== void 0) cursors.add(cursor);
|
|
128
|
+
if (cursors.size >= 100)
|
|
129
|
+
throw new Error("MCP discovery exceeded 100 pages");
|
|
130
|
+
} while (cursor !== void 0);
|
|
131
|
+
return discoverySchema.parse(
|
|
132
|
+
redactMcp({ tools, transport: this.selected }, this.redactionHeaders())
|
|
133
|
+
);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (![401, 403].includes(this.lastStatus)) throw this.safeError(error);
|
|
136
|
+
const metadataUrl = /resource_metadata="([^"]+)"/.exec(
|
|
137
|
+
this.challenge ?? ""
|
|
138
|
+
)?.[1];
|
|
139
|
+
const resourceMetadata = await discoverOAuthProtectedResourceMetadata(
|
|
140
|
+
this.connection.endpoint,
|
|
141
|
+
{
|
|
142
|
+
...metadataUrl ? { resourceMetadataUrl: new URL(metadataUrl) } : {}
|
|
143
|
+
},
|
|
144
|
+
endpointFetch(
|
|
145
|
+
this.connection.endpoint,
|
|
146
|
+
AbortSignal.any([this.signal, AbortSignal.timeout(15e3)])
|
|
147
|
+
)
|
|
148
|
+
).catch(() => void 0);
|
|
149
|
+
return discoverySchema.parse(
|
|
150
|
+
redactMcp(
|
|
151
|
+
{
|
|
152
|
+
tools: [],
|
|
153
|
+
transport: this.selected,
|
|
154
|
+
authRequired: true,
|
|
155
|
+
resourceMetadata
|
|
156
|
+
},
|
|
157
|
+
this.redactionHeaders()
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
} finally {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
inputValidator(tool) {
|
|
165
|
+
const cached = this.validators.get(tool.alias);
|
|
166
|
+
if (cached) {
|
|
167
|
+
return cached;
|
|
168
|
+
}
|
|
169
|
+
const dialect = String(tool.inputSchema.$schema);
|
|
170
|
+
const validatorClass = dialect.includes("draft-07") ? AjvDraft7 : dialect.includes("2019-09") ? Ajv2019 : Ajv;
|
|
171
|
+
const validate = new validatorClass({
|
|
172
|
+
strict: false,
|
|
173
|
+
validateFormats: false,
|
|
174
|
+
allErrors: false
|
|
175
|
+
}).compile(tool.inputSchema);
|
|
176
|
+
this.validators.set(tool.alias, validate);
|
|
177
|
+
return validate;
|
|
178
|
+
}
|
|
179
|
+
async call(alias, args) {
|
|
180
|
+
const tool = this.connection.tools.find(
|
|
181
|
+
(candidate) => candidate.alias === alias
|
|
182
|
+
);
|
|
183
|
+
if (!tool) throw new Error("Tool is outside the approved MCP catalogue");
|
|
184
|
+
try {
|
|
185
|
+
if (!this.inputValidator(tool)(args))
|
|
186
|
+
throw new Error("Arguments do not match the MCP tool input schema");
|
|
187
|
+
const client = await this.ready();
|
|
188
|
+
const result = await client.callTool(
|
|
189
|
+
{
|
|
190
|
+
name: tool.name,
|
|
191
|
+
arguments: argumentsSchema.parse(args)
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
signal: this.signal,
|
|
195
|
+
timeout: 6e4,
|
|
196
|
+
toolDefinition: {
|
|
197
|
+
...tool,
|
|
198
|
+
inputSchema: { ...tool.inputSchema, type: "object" }
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
const clean = redactMcp(result, this.redactionHeaders());
|
|
203
|
+
if (JSON.stringify(clean).length > 1e6)
|
|
204
|
+
throw new Error("MCP result exceeds the supported size");
|
|
205
|
+
if (result.isError)
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Remote MCP tool failed: ${JSON.stringify(clean).slice(0, 1500)}`
|
|
208
|
+
);
|
|
209
|
+
return clean;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
throw this.safeError(error);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
redactionHeaders() {
|
|
215
|
+
return Object.fromEntries(
|
|
216
|
+
[...this.secrets].map((secret, index) => [String(index), secret])
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
safeError(error) {
|
|
220
|
+
return new Error(
|
|
221
|
+
String(
|
|
222
|
+
redactMcp(
|
|
223
|
+
error instanceof Error ? error.message : "MCP request failed",
|
|
224
|
+
this.redactionHeaders()
|
|
225
|
+
)
|
|
226
|
+
).slice(0, 2e3)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
async close() {
|
|
230
|
+
if (this.closing) return this.closing;
|
|
231
|
+
this.signal.removeEventListener("abort", this.onAbort);
|
|
232
|
+
this.controller.abort();
|
|
233
|
+
this.closing = this.client?.close().catch(() => void 0) ?? Promise.resolve();
|
|
234
|
+
return this.closing;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
export {
|
|
238
|
+
McpRuntime
|
|
239
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/mcp/contract.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var jsonObject = z.record(z.string(), z.json());
|
|
4
|
+
var endpointSchema = z.string().url().max(2e3).refine((value) => {
|
|
5
|
+
const url = new URL(value);
|
|
6
|
+
return ["https:", "http:"].includes(url.protocol) && !url.username && !url.password && !url.hash;
|
|
7
|
+
}, "Use an HTTP(S) URL without embedded credentials or a fragment");
|
|
8
|
+
var transportSchema = z.enum(["auto", "streamable-http", "sse"]);
|
|
9
|
+
var remoteToolSchema = z.object({
|
|
10
|
+
name: z.string().min(1).max(256),
|
|
11
|
+
description: z.string().max(1e4).optional(),
|
|
12
|
+
inputSchema: jsonObject,
|
|
13
|
+
outputSchema: jsonObject.optional(),
|
|
14
|
+
annotations: jsonObject.optional()
|
|
15
|
+
}).strip();
|
|
16
|
+
var approvedToolSchema = remoteToolSchema.extend({
|
|
17
|
+
alias: z.string().regex(/^[a-z][a-zA-Z0-9]*$/).max(100)
|
|
18
|
+
});
|
|
19
|
+
var connectionSchema = z.object({
|
|
20
|
+
id: z.string().uuid(),
|
|
21
|
+
endpoint: endpointSchema,
|
|
22
|
+
transport: transportSchema,
|
|
23
|
+
revision: z.number().int().nonnegative(),
|
|
24
|
+
tools: z.array(approvedToolSchema).max(1e3)
|
|
25
|
+
});
|
|
26
|
+
var discoverySchema = z.object({
|
|
27
|
+
tools: z.array(remoteToolSchema).max(1e3),
|
|
28
|
+
transport: z.enum(["streamable-http", "sse"]),
|
|
29
|
+
authRequired: z.boolean().default(false),
|
|
30
|
+
resourceMetadata: jsonObject.optional()
|
|
31
|
+
});
|
|
32
|
+
var headerSchema = z.record(
|
|
33
|
+
z.string().regex(/^[!#$%&'*+.^_`|~0-9a-z-]+$/i),
|
|
34
|
+
z.string().max(8e3).refine((value) => !/[\r\n]/.test(value))
|
|
35
|
+
).refine(
|
|
36
|
+
(headers) => Object.keys(headers).length <= 20 && Object.keys(headers).every(
|
|
37
|
+
(name) => ![
|
|
38
|
+
"host",
|
|
39
|
+
"connection",
|
|
40
|
+
"content-length",
|
|
41
|
+
"content-type",
|
|
42
|
+
"accept",
|
|
43
|
+
"mcp-session-id",
|
|
44
|
+
"mcp-protocol-version"
|
|
45
|
+
].includes(name.toLowerCase())
|
|
46
|
+
),
|
|
47
|
+
"Unsupported authentication header"
|
|
48
|
+
);
|
|
49
|
+
export {
|
|
50
|
+
approvedToolSchema,
|
|
51
|
+
connectionSchema,
|
|
52
|
+
discoverySchema,
|
|
53
|
+
endpointSchema,
|
|
54
|
+
headerSchema,
|
|
55
|
+
remoteToolSchema,
|
|
56
|
+
transportSchema
|
|
57
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/mcp/functions.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { McpRuntime } from "./client.js";
|
|
4
|
+
import { connectionSchema, headerSchema } from "./contract.js";
|
|
5
|
+
var executionSecretSchema = z.object({
|
|
6
|
+
headers: z.unknown(),
|
|
7
|
+
expires_at: z.number().optional()
|
|
8
|
+
});
|
|
9
|
+
function mcpPlugin(plugin, client, signal) {
|
|
10
|
+
const connection = connectionSchema.parse(plugin.mcp);
|
|
11
|
+
let cached;
|
|
12
|
+
const runtime = new McpRuntime(
|
|
13
|
+
connection,
|
|
14
|
+
async () => {
|
|
15
|
+
if (!plugin.credential_id) return {};
|
|
16
|
+
if (cached && cached.expiresAt > Date.now() + 6e4)
|
|
17
|
+
return cached.headers;
|
|
18
|
+
const secret = executionSecretSchema.parse(
|
|
19
|
+
await client.secret(plugin.credential_id)
|
|
20
|
+
);
|
|
21
|
+
cached = {
|
|
22
|
+
headers: headerSchema.parse(secret.headers),
|
|
23
|
+
expiresAt: secret.expires_at ?? Number.POSITIVE_INFINITY
|
|
24
|
+
};
|
|
25
|
+
return cached.headers;
|
|
26
|
+
},
|
|
27
|
+
signal
|
|
28
|
+
);
|
|
29
|
+
const functions = connection.tools.map((tool) => ({
|
|
30
|
+
name: tool.alias,
|
|
31
|
+
category: plugin.slug,
|
|
32
|
+
calling: "named",
|
|
33
|
+
description: tool.description ?? "",
|
|
34
|
+
handler: (args) => runtime.call(tool.alias, args)
|
|
35
|
+
}));
|
|
36
|
+
return { runtime, functions };
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
mcpPlugin
|
|
40
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/mcp/network.ts
|
|
2
|
+
import { endpointSchema } from "./contract.js";
|
|
3
|
+
function endpointFetch(endpoint, signal, headers = {}, limit = 1e6) {
|
|
4
|
+
const origin = new URL(endpointSchema.parse(endpoint)).origin;
|
|
5
|
+
return async (input, init) => {
|
|
6
|
+
const request = new Request(input, init);
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
if (url.origin !== origin)
|
|
9
|
+
throw new Error(
|
|
10
|
+
"MCP request changed origin; configure the destination explicitly"
|
|
11
|
+
);
|
|
12
|
+
const authenticated = new Headers(request.headers);
|
|
13
|
+
for (const [name, value] of Object.entries(headers))
|
|
14
|
+
authenticated.set(name, value);
|
|
15
|
+
const response = await fetch(request, {
|
|
16
|
+
headers: authenticated,
|
|
17
|
+
redirect: "error",
|
|
18
|
+
signal: AbortSignal.any([signal, request.signal])
|
|
19
|
+
});
|
|
20
|
+
if (!response.body) return response;
|
|
21
|
+
let bytes = 0;
|
|
22
|
+
const body = response.body.pipeThrough(
|
|
23
|
+
new TransformStream({
|
|
24
|
+
transform(chunk, controller) {
|
|
25
|
+
bytes += chunk.byteLength;
|
|
26
|
+
if (bytes > limit)
|
|
27
|
+
throw new Error("MCP response exceeds the supported size");
|
|
28
|
+
controller.enqueue(chunk);
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
return new Response(body, {
|
|
33
|
+
status: response.status,
|
|
34
|
+
statusText: response.statusText,
|
|
35
|
+
headers: response.headers
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function redactMcp(value, headers) {
|
|
40
|
+
const secrets = Object.values(headers).flatMap((header) => [header, header.replace(/^Bearer /i, "")]).filter(Boolean);
|
|
41
|
+
const text = (input) => secrets.reduce(
|
|
42
|
+
(result, secret) => result.split(secret).join("[REDACTED]"),
|
|
43
|
+
input
|
|
44
|
+
);
|
|
45
|
+
const visit = (input) => {
|
|
46
|
+
if (typeof input === "string") return text(input);
|
|
47
|
+
if (typeof input === "number" && secrets.includes(String(input)))
|
|
48
|
+
return "[REDACTED]";
|
|
49
|
+
if (Array.isArray(input)) return input.map(visit);
|
|
50
|
+
if (input !== null && typeof input === "object")
|
|
51
|
+
return Object.fromEntries(
|
|
52
|
+
Object.entries(input).map(([key, item]) => [text(key), visit(item)])
|
|
53
|
+
);
|
|
54
|
+
return input;
|
|
55
|
+
};
|
|
56
|
+
return visit(value);
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
endpointFetch,
|
|
60
|
+
redactMcp
|
|
61
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/mcp/schema-types.ts
|
|
2
|
+
function schemaType(value, depth = 0) {
|
|
3
|
+
if (depth > 8 || !value || typeof value !== "object" || Array.isArray(value))
|
|
4
|
+
return "unknown";
|
|
5
|
+
const schema = value;
|
|
6
|
+
if (schema.$ref || schema.allOf || schema.not || schema.if) return "unknown";
|
|
7
|
+
if (Array.isArray(schema.enum) && schema.enum.length <= 50)
|
|
8
|
+
return schema.enum.map(
|
|
9
|
+
(item) => typeof item === "string" || typeof item === "boolean" || typeof item === "number" || item === null ? JSON.stringify(item) : "unknown"
|
|
10
|
+
).join(" | ") || "never";
|
|
11
|
+
const variants = schema.anyOf ?? schema.oneOf;
|
|
12
|
+
if (Array.isArray(variants))
|
|
13
|
+
return variants.length > 30 ? "unknown" : variants.map((item) => schemaType(item, depth + 1)).join(" | ") || "unknown";
|
|
14
|
+
if (Array.isArray(schema.type))
|
|
15
|
+
return schema.type.map((type) => schemaType({ ...schema, type }, depth + 1)).join(" | ");
|
|
16
|
+
if (["string", "boolean", "number", "null"].includes(String(schema.type)))
|
|
17
|
+
return String(schema.type);
|
|
18
|
+
if (schema.type === "integer") return "number";
|
|
19
|
+
if (schema.type === "array")
|
|
20
|
+
return `Array<${schemaType(schema.items, depth + 1)}>`;
|
|
21
|
+
if (schema.type === "object" || schema.properties) {
|
|
22
|
+
if (!schema.properties || typeof schema.properties !== "object" || Array.isArray(schema.properties))
|
|
23
|
+
return "Record<string, unknown>";
|
|
24
|
+
const required = new Set(
|
|
25
|
+
Array.isArray(schema.required) ? schema.required : []
|
|
26
|
+
);
|
|
27
|
+
const properties = Object.entries(schema.properties);
|
|
28
|
+
if (properties.length > 100) return "Record<string, unknown>";
|
|
29
|
+
return `{${properties.map(([key, child]) => `${JSON.stringify(key)}${required.has(key) ? "" : "?"}: ${schemaType(child, depth + 1)}`).join("; ")}${schema.additionalProperties === false ? "" : "; [key: string]: unknown"}}`;
|
|
30
|
+
}
|
|
31
|
+
return "unknown";
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
schemaType
|
|
35
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/mcp/transport.ts
|
|
2
|
+
import {
|
|
3
|
+
StreamableHTTPClientTransport,
|
|
4
|
+
SSEClientTransport
|
|
5
|
+
} from "@modelcontextprotocol/client";
|
|
6
|
+
var httpTransport = (endpoint, kind, fetcher) => kind === "sse" ? new SSEClientTransport(new URL(endpoint), { fetch: fetcher }) : new StreamableHTTPClientTransport(new URL(endpoint), {
|
|
7
|
+
fetch: fetcher,
|
|
8
|
+
reconnectionOptions: {
|
|
9
|
+
maxRetries: 0,
|
|
10
|
+
initialReconnectionDelay: 1e3,
|
|
11
|
+
maxReconnectionDelay: 1e3,
|
|
12
|
+
reconnectionDelayGrowFactor: 1
|
|
13
|
+
},
|
|
14
|
+
onInsufficientScope: "throw"
|
|
15
|
+
});
|
|
16
|
+
export {
|
|
17
|
+
httpTransport
|
|
18
|
+
};
|
|
@@ -28,7 +28,7 @@ function validJsonText(value) {
|
|
|
28
28
|
function projectDataFunctions(client, signal) {
|
|
29
29
|
const call = (operation, params) => {
|
|
30
30
|
signal.throwIfAborted();
|
|
31
|
-
return client.
|
|
31
|
+
return client.projectData(operation, params);
|
|
32
32
|
};
|
|
33
33
|
const page = (start, count) => ({
|
|
34
34
|
offset: offset.parse(start),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/register-executor.ts
|
|
2
|
+
var capabilities = ["action", "code", "validate", "test", "mcp_discover"];
|
|
3
|
+
var unsupported = 'API 400: {"detail":"Unsupported executor protocol or capability."}';
|
|
4
|
+
async function registerExecutor(client, agentId) {
|
|
5
|
+
const registration = {
|
|
6
|
+
protocol_version: 4,
|
|
7
|
+
agent_id: agentId
|
|
8
|
+
};
|
|
9
|
+
try {
|
|
10
|
+
return await client.register({
|
|
11
|
+
...registration,
|
|
12
|
+
capabilities: [...capabilities, "session"]
|
|
13
|
+
});
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (!(error instanceof Error) || error.message !== unsupported) {
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
return client.register({ ...registration, capabilities });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
registerExecutor
|
|
23
|
+
};
|