@jini-ai/mcp 0.7.3-next.1 → 0.7.3-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +15 -0
  3. package/dist/agent-install/owned-json-install.d.ts +1 -1
  4. package/dist/client/client.js +1 -1
  5. package/dist/client/css-url-refs.d.ts +3 -1
  6. package/dist/client/css-url-refs.js +1 -1
  7. package/dist/external/access-review.d.ts +46 -0
  8. package/dist/external/access-review.js +175 -0
  9. package/dist/external/agent-tools.d.ts +72 -0
  10. package/dist/external/agent-tools.js +218 -0
  11. package/dist/external/built-in-connections.d.ts +17 -0
  12. package/dist/external/built-in-connections.js +15 -0
  13. package/dist/external/external-mcp-host-copy.d.ts +14 -0
  14. package/dist/external/external-mcp-host-copy.js +8 -0
  15. package/dist/external/operations-tools.d.ts +69 -0
  16. package/dist/external/operations-tools.js +96 -0
  17. package/dist/external/save-form.d.ts +105 -0
  18. package/dist/external/save-form.js +260 -0
  19. package/dist/external/save-input.d.ts +41 -0
  20. package/dist/external/save-input.js +149 -0
  21. package/dist/external/tool-registrations.d.ts +130 -0
  22. package/dist/external/tool-registrations.js +299 -0
  23. package/dist/federation/bootstrap.d.ts +18 -0
  24. package/dist/federation/bootstrap.js +2 -2
  25. package/dist/federation/external-mcp-admissions.d.ts +19 -0
  26. package/dist/federation/external-mcp-admissions.js +30 -0
  27. package/dist/federation/external-mcp-probe.d.ts +86 -0
  28. package/dist/federation/external-mcp-probe.js +75 -0
  29. package/dist/federation/hosted/external-mcp-repo.d.ts +108 -0
  30. package/dist/federation/hosted/external-mcp-repo.js +210 -0
  31. package/dist/federation/hosted/external-mcp-repo.writes.d.ts +75 -0
  32. package/dist/federation/hosted/external-mcp-repo.writes.js +131 -0
  33. package/dist/federation/hosted/store-credentials.d.ts +6 -1
  34. package/dist/federation/hosted/store-credentials.js +2 -2
  35. package/dist/federation/hosted/store-input.d.ts +11 -3
  36. package/dist/federation/hosted/store-input.js +5 -5
  37. package/dist/federation/hosted/store-oauth-fields.d.ts +10 -2
  38. package/dist/federation/hosted/store-oauth-fields.js +7 -7
  39. package/dist/federation/hosted/store-view.d.ts +6 -1
  40. package/dist/federation/hosted/store-view.js +2 -2
  41. package/dist/federation/hosted/store.js +7 -7
  42. package/dist/federation/hosted/store.memory.d.ts +2 -0
  43. package/dist/federation/hosted/store.memory.js +6 -2
  44. package/dist/federation/index.d.ts +2 -0
  45. package/dist/federation/index.js +2 -0
  46. package/dist/federation/registrations.js +73 -56
  47. package/dist/federation/roster-change.d.ts +63 -0
  48. package/dist/federation/roster-change.js +68 -0
  49. package/dist/federation/runtime.d.ts +140 -0
  50. package/dist/federation/runtime.js +118 -0
  51. package/dist/react/external-mcp/ExternalMcpAdmissionsBanner.d.ts +42 -0
  52. package/dist/react/external-mcp/ExternalMcpAdmissionsBanner.js +80 -0
  53. package/dist/react/external-mcp/ExternalMcpPanelSections.d.ts +50 -0
  54. package/dist/react/external-mcp/ExternalMcpPanelSections.js +35 -0
  55. package/dist/react/external-mcp/ExternalMcpSettingsPanel.d.ts +446 -0
  56. package/dist/react/external-mcp/ExternalMcpSettingsPanel.hooks.d.ts +135 -0
  57. package/dist/react/external-mcp/ExternalMcpSettingsPanel.hooks.js +122 -0
  58. package/dist/react/external-mcp/ExternalMcpSettingsPanel.js +63 -0
  59. package/dist/react/external-mcp/ExternalMcpSourceRow.d.ts +40 -0
  60. package/dist/react/external-mcp/ExternalMcpSourceRow.js +100 -0
  61. package/dist/react/external-mcp/hooks/external-mcp-form.rules.d.ts +58 -0
  62. package/dist/react/external-mcp/hooks/external-mcp-form.rules.js +209 -0
  63. package/dist/react/external-mcp/hooks/external-mcp-source-actions.d.ts +115 -0
  64. package/dist/react/external-mcp/hooks/external-mcp-source-actions.js +152 -0
  65. package/dist/react/external-mcp/hooks/use-external-mcp-admissions.hooks.d.ts +166 -0
  66. package/dist/react/external-mcp/hooks/use-external-mcp-admissions.hooks.js +209 -0
  67. package/dist/react/external-mcp/hooks/use-external-mcp.hooks.d.ts +132 -0
  68. package/dist/react/external-mcp/hooks/use-external-mcp.hooks.js +37 -0
  69. package/dist/server/tool-arguments.d.ts +5 -1
  70. package/dist/server/tool-arguments.js +13 -9
  71. package/dist/server/tool-protocol.js +7 -5
  72. package/dist/server/tools/tool-catalog-tools.js +6 -3
  73. package/dist/tools/ask-choice/custom-answer.d.ts +77 -0
  74. package/dist/tools/ask-choice/custom-answer.js +113 -0
  75. package/dist/tools/ask-choice/index.d.ts +2 -0
  76. package/dist/tools/ask-choice/index.js +1 -0
  77. package/package.json +122 -7
@@ -0,0 +1,63 @@
1
+ import type { ToolAccessChange } from "@jini-ai/core/contracts/site/daemon";
2
+ /**
3
+ * @file A keyed, last-wins fan-out for "the external-MCP roster changed" — the seam that lets every
4
+ * runtime holding a live federated-tool registry (an agent daemon's own, a per-request BYOK
5
+ * federation runtime) hear about a roster write without each writer (a connection PUT, an OAuth
6
+ * callback, a model-facing roster tool) having to know how many runtimes exist or what each one's
7
+ * reload method is called.
8
+ *
9
+ * Keyed rather than a plain list: a composition root that calls its own registration twice (a
10
+ * hot-reloaded module, a test that rebuilds the app) must replace its own listener, not accumulate a
11
+ * second one that fires the same reload twice per roster change.
12
+ *
13
+ * Ordinary discovery refreshes never reject or wait past `waitMs` for a stuck listener: callers
14
+ * that await it (an OAuth callback) do so to let an operator return to the chat and find a newly
15
+ * authorized connection already usable, not to gate their own response's correctness on every
16
+ * registered runtime's reload succeeding — a listener that never resolves must not turn into a
17
+ * request that never resolves either. Lowering tool access is different: callers await Stop and
18
+ * cleanup, and a failure or deadline rejects with the host's safe, actionable error
19
+ * (`createLoweringError`), so this package never owns the host's error class or wording.
20
+ *
21
+ * State is owned by each bus instance (no module-level registry): the host creates ONE bus in its
22
+ * composition module and binds `on`/`notify`/`reset` from it.
23
+ *
24
+ * Architectural role:
25
+ * In-memory registry. No I/O of its own; every listener performs its own.
26
+ */
27
+ /** A registered reaction to a roster change. Return shape varies by runtime (a reload result, an
28
+ * `{ok}` shape, or nothing at all) — `notify` only needs to know when each one settles, never what
29
+ * it settled with. */
30
+ export type McpRosterChangeListener = (lowered?: ToolAccessChange) => unknown;
31
+ /** Options for one `notify` call. */
32
+ export interface McpRosterChangeNotifyOptions {
33
+ readonly waitMs?: number;
34
+ readonly lowered?: ToolAccessChange;
35
+ }
36
+ /** Collaborators the host injects into {@link createMcpRosterChangeBus}. */
37
+ export interface McpRosterChangeBusDeps {
38
+ /** Builds the safe, actionable error a failed or timed-out lowering rejects with. It must not carry
39
+ * the listener's own failure text (that may hold secrets or internal detail). */
40
+ readonly createLoweringError: () => Error;
41
+ /** Default cap for one `notify` call. */
42
+ readonly defaultWaitMs?: number;
43
+ }
44
+ /** One instance-owned roster-change fan-out. */
45
+ export interface McpRosterChangeBus {
46
+ /** Registers a reaction under `key`; re-registering the same key REPLACES the earlier listener. */
47
+ on(args: {
48
+ key: string;
49
+ listener: McpRosterChangeListener;
50
+ }, _optional?: object): void;
51
+ /** Fans a change out to every listener; lowering rejects with the injected error on failure. */
52
+ notify(options?: McpRosterChangeNotifyOptions): Promise<void>;
53
+ /** Drops every registered listener (tests that rebuild composition roots in one process). */
54
+ reset(): void;
55
+ }
56
+ /**
57
+ * Creates an instance-owned roster-change bus. The host injects `createLoweringError` so a failed
58
+ * lowering rejects with the host's own error type.
59
+ *
60
+ * @complexity `notify` is O(1) plus the cost of every registered listener, in parallel, once.
61
+ */
62
+ export declare function createMcpRosterChangeBus(deps: McpRosterChangeBusDeps, _optional?: {}): McpRosterChangeBus;
63
+ //# sourceMappingURL=roster-change.d.ts.map
@@ -0,0 +1,68 @@
1
+ /** Bounds one `notify()` call: one on-demand, idempotent attempt should fail fast rather than hold a
2
+ * caller's response open, applied across every registered listener at once. */
3
+ const DEFAULT_WAIT_MS = 5_000;
4
+ /** Invokes a listener without letting a synchronous throw escape before `Promise.allSettled` ever
5
+ * sees it — `Array.prototype.map` would otherwise abort the whole fan-out on the first offender. */
6
+ function invokeSafely(listener, lowered) {
7
+ try {
8
+ return Promise.resolve(listener(lowered));
9
+ }
10
+ catch (err) {
11
+ return Promise.reject(err);
12
+ }
13
+ }
14
+ /** Lowering is a correctness boundary, unlike a best-effort discovery refresh: the serving listener
15
+ * awaits the authenticated daemon Stop/cleanup control and failures reach the writer. */
16
+ function awaitLowering(args) {
17
+ const { listeners, lowered, waitMs, createLoweringError } = args;
18
+ return new Promise((resolve, reject) => {
19
+ const timer = setTimeout(() => reject(createLoweringError()), waitMs);
20
+ void Promise.all(listeners.map(listener => invokeSafely(listener, lowered))).then(() => { clearTimeout(timer); resolve(); }, () => { clearTimeout(timer); reject(createLoweringError()); });
21
+ });
22
+ }
23
+ /** Best-effort refresh: `allSettled`, so one throwing or rejecting listener never stops the rest,
24
+ * capped at `waitMs` so a listener cannot hold a caller open indefinitely. */
25
+ function awaitRefresh(listeners, waitMs) {
26
+ return new Promise((resolve) => {
27
+ let timer = setTimeout(() => {
28
+ timer = undefined;
29
+ resolve();
30
+ }, waitMs);
31
+ void Promise.allSettled(listeners.map(listener => invokeSafely(listener))).then(() => {
32
+ if (timer !== undefined) {
33
+ clearTimeout(timer);
34
+ resolve();
35
+ }
36
+ });
37
+ });
38
+ }
39
+ /**
40
+ * Creates an instance-owned roster-change bus. The host injects `createLoweringError` so a failed
41
+ * lowering rejects with the host's own error type.
42
+ *
43
+ * @complexity `notify` is O(1) plus the cost of every registered listener, in parallel, once.
44
+ */
45
+ export function createMcpRosterChangeBus(deps, _optional = {}) {
46
+ const listenersByKey = new Map();
47
+ const defaultWaitMs = deps.defaultWaitMs ?? DEFAULT_WAIT_MS;
48
+ return {
49
+ on({ key, listener }) {
50
+ listenersByKey.set(key, listener);
51
+ },
52
+ async notify(options = {}) {
53
+ const waitMs = options.waitMs ?? defaultWaitMs;
54
+ const listeners = [...listenersByKey.values()];
55
+ if (listeners.length === 0)
56
+ return;
57
+ if (options.lowered) {
58
+ await awaitLowering({ listeners, lowered: options.lowered, waitMs, createLoweringError: deps.createLoweringError });
59
+ return;
60
+ }
61
+ await awaitRefresh(listeners, waitMs);
62
+ },
63
+ reset() {
64
+ listenersByKey.clear();
65
+ },
66
+ };
67
+ }
68
+ //# sourceMappingURL=roster-change.js.map
@@ -0,0 +1,140 @@
1
+ import type { ResolvedFederatedConnection } from "./config.js";
2
+ import { type AttachFederatedToolsResult } from "./bootstrap.js";
3
+ import type { FederationReloadResult } from "./reload.js";
4
+ import type { FederationRefusalMessages } from "./messages.js";
5
+ /**
6
+ * @file One federation runtime per process, shared by every host root that federates (a daemon, a
7
+ * BYOK turn loop). Boot and reload own one accounting state: `start()` seeds it, `reload()` extends
8
+ * it, and `reports()`/`refusalPrefix()` read it live. Separate state for these views would allow drift.
9
+ *
10
+ * Architectural role:
11
+ * Composition. No I/O of its own — every I/O call (`boot`, `resolveConnections`, the reload
12
+ * coordinator, preset resolution) is a parameter, so this file is importable and testable without
13
+ * booting a real process, matching `bootstrap.ts` and `reload.ts`'s own posture. The host binds its
14
+ * registry, approval deps, preset registry and messages into those closures.
15
+ */
16
+ /** Where the admission report goes. Injected so tests assert on it instead of scraping stdout, and
17
+ * so a future structured logger is a parameter change rather than an edit. */
18
+ export interface FederationHostLogger {
19
+ info(required: {
20
+ message: string;
21
+ }, optional?: {
22
+ error?: unknown;
23
+ }): void;
24
+ warn(required: {
25
+ message: string;
26
+ }, optional?: {
27
+ error?: unknown;
28
+ }): void;
29
+ }
30
+ type RuntimeReports = AttachFederatedToolsResult["reports"];
31
+ type RuntimeConnectFailures = AttachFederatedToolsResult["connectFailures"];
32
+ /** The host's reload coordinator, already bound to its registry/deps/attach — usually
33
+ * `createFederationReloadCoordinator` from `reload.ts` wrapped by the host's own adapter. */
34
+ export interface FederationRuntimeReloader {
35
+ reload(): Promise<FederationReloadResult>;
36
+ }
37
+ /** Host-bound I/O the runtime drives. */
38
+ export interface CreateFederationRuntimeRequired {
39
+ /** Reads the operator-editable roster fresh. Called once at boot and once per actual reload pass,
40
+ * never once per `reload()` caller — see `reload.ts`'s own coalescing doc. */
41
+ readonly resolveConnections: () => Promise<readonly ResolvedFederatedConnection[]>;
42
+ /** The boot pass: the host's attach bound to its registry, deps and preset registry. Presets are
43
+ * the host's concern here; the runtime only hands over the roster as `extraConnections`. */
44
+ readonly boot: (args: {
45
+ extraConnections: readonly ResolvedFederatedConnection[];
46
+ logger: FederationHostLogger;
47
+ }) => Promise<AttachFederatedToolsResult>;
48
+ /** Re-resolves the preset registry for each reload pass. */
49
+ readonly resolvePresetConnections: (args: {
50
+ logger: FederationHostLogger;
51
+ }) => readonly ResolvedFederatedConnection[];
52
+ /** Builds the reload coordinator once the boot pass has seeded the accounting. */
53
+ readonly createReloadCoordinator: (args: {
54
+ resolveConnections: () => Promise<readonly ResolvedFederatedConnection[]>;
55
+ logger: FederationHostLogger;
56
+ initiallyAdmitted: readonly string[];
57
+ initiallyAwaitingGrants: readonly string[];
58
+ }) => FederationRuntimeReloader;
59
+ /** Refusal-prefix copy for {@link FederationRuntime.refusalPrefix}. */
60
+ readonly messages: FederationRefusalMessages;
61
+ /** The host's log sink for boot/reload lines (a host typically prefixes them per process). */
62
+ readonly logger: FederationHostLogger;
63
+ }
64
+ export interface CreateFederationRuntimeOptions {
65
+ /**
66
+ * Resolved before `start()`'s own boot pass ever calls `boot` — e.g. an installed-extension
67
+ * registration promise, so a federated id can never win a registration race against an
68
+ * installed-extension id for the same slot. Defaults to an already-resolved promise.
69
+ */
70
+ readonly after?: Promise<void>;
71
+ /** Called once per reload pass that actually admitted something new — never for a no-op reload.
72
+ * A daemon rebinds its live tool catalog here; a BYOK loop rebuilds its search index. */
73
+ readonly onAdmitted?: (result: FederationReloadResult) => void;
74
+ /** Refresh installed guidance on the same operator-triggered path; true invalidates discovery. */
75
+ readonly beforeReload?: () => Promise<boolean>;
76
+ }
77
+ export interface FederationRuntime {
78
+ /** The boot pass: presets plus the roster `resolveConnections` returns. Single-flight and
79
+ * idempotent — calling it any number of times performs the boot pass exactly once and every call
80
+ * shares that one result. Never rejects: attach absorbs per-connection failures, and this
81
+ * runtime catches failures from `after` and `resolveConnections` so callers can await boot
82
+ * unconditionally and `started` reaches its terminal state. */
83
+ start(): Promise<void>;
84
+ /** Re-admits every roster connection not yet admitted. Resolves `{newlyAdmittedConnectionIds: [],
85
+ * reports: []}` with no roster read at all if `start()` was never called — there is nothing yet to
86
+ * extend. Installed guidance can refresh independently before a lazy federation boot.
87
+ * If a `start()` is in flight, waits for it first, so a reload can never run against a
88
+ * boot pass's stale pre-seed state. */
89
+ reload(): Promise<FederationReloadResult>;
90
+ /** A live read of the merged boot-plus-every-reload admission accounting. */
91
+ reports(): RuntimeReports;
92
+ /** A live read of the merged boot-plus-every-reload CONNECT failures — one entry per
93
+ * connection that never reached admission at all (bad spawn, timed-out handshake, malformed
94
+ * listing), so it has no entry in `reports()` either. Same shape and same merge discipline as
95
+ * `reports()`. */
96
+ connectFailures(): RuntimeConnectFailures;
97
+ /** The refusal-prefix text for `reports()`, cached and recomputed only when `reports()` changes —
98
+ * `""` when there is nothing to report. */
99
+ refusalPrefix(): string;
100
+ /** Whether the boot pass has completed — successfully or not; see `start()`'s own doc. */
101
+ readonly started: boolean;
102
+ /**
103
+ * The boot roster's connection ids — `undefined` until `resolveConnections()` resolves
104
+ * (the roster itself is not known yet), then fixed for the rest of boot. Lets a caller building a
105
+ * federation boot status tell "a real, pending roster connection" apart from "never configured at
106
+ * all" while `!started`, without waiting for the whole boot pass — `undefined` and `[]` are
107
+ * different claims.
108
+ */
109
+ configuredConnectionIds(): readonly string[] | undefined;
110
+ }
111
+ /** Roster connections that were admitted with an empty grant: the reload coordinator must not
112
+ * re-handshake them until the owner's grants change.
113
+ * @complexity O(c + r) in boot connections and reports.
114
+ */
115
+ export declare function selectAwaitingGrantConnectionIds({ connections, reports }: {
116
+ connections: readonly ResolvedFederatedConnection[];
117
+ reports: RuntimeReports;
118
+ }, _optional?: {}): string[];
119
+ /** A reload's own connect failures are merged unconditionally, even when nothing was newly
120
+ * admitted — a reload that only ever fails a connection must still make that failure visible. Every
121
+ * connection this pass attempted (admitted or failed) first drops its older entry: a now-admitted
122
+ * one must leave the list (the admissions wire documents `connections`/`configFailures` as
123
+ * disjoint), and a repeat failure replaces rather than piling up one entry per reload.
124
+ * @complexity O(f + a) in prior failures and this pass's attempts.
125
+ */
126
+ export declare function mergeReloadConnectFailures({ previous, result }: {
127
+ previous: RuntimeConnectFailures;
128
+ result: FederationReloadResult;
129
+ }, _optional?: {}): RuntimeConnectFailures;
130
+ /**
131
+ * Builds one process's federation runtime. Nothing here performs I/O until `start()` or `reload()` is
132
+ * called — constructing this is free, which is what lets a host build it unconditionally and leave
133
+ * starting it to whichever root decides when.
134
+ *
135
+ * @complexity O(1) to construct; `start()`/`reload()` inherit their cost from the injected `boot`
136
+ * and reload coordinator.
137
+ */
138
+ export declare function createFederationRuntime(required: CreateFederationRuntimeRequired, options?: CreateFederationRuntimeOptions): FederationRuntime;
139
+ export {};
140
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,118 @@
1
+ import { withPresetOrigin } from "./bootstrap.js";
2
+ import { buildFederatedRefusalPrefix } from "./refusal-notice.js";
3
+ /** Roster connections that were admitted with an empty grant: the reload coordinator must not
4
+ * re-handshake them until the owner's grants change.
5
+ * @complexity O(c + r) in boot connections and reports.
6
+ */
7
+ export function selectAwaitingGrantConnectionIds({ connections, reports }, _optional = {}) {
8
+ const emptyGrantIds = new Set(connections.filter(connection => connection.config.allowedToolNames.length === 0).map(connection => connection.config.connectionId));
9
+ return reports.filter(entry => !entry.isPreset && entry.report.admitted.length === 0 && emptyGrantIds.has(entry.connectionId))
10
+ .map(entry => entry.connectionId);
11
+ }
12
+ function buildRuntimeReloadCoordinator({ required, logger }, { connections, mergedReports }) {
13
+ return required.createReloadCoordinator({
14
+ // Presets can arrive after a failed desktop listener bind. The existing coordinator
15
+ // retries only unadmitted identities and still freezes every successfully admitted tool.
16
+ resolveConnections: async () => [
17
+ ...required.resolvePresetConnections({ logger }).map(connection => withPresetOrigin({ connection })),
18
+ ...await required.resolveConnections(),
19
+ ],
20
+ logger,
21
+ initiallyAdmitted: mergedReports.map((entry) => entry.connectionId),
22
+ initiallyAwaitingGrants: selectAwaitingGrantConnectionIds({ connections, reports: mergedReports }),
23
+ });
24
+ }
25
+ /** A reload's own connect failures are merged unconditionally, even when nothing was newly
26
+ * admitted — a reload that only ever fails a connection must still make that failure visible. Every
27
+ * connection this pass attempted (admitted or failed) first drops its older entry: a now-admitted
28
+ * one must leave the list (the admissions wire documents `connections`/`configFailures` as
29
+ * disjoint), and a repeat failure replaces rather than piling up one entry per reload.
30
+ * @complexity O(f + a) in prior failures and this pass's attempts.
31
+ */
32
+ export function mergeReloadConnectFailures({ previous, result }, _optional = {}) {
33
+ const attemptedIds = new Set([...result.newlyAdmittedConnectionIds, ...result.connectFailures.map((entry) => entry.connectionId)]);
34
+ if (attemptedIds.size === 0)
35
+ return previous;
36
+ return [...previous.filter((entry) => !attemptedIds.has(entry.connectionId)), ...result.connectFailures];
37
+ }
38
+ function createFederationAccounting(bound, getStartPromise) {
39
+ let mergedReports = [];
40
+ let mergedConnectFailures = [];
41
+ let cachedPrefix = "";
42
+ let startedFlag = false;
43
+ let coordinator;
44
+ let configuredConnectionIds;
45
+ function recomputePrefix() {
46
+ cachedPrefix = buildFederatedRefusalPrefix({ snapshot: mergedReports, messages: bound.required.messages });
47
+ }
48
+ async function reload() {
49
+ // Federation remains lazy before the first BYOK turn; installed guidance still needs the
50
+ // operator's reload now. An in-flight boot must finish before refreshing either catalog.
51
+ const startPromise = getStartPromise();
52
+ if (startPromise)
53
+ await startPromise;
54
+ const installedChanged = await bound.options.beforeReload?.() ?? false;
55
+ const result = coordinator ? await coordinator.reload()
56
+ : { newlyAdmittedConnectionIds: [], reports: [], connectFailures: [] };
57
+ // Does not touch `cachedPrefix`: `buildFederatedRefusalPrefix` is a pure function of
58
+ // `mergedReports` alone, and a connect failure never produces a report entry to feed it.
59
+ mergedConnectFailures = mergeReloadConnectFailures({ previous: mergedConnectFailures, result });
60
+ if (result.newlyAdmittedConnectionIds.length === 0 && !installedChanged)
61
+ return result;
62
+ const refreshedIds = new Set(result.reports.map(entry => entry.connectionId));
63
+ mergedReports = [...mergedReports.filter(entry => !refreshedIds.has(entry.connectionId)), ...result.reports];
64
+ recomputePrefix();
65
+ bound.options.onAdmitted?.(result);
66
+ return result;
67
+ }
68
+ function seed(attached, connections) {
69
+ mergedReports = attached.reports;
70
+ mergedConnectFailures = attached.connectFailures;
71
+ recomputePrefix();
72
+ coordinator = buildRuntimeReloadCoordinator(bound, { connections, mergedReports });
73
+ }
74
+ return { reload, seed, configure: (ids) => { configuredConnectionIds = ids; }, complete: () => { startedFlag = true; },
75
+ reports: () => mergedReports, connectFailures: () => mergedConnectFailures, refusalPrefix: () => cachedPrefix,
76
+ configuredConnectionIds: () => configuredConnectionIds, get started() { return startedFlag; } };
77
+ }
78
+ /**
79
+ * Builds one process's federation runtime. Nothing here performs I/O until `start()` or `reload()` is
80
+ * called — constructing this is free, which is what lets a host build it unconditionally and leave
81
+ * starting it to whichever root decides when.
82
+ *
83
+ * @complexity O(1) to construct; `start()`/`reload()` inherit their cost from the injected `boot`
84
+ * and reload coordinator.
85
+ */
86
+ export function createFederationRuntime(required, options = {}) {
87
+ const { logger } = required;
88
+ let startPromise;
89
+ const accounting = createFederationAccounting({ required, options, logger }, () => startPromise);
90
+ async function runStart() {
91
+ // Catch prerequisites as well as attachment: a failed roster read must complete boot's
92
+ // lifecycle so later calls are diagnosed as failed rather than "still connecting" forever.
93
+ // Optional federation failures cannot disable the native assistant.
94
+ try {
95
+ await (options.after ?? Promise.resolve());
96
+ const connections = await required.resolveConnections();
97
+ accounting.configure(connections.map((connection) => connection.config.connectionId));
98
+ const attached = await required.boot({ extraConnections: connections, logger });
99
+ accounting.seed(attached, connections);
100
+ }
101
+ catch (error) {
102
+ // The error goes in the logger's error bag (the host sink describes it), never into the line text.
103
+ logger.warn({ message: "mcp-federation: boot pass failed, continuing without federated tools" }, { error });
104
+ }
105
+ finally {
106
+ accounting.complete();
107
+ }
108
+ }
109
+ function start() {
110
+ if (!startPromise)
111
+ startPromise = runStart();
112
+ return startPromise;
113
+ }
114
+ return { start, reload: accounting.reload, reports: accounting.reports, connectFailures: accounting.connectFailures,
115
+ refusalPrefix: accounting.refusalPrefix, configuredConnectionIds: accounting.configuredConnectionIds,
116
+ get started() { return accounting.started; } };
117
+ }
118
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,42 @@
1
+ import { type Translate } from "@jini-ai/core/text";
2
+ type AdmissionDriftEntry = {
3
+ connectionId: string;
4
+ remoteName: string | null;
5
+ kind: string;
6
+ messageKey: string;
7
+ messageVars: Readonly<Record<string, string>>;
8
+ };
9
+ type AdmissionDriftConnection = {
10
+ connectionId: string;
11
+ notLoaded: readonly string[];
12
+ liveToolCount: number;
13
+ savedToolCount: number;
14
+ entries: readonly AdmissionDriftEntry[];
15
+ };
16
+ type ExternalMcpAdmissionsController<Connection extends AdmissionDriftConnection = AdmissionDriftConnection> = {
17
+ loading: boolean;
18
+ waitingForAssistant: boolean;
19
+ unavailable: string | null;
20
+ connections: readonly Connection[];
21
+ restartHelps: boolean;
22
+ canRestart: boolean;
23
+ restarting: boolean;
24
+ restartError: string | null;
25
+ restartAccepted: boolean;
26
+ restart: () => void;
27
+ };
28
+ export interface ExternalMcpAdmissionsBannerProps<Connection extends AdmissionDriftConnection = AdmissionDriftConnection> {
29
+ describeHeadline: (required: {
30
+ connections: readonly Connection[];
31
+ }, optional?: Record<string, never>) => string;
32
+ controller: ExternalMcpAdmissionsController<Connection>;
33
+ t: Translate;
34
+ /** Ticks "Allow changes" for one tool by writing the connection's `writeAllowedToolNames` field
35
+ * through the same `updateSource` port the card's own edit form uses. */
36
+ onAllowWrite: (connectionId: string, remoteName: string) => void;
37
+ /** Opens the existing confirmation dialog; only its Confirm calls the existing delete hook. */
38
+ onRequestRemove: (connectionId: string) => void;
39
+ }
40
+ export declare function ExternalMcpAdmissionsBanner<Connection extends AdmissionDriftConnection>({ controller, t, onAllowWrite, onRequestRemove, describeHeadline }: ExternalMcpAdmissionsBannerProps<Connection>): import("react").JSX.Element | null;
41
+ export {};
42
+ //# sourceMappingURL=ExternalMcpAdmissionsBanner.d.ts.map
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { interpolate } from "@jini-ai/core/text";
3
+ /**
4
+ * @file "What the assistant is actually running" — the operator half of the refusal channel.
5
+ *
6
+ * The tab above this banner shows what was SAVED. `Jini packages/mcp/src/federation/trust.ts` R5 freezes the admitted
7
+ * set at connect, so those are two different objects, and until now the only way to see the gap was
8
+ * to read the daemon's terminal at the moment it booted. That is how this project discovered
9
+ * Higgsfield's blocked `generate_image` in the first place — and on a desktop app nobody can SSH
10
+ * into, a terminal is not a support channel.
11
+ *
12
+ * Renders NOTHING when the live assistant and the saved roster agree, which is the normal state. A
13
+ * banner that is always present is a banner nobody reads.
14
+ *
15
+ * All display decisions live in `external-mcp-admissions-rules.ts` and the hook beside it; this
16
+ * file only maps already-decided rows onto elements. The copy strings are their own i18n keys
17
+ * (`dictionary-translator.ts`) and are passed through `t` verbatim — six of them were written and
18
+ * translated into 21 locales in Phase 2C for exactly this UI and have never been rendered.
19
+ */
20
+ /** One row: what the assistant refused, and — for the one case an operator can fix from here —
21
+ * the tick that fixes it. A real `<label>`, not an `aria-label`: an icon-only or bare checkbox
22
+ * would have no accessible name at all, and `agentHandle`'s `label` does not supply one (it emits
23
+ * `data-agent-label`). The visible words also make the translated sentence beside it
24
+ * ("Tick 'Allow changes' to enable this tool.") literally true rather than a reference to a control
25
+ * that is not there. */
26
+ function AdmissionDriftRow(props) {
27
+ const { entry, t, onAllowWrite, onRequestRemove } = props;
28
+ const message = interpolate({ template: t(entry.messageKey), vars: entry.messageVars });
29
+ // Bound locally so the null check below narrows inside the `onChange` closure too. A
30
+ // `needs-write-grant` row always names a tool (it comes from a gate refusal), but the type cannot
31
+ // know that, and asserting it would be the more expensive way to be right.
32
+ const { remoteName } = entry;
33
+ return (_jsxs("li", { className: "external-mcp-drift-row", children: [remoteName === null ? null : (_jsxs(_Fragment, { children: [_jsx("code", { children: remoteName }), " \u2014", " "] })), _jsx("span", { children: message }), entry.kind === "missing-launcher" ? (_jsx("button", { type: "button", onClick: () => onRequestRemove(entry.connectionId), "data-agent-element": `mcp-drift-remove-${entry.connectionId}`, children: t("Remove") })) : null, entry.kind === "needs-write-grant" && remoteName !== null ? (_jsxs("label", { className: "external-mcp-drift-grant", children: [_jsx("input", { type: "checkbox", checked: false, onChange: () => onAllowWrite(entry.connectionId, remoteName), "data-agent-element": `mcp-drift-grant-${entry.connectionId}-${remoteName}` }), _jsx("span", { children: t("Allow changes") })] })) : null] }));
34
+ }
35
+ /** One connection's saved-vs-live line plus its rows. The count line is only rendered when names
36
+ * are actually missing: "Live now: 5. Saved: 5." is noise, and the parameterized key is written
37
+ * around naming the absent ones. */
38
+ function AdmissionConnectionSection(props) {
39
+ const { connection, t, onAllowWrite, onRequestRemove } = props;
40
+ return (_jsxs("section", { className: "external-mcp-drift-connection", children: [_jsx("h4", { children: connection.connectionId }), connection.notLoaded.length > 0 ? (_jsx("p", { children: interpolate({ template: t("Live now: {live} tools. Saved: {saved} tools — {names} are not loaded."), vars: {
41
+ live: connection.liveToolCount,
42
+ saved: connection.savedToolCount,
43
+ names: connection.notLoaded.join(", "),
44
+ } }) })) : null, _jsx("ul", { children: connection.entries.map((entry) => (_jsx(AdmissionDriftRow, { entry: entry, t: t, onAllowWrite: onAllowWrite, onRequestRemove: onRequestRemove }, `${entry.connectionId}:${entry.remoteName}:${entry.kind}`))) })] }));
45
+ }
46
+ /**
47
+ * The restart footer. D-4: the restart route is `system.write`-gated while this tab is
48
+ * `admin.integrations.manage`-gated, so an operator with integration rights and no system rights is
49
+ * told who can do it instead of being handed a button that 403s on click.
50
+ *
51
+ * "Accepted", never "restarted": the route answers as soon as a restart is INITIATED and no "the
52
+ * daemon became healthy" signal exists anywhere in this codebase (that route's own header). Saying
53
+ * more than was actually learned is the failure mode this whole slice exists to close.
54
+ */
55
+ function AdmissionRestartFooter(props) {
56
+ const { controller, t } = props;
57
+ if (!controller.canRestart) {
58
+ return (_jsx("p", { className: "external-mcp-drift-restart", children: t("You don't have permission to restart the assistant. Ask someone who does to restart it so this change takes effect.") }));
59
+ }
60
+ return (_jsxs("p", { className: "external-mcp-drift-restart", children: [_jsx("button", { type: "button", onClick: controller.restart, disabled: controller.restarting, "data-agent-element": "mcp-drift-restart", children: t("Restart the assistant") }), " ", _jsx("span", { children: t("This ends any conversation in progress.") }), controller.restartError ? _jsx("span", { role: "alert", children: controller.restartError }) : null, controller.restartAccepted ? _jsx("span", { role: "status", children: t("Restarting…") }) : null] }));
61
+ }
62
+ export function ExternalMcpAdmissionsBanner({ controller, t, onAllowWrite, onRequestRemove, describeHeadline }) {
63
+ if (controller.loading)
64
+ return null;
65
+ if (controller.waitingForAssistant) {
66
+ return (_jsx("p", { className: "external-mcp-status", role: "status", children: t("The assistant is starting. This list updates on its own when it's ready.") }));
67
+ }
68
+ if (controller.unavailable) {
69
+ return (_jsx("div", { className: "external-mcp-banner", role: "status", children: controller.unavailable }));
70
+ }
71
+ if (controller.connections.length === 0)
72
+ return null;
73
+ return (
74
+ // No `role` on the wrapper: this renders on load rather than in response to an action, so it is
75
+ // ordinary content, and a live region wrapping the two live regions below (the restart refusal's
76
+ // `alert` and its `status`) would make a screen reader announce the whole banner again on every
77
+ // inner change.
78
+ _jsxs("div", { className: "external-mcp-banner external-mcp-drift", children: [_jsx("p", { children: t(describeHeadline({ connections: controller.connections })) }), controller.connections.map((connection) => (_jsx(AdmissionConnectionSection, { connection: connection, t: t, onAllowWrite: onAllowWrite, onRequestRemove: onRequestRemove }, connection.connectionId))), controller.restartHelps ? _jsx(AdmissionRestartFooter, { controller: controller, t: t }) : null] }));
79
+ }
80
+ //# sourceMappingURL=ExternalMcpAdmissionsBanner.js.map
@@ -0,0 +1,50 @@
1
+ import type { ExternalMcpSettingsPanelProps } from "./ExternalMcpSettingsPanel.js";
2
+ import type { Translate } from "@jini-ai/core/text";
3
+ type SourceConfigItem = Awaited<ReturnType<ExternalMcpSettingsPanelProps["dependencies"]["port"]["fetchSources"]>>[number];
4
+ type SourceFieldSpec = ReturnType<ExternalMcpSettingsPanelProps["deps"]["buildExternalMcpFieldSpecs"]>[number];
5
+ type SourceConfigList = ReturnType<ExternalMcpSettingsPanelProps["hooks"]["useWiredSourceConfigListHook"]>;
6
+ /** The "Add server" form, split out from `ExternalMcpSettingsPanel` purely to keep that
7
+ * component's own cognitive complexity under the gate — same conditional rendering, same two
8
+ * presence-only prop spreads (`submitError`, the draft's own `testResult`), just out of the
9
+ * parent's nesting scope. `null` while the form is closed, same as the inline ternary it replaces. */
10
+ export declare function ExternalMcpAddFormSection(props: {
11
+ kit: ExternalMcpSettingsPanelProps["kit"];
12
+ deps: ExternalMcpSettingsPanelProps["deps"];
13
+ t: (key: string) => string;
14
+ open: boolean;
15
+ fieldSpecs: SourceFieldSpec[];
16
+ addForm: ReturnType<ExternalMcpSettingsPanelProps["hooks"]["useExternalMcpAddFormHook"]>["addForm"];
17
+ canTest: boolean;
18
+ testing: boolean;
19
+ testResult: SourceConfigList["testResults"][string] | undefined;
20
+ onTest: () => void;
21
+ onCancel: () => void;
22
+ }, _optional?: {}): import("react").JSX.Element | null;
23
+ /** The remove-confirmation dialog, split out for the same complexity-budget reason as
24
+ * {@link ExternalMcpAddFormSection}/{@link ExternalMcpSourcesSection} above. Renders nothing until
25
+ * `confirmRemoveId` names a still-configured source — cleared (by the panel) the instant Confirm
26
+ * or Cancel resolves, so a stale id from a source removed some other way (e.g. a second tab)
27
+ * degrades to "no dialog" rather than throwing on a missing source. */
28
+ export declare function ExternalMcpRemoveConfirmSection(props: {
29
+ kit: ExternalMcpSettingsPanelProps["kit"];
30
+ hooks: ExternalMcpSettingsPanelProps["hooks"];
31
+ deps: ExternalMcpSettingsPanelProps["deps"];
32
+ confirmRemoveId: string | null;
33
+ sources: readonly SourceConfigItem[];
34
+ cardHandles: string[];
35
+ t: Translate;
36
+ tDrift: Translate;
37
+ onConfirm: (sourceId: string) => void;
38
+ onCancel: () => void;
39
+ }, _optional?: {}): import("react").JSX.Element | null;
40
+ export declare function ExternalMcpSettingsHeader({ kit, showTitle, t, tDrift, toggleForm, formOpen, banner }: {
41
+ kit: ExternalMcpSettingsPanelProps["kit"];
42
+ showTitle: boolean;
43
+ t: Translate;
44
+ tDrift: Translate;
45
+ toggleForm: ReturnType<ExternalMcpSettingsPanelProps["hooks"]["useExternalMcpAddFormHook"]>['toggleForm'];
46
+ formOpen: boolean;
47
+ banner: SourceConfigList['error'];
48
+ }, _optional?: {}): import("react").JSX.Element;
49
+ export {};
50
+ //# sourceMappingURL=ExternalMcpPanelSections.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /** The "Add server" form, split out from `ExternalMcpSettingsPanel` purely to keep that
3
+ * component's own cognitive complexity under the gate — same conditional rendering, same two
4
+ * presence-only prop spreads (`submitError`, the draft's own `testResult`), just out of the
5
+ * parent's nesting scope. `null` while the form is closed, same as the inline ternary it replaces. */
6
+ export function ExternalMcpAddFormSection(props, _optional = {}) {
7
+ const { SourceConfigAddForm } = props.kit;
8
+ const { EXTERNAL_MCP_ADD_FORM_HANDLE } = props.deps;
9
+ if (!props.open)
10
+ return null;
11
+ const { t, fieldSpecs, addForm, canTest, testing, testResult, onTest, onCancel } = props;
12
+ return (_jsx(SourceConfigAddForm, { fieldSpecs: fieldSpecs, values: addForm.values, validation: addForm.validation, submitAttempted: addForm.submitAttempted, submitting: addForm.submitting, ...(addForm.submitError ? { submitError: addForm.submitError } : {}), onFieldChange: addForm.setField, onSubmit: () => void addForm.submit(), canTest: canTest, testing: testing, ...(testResult ? { testResult } : {}), onTest: onTest, addLabel: "Add server", agentHandle: EXTERNAL_MCP_ADD_FORM_HANDLE, onCancel: onCancel }));
13
+ }
14
+ /** The remove-confirmation dialog, split out for the same complexity-budget reason as
15
+ * {@link ExternalMcpAddFormSection}/{@link ExternalMcpSourcesSection} above. Renders nothing until
16
+ * `confirmRemoveId` names a still-configured source — cleared (by the panel) the instant Confirm
17
+ * or Cancel resolves, so a stale id from a source removed some other way (e.g. a second tab)
18
+ * degrades to "no dialog" rather than throwing on a missing source. */
19
+ export function ExternalMcpRemoveConfirmSection(props, _optional = {}) {
20
+ const { ExternalMcpRemoveConfirmDialog } = props.kit;
21
+ const { sourceDisplayLabel, buildExternalMcpFieldSpecs, resolveExternalMcpEffectiveAuthMode } = props.deps;
22
+ const { confirmRemoveId, sources, cardHandles, tDrift, onConfirm, onCancel } = props;
23
+ if (confirmRemoveId === null)
24
+ return null;
25
+ const index = sources.findIndex((source) => source.id === confirmRemoveId);
26
+ if (index === -1)
27
+ return null;
28
+ const source = sources[index];
29
+ return (_jsx(ExternalMcpRemoveConfirmDialog, { name: sourceDisplayLabel({ source, fieldSpecs: buildExternalMcpFieldSpecs(source.fields, { t: tDrift }) }), isOAuth: resolveExternalMcpEffectiveAuthMode(source.fields) === "oauth", cardHandle: cardHandles[index], onConfirm: () => onConfirm(source.id), onCancel: onCancel, t: tDrift, ConfirmDialog: props.kit.ConfirmActionDialog, buildCopy: props.deps.buildExternalMcpRemoveConfirmCopy, useExternalMcpRemoveConfirmHook: props.hooks.useExternalMcpRemoveConfirm, useFocusTrapHook: props.hooks.useFocusTrap }));
30
+ }
31
+ export function ExternalMcpSettingsHeader({ kit, showTitle, t, tDrift, toggleForm, formOpen, banner }, _optional = {}) {
32
+ const { Icon } = kit;
33
+ return _jsxs(_Fragment, { children: [_jsxs("div", { className: "external-mcp-head", children: [_jsxs("div", { children: [showTitle ? _jsx("h3", { children: t("External MCP servers") }) : null, _jsx("p", { className: "external-mcp-subtitle", children: tDrift("Third-party tools for your coding agent.") })] }), _jsxs("button", { type: "button", className: "external-mcp-add-button", onClick: toggleForm, "aria-expanded": formOpen, children: [_jsx(Icon, { name: "plus", size: 14 }), _jsx("span", { children: t("Add server") })] })] }), banner ? (_jsx("div", { className: "external-mcp-banner", role: "alert", children: t(banner) })) : null] });
34
+ }
35
+ //# sourceMappingURL=ExternalMcpPanelSections.js.map