@jini-ai/agent-plugins 0.6.22 → 0.7.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/CHANGELOG.md +51 -0
- package/README.md +13 -0
- package/calendly/exports/booking-calendar.css +7 -0
- package/calendly/exports/booking-calendar.html +5 -0
- package/calendly/mcp.json +10 -0
- package/calendly/plugin.json +47 -0
- package/calendly/skills/calendly/SKILL.md +27 -0
- package/charts-echarts/plugin.json +2 -2
- package/charts-recharts/plugin.json +2 -2
- package/cloudflare/lib/cms-forms.mjs +57 -0
- package/cloudflare/lib/forms.mjs +78 -18
- package/cloudflare/lib/target.mjs +17 -4
- package/cloudflare/plugin.json +2 -2
- package/cloudflare/skills/cloudflare/SKILL.md +4 -4
- package/cloudflare/skills/cloudflare/references/workers.md +4 -4
- package/cloudflare/worker/forms-receiver.mjs +81 -41
- package/cloudflare/worker/portable-validation.mjs +220 -0
- package/commerce/plugin.json +17 -0
- package/commerce/skills/commerce/SKILL.md +23 -0
- package/composio/mcp.json +1 -1
- package/composio/plugin.json +2 -2
- package/composio/skills/composio/SKILL.md +4 -4
- package/core/commerce-server.d.ts +2 -0
- package/core/commerce-server.mjs +2 -0
- package/dist/admin-surfaces/connections/connections.d.ts +35 -0
- package/dist/admin-surfaces/connections/connections.js +135 -0
- package/dist/admin-surfaces/connections/index.d.ts +3 -0
- package/dist/admin-surfaces/connections/index.js +2 -0
- package/dist/admin-surfaces/connections/ports.d.ts +110 -0
- package/dist/admin-surfaces/connections/ports.js +2 -0
- package/dist/admin-surfaces/index.d.ts +2 -0
- package/dist/admin-surfaces/index.js +1 -0
- package/dist/admin-surfaces/plugin-state-persistence.d.ts +27 -0
- package/dist/admin-surfaces/plugin-state-persistence.js +2 -0
- package/dist/admin-surfaces/plugin-state.d.ts +51 -0
- package/dist/admin-surfaces/plugin-state.js +106 -0
- package/dist/connect/access-token-tool.d.ts +240 -0
- package/dist/connect/access-token-tool.js +213 -0
- package/dist/connect/apply-connect-defaults.d.ts +91 -0
- package/dist/connect/apply-connect-defaults.js +113 -0
- package/dist/connect/apply-tool-renames.d.ts +72 -0
- package/dist/connect/apply-tool-renames.js +105 -0
- package/dist/connect/connect-card-ui.d.ts +143 -0
- package/dist/connect/connect-card-ui.js +106 -0
- package/dist/connect/connect-destination.d.ts +35 -0
- package/dist/connect/connect-destination.js +45 -0
- package/dist/connect/connect-sign-in-wait.d.ts +31 -0
- package/dist/connect/connect-sign-in-wait.js +21 -0
- package/dist/connect/connect-tool.d.ts +314 -0
- package/dist/connect/connect-tool.js +431 -0
- package/dist/connect/connection-status.d.ts +33 -0
- package/dist/connect/connection-status.js +63 -0
- package/dist/connect/credential-cards.d.ts +15 -0
- package/dist/connect/credential-cards.js +49 -0
- package/dist/connect/credential-save-tool.d.ts +45 -0
- package/dist/connect/credential-save-tool.js +156 -0
- package/dist/connect/enable-access.d.ts +67 -0
- package/dist/connect/enable-access.js +74 -0
- package/dist/connect/executable/approval.d.ts +58 -0
- package/dist/connect/executable/approval.js +40 -0
- package/dist/connect/executable/host-capabilities.d.ts +76 -0
- package/dist/connect/executable/host-capabilities.js +100 -0
- package/dist/connect/executable/index.d.ts +10 -0
- package/dist/connect/executable/index.js +9 -0
- package/dist/connect/executable/ports.d.ts +189 -0
- package/dist/connect/executable/ports.js +2 -0
- package/dist/connect/executable/register.d.ts +21 -0
- package/dist/connect/executable/register.js +125 -0
- package/dist/connect/federate-mcp.d.ts +190 -0
- package/dist/connect/federate-mcp.js +440 -0
- package/dist/connect/grant-signed-in-defaults.d.ts +96 -0
- package/dist/connect/grant-signed-in-defaults.js +100 -0
- package/dist/connect/import-access-token.d.ts +114 -0
- package/dist/connect/import-access-token.js +103 -0
- package/dist/connect/index.d.ts +19 -0
- package/dist/connect/index.js +19 -0
- package/dist/connect/plugin-credential-card.d.ts +46 -0
- package/dist/connect/plugin-credential-card.js +63 -0
- package/dist/connect/plugin-host/index.d.ts +203 -0
- package/dist/connect/plugin-host/index.js +153 -0
- package/dist/connect/ports.d.ts +74 -0
- package/dist/connect/ports.js +2 -0
- package/dist/connect/switch-on-saved-token.d.ts +48 -0
- package/dist/connect/switch-on-saved-token.js +20 -0
- package/dist/connect/token-sign-in.d.ts +51 -0
- package/dist/connect/token-sign-in.js +43 -0
- package/dist/core/identity-namespace.d.ts +39 -0
- package/dist/core/identity-namespace.js +61 -3
- package/dist/folder-zip-node.js +3 -1
- package/dist/lifecycle/automatic-use.d.ts +12 -7
- package/dist/lifecycle/automatic-use.js +37 -28
- package/dist/lifecycle/capability-projection.js +5 -1
- package/dist/lifecycle/contribution-loader.d.ts +2 -7
- package/dist/lifecycle/contribution-types.d.ts +8 -0
- package/dist/lifecycle/contribution-types.js +2 -0
- package/dist/lifecycle/credential-card-metadata.d.ts +23 -0
- package/dist/lifecycle/credential-card-metadata.js +184 -0
- package/dist/lifecycle/exports.d.ts +11 -0
- package/dist/lifecycle/exports.js +64 -3
- package/dist/lifecycle/host-tools/identity.d.ts +38 -0
- package/dist/lifecycle/host-tools/identity.js +58 -0
- package/dist/lifecycle/host-tools/index.d.ts +20 -0
- package/dist/lifecycle/host-tools/index.js +20 -0
- package/dist/lifecycle/host-tools/memory-tools.d.ts +22 -0
- package/dist/lifecycle/host-tools/memory-tools.js +63 -0
- package/dist/lifecycle/host-tools/ports.d.ts +121 -0
- package/dist/lifecycle/host-tools/ports.js +2 -0
- package/dist/lifecycle/host-tools/provider-status-tool.d.ts +88 -0
- package/dist/lifecycle/host-tools/provider-status-tool.js +45 -0
- package/dist/lifecycle/host-tools/search-tool.d.ts +74 -0
- package/dist/lifecycle/host-tools/search-tool.js +282 -0
- package/dist/lifecycle/host-tools/skill-tool.d.ts +219 -0
- package/dist/lifecycle/host-tools/skill-tool.js +482 -0
- package/dist/lifecycle/host-tools/write-note-tool.d.ts +22 -0
- package/dist/lifecycle/host-tools/write-note-tool.js +47 -0
- package/dist/lifecycle/index.d.ts +2 -1
- package/dist/lifecycle/install.js +2 -1
- package/dist/lifecycle/installed-package-index.js +5 -8
- package/dist/lifecycle/mail/adapter-descriptors.d.ts +78 -0
- package/dist/lifecycle/mail/adapter-descriptors.js +155 -0
- package/dist/lifecycle/mail/catalog.d.ts +116 -0
- package/dist/lifecycle/mail/catalog.js +72 -0
- package/dist/lifecycle/mail/configuration.d.ts +25 -0
- package/dist/lifecycle/mail/configuration.js +62 -0
- package/dist/lifecycle/mail/contribution.d.ts +89 -0
- package/dist/lifecycle/mail/contribution.js +115 -0
- package/dist/lifecycle/mail/host-mailer.d.ts +24 -0
- package/dist/lifecycle/mail/host-mailer.js +10 -0
- package/dist/lifecycle/mail/index.d.ts +16 -0
- package/dist/lifecycle/mail/index.js +16 -0
- package/dist/lifecycle/mail/selection.d.ts +40 -0
- package/dist/lifecycle/mail/selection.js +86 -0
- package/dist/lifecycle/manifest.d.ts +7 -2
- package/dist/lifecycle/manifest.js +32 -9
- package/dist/lifecycle/metadata.d.ts +31 -0
- package/dist/lifecycle/metadata.js +80 -0
- package/dist/lifecycle/persistent-state.js +2 -1
- package/dist/lifecycle/ports.d.ts +2 -0
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.js +14 -8
- package/dist/lifecycle/search-projection.d.ts +3 -4
- package/dist/lifecycle/search-projection.js +5 -7
- package/dist/lifecycle/search.js +3 -2
- package/fly/plugin.json +5 -5
- package/fly/skills/fly/SKILL.md +1 -1
- package/formspree/plugin.json +7 -0
- package/formspree/skills/formspree/SKILL.md +11 -0
- package/github/plugin.json +2 -2
- package/github/skills/github/SKILL.md +28 -28
- package/github/skills/github/references/actions.md +8 -8
- package/github/skills/github/references/auth-and-tokens.md +7 -7
- package/github/skills/github/references/repo-files.md +5 -5
- package/github/skills/github/references/site-backup.md +16 -16
- package/github/skills/github/references/source-control.md +17 -17
- package/github-pages/plugin.json +2 -2
- package/github-pages/skills/github-pages/SKILL.md +3 -3
- package/google-forms/plugin.json +7 -0
- package/google-forms/skills/google-forms/SKILL.md +15 -0
- package/google-login/plugin.json +3 -3
- package/google-login/skills/google-login/SKILL.md +17 -60
- package/google-workspace/plugin.json +6 -6
- package/google-workspace/skills/google-workspace/references/connection.md +1 -1
- package/google-workspace/skills/google-workspace/references/form-delivery.md +4 -4
- package/google-workspace/tovu-admin-surfaces.json +5 -5
- package/higgsfield-media/plugin.json +5 -5
- package/higgsfield-media/skills/higgsfield-media/SKILL.md +31 -33
- package/higgsfield-media/skills/higgsfield-media/references/failure-modes.md +7 -7
- package/higgsfield-media/skills/higgsfield-media/references/models-and-plan-gates.md +3 -3
- package/jev/plugin.json +2 -2
- package/langfuse/plugin.json +2 -2
- package/meilisearch/plugin.json +2 -2
- package/meilisearch/skills/meilisearch/SKILL.md +1 -1
- package/netlify/plugin.json +2 -2
- package/netlify/skills/netlify/SKILL.md +3 -3
- package/opentelemetry/plugin.json +2 -2
- package/opentelemetry/skills/opentelemetry/SKILL.md +7 -7
- package/package.json +92 -14
- package/posthog/plugin.json +2 -2
- package/posthog/skills/posthog/SKILL.md +7 -7
- package/railway/plugin.json +3 -3
- package/railway/skills/railway/SKILL.md +10 -11
- package/render/plugin.json +3 -3
- package/render/skills/render/SKILL.md +7 -8
- package/resend/NOTES.md +2 -2
- package/resend/mcp.json +1 -1
- package/resend/plugin.json +5 -5
- package/resend/skills/resend/SKILL.md +13 -13
- package/s3-compatible/plugin.json +2 -2
- package/s3-compatible/skills/s3-compatible/SKILL.md +4 -4
- package/sentry/plugin.json +2 -2
- package/sentry/skills/sentry/SKILL.md +7 -7
- package/shopify/plugin.json +2 -2
- package/site-compliance/plugin.json +2 -2
- package/site-compliance/skills/site-compliance/SKILL.md +3 -3
- package/site-compliance/skills/site-compliance/references/gdpr-eu-uk.md +1 -1
- package/site-import/plugin.json +2 -2
- package/slide-design/plugin.json +2 -2
- package/software-engineering/LICENSE +201 -0
- package/software-engineering/NOTICE +9 -0
- package/software-engineering/README.md +89 -0
- package/software-engineering/plugin.json +24 -0
- package/software-engineering/skills/software-engineering/SKILL.md +33 -0
- package/software-engineering/skills/software-engineering/references/debugging.md +54 -0
- package/software-engineering/skills/software-engineering/references/implementation.md +27 -0
- package/software-engineering/skills/software-engineering/references/planning.md +27 -0
- package/software-engineering/skills/software-engineering/references/prototyping.md +14 -0
- package/software-engineering/skills/software-engineering/references/security.md +47 -0
- package/software-engineering/skills/software-engineering/references/verification.md +53 -0
- package/stripe/plugin.json +2 -2
- package/supabase/mcp.json +4 -4
- package/supabase/plugin.json +3 -3
- package/supabase/skills/supabase/SKILL.md +8 -8
- package/supabase/skills/supabase/references/failure-modes.md +5 -5
- package/ui-ux-design/plugin.json +2 -2
- package/vercel/plugin.json +2 -2
- package/vercel/skills/vercel/SKILL.md +3 -3
- package/wordpress/plugin.json +2 -2
- package/wordpress/skills/wordpress/SKILL.md +3 -3
- package/wordpress/skills/wordpress/references/free-site-redirect.md +2 -2
- package/wordpress/skills/wordpress/references/subdomain.md +5 -5
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Phase 4 of the 2026-09-10 plugin-MCP-wiring work: PROVISIONS an activated Agent Plugin's
|
|
3
|
+
* auto-admitted remote MCP servers as real rows in the SAME external-MCP store
|
|
4
|
+
* (`features/external-mcp/external-mcp-store.ts`) Settings → External MCP already owns — reusing that path
|
|
5
|
+
* rather than building a parallel one. A provisioned row appears in Settings → External MCP exactly
|
|
6
|
+
* like an operator-typed one: the same allowlist/"may write" tool picker, the same enable toggle,
|
|
7
|
+
* the same revoke button. There is no second, plugin-only registration path.
|
|
8
|
+
*
|
|
9
|
+
* ---------------------------------------------------------------------------
|
|
10
|
+
* 2026-09-10, owner refinement — three collision rules, and why each exists
|
|
11
|
+
* ---------------------------------------------------------------------------
|
|
12
|
+
* A `higgsfield` row already exists on the live dev site with connected OAuth tokens, an allowlist,
|
|
13
|
+
* and write grants — created by hand, by an operator following the bundled skill's old instructions,
|
|
14
|
+
* before this file existed. That row is the concrete case every rule below defends:
|
|
15
|
+
*
|
|
16
|
+
* 1. **NEVER CLOBBER AN EXISTING ROW — ADOPT IT INSTEAD.** {@link provisionAgentPluginMcpServers}
|
|
17
|
+
* calls `deps.repo.findByServerId` BEFORE ever calling {@link saveExternalMcpServer}. A row
|
|
18
|
+
* already at the derived id is NEVER passed through {@link saveExternalMcpServer} — no field an
|
|
19
|
+
* operator or an earlier boot wrote (url, transport, auth mode, allowlist, write grants, any
|
|
20
|
+
* oauth/sealed column) is ever recomputed or overwritten here. This is why
|
|
21
|
+
* {@link deriveAgentPluginConnectionId} below no longer hashes or namespaces the id: an id
|
|
22
|
+
* genuinely equal to what an operator would have hand-typed (the plugin's own declared server
|
|
23
|
+
* key, e.g. `higgsfield`) is what lets this rule recognize the ACTUAL pre-existing row, rather
|
|
24
|
+
* than shadowing it with a second, uniquely-derived connection beside it. There is deliberately no
|
|
25
|
+
* hash-suffixed fallback id — one id, verbatim, always; a vendor's own SKILL.md documents
|
|
26
|
+
* `mcp__<serverKey>__<tool>` and cannot predict any suffix the host might mint, so a fallback scheme
|
|
27
|
+
* would defeat the exact "no guessing" goal this feature exists for.
|
|
28
|
+
*
|
|
29
|
+
* A row already at that id splits into two cases, neither of which ever calls
|
|
30
|
+
* `saveExternalMcpServer`:
|
|
31
|
+
* - `provisionedByPluginId === input.pluginId` — this same plugin provisioned it on an earlier
|
|
32
|
+
* enable; nothing has changed. Reported {@link ProvisionAgentPluginMcpServersResult
|
|
33
|
+
* .alreadyProvisioned}.
|
|
34
|
+
* - anything else (`null`, or a DIFFERENT plugin's id) — an operator's own hand-configured
|
|
35
|
+
* connection (with its earned OAuth tokens, allowlist, and write grants), or another plugin's
|
|
36
|
+
* row. This is ADOPTION: `deps.repo.upsert({ ...existing, provisionedByPluginId: input.pluginId })`
|
|
37
|
+
* is called directly against the repo port — the raw record, spread, with only that one field
|
|
38
|
+
* changed — never `saveExternalMcpServer`, which has no way to leave every other field
|
|
39
|
+
* untouched while changing just this one (even its "tri-state" fields resolve a default the
|
|
40
|
+
* caller must supply). Reported {@link ProvisionAgentPluginMcpServersResult.adopted}. The
|
|
41
|
+
* operator's own configuration and any live tokens always outrank a package's declaration —
|
|
42
|
+
* that is this rule, applied to the id-collision case specifically.
|
|
43
|
+
* - EXCEPT a row owned by a DIFFERENT plugin whose url, transport, or auth mode DIFFERS from the
|
|
44
|
+
* declaration — a different server whose key merely normalized to the same id. Rewriting that
|
|
45
|
+
* plugin's provenance would leave calls for this plugin pointing at the other plugin's
|
|
46
|
+
* endpoint, so the collision is refused, never adopted, and reported
|
|
47
|
+
* {@link ProvisionAgentPluginMcpServersResult.failed}. Two plugins declaring the identical key
|
|
48
|
+
* AND endpoint therefore share one row (whichever enabled most recently owns
|
|
49
|
+
* `provisionedByPluginId`); two declaring the same key but different endpoints do not. An
|
|
50
|
+
* operator's row (`provisionedByPluginId === null`) is still adopted unconditionally — the
|
|
51
|
+
* operator typed the endpoint they wanted, so recording the association is not a rewrite of
|
|
52
|
+
* another plugin's provenance.
|
|
53
|
+
* KNOWN RACE: the existence check and the create/adopt are not one atomic operation (no
|
|
54
|
+
* compare-and-set primitive exists on `ExternalMcpServerRepoPort` today, unlike
|
|
55
|
+
* `tryClaimOAuthRefreshLease`'s purpose-built one). Two concurrent provisioning attempts for the
|
|
56
|
+
* SAME id are harmless — creation races write the identical disabled/empty-allowlist config, and
|
|
57
|
+
* adoption races both write the same one field. A provisioning attempt racing an operator's
|
|
58
|
+
* concurrent hand-edit of the same id is the one real gap, and it is the same class of risk any two
|
|
59
|
+
* concurrent saves to this store already have — not a new one, but also not eliminated by this
|
|
60
|
+
* file. Closing it fully needs a new repo primitive, deliberately not added here as disproportionate
|
|
61
|
+
* to this feature's scope.
|
|
62
|
+
*
|
|
63
|
+
* 1b. **EXCEPT A STALE ROW THIS SAME PLUGIN PROVISIONED AND NOBODY USED.** When a plugin update
|
|
64
|
+
* changes a server's url or auth mode, a row the plugin provisioned earlier is re-provisioned from
|
|
65
|
+
* the new declaration (deleted, then saved fresh) — but only while it is still exactly what
|
|
66
|
+
* provisioning left behind: never enabled, both tool lists empty. Otherwise the new url could
|
|
67
|
+
* never reach an existing site, and `apply-connect-defaults.ts` (which grants defaults only when
|
|
68
|
+
* the row's url equals the declared one) would never fire there. Any sign-in state on such a row
|
|
69
|
+
* was minted for the old endpoint and is dropped with it. A saved access token on a server that
|
|
70
|
+
* declares `tokenAuth` counts as the declared auth mode, so it is only dropped when the url
|
|
71
|
+
* itself changes. A row that is enabled or has any tool
|
|
72
|
+
* granted is the operator's, and stays byte-identical as above.
|
|
73
|
+
*
|
|
74
|
+
* 2. **SEED DISABLED, LIKE BUNDLED PLUGINS ALREADY DO.** Mirrors `activation.ts`'s
|
|
75
|
+
* `recordBundledAgentPluginIfAbsent`: idempotent, create-if-absent, and — because rule 1 already
|
|
76
|
+
* means an existing row is never revisited — a row this file created is never re-enabled by a
|
|
77
|
+
* later boot or a later plugin toggle either. `enabled: false` is passed on the ONE
|
|
78
|
+
* {@link saveExternalMcpServer} call that creates a brand-new row; there is no code path here that
|
|
79
|
+
* ever sets `enabled: true` on any row, new or existing.
|
|
80
|
+
*
|
|
81
|
+
* 3. **PROVISIONING IS NOT AUTHORIZATION.** `allowedToolNames`/`writeAllowedToolNames` are always
|
|
82
|
+
* `""` on a newly created row, even though a plugin's `mcp.json`/skill content might suggest
|
|
83
|
+
* names. A downloaded marketplace package must not be able to grant itself tool access — the same
|
|
84
|
+
* trust argument Phase 3's stdio split makes, applied here to the allowlist instead of to
|
|
85
|
+
* execution. The operator ticks tools in Settings → External MCP's picker, which already lets
|
|
86
|
+
* them choose from a live, server-advertised list (`probe.ts`) rather than guessing names. The one
|
|
87
|
+
* other writer is the operator's own first sign-in, which grants the plugin's declared
|
|
88
|
+
* `defaultTools` to a still-empty row (`apply-connect-defaults.ts`) — the sign-in, not this
|
|
89
|
+
* file, is what authorizes.
|
|
90
|
+
*
|
|
91
|
+
* ---------------------------------------------------------------------------
|
|
92
|
+
* What happens on plugin disable or uninstall: THE ROW SURVIVES
|
|
93
|
+
* ---------------------------------------------------------------------------
|
|
94
|
+
* Nothing in this file, and nothing this dispatch added to `set-enabled.ts` or
|
|
95
|
+
* `features/agent-plugins/uninstall.ts`, ever deletes or disables a provisioned row when its plugin
|
|
96
|
+
* is turned off or removed. This is a deliberate position, not an oversight: a provisioned row may
|
|
97
|
+
* already hold OAuth tokens the operator earned through a real browser sign-in, and deleting an
|
|
98
|
+
* external MCP connection is UNRECOVERABLE in this app (`project_external_mcp_delete_is_unrecoverable`
|
|
99
|
+
* — no soft-delete, no undo). Silently destroying that on a disable/uninstall would be a strictly
|
|
100
|
+
* worse failure mode than leaving an inert, disabled row behind. `provisioned_by_plugin_id`
|
|
101
|
+
* (`schema.sqlite.ts`) records which plugin created a surviving row, so a FUTURE uninstall flow can offer
|
|
102
|
+
* to remove it explicitly — an operator decision, never an automatic side effect of this file.
|
|
103
|
+
*
|
|
104
|
+
* ---------------------------------------------------------------------------
|
|
105
|
+
* What this does NOT do
|
|
106
|
+
* ---------------------------------------------------------------------------
|
|
107
|
+
* - Never touches a `stdio` server. `classifyAgentPluginMcpServerTrust` (`capability-projection.ts`)
|
|
108
|
+
* is consulted first, and only an `"auto-admit"` (remote) server ever reaches
|
|
109
|
+
* {@link saveExternalMcpServer}. There is no code path in this file that can launch a local
|
|
110
|
+
* process on a plugin's say-so — see Phase 3's own gate for the full argument.
|
|
111
|
+
* - Never completes an OAuth handshake. `authMode: "oauth"` rows still need the operator's own
|
|
112
|
+
* browser-interactive consent (Higgsfield's authorization_code + PKCE flow has no other kind) —
|
|
113
|
+
* this file only makes sure the row EXISTS with the right URL and transport so that consent step
|
|
114
|
+
* is the operator's only remaining action.
|
|
115
|
+
* - Does not run at request time and makes no live network call. Only the row's own data is
|
|
116
|
+
* written. The daemon's boot-time federation read (`resolveStoredExternalMcpConnections`) is what
|
|
117
|
+
* actually connects, and per that module's own doc, requires an assistant restart to pick up a
|
|
118
|
+
* newly-provisioned (and since-enabled) row.
|
|
119
|
+
*
|
|
120
|
+
* ---------------------------------------------------------------------------
|
|
121
|
+
* Why authMode defaults to "none", not "oauth"
|
|
122
|
+
* ---------------------------------------------------------------------------
|
|
123
|
+
* The real Agent Plugins v1.0.0 mcp.schema.json defines NO auth field at all (verified live,
|
|
124
|
+
* 2026-09-10 — see `manifest.ts`'s header). Guessing "oauth" for every remote server would attempt
|
|
125
|
+
* RFC 8414 discovery against a plugin's server even when it needs no auth at all, failing where a
|
|
126
|
+
* plain connection would have worked. `"none"` is the safe default; a plugin author who KNOWS their
|
|
127
|
+
* server requires OAuth (Higgsfield's own `mcp.json` does) sets the `authMode` extension
|
|
128
|
+
* (`manifest.ts`) to say so explicitly.
|
|
129
|
+
*/
|
|
130
|
+
/** `mcp-federation/trust.ts`'s `CONNECTION_ID_PATTERN` caps a connection id at 40 characters. */
|
|
131
|
+
const MAX_CONNECTION_ID_LENGTH = 40;
|
|
132
|
+
/**
|
|
133
|
+
* Derives the `external_mcp_servers.serverId` one plugin-declared server maps to: its OWN declared
|
|
134
|
+
* server key (the `mcp.json` object member name), sanitized into `CONNECTION_ID_PATTERN`'s
|
|
135
|
+
* `[a-z0-9][a-z0-9-]{0,39}` charset — lowercased, every run of other characters collapsed to one
|
|
136
|
+
* `-`, leading/trailing `-` trimmed, truncated to 40.
|
|
137
|
+
*
|
|
138
|
+
* Deliberately NOT namespaced by `pluginId` and NOT hash-suffixed (an earlier revision of this file
|
|
139
|
+
* did both, for collision safety) — see this file's header, rule 1: the id must equal what an
|
|
140
|
+
* operator would have hand-typed, because matching that exact id is what lets a pre-existing,
|
|
141
|
+
* hand-configured row (e.g. `higgsfield`) be recognized and left untouched rather than shadowed by a
|
|
142
|
+
* second, uniquely-derived connection beside it.
|
|
143
|
+
*
|
|
144
|
+
* @returns The derived id, or `null` when the server key sanitizes to nothing usable (e.g. a key
|
|
145
|
+
* made entirely of characters outside `[a-z0-9-]`) — reported as a skip by
|
|
146
|
+
* {@link classifyAgentPluginMcpServerForFederation}, never thrown.
|
|
147
|
+
* @complexity O(n) in the server key's length.
|
|
148
|
+
*/
|
|
149
|
+
export function deriveAgentPluginConnectionId({ serverKey }, _optional = {}) {
|
|
150
|
+
const sanitized = serverKey
|
|
151
|
+
.toLowerCase()
|
|
152
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
153
|
+
.replace(/^-|-$/g, "")
|
|
154
|
+
.slice(0, MAX_CONNECTION_ID_LENGTH)
|
|
155
|
+
.replace(/-$/, "");
|
|
156
|
+
return sanitized.length > 0 ? sanitized : null;
|
|
157
|
+
}
|
|
158
|
+
/** One server's classification result — either it is planned for provisioning, or it is skipped
|
|
159
|
+
* with a reason. Split out of {@link planAgentPluginMcpFederation}'s loop so that function has
|
|
160
|
+
* exactly one branch point per entry instead of several sequential early-exits.
|
|
161
|
+
*
|
|
162
|
+
* Narrows on the server's OWN `type` first — not merely on `classifyAgentPluginMcpServerTrust`'s
|
|
163
|
+
* return value — so `config.url` below is real TypeScript narrowing, not an assertion. The
|
|
164
|
+
* classifier is still consulted right after: if its rule ever changes to reclassify a remote
|
|
165
|
+
* transport as "requires-confirmation" without this file being updated to match, that mismatch is
|
|
166
|
+
* caught here and refused rather than silently auto-wired against stale reasoning.
|
|
167
|
+
*
|
|
168
|
+
* @complexity O(1).
|
|
169
|
+
*/
|
|
170
|
+
function classifyAgentPluginMcpServerForFederation(serverKey, config, classifyTrust, messages) {
|
|
171
|
+
if (config.type === "stdio") {
|
|
172
|
+
return { kind: "skip", reason: "declares a 'stdio' local process — requires explicit operator confirmation, never auto-wired from a plugin" };
|
|
173
|
+
}
|
|
174
|
+
if (classifyTrust(config) !== "auto-admit") {
|
|
175
|
+
return {
|
|
176
|
+
kind: "skip",
|
|
177
|
+
reason: "this server's trust classification is not 'auto-admit' — refusing to wire it until this file is re-verified against classifyAgentPluginMcpServerTrust's current rule",
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (config.type === "sse") {
|
|
181
|
+
return {
|
|
182
|
+
kind: "skip",
|
|
183
|
+
reason: messages.sseTransportUnsupported(),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// `headers` is validated and preserved by `manifest.ts` but has no column in the external-MCP
|
|
187
|
+
// store, so a non-empty set would otherwise vanish without a skip, warning, or failure. Refuse it
|
|
188
|
+
// explicitly rather than silently provisioning a row that omits configuration the plugin declared —
|
|
189
|
+
// and never copy a header that may carry authorization material into a row this store cannot seal.
|
|
190
|
+
if (config.headers !== undefined && Object.keys(config.headers).length > 0) {
|
|
191
|
+
return {
|
|
192
|
+
kind: "skip",
|
|
193
|
+
reason: messages.headersUnsupported(),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const connectionId = deriveAgentPluginConnectionId({ serverKey });
|
|
197
|
+
if (connectionId === null) {
|
|
198
|
+
return { kind: "skip", reason: `server key '${serverKey}' has no valid characters to derive a connection id from` };
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
kind: "upsert",
|
|
202
|
+
planned: { connectionId, serverKey, url: config.url, authMode: config.authMode ?? "none", acceptsAccessToken: config.tokenAuth !== undefined },
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Pure classification pass over one plugin's full mcp.json server configs — no I/O, no
|
|
207
|
+
* `saveExternalMcpServer` call, so this is independently testable from the store's own DB-shaped
|
|
208
|
+
* dependencies.
|
|
209
|
+
*
|
|
210
|
+
* @complexity O(s) in the declared server count.
|
|
211
|
+
*/
|
|
212
|
+
export function planAgentPluginMcpFederation(input, options) {
|
|
213
|
+
const classifyTrust = options.classifyTrust;
|
|
214
|
+
const toUpsert = [];
|
|
215
|
+
const skipped = [];
|
|
216
|
+
for (const [serverKey, config] of Object.entries(input.servers)) {
|
|
217
|
+
const result = classifyAgentPluginMcpServerForFederation(serverKey, config, classifyTrust, options.messages);
|
|
218
|
+
if (result.kind === "upsert")
|
|
219
|
+
toUpsert.push(result.planned);
|
|
220
|
+
else
|
|
221
|
+
skipped.push({ serverKey, reason: result.reason });
|
|
222
|
+
}
|
|
223
|
+
return { toUpsert, skipped };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Resolves one installed plugin's full, validated `mcp.json` server configs, given only its
|
|
227
|
+
* `workspaceId`/`pluginId` — the pair a route naturally has, rather than the `packageRoot`
|
|
228
|
+
* `readInstalledMcpServers` actually needs (`AgentPluginSearchCandidate`, the admin route's own read
|
|
229
|
+
* model, deliberately never carries `packageRoot`: an absolute host path, per
|
|
230
|
+
* `tool-registrations.ts`'s own header). Mirrors the identical `listInstalledPlugins` lookup
|
|
231
|
+
* `set-enabled.ts`'s `setAgentPluginEnabled` already performs for its own installed-check — kept as
|
|
232
|
+
* an independent, small duplication rather than widening that function's settled, tested return
|
|
233
|
+
* shape just to smuggle a path through it.
|
|
234
|
+
*
|
|
235
|
+
* @returns `{}` for a plugin id not installed in this workspace — the caller (a route that already
|
|
236
|
+
* 404s on that condition via `setAgentPluginEnabled`'s own precondition) never actually reaches this
|
|
237
|
+
* case, but this function fails closed rather than throwing a second, redundant error for it.
|
|
238
|
+
* @complexity O(d) in installed-digest count, plus one `mcp.json` read.
|
|
239
|
+
*/
|
|
240
|
+
export async function resolveAgentPluginMcpServers(input, _optional = {}) {
|
|
241
|
+
const workspaceLayout = input.agentPluginLayout.forWorkspace(input.workspaceId);
|
|
242
|
+
// A bundled plugin that was upgraded in place has its superseded package dropped here, so the
|
|
243
|
+
// servers this provisions come from the digest the running build published rather than whichever
|
|
244
|
+
// one the directory walk happened to reach first (`bundled-digests.ts`).
|
|
245
|
+
const bundledDigests = await input.lifecycle.readBundledAgentPluginDigests({ workspaceRoot: workspaceLayout.root });
|
|
246
|
+
if (input.bundledOnly && !bundledDigests.has(input.pluginId))
|
|
247
|
+
return {};
|
|
248
|
+
const installed = input.lifecycle.preferBundledAgentPluginDigests({
|
|
249
|
+
installed: await input.lifecycle.listInstalledPlugins({ workspaceRoot: workspaceLayout.root }),
|
|
250
|
+
bundled: bundledDigests,
|
|
251
|
+
});
|
|
252
|
+
const plugin = installed.find((candidate) => candidate.pluginId === input.pluginId);
|
|
253
|
+
if (input.bundledOnly && plugin?.archiveDigest !== bundledDigests.get(input.pluginId))
|
|
254
|
+
return {};
|
|
255
|
+
return plugin ? input.lifecycle.readInstalledMcpServers({ packageRoot: plugin.packageRoot }) : {};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Matches a declaration to the stored server identity AND exact endpoint. A URL edit or
|
|
259
|
+
* normalized-name collision must never inherit another endpoint's defaults.
|
|
260
|
+
* @returns The matching defaults, or `null`.
|
|
261
|
+
* @complexity O(s) time, O(1) space in declared servers.
|
|
262
|
+
*/
|
|
263
|
+
export function findAgentPluginMcpServerDefaults(servers, row) {
|
|
264
|
+
for (const [serverKey, config] of Object.entries(servers)) {
|
|
265
|
+
if (config.type === "stdio" || deriveAgentPluginConnectionId({ serverKey }) !== row.serverId)
|
|
266
|
+
continue;
|
|
267
|
+
return config.url === row.url ? config.defaultTools ?? null : null;
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Reads the bundled plugin's current manifest on every roster load. Only a build-seeded
|
|
273
|
+
* digest supplies read trust; URL-only connections and arbitrary installed packages cannot.
|
|
274
|
+
* @returns Reviewed remote names for this exact stored endpoint, otherwise an empty set.
|
|
275
|
+
* @complexity One installed-package scan and manifest read, plus O(s + r) matching/list conversion.
|
|
276
|
+
*/
|
|
277
|
+
export async function resolveAgentPluginReadOnlyRemoteNames(input, _optional = {}) {
|
|
278
|
+
const servers = await resolveAgentPluginMcpServers({ ...input, bundledOnly: true });
|
|
279
|
+
return new Set(findAgentPluginMcpServerDefaults(servers, input)?.read ?? []);
|
|
280
|
+
}
|
|
281
|
+
/** Builds the ONE-TIME creation input for a planned server that rule 1's existence check already
|
|
282
|
+
* confirmed has no row yet. Split out of {@link provisionAgentPluginMcpServers} purely to keep that
|
|
283
|
+
* function's complexity under the shop ceiling. `enabled: false` and empty allowlists are rules 2
|
|
284
|
+
* and 3 — see this file's header. */
|
|
285
|
+
function buildProvisioningSaveInput(planned, input) {
|
|
286
|
+
return {
|
|
287
|
+
workspaceId: input.workspaceId,
|
|
288
|
+
serverId: planned.connectionId,
|
|
289
|
+
label: `${input.pluginId} · ${planned.serverKey}`,
|
|
290
|
+
transport: "streamable_http",
|
|
291
|
+
authMode: planned.authMode,
|
|
292
|
+
enabled: false,
|
|
293
|
+
command: "",
|
|
294
|
+
url: planned.url,
|
|
295
|
+
args: "",
|
|
296
|
+
allowedToolNames: "",
|
|
297
|
+
writeAllowedToolNames: "",
|
|
298
|
+
// A brand-new oauth row structurally REQUIRES a grant (`external-mcp-store.ts`'s
|
|
299
|
+
// `assertOAuthGrant`) even though nothing else is set — `authorization_code` is the only grant
|
|
300
|
+
// The host's own RFC 8414/7591 discovery-then-DCR flow can complete without a device-code endpoint,
|
|
301
|
+
// which the Agent Plugins spec has no field to declare anyway.
|
|
302
|
+
...(planned.authMode === "oauth" ? { oauth: { grant: "authorization_code" } } : {}),
|
|
303
|
+
principalId: input.principalId,
|
|
304
|
+
provisionedByPluginId: input.pluginId,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Whether a row this same plugin provisioned still sits at an endpoint or auth mode the plugin no
|
|
308
|
+
* longer declares AND nobody has used it yet (never enabled, both tool lists empty, no saved
|
|
309
|
+
* secret). Such a row holds nothing an operator chose, only provisioning's own defaults plus, at
|
|
310
|
+
* most, a registered OAuth client minted for the OLD endpoint, which must not carry over to the new
|
|
311
|
+
* one. It is re-provisioned from the current declaration (rule 1b in this file's header).
|
|
312
|
+
* @complexity O(1) plus two short JSON parses. */
|
|
313
|
+
function isStaleUntouchedProvisioning({ existing, planned, projections }, _options = {}) {
|
|
314
|
+
// Saved tokens (OAuth or a pasted access token) mean someone signed in: the row may differ from
|
|
315
|
+
// the declaration because an operator edited its URL or auth mode, and deleting it would throw
|
|
316
|
+
// away those edits and the sign-in (Gemini triage T15).
|
|
317
|
+
if (existing.sealedOAuth)
|
|
318
|
+
return false;
|
|
319
|
+
// A saved access token on a server that declares token sign-in is that declaration in use, not a
|
|
320
|
+
// changed auth mode: treating it as stale deleted the token whenever the row was still disabled
|
|
321
|
+
// (e.g. saved while an operator keeps the plugin off) — Codex review 2026-09-29.
|
|
322
|
+
const authModeMatches = existing.authMode === planned.authMode || (planned.acceptsAccessToken && projections.hasStaticAccessToken(existing));
|
|
323
|
+
const declarationChanged = existing.url !== planned.url || !authModeMatches;
|
|
324
|
+
return declarationChanged && !existing.enabled && isEmptyJsonList({ raw: existing.allowedToolNames }) && isEmptyJsonList({ raw: existing.writeAllowedToolNames });
|
|
325
|
+
}
|
|
326
|
+
/** A stored JSON tool list that is null, blank, `[]`, or unreadable (the store reads those as `[]`).
|
|
327
|
+
* Shared with `apply-connect-defaults.ts`. */
|
|
328
|
+
export function isEmptyJsonList({ raw }, _optional = {}) {
|
|
329
|
+
if (!raw)
|
|
330
|
+
return true;
|
|
331
|
+
try {
|
|
332
|
+
const parsed = JSON.parse(raw);
|
|
333
|
+
return !Array.isArray(parsed) || parsed.length === 0;
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** One outcome of handling a planned server for which rule 1's existence check found a row already
|
|
340
|
+
* present. `alreadyProvisioned` and `adopted` leave every field but `provisionedByPluginId`
|
|
341
|
+
* untouched (see this file's header); `failed` reports either a refused collision (a DIFFERENT
|
|
342
|
+
* plugin's row whose endpoint/transport/auth differ from this declaration) or an upsert error. Split
|
|
343
|
+
* out of {@link provisionAgentPluginMcpServers} purely to keep that function's complexity under the
|
|
344
|
+
* shop ceiling: the loop gets exactly one branch point per planned server instead of a nested
|
|
345
|
+
* try/catch inline.
|
|
346
|
+
* @complexity O(1) plus at most one `repo.upsert` for the adoption case. */
|
|
347
|
+
async function adoptOrRecognizeExistingAgentPluginMcpServer(deps, existing, planned, pluginId) {
|
|
348
|
+
if (existing.provisionedByPluginId === pluginId) {
|
|
349
|
+
return { kind: isStaleUntouchedProvisioning({ existing, planned, projections: deps.projections }) ? "stale" : "alreadyProvisioned" };
|
|
350
|
+
}
|
|
351
|
+
// The connection id is unnamespaced and normalized, so a row already owned by a DIFFERENT plugin
|
|
352
|
+
// may belong to a different server whose key merely sanitized to the same id. Adopting it would
|
|
353
|
+
// rewrite that plugin's provenance while the endpoint stayed put — calls this plugin expects at
|
|
354
|
+
// `mcp__<serverKey>__*` would still reach the other plugin's server (finding 5-2). Such a collision
|
|
355
|
+
// is adopted only when the declared endpoint, transport, and auth mode match exactly; otherwise it
|
|
356
|
+
// is refused and reported, never silently rebound. An operator's own row (`provisionedByPluginId
|
|
357
|
+
// === null`) is still adopted unconditionally: recording an association where none existed is the
|
|
358
|
+
// documented rule-1 behavior, not a rewrite of another plugin's provenance.
|
|
359
|
+
if (existing.provisionedByPluginId !== null &&
|
|
360
|
+
(existing.url !== planned.url ||
|
|
361
|
+
existing.transport !== "streamable_http" ||
|
|
362
|
+
existing.authMode !== planned.authMode)) {
|
|
363
|
+
return {
|
|
364
|
+
kind: "failed",
|
|
365
|
+
reason: `connection id '${planned.connectionId}' is owned by plugin '${existing.provisionedByPluginId}' at a different endpoint (url='${existing.url ?? ""}', transport='${existing.transport}', authMode='${existing.authMode}') — refusing to rebind it to plugin '${pluginId}' (declared url='${planned.url}', transport='streamable_http', authMode='${planned.authMode}')`,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
// Direct repo write, never `saveExternalMcpServer` — that function has no way to leave every
|
|
369
|
+
// other field untouched while changing only this one (even its "tri-state" fields resolve a
|
|
370
|
+
// default the caller must supply). Spreading `existing` and changing one property is the only
|
|
371
|
+
// way to guarantee byte-identical preservation of the operator's url/transport/auth/allowlist/
|
|
372
|
+
// write-grants/oauth state.
|
|
373
|
+
await deps.repo.upsert({ ...existing, provisionedByPluginId: pluginId });
|
|
374
|
+
return { kind: "adopted" };
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Idempotently provisions one plugin's auto-admitted remote MCP servers into the external-MCP
|
|
378
|
+
* store, called when an operator ENABLES the plugin (never on disable — see this file's header:
|
|
379
|
+
* disabling a plugin has no effect on any row).
|
|
380
|
+
*
|
|
381
|
+
* Rule 1 is enforced per server, right here: `deps.repo.findByServerId` runs BEFORE any write. A row
|
|
382
|
+
* already at the derived id is NEVER passed through `saveExternalMcpServer` — it is either
|
|
383
|
+
* recognized as this same plugin's earlier work (`alreadyProvisioned`), adopted byte-identical
|
|
384
|
+
* except for `provisionedByPluginId` via a direct `repo.upsert` (`adopted`), or, when it belongs to a
|
|
385
|
+
* DIFFERENT plugin at a non-matching endpoint/transport/auth mode, refused as a genuine collision
|
|
386
|
+
* (`failed`). See {@link adoptOrRecognizeExistingAgentPluginMcpServer}.
|
|
387
|
+
*
|
|
388
|
+
* Per-server failures (a store validation error, an unconfigured secret store, a refused collision,
|
|
389
|
+
* or an adoption's upsert failing) are caught and reported rather than thrown, matching
|
|
390
|
+
* `readEnabledExternalMcpConfigs`'s own fail-open posture: one unwritable row must not stop every
|
|
391
|
+
* other server in the same plugin, or the plugin's own activation, from succeeding.
|
|
392
|
+
*
|
|
393
|
+
* @complexity O(s) in the plugin's declared server count, each one an existence check plus at most
|
|
394
|
+
* one create or adopt.
|
|
395
|
+
*/
|
|
396
|
+
export async function provisionAgentPluginMcpServers(deps, input) {
|
|
397
|
+
const plan = planAgentPluginMcpFederation(input, { classifyTrust: input.classifyTrust, messages: input.messages });
|
|
398
|
+
const provisioned = [];
|
|
399
|
+
const alreadyProvisioned = [];
|
|
400
|
+
const adopted = [];
|
|
401
|
+
const failed = [];
|
|
402
|
+
// Resolved once per call: every stale-row check uses the host's own projections (required: a
|
|
403
|
+
// portable body never falls back to one host's projections; a host's legacy shim adds its pair).
|
|
404
|
+
const bound = { repo: deps.repo, saveServer: (save) => deps.saveServer(save), projections: deps.projections, classifyError: deps.classifyError };
|
|
405
|
+
for (const planned of plan.toUpsert) {
|
|
406
|
+
const outcome = await provisionPlannedServer({ deps: bound, input, planned });
|
|
407
|
+
if (outcome.kind === "failed")
|
|
408
|
+
failed.push({ serverKey: planned.serverKey, reason: outcome.reason });
|
|
409
|
+
else if (outcome.kind === "provisioned")
|
|
410
|
+
provisioned.push(planned.connectionId);
|
|
411
|
+
else if (outcome.kind === "adopted")
|
|
412
|
+
adopted.push(planned.connectionId);
|
|
413
|
+
else
|
|
414
|
+
alreadyProvisioned.push(planned.connectionId);
|
|
415
|
+
}
|
|
416
|
+
// Both admin and chat enable use this owner. Even a plugin with no MCP servers contributes
|
|
417
|
+
// guidance, so notify after provisioning settles rather than only after a connection write.
|
|
418
|
+
await deps.notifyRosterChanged?.({}, {});
|
|
419
|
+
return { provisioned, alreadyProvisioned, adopted, skipped: plan.skipped, failed };
|
|
420
|
+
}
|
|
421
|
+
/** Execute one planned write, keeping lookup, adoption and replacement failures isolated. */
|
|
422
|
+
async function provisionPlannedServer(required, _options = {}) {
|
|
423
|
+
const { deps, input, planned } = required;
|
|
424
|
+
try {
|
|
425
|
+
const existing = await deps.repo.findByServerId({ workspaceId: input.workspaceId, serverId: planned.connectionId });
|
|
426
|
+
if (existing) {
|
|
427
|
+
const outcome = await adoptOrRecognizeExistingAgentPluginMcpServer(deps, existing, planned, input.pluginId);
|
|
428
|
+
if (outcome.kind !== "stale")
|
|
429
|
+
return outcome;
|
|
430
|
+
// Rule 1b: replaced by a fresh row, exactly as a first enable would write it.
|
|
431
|
+
await deps.repo.deleteByServerId({ workspaceId: input.workspaceId, serverId: planned.connectionId });
|
|
432
|
+
}
|
|
433
|
+
await deps.saveServer(buildProvisioningSaveInput(planned, input));
|
|
434
|
+
return { kind: "provisioned" };
|
|
435
|
+
}
|
|
436
|
+
catch (err) {
|
|
437
|
+
return { kind: "failed", reason: err instanceof Error ? err.message : String(err) };
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=federate-mcp.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type ApplyConnectDefaultsDeps } from "./apply-connect-defaults.js";
|
|
2
|
+
import type { InstalledAgentPluginServers, TokenImportLog } from "./import-access-token.js";
|
|
3
|
+
import type { McpServerConfig } from "../lifecycle/manifest.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file "Plugin on + account connected" grants the plugin's declared tools, whichever of the two
|
|
6
|
+
* happens LAST — not only when the sign-in happens last.
|
|
7
|
+
*
|
|
8
|
+
* `apply-connect-defaults.ts` grants a plugin's declared `defaultTools` (allowlist and "may
|
|
9
|
+
* write") when the operator's sign-in finishes, and `agent_plugin_connect` re-runs that grant for an
|
|
10
|
+
* already signed-in row. Both are sign-in moments. Bug 2026-11-04 (jared-floyd, Higgsfield Media):
|
|
11
|
+
* the owner turned the plugin on and signed in, yet the connection stayed off with zero tools, and
|
|
12
|
+
* the chat could only tell them to tick 8 tools and 3 writes by hand. Whenever the sign-in grant
|
|
13
|
+
* skipped or failed at sign-in time (the plugin was off then, the plugin did not declare the tools
|
|
14
|
+
* yet, a post-connect step failed and was only logged), nothing ever tried again: switching the
|
|
15
|
+
* plugin on and restarting the host both left the signed-in row empty. This file is the two other
|
|
16
|
+
* moments, and both reuse the sign-in grant itself (`createApplyConnectDefaults`) so every rule it
|
|
17
|
+
* enforces still holds — only a still-empty row this plugin provisioned, at the url it still
|
|
18
|
+
* declares, never for a plugin an operator turned off, exactly the declared lists:
|
|
19
|
+
*
|
|
20
|
+
* - {@link grantDeclaredToolsToSignedInRows} — the operator switching the plugin on (the admin
|
|
21
|
+
* toggle and `plugins_set_enabled`). Switching on is the operator's consent, the sign-in already
|
|
22
|
+
* was; a row that is not signed in gets nothing, because enabling alone is not a connection.
|
|
23
|
+
* - {@link grantDeclaredToolsAtBoot} — boot, for every plugin that is on. Heals a site whose grant
|
|
24
|
+
* was missed before this file existed, with no action from the owner. Narrower than the toggle: a
|
|
25
|
+
* row whose write grants were ever set by anyone (`writeGrantsUpdatedByPrincipalId`) is skipped,
|
|
26
|
+
* so a boot never re-grants what an operator emptied on purpose after an earlier grant.
|
|
27
|
+
*
|
|
28
|
+
* Automatic healing never widens a grant: a row with any tool already listed is left alone (the
|
|
29
|
+
* sign-in grant's own rule), so an update cannot silently reach a row that already has its tools.
|
|
30
|
+
* An explicit enable card is the exception: the owner reviewed the source and resulting lists,
|
|
31
|
+
* so its approvedEnable option can add those declared names even before sign-in.
|
|
32
|
+
* The grant writes the row on and notifies the roster, so the running assistant admits the
|
|
33
|
+
* connection's tools without a restart (Jini `federation/reload.ts` admits a not-yet-admitted row).
|
|
34
|
+
*/
|
|
35
|
+
/** @agent-note Bind the SAME repo/private context, projection/error pair, stable saved actor ids
|
|
36
|
+
* and activation queue as the sign-in grant/admin toggle. Projections are pure; approval key and
|
|
37
|
+
* principal pass through unchanged. No host defaults or extra store/activation instance here. */
|
|
38
|
+
export type GrantSignedInDefaultsDeps = ApplyConnectDefaultsDeps & {
|
|
39
|
+
/** Injected for tests. Defaults to the sign-in's own grant, {@link createApplyConnectDefaults}. */
|
|
40
|
+
readonly onConnected?: (serverId: string) => Promise<void>;
|
|
41
|
+
/** @agent-note Your diagnostic sink. Advisory failures remain warnings and later rows still run. */
|
|
42
|
+
readonly warn: (message: string) => void;
|
|
43
|
+
/** @agent-note YOUR enable-tool retry guidance; detail is bounded and the complete result is
|
|
44
|
+
* redacted before becoming a public ToolInputError. Do not add credential material. */
|
|
45
|
+
readonly approvedFailure: (required: {
|
|
46
|
+
connectionId: string;
|
|
47
|
+
detail: string;
|
|
48
|
+
}) => string;
|
|
49
|
+
};
|
|
50
|
+
interface GrantDeclaredToolsOptions {
|
|
51
|
+
readonly onlyNeverGranted?: boolean;
|
|
52
|
+
/** Servers whose provisioning just failed (their row could not even be read or written): nothing to grant. */
|
|
53
|
+
readonly skipServerKeys?: readonly string[];
|
|
54
|
+
/** The enable card already named these sources and grants; sign-in can happen afterwards. */
|
|
55
|
+
readonly approvedEnable?: {
|
|
56
|
+
readonly principalId: string;
|
|
57
|
+
readonly accessKey: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Runs the sign-in grant on each of `pluginId`'s declared remote servers whose row this plugin
|
|
62
|
+
* provisioned and that already holds a credential (finished sign-in or saved access token).
|
|
63
|
+
*
|
|
64
|
+
* @returns The connection ids whose tools the grant actually turned on (its own rules may skip one).
|
|
65
|
+
* @throws Nothing: a failing row is a warning naming the row and the cause; the others still run.
|
|
66
|
+
* @complexity O(s) in declared servers: one row read each, plus at most one grant and one re-read.
|
|
67
|
+
*/
|
|
68
|
+
export declare function grantDeclaredToolsToSignedInRows(required: {
|
|
69
|
+
readonly deps: GrantSignedInDefaultsDeps;
|
|
70
|
+
readonly pluginId: string;
|
|
71
|
+
readonly servers: Readonly<Record<string, McpServerConfig>>;
|
|
72
|
+
}, optional?: GrantDeclaredToolsOptions): Promise<readonly string[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Boot: {@link grantDeclaredToolsToSignedInRows} for every installed plugin that is on (no record
|
|
75
|
+
* reads as on, as everywhere else; the seeder's default-off and an operator's off are both skipped,
|
|
76
|
+
* so a boot never switches a plugin on), limited to rows nobody ever granted write access on.
|
|
77
|
+
*
|
|
78
|
+
* @throws Nothing: a listing or activation-read failure is one warning, and the next boot retries.
|
|
79
|
+
* @complexity O(p·s) over installed plugins and their servers.
|
|
80
|
+
*/
|
|
81
|
+
export declare function grantDeclaredToolsAtBoot(required: {
|
|
82
|
+
readonly deps: GrantSignedInDefaultsDeps & {
|
|
83
|
+
/** @agent-note Fresh installed declarations from your lifecycle owner; no filesystem default. */
|
|
84
|
+
readonly listPlugins: () => Promise<readonly InstalledAgentPluginServers[]>;
|
|
85
|
+
/** @agent-note ONE activation snapshot from the SAME activation owner/queue as enablePlugin;
|
|
86
|
+
* read after listing, absent records mean enabled, explicit off never grants at boot. */
|
|
87
|
+
readonly readActivations: () => Promise<{
|
|
88
|
+
readonly plugins: Readonly<Record<string, {
|
|
89
|
+
readonly enabled: boolean;
|
|
90
|
+
} | undefined>>;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
readonly log: TokenImportLog;
|
|
94
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=grant-signed-in-defaults.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ToolInputError, redactSecrets } from '@jini-ai/core';
|
|
2
|
+
import { createApplyConnectDefaults } from "./apply-connect-defaults.js";
|
|
3
|
+
import { hasStoredAgentPluginCredential } from "./connect-tool.js";
|
|
4
|
+
import { deriveAgentPluginConnectionId } from "./federate-mcp.js";
|
|
5
|
+
/** Bind the existing sign-in grant to its explicit approval occasion; test ports retain precedence.
|
|
6
|
+
* @complexity O(1) construction, no I/O.
|
|
7
|
+
*/
|
|
8
|
+
function connectGrantFor({ deps, options, ports }) {
|
|
9
|
+
return deps.onConnected ?? createApplyConnectDefaults({ ...deps, ...ports }, options.approvedEnable ? { approvedEnable: options.approvedEnable } : {});
|
|
10
|
+
}
|
|
11
|
+
/** Run the existing grant owner for one eligible row, then report its actual durable change.
|
|
12
|
+
* @complexity Two indexed row reads plus the existing grant's own point read/write and reload.
|
|
13
|
+
*/
|
|
14
|
+
async function grantConnection({ deps, pluginId, connectionId, onConnected, options, ports }) {
|
|
15
|
+
const row = await deps.repo.findByServerId({ workspaceId: deps.workspaceId, serverId: connectionId });
|
|
16
|
+
if (!row || !eligibleGrantRow({ row, pluginId, approvedEnable: options.approvedEnable !== undefined, ports }))
|
|
17
|
+
return false;
|
|
18
|
+
if (!options.approvedEnable && row.writeGrantsUpdatedByPrincipalId === deps.actors.connectDeclined)
|
|
19
|
+
return false;
|
|
20
|
+
if (options.onlyNeverGranted && row.writeGrantsUpdatedByPrincipalId !== null)
|
|
21
|
+
return false;
|
|
22
|
+
await onConnected(connectionId);
|
|
23
|
+
const after = await deps.repo.findByServerId({ workspaceId: deps.workspaceId, serverId: connectionId });
|
|
24
|
+
return after !== null && (after.enabled !== row.enabled || after.allowedToolNames !== row.allowedToolNames || after.writeAllowedToolNames !== row.writeAllowedToolNames);
|
|
25
|
+
}
|
|
26
|
+
/** Explicit approvals must report a partial failure to the caller; boot healing remains advisory.
|
|
27
|
+
* @throws ToolInputError for the approved enable path, with bounded redacted cause.
|
|
28
|
+
* @complexity O(e) in error-message bytes; no I/O beyond the injected warning port.
|
|
29
|
+
*/
|
|
30
|
+
function grantFailure({ error, pluginId, connectionId, approved, warn, approvedFailure }) {
|
|
31
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
32
|
+
if (approved)
|
|
33
|
+
throw new ToolInputError({ message: redactSecrets({ input: approvedFailure({ connectionId, detail: detail.slice(0, 2000) }) }) });
|
|
34
|
+
warn(`[agent-plugins] '${pluginId}': could not turn on the '${connectionId}' connection with the tools the plugin declares — ${detail}`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs the sign-in grant on each of `pluginId`'s declared remote servers whose row this plugin
|
|
38
|
+
* provisioned and that already holds a credential (finished sign-in or saved access token).
|
|
39
|
+
*
|
|
40
|
+
* @returns The connection ids whose tools the grant actually turned on (its own rules may skip one).
|
|
41
|
+
* @throws Nothing: a failing row is a warning naming the row and the cause; the others still run.
|
|
42
|
+
* @complexity O(s) in declared servers: one row read each, plus at most one grant and one re-read.
|
|
43
|
+
*/
|
|
44
|
+
export async function grantDeclaredToolsToSignedInRows(required, optional = {}) {
|
|
45
|
+
const { deps, pluginId, servers } = required;
|
|
46
|
+
const warn = deps.warn;
|
|
47
|
+
// Resolved once per call: the eligibility check and the grant use the host's same pair.
|
|
48
|
+
const ports = deps;
|
|
49
|
+
const onConnected = connectGrantFor({ deps, options: optional, ports });
|
|
50
|
+
const granted = [];
|
|
51
|
+
for (const [serverKey, config] of Object.entries(servers)) {
|
|
52
|
+
const connectionId = config.type === "stdio" || optional.skipServerKeys?.includes(serverKey) ? null : deriveAgentPluginConnectionId({ serverKey });
|
|
53
|
+
if (connectionId === null)
|
|
54
|
+
continue;
|
|
55
|
+
try {
|
|
56
|
+
if (await grantConnection({ deps, pluginId, connectionId, onConnected, options: optional, ports }))
|
|
57
|
+
granted.push(connectionId);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
grantFailure({ error, pluginId, connectionId, approved: optional.approvedEnable !== undefined, warn, approvedFailure: deps.approvedFailure });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return granted;
|
|
64
|
+
}
|
|
65
|
+
/** Explicit activation consent can precede sign-in; automatic healing still requires credentials.
|
|
66
|
+
* @complexity O(1), no I/O. */
|
|
67
|
+
function eligibleGrantRow({ row, pluginId, approvedEnable, ports }, _options = {}) {
|
|
68
|
+
if (row.provisionedByPluginId !== pluginId)
|
|
69
|
+
return false;
|
|
70
|
+
return approvedEnable || hasStoredAgentPluginCredential({ row, projections: ports.projections });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Boot: {@link grantDeclaredToolsToSignedInRows} for every installed plugin that is on (no record
|
|
74
|
+
* reads as on, as everywhere else; the seeder's default-off and an operator's off are both skipped,
|
|
75
|
+
* so a boot never switches a plugin on), limited to rows nobody ever granted write access on.
|
|
76
|
+
*
|
|
77
|
+
* @throws Nothing: a listing or activation-read failure is one warning, and the next boot retries.
|
|
78
|
+
* @complexity O(p·s) over installed plugins and their servers.
|
|
79
|
+
*/
|
|
80
|
+
export async function grantDeclaredToolsAtBoot(required, _optional = {}) {
|
|
81
|
+
const { deps, log } = required;
|
|
82
|
+
let plugins;
|
|
83
|
+
let activations;
|
|
84
|
+
try {
|
|
85
|
+
plugins = await deps.listPlugins();
|
|
86
|
+
activations = await deps.readActivations();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
log.warn(`[agent-plugins] could not check signed-in plugin connections for their declared tools: ${error instanceof Error ? error.message : String(error)}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const { pluginId, servers } of plugins) {
|
|
93
|
+
if (activations.plugins[pluginId]?.enabled === false)
|
|
94
|
+
continue;
|
|
95
|
+
const granted = await grantDeclaredToolsToSignedInRows({ deps: { ...deps, warn: (message) => log.warn(message) }, pluginId, servers }, { onlyNeverGranted: true });
|
|
96
|
+
if (granted.length > 0)
|
|
97
|
+
log.info(`[agent-plugins] '${pluginId}': turned on its signed-in connection(s) ${granted.join(", ")} with the tools the plugin declares.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=grant-signed-in-defaults.js.map
|