@jini-ai/mcp 0.7.3-next.2 → 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.
- package/README.md +15 -0
- package/dist/agent-install/owned-json-install.d.ts +1 -1
- package/dist/client/client.js +1 -1
- package/dist/client/css-url-refs.d.ts +3 -1
- package/dist/client/css-url-refs.js +1 -1
- package/dist/external/access-review.d.ts +46 -0
- package/dist/external/access-review.js +175 -0
- package/dist/external/agent-tools.d.ts +72 -0
- package/dist/external/agent-tools.js +218 -0
- package/dist/external/built-in-connections.d.ts +17 -0
- package/dist/external/built-in-connections.js +15 -0
- package/dist/external/external-mcp-host-copy.d.ts +14 -0
- package/dist/external/external-mcp-host-copy.js +8 -0
- package/dist/external/operations-tools.d.ts +69 -0
- package/dist/external/operations-tools.js +96 -0
- package/dist/external/save-form.d.ts +105 -0
- package/dist/external/save-form.js +260 -0
- package/dist/external/save-input.d.ts +41 -0
- package/dist/external/save-input.js +149 -0
- package/dist/external/tool-registrations.d.ts +130 -0
- package/dist/external/tool-registrations.js +299 -0
- package/dist/federation/bootstrap.d.ts +18 -0
- package/dist/federation/bootstrap.js +2 -2
- package/dist/federation/external-mcp-admissions.d.ts +19 -0
- package/dist/federation/external-mcp-admissions.js +30 -0
- package/dist/federation/external-mcp-probe.d.ts +86 -0
- package/dist/federation/external-mcp-probe.js +75 -0
- package/dist/federation/hosted/external-mcp-repo.d.ts +108 -0
- package/dist/federation/hosted/external-mcp-repo.js +210 -0
- package/dist/federation/hosted/external-mcp-repo.writes.d.ts +75 -0
- package/dist/federation/hosted/external-mcp-repo.writes.js +131 -0
- package/dist/federation/hosted/store-credentials.d.ts +6 -1
- package/dist/federation/hosted/store-credentials.js +2 -2
- package/dist/federation/hosted/store-input.d.ts +11 -3
- package/dist/federation/hosted/store-input.js +5 -5
- package/dist/federation/hosted/store-oauth-fields.d.ts +10 -2
- package/dist/federation/hosted/store-oauth-fields.js +7 -7
- package/dist/federation/hosted/store-view.d.ts +6 -1
- package/dist/federation/hosted/store-view.js +2 -2
- package/dist/federation/hosted/store.js +7 -7
- package/dist/federation/hosted/store.memory.d.ts +2 -0
- package/dist/federation/hosted/store.memory.js +6 -2
- package/dist/federation/index.d.ts +2 -0
- package/dist/federation/index.js +2 -0
- package/dist/federation/registrations.js +73 -56
- package/dist/federation/roster-change.d.ts +63 -0
- package/dist/federation/roster-change.js +68 -0
- package/dist/federation/runtime.d.ts +140 -0
- package/dist/federation/runtime.js +118 -0
- package/dist/react/external-mcp/ExternalMcpAdmissionsBanner.d.ts +42 -0
- package/dist/react/external-mcp/ExternalMcpAdmissionsBanner.js +80 -0
- package/dist/react/external-mcp/ExternalMcpPanelSections.d.ts +50 -0
- package/dist/react/external-mcp/ExternalMcpPanelSections.js +35 -0
- package/dist/react/external-mcp/ExternalMcpSettingsPanel.d.ts +446 -0
- package/dist/react/external-mcp/ExternalMcpSettingsPanel.hooks.d.ts +135 -0
- package/dist/react/external-mcp/ExternalMcpSettingsPanel.hooks.js +122 -0
- package/dist/react/external-mcp/ExternalMcpSettingsPanel.js +63 -0
- package/dist/react/external-mcp/ExternalMcpSourceRow.d.ts +40 -0
- package/dist/react/external-mcp/ExternalMcpSourceRow.js +100 -0
- package/dist/react/external-mcp/hooks/external-mcp-form.rules.d.ts +58 -0
- package/dist/react/external-mcp/hooks/external-mcp-form.rules.js +209 -0
- package/dist/react/external-mcp/hooks/external-mcp-source-actions.d.ts +115 -0
- package/dist/react/external-mcp/hooks/external-mcp-source-actions.js +152 -0
- package/dist/react/external-mcp/hooks/use-external-mcp-admissions.hooks.d.ts +166 -0
- package/dist/react/external-mcp/hooks/use-external-mcp-admissions.hooks.js +209 -0
- package/dist/react/external-mcp/hooks/use-external-mcp.hooks.d.ts +132 -0
- package/dist/react/external-mcp/hooks/use-external-mcp.hooks.js +37 -0
- package/dist/server/tool-arguments.d.ts +5 -1
- package/dist/server/tool-arguments.js +13 -9
- package/dist/server/tool-protocol.js +7 -5
- package/dist/server/tools/tool-catalog-tools.js +6 -3
- package/dist/tools/ask-choice/custom-answer.d.ts +77 -0
- package/dist/tools/ask-choice/custom-answer.js +113 -0
- package/dist/tools/ask-choice/index.d.ts +2 -0
- package/dist/tools/ask-choice/index.js +1 -0
- package/package.json +122 -7
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @file `ExternalMcpSettingsPanel.tsx`'s own derived-value logic, split out per the
|
|
4
|
+
* `<Name>.tsx`/`<Name>.hooks.tsx` pattern `TabBar.tsx`/`TabBar.hooks.tsx` establishes (admin
|
|
5
|
+
* TSX-logic-sweep, 2026-09-05) — this repo's rule that a `.tsx` file carries no functions or derived
|
|
6
|
+
* logic of its own.
|
|
7
|
+
*/
|
|
8
|
+
/** `ExternalMcpSettingsPanel`'s own per-card agent handles. Not `useMemo`'d: an O(n) pass (see
|
|
9
|
+
* `buildAgentListHandles`'s own `@complexity` doc, which `buildExternalMcpCardHandles` wraps) over
|
|
10
|
+
* one workspace's own configured external MCP servers — small and cheap enough next to the render
|
|
11
|
+
* it feeds that memoizing it was not judged worth the added indirection. That is a decision about
|
|
12
|
+
* memoization, separate from why this now lives outside the component body at all (the
|
|
13
|
+
* `.tsx` bodies carry no derived logic). */
|
|
14
|
+
export function resolveExternalMcpCardHandles({ sources, buildHandles }, _optional = {}) {
|
|
15
|
+
return buildHandles({ sourceIds: sources.map((source) => source.id) });
|
|
16
|
+
}
|
|
17
|
+
/** Each card's saved intent, keyed by server id — the "saved" half of the saved-vs-live comparison
|
|
18
|
+
* the admissions banner states. Memoized because it is the dependency of a `useMemo` inside
|
|
19
|
+
* `useExternalMcpAdmissions`: rebuilding the object every render would make that memo useless.
|
|
20
|
+
*
|
|
21
|
+
* `enabled` joined `allowedToolNames` here for ADM-001 (2026-09-07): the banner now reports a saved
|
|
22
|
+
* connection the daemon is not running, and without the toggle it would report every server the
|
|
23
|
+
* operator deliberately switched off as a fault. `SourceConfigItem.enabled` is optional in
|
|
24
|
+
* `@jini-ai/ui`'s type; `toItem` in `use-external-mcp.hooks.ts` always sets it from the stored
|
|
25
|
+
* record, so `?? true` only ever covers a source that came from somewhere else — and "on" is the
|
|
26
|
+
* right reading of a missing flag, since a card with no toggle state is not one the operator
|
|
27
|
+
* turned off. Saved transport/command identify missing stdio launchers; the existing transport
|
|
28
|
+
* rule also supplies the legacy stdio default for cards without an explicit transport. */
|
|
29
|
+
export function useSavedAllowedToolNamesById({ sources, resolveTransport, needsSignIn }, _optional = {}) {
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
const byId = {};
|
|
32
|
+
for (const source of sources) {
|
|
33
|
+
byId[source.id] = {
|
|
34
|
+
allowedToolNames: source.fields["allowedToolNames"] ?? "",
|
|
35
|
+
enabled: source.enabled ?? true,
|
|
36
|
+
transport: resolveTransport(source.fields),
|
|
37
|
+
command: source.fields["command"] ?? "",
|
|
38
|
+
needsSignIn: needsSignIn({ source }),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return byId;
|
|
42
|
+
}, [sources, resolveTransport, needsSignIn]);
|
|
43
|
+
}
|
|
44
|
+
export function useExternalMcpDriftCopy({ useLocaleHook, translate }, _optional = {}) {
|
|
45
|
+
const locale = useLocaleHook();
|
|
46
|
+
return useCallback((key) => translate({ locale: locale, key: key }), [locale, translate]);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The banner's one-click fix, as the panel's `updateSource` patch.
|
|
50
|
+
*
|
|
51
|
+
* Written through the SAME port the card's own edit form uses, so `mergeSourceUpdate` fills in
|
|
52
|
+
* every field this patch does not mention and `toWriteBody`'s omit-when-blank rules keep `env` and
|
|
53
|
+
* `oauthClientSecret` from being wiped — the asymmetry `use-external-mcp.hooks.ts`'s header calls
|
|
54
|
+
* the safe direction. Reaching for `api.saveExternalMcpServer` directly here would bypass both.
|
|
55
|
+
*
|
|
56
|
+
* @returns The patch, or `null` when the id names no configured card (nothing to write).
|
|
57
|
+
*/
|
|
58
|
+
export function buildAllowWritePatch({ sources, connectionId, remoteName, grantWriteFieldValue }, _options = {}) {
|
|
59
|
+
const source = sources.find((candidate) => candidate.id === connectionId);
|
|
60
|
+
if (!source)
|
|
61
|
+
return null;
|
|
62
|
+
return { fields: { writeAllowedToolNames: grantWriteFieldValue({ currentWriteAllowedToolNames: source.fields["writeAllowedToolNames"], remoteName }) } };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Owns `ExternalMcpSettingsPanel`'s "Add server" form: its open state, the draft, and the lagged
|
|
66
|
+
* transport/auth-mode sync that keeps the form's field specs following the operator's own choices
|
|
67
|
+
* (see `ExternalMcpSettingsPanel.tsx`'s "two-pass reactive field-spec sync" header for why the sync
|
|
68
|
+
* is one render behind, by design).
|
|
69
|
+
*
|
|
70
|
+
* `fieldSpecs` is deliberately rebuilt every render (not `useMemo`'d), exactly as it was when this
|
|
71
|
+
* lived in the component body — this move changes where the logic lives, not how often it runs.
|
|
72
|
+
*
|
|
73
|
+
* @param input.dependencies - The same source-config port the panel's list uses.
|
|
74
|
+
* @param input.list - Receives a newly added server (`addSourceToList`), so the roster shows it
|
|
75
|
+
* without a reload.
|
|
76
|
+
* @returns See {@link ExternalMcpAddFormController}.
|
|
77
|
+
* @complexity O(1) per render beyond `buildExternalMcpFieldSpecs`'s fixed-size spec list.
|
|
78
|
+
*/
|
|
79
|
+
export function useExternalMcpAddForm({ dependencies, list, useDriftCopyHook, useSourceConfigAddFormHook, buildFieldSpecs, resolveTransport, resolveAuthMode }, _optional = {}) {
|
|
80
|
+
const t = useDriftCopyHook();
|
|
81
|
+
const [formOpen, setFormOpen] = useState(false);
|
|
82
|
+
const [transportGuess, setTransportGuess] = useState("stdio");
|
|
83
|
+
const [authModeGuess, setAuthModeGuess] = useState("static_env");
|
|
84
|
+
const fieldSpecs = buildFieldSpecs({ transport: transportGuess, authMode: authModeGuess }, { t });
|
|
85
|
+
const addForm = useSourceConfigAddFormHook({
|
|
86
|
+
dependencies,
|
|
87
|
+
fieldSpecs,
|
|
88
|
+
onAdded: (source) => {
|
|
89
|
+
list.addSourceToList(source);
|
|
90
|
+
setFormOpen(false);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
// Pre-select sensible defaults the instant the form opens, so the two `select` fields never show
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!formOpen)
|
|
96
|
+
return;
|
|
97
|
+
if (addForm.values.transport === "")
|
|
98
|
+
addForm.setField("transport", "stdio");
|
|
99
|
+
if (addForm.values.authMode === "")
|
|
100
|
+
addForm.setField("authMode", "static_env");
|
|
101
|
+
}, [formOpen, addForm.values.transport, addForm.values.authMode, addForm.setField]);
|
|
102
|
+
// The lagged sync `ExternalMcpSettingsPanel.tsx`'s header describes.
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const nextTransport = resolveTransport(addForm.values);
|
|
105
|
+
const nextAuthMode = resolveAuthMode(addForm.values);
|
|
106
|
+
if (nextTransport !== transportGuess)
|
|
107
|
+
setTransportGuess(nextTransport);
|
|
108
|
+
if (nextAuthMode !== authModeGuess)
|
|
109
|
+
setAuthModeGuess(nextAuthMode);
|
|
110
|
+
}, [addForm.values, transportGuess, authModeGuess, resolveTransport, resolveAuthMode]);
|
|
111
|
+
return {
|
|
112
|
+
formOpen,
|
|
113
|
+
toggleForm: () => setFormOpen((open) => !open),
|
|
114
|
+
cancelForm: () => {
|
|
115
|
+
addForm.reset();
|
|
116
|
+
setFormOpen(false);
|
|
117
|
+
},
|
|
118
|
+
fieldSpecs,
|
|
119
|
+
addForm,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=ExternalMcpSettingsPanel.hooks.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { buildAllowWritePatch, resolveExternalMcpCardHandles } from "./ExternalMcpSettingsPanel.hooks.js";
|
|
4
|
+
import { ExternalMcpAdmissionsBanner } from "./ExternalMcpAdmissionsBanner.js";
|
|
5
|
+
import { ExternalMcpSourcesSection } from "./ExternalMcpSourceRow.js";
|
|
6
|
+
import { ExternalMcpAddFormSection, ExternalMcpRemoveConfirmSection, ExternalMcpSettingsHeader } from "./ExternalMcpPanelSections.js";
|
|
7
|
+
/**
|
|
8
|
+
* Mirrors `@jini-ai/ui`'s own `source-config-list/constants.ts`'s `DRAFT_TEST_SCOPE` — the pseudo-id
|
|
9
|
+
* that feature's `useSourceConfigList().test`/`.isPending`/`.testResults` key a "test before save"
|
|
10
|
+
* call on, for the add-form's still-unsaved draft. Not part of that package's public barrel (only
|
|
11
|
+
* `MASK_CHAR` and its two siblings are re-exported from `constants.ts`), so it is restated here
|
|
12
|
+
* rather than imported — same restatement `use-external-mcp.hooks.ts`'s own header describes for
|
|
13
|
+
* `SourceUpdateInput`. Must keep matching the private constant it mirrors; `ExternalMcpTab.tsx` in
|
|
14
|
+
* Jini is the source of truth for the literal value.
|
|
15
|
+
*/
|
|
16
|
+
const DRAFT_TEST_SCOPE = "__draft__";
|
|
17
|
+
export function ExternalMcpSettingsPanel({ dependencies, saveStatusLabel, showTitle = true, hooks, kit, deps }, _optional = {}) {
|
|
18
|
+
const { useTHook, useWiredSourceConfigListHook, useExternalMcpAddFormHook, useSavedAllowedToolNamesByIdHook, useExternalMcpAdmissionsHook, useExternalMcpDriftCopyHook } = hooks;
|
|
19
|
+
const { buildExternalMcpCardHandles, resolveExternalMcpEffectiveTransport, externalMcpNeedsSignIn } = deps;
|
|
20
|
+
const t = useTHook();
|
|
21
|
+
// The id of the source Remove was pressed for, until Confirm or Cancel resolves it — see this
|
|
22
|
+
// file's own "Remove asks first" header note. `null` means no confirmation dialog is open.
|
|
23
|
+
const [confirmRemoveId, setConfirmRemoveId] = useState(null);
|
|
24
|
+
const list = useWiredSourceConfigListHook({ dependencies });
|
|
25
|
+
// The "Add server" form: open state, draft, and the lagged field-spec sync this file's header
|
|
26
|
+
// describes — all owned by the hook.
|
|
27
|
+
const { formOpen, toggleForm, cancelForm, fieldSpecs: addFormFieldSpecs, addForm } = useExternalMcpAddFormHook({
|
|
28
|
+
dependencies,
|
|
29
|
+
list,
|
|
30
|
+
});
|
|
31
|
+
const banner = list.error;
|
|
32
|
+
const cardHandles = resolveExternalMcpCardHandles({ sources: list.sources, buildHandles: buildExternalMcpCardHandles });
|
|
33
|
+
// What the RUNNING assistant admitted, as opposed to what this tab saved — two different objects,
|
|
34
|
+
// because `Jini packages/mcp/src/federation/trust.ts` R5 freezes the admitted set at connect. Until this banner
|
|
35
|
+
// existed the gap was visible only in the daemon's boot terminal.
|
|
36
|
+
const savedAllowedToolNamesById = useSavedAllowedToolNamesByIdHook({ sources: list.sources, resolveTransport: resolveExternalMcpEffectiveTransport, needsSignIn: externalMcpNeedsSignIn });
|
|
37
|
+
const admissions = useExternalMcpAdmissionsHook(savedAllowedToolNamesById);
|
|
38
|
+
const tDrift = useExternalMcpDriftCopyHook();
|
|
39
|
+
return _jsx(ExternalMcpSettingsPanelBody, { hooks: hooks, kit: kit, deps: deps, list: list, t: t, tDrift: tDrift, showTitle: showTitle, saveStatusLabel: saveStatusLabel, formOpen: formOpen, toggleForm: toggleForm, cancelForm: cancelForm, addFormFieldSpecs: addFormFieldSpecs, addForm: addForm, banner: banner, cardHandles: cardHandles, admissions: admissions, confirmRemoveId: confirmRemoveId, setConfirmRemoveId: setConfirmRemoveId });
|
|
40
|
+
}
|
|
41
|
+
function ExternalMcpSettingsPanelBody(props, _optional = {}) {
|
|
42
|
+
const { hooks, kit, deps, list, cardHandles, t, tDrift, confirmRemoveId, setConfirmRemoveId, saveStatusLabel } = props;
|
|
43
|
+
return (_jsxs("section", { className: "external-mcp-tab", children: [ExternalMcpPanelHead(props), _jsx(ExternalMcpSourcesSection, { kit: kit, hooks: hooks, deps: deps, list: list, cardHandles: cardHandles, t: t, tDrift: tDrift, onRequestRemove: setConfirmRemoveId }), _jsx(ExternalMcpRemoveConfirmSection, { kit: kit, hooks: hooks, deps: deps, confirmRemoveId: confirmRemoveId, sources: list.sources, cardHandles: cardHandles, t: t, tDrift: tDrift, onConfirm: (sourceId) => {
|
|
44
|
+
setConfirmRemoveId(null);
|
|
45
|
+
void list.remove(sourceId);
|
|
46
|
+
}, onCancel: () => setConfirmRemoveId(null) }), saveStatusLabel ? (_jsx("div", { className: "external-mcp-footer", children: _jsx("span", { className: "external-mcp-save-pill", children: t(saveStatusLabel) }) })) : null] }));
|
|
47
|
+
}
|
|
48
|
+
function ExternalMcpPanelHead(props, _optional = {}) {
|
|
49
|
+
const { kit, deps, list, t, tDrift, showTitle, formOpen, toggleForm, cancelForm, addFormFieldSpecs, addForm, banner, admissions, setConfirmRemoveId } = props;
|
|
50
|
+
return _jsxs(_Fragment, { children: [_jsx(ExternalMcpSettingsHeader, { kit: kit, showTitle: showTitle, t: t, tDrift: tDrift, toggleForm: toggleForm, formOpen: formOpen, banner: banner }), _jsx(ExternalMcpAddFormSection, { kit: kit, deps: deps, t: t, open: formOpen, fieldSpecs: addFormFieldSpecs, addForm: addForm, canTest: list.capabilities.canTest, testing: list.isPending(DRAFT_TEST_SCOPE, "test"), testResult: list.testResults[DRAFT_TEST_SCOPE], onTest: () => void list.test(undefined, addForm.values),
|
|
51
|
+
// Cancel discards the draft, not just hides it — see `useExternalMcpAddForm`'s `cancelForm`.
|
|
52
|
+
onCancel: cancelForm }), _jsx(ExternalMcpAdmissionsBanner, { describeHeadline: (required) => deps.describeDriftHeadline({ ...required, copy: deps.driftCopy }), controller: admissions, t: tDrift, onRequestRemove: setConfirmRemoveId, onAllowWrite: (connectionId, remoteName) => {
|
|
53
|
+
const patch = buildAllowWritePatch({ sources: list.sources, connectionId, remoteName, grantWriteFieldValue: deps.grantWriteFieldValue });
|
|
54
|
+
if (patch)
|
|
55
|
+
void list.update(connectionId, patch);
|
|
56
|
+
} })] });
|
|
57
|
+
}
|
|
58
|
+
export function bindExternalMcpSettingsPanel({ hooks, kit, deps }, _optional = {}) {
|
|
59
|
+
return function BoundExternalMcpSettingsPanel(props, _optional = {}) {
|
|
60
|
+
return _jsx(ExternalMcpSettingsPanel, { ...props, kit: kit, deps: deps, hooks: hooks });
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ExternalMcpSettingsPanel.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
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 unmodified `SourceConfigItemCard`, exactly as it rendered before the Connection/Tools tab
|
|
7
|
+
* split ever existed (and still does — see this file's "Per-server Tools modal" header, the modal
|
|
8
|
+
* replaced the TABS, not this card). Split into its own component so its `testResult`
|
|
9
|
+
* presence-spread is not a conditional expression NESTED inside {@link ExternalMcpSourceRow}'s own
|
|
10
|
+
* JSX — `sonarjs/no-nested-conditional`'s complaint about the shape, not about anything the values
|
|
11
|
+
* do. */
|
|
12
|
+
export declare function ExternalMcpConnectionCard({ hooks, kit, deps, ...props }: {
|
|
13
|
+
hooks: ExternalMcpSettingsPanelProps["hooks"];
|
|
14
|
+
kit: ExternalMcpSettingsPanelProps["kit"];
|
|
15
|
+
deps: ExternalMcpSettingsPanelProps["deps"];
|
|
16
|
+
source: SourceConfigItem;
|
|
17
|
+
cardHandle: string;
|
|
18
|
+
fieldSpecs: SourceFieldSpec[];
|
|
19
|
+
list: SourceConfigList;
|
|
20
|
+
onRequestRemove: (sourceId: string) => void;
|
|
21
|
+
}, _optional?: {}): import("react").JSX.Element;
|
|
22
|
+
/** The loading / empty-state / configured-server-list body, split out for the same
|
|
23
|
+
* complexity-budget reason as {@link ExternalMcpAddFormSection} above — the triple-branch
|
|
24
|
+
* loading/empty/list ternary was the parent's deepest nesting. Each configured server is now one
|
|
25
|
+
* {@link ExternalMcpSourceRow}, which owns the per-card `testResult` presence-spread and its own
|
|
26
|
+
* Tools-modal-open state. */
|
|
27
|
+
export declare function ExternalMcpSourcesSection(props: {
|
|
28
|
+
hooks: ExternalMcpSettingsPanelProps["hooks"];
|
|
29
|
+
kit: ExternalMcpSettingsPanelProps["kit"];
|
|
30
|
+
deps: ExternalMcpSettingsPanelProps["deps"];
|
|
31
|
+
list: SourceConfigList;
|
|
32
|
+
cardHandles: string[];
|
|
33
|
+
t: Translate;
|
|
34
|
+
tDrift: Translate;
|
|
35
|
+
/** Opens the remove-confirmation dialog for this source id, instead of deleting immediately —
|
|
36
|
+
* see this file's own "Remove asks first" header note. */
|
|
37
|
+
onRequestRemove: (sourceId: string) => void;
|
|
38
|
+
}, _optional?: {}): import("react").JSX.Element;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=ExternalMcpSourceRow.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { agentHandle } from "@jini-ai/core/agent-handles";
|
|
4
|
+
/** The unmodified `SourceConfigItemCard`, exactly as it rendered before the Connection/Tools tab
|
|
5
|
+
* split ever existed (and still does — see this file's "Per-server Tools modal" header, the modal
|
|
6
|
+
* replaced the TABS, not this card). Split into its own component so its `testResult`
|
|
7
|
+
* presence-spread is not a conditional expression NESTED inside {@link ExternalMcpSourceRow}'s own
|
|
8
|
+
* JSX — `sonarjs/no-nested-conditional`'s complaint about the shape, not about anything the values
|
|
9
|
+
* do. */
|
|
10
|
+
export function ExternalMcpConnectionCard({ hooks, kit, deps, ...props }, _optional = {}) {
|
|
11
|
+
const { useExternalMcpDriftCopyHook } = hooks;
|
|
12
|
+
const { SourceConfigItemCard } = kit;
|
|
13
|
+
const { isBuiltInExternalMcpSource } = deps;
|
|
14
|
+
const { source, cardHandle, fieldSpecs, list, onRequestRemove } = props;
|
|
15
|
+
const testResult = list.testResults[source.id];
|
|
16
|
+
const tBuiltIn = useExternalMcpDriftCopyHook();
|
|
17
|
+
if (isBuiltInExternalMcpSource({ source })) {
|
|
18
|
+
return _jsx(ExternalMcpBuiltInCard, { source: source, cardHandle: cardHandle, fieldSpecs: fieldSpecs, list: list, tBuiltIn: tBuiltIn, kit: kit, deps: deps });
|
|
19
|
+
}
|
|
20
|
+
return (_jsx(SourceConfigItemCard, { source: source, agentHandle: cardHandle, fieldSpecs: fieldSpecs, capabilities: list.capabilities, removing: list.isPending(source.id, "remove"), refreshing: list.isPending(source.id, "refresh"), settingTrust: list.isPending(source.id, "trust"), testing: list.isPending(source.id, "test"), updating: list.isPending(source.id, "update"), onRefresh: () => void list.refresh(source.id), onRemove: () => onRequestRemove(source.id), onTest: () => void list.test(source.id), onUpdate: (patch) => void list.update(source.id, patch), ...(testResult ? { testResult } : {}) }));
|
|
21
|
+
}
|
|
22
|
+
function ExternalMcpBuiltInCard({ source, cardHandle, fieldSpecs, list, tBuiltIn, kit, deps }, _optional = {}) {
|
|
23
|
+
const { InfoTip } = kit;
|
|
24
|
+
const { sourceDisplayLabel, EXTERNAL_MCP_PRODUCT_VARS } = deps;
|
|
25
|
+
// Same head-row shape as `SourceConfigItemCard` (toggle, name, then a small badge and ⓘ), minus
|
|
26
|
+
// Remove and the expandable fields: a built-in connection is the host's, not the operator's.
|
|
27
|
+
const label = sourceDisplayLabel({ source, fieldSpecs });
|
|
28
|
+
const enableLabel = tBuiltIn("Enable {name}").replace("{name}", () => label);
|
|
29
|
+
return (_jsx("div", { className: "source-config-item-card external-mcp-builtin-card", role: "region", "aria-label": label, ...agentHandle({ handle: cardHandle }, { role: "region", label }), children: _jsxs("div", { className: "source-config-item-card-head", children: [_jsx("label", { className: "source-config-item-card-enabled-toggle", title: enableLabel, children: _jsx("input", { type: "checkbox", "aria-label": enableLabel, ...agentHandle({ handle: `${cardHandle}-enabled` }, { role: "checkbox", label: enableLabel }), checked: source.enabled, disabled: list.isPending(source.id, "update"), onChange: (event) => void list.update(source.id, { enabled: event.target.checked }) }) }), _jsxs("span", { className: "external-mcp-builtin-summary", children: [_jsx("span", { className: "source-config-item-card-label", children: label }), _jsx("span", { className: "external-mcp-builtin-badge", children: tBuiltIn("Built-in") }), _jsx(InfoTip, { label: tBuiltIn("Lets this site's assistant list your other {productName} sites, add a site pointer, and reveal a site folder.").replace("{productName}", () => EXTERNAL_MCP_PRODUCT_VARS.productName), triggerLabel: tBuiltIn("About {name}").replace("{name}", () => label), agentHandle: `${cardHandle}-info` })] })] }) }));
|
|
30
|
+
}
|
|
31
|
+
/** The "Connect" button for an OAuth row that isn't signed in (2026-10-23). It disappears once the
|
|
32
|
+
* roster re-reads the row as `connected` — see Jini's `useExternalMcpOAuthConnect` for the flow. While a
|
|
33
|
+
* sign-in is in flight it stays put, disabled, with the same label (no width jump); the line under
|
|
34
|
+
* the row says what it is waiting on. */
|
|
35
|
+
function ExternalMcpConnectButton(props, _optional = {}) {
|
|
36
|
+
const { cardHandle, rowLabel, busy, tDrift, onConnect } = props;
|
|
37
|
+
const label = tDrift("Sign in to {name}").replace("{name}", () => rowLabel);
|
|
38
|
+
return (_jsx("button", { type: "button", className: "external-mcp-source-connect", onClick: onConnect, disabled: busy, "aria-label": label, ...agentHandle({ handle: `${cardHandle}-connect` }, { role: "button", label }), children: tDrift("Connect") }));
|
|
39
|
+
}
|
|
40
|
+
/** The verification page's host, for the device-code line; the raw string if it won't parse. */
|
|
41
|
+
function displayHost({ uri }, _options = {}) {
|
|
42
|
+
try {
|
|
43
|
+
return new URL(uri).host;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return uri;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** The line under a row while sign-in is in flight, or why it failed. `null` when there is
|
|
50
|
+
* nothing to say. */
|
|
51
|
+
function ExternalMcpConnectStatus(props, _optional = {}) {
|
|
52
|
+
const { state, tDrift, onCancel } = props;
|
|
53
|
+
if (state.phase === "idle") {
|
|
54
|
+
return state.error ? _jsx("p", { className: "external-mcp-connect-status external-mcp-connect-status--error", role: "alert", children: state.error }) : null;
|
|
55
|
+
}
|
|
56
|
+
if (state.phase === "starting")
|
|
57
|
+
return null;
|
|
58
|
+
return (_jsxs("p", { className: "external-mcp-connect-status", role: "status", children: [state.phase === "device" ? (_jsxs("span", { children: [tDrift("Enter this code on the sign-in page:"), " ", _jsx("code", { children: state.userCode }), " ", _jsx("a", { href: state.verificationUri, target: "_blank", rel: "noreferrer", children: displayHost({ uri: state.verificationUri }) })] })) : (_jsx("span", { children: tDrift("Finish signing in in the new window.") })), _jsx("button", { type: "button", className: "external-mcp-connect-cancel", onClick: onCancel, children: tDrift("Cancel") })] }));
|
|
59
|
+
}
|
|
60
|
+
function ExternalMcpSourceRow({ hooks, kit, deps, ...props }, _optional = {}) {
|
|
61
|
+
const { useConnect } = hooks;
|
|
62
|
+
const { ExternalMcpSharedChoice } = kit;
|
|
63
|
+
const { buildExternalMcpFieldSpecs, parseSavedToolNames, sourceDisplayLabel, externalMcpNeedsSignIn } = deps;
|
|
64
|
+
const { source, cardHandle, list, tDrift, onRequestRemove } = props;
|
|
65
|
+
const [toolsOpen, setToolsOpen] = useState(false);
|
|
66
|
+
const fieldSpecs = buildExternalMcpFieldSpecs(source.fields, { t: tDrift });
|
|
67
|
+
// The SAVED count, not the picker's own draft — see this file's header on why.
|
|
68
|
+
const enabledToolCount = parseSavedToolNames({ value: source.fields["allowedToolNames"] }).length;
|
|
69
|
+
const rowLabel = sourceDisplayLabel({ source, fieldSpecs });
|
|
70
|
+
// Idle (no listeners, no timers) for every row until its Connect is pressed.
|
|
71
|
+
const signIn = useConnect({ serverId: source.id, grant: source.fields["oauthGrant"] ?? "", onConnected: () => void list.reload() }, { fallbackError: tDrift("Sign-in could not start.") });
|
|
72
|
+
const showConnect = externalMcpNeedsSignIn({ source }) || signIn.state.phase !== "idle";
|
|
73
|
+
return (_jsxs("div", { className: "external-mcp-source", children: [_jsxs("div", { className: "external-mcp-source-row", children: [_jsx("div", { className: "external-mcp-source-card", children: _jsx(ExternalMcpConnectionCard, { source: source, cardHandle: cardHandle, fieldSpecs: fieldSpecs, list: list, onRequestRemove: onRequestRemove, kit: kit, hooks: hooks, deps: deps }) }), ExternalMcpSourceActions({ cardHandle, rowLabel, enabledToolCount, showConnect, signIn, tDrift, setToolsOpen })] }), _jsx(ExternalMcpConnectStatus, { state: signIn.state, tDrift: tDrift, onCancel: signIn.cancel }), source.fields["authMode"] === "oauth" && source.fields["transport"] !== "stdio" && _jsx(ExternalMcpSharedChoice, { serverId: source.id, busy: signIn.state.phase !== "idle", signIn: () => void signIn.connect({ destination: "shared" }), onChanged: () => void list.reload(), t: tDrift, useExternalMcpSharedChoiceHook: hooks.useHostExternalMcpSharedChoice }), ExternalMcpSourceTools({ toolsOpen, setToolsOpen, rowLabel, cardHandle, source, list, kit, hooks, deps })] }));
|
|
74
|
+
}
|
|
75
|
+
function ExternalMcpSourceActions({ cardHandle, rowLabel, enabledToolCount, showConnect, signIn, tDrift, setToolsOpen }, _optional = {}) {
|
|
76
|
+
return _jsxs(_Fragment, { children: [showConnect ? (_jsx(ExternalMcpConnectButton, { cardHandle: cardHandle, rowLabel: rowLabel, busy: signIn.state.phase !== "idle", tDrift: tDrift, onConnect: () => void signIn.connect() })) : null, _jsxs("button", { type: "button", className: "external-mcp-source-tools-open", onClick: () => setToolsOpen(true), "aria-label": `Open tool permissions for ${rowLabel} — ${enabledToolCount} enabled`, ...agentHandle({ handle: `${cardHandle}-tools-open` }, {
|
|
77
|
+
role: "button",
|
|
78
|
+
label: `Open tool permissions for ${rowLabel} — ${enabledToolCount} enabled`,
|
|
79
|
+
}), children: [_jsx("span", { children: tDrift("Tools") }), _jsx("span", { className: "external-mcp-source-tools-count", children: enabledToolCount })] })] });
|
|
80
|
+
}
|
|
81
|
+
function ExternalMcpSourceTools({ toolsOpen, setToolsOpen, rowLabel, cardHandle, source, list, kit, hooks, deps }, _optional = {}) {
|
|
82
|
+
const { ExternalMcpToolsModal } = kit;
|
|
83
|
+
return _jsx(_Fragment, { children: toolsOpen ? (_jsx(ExternalMcpToolsModal, { name: rowLabel, cardHandle: cardHandle, onClose: () => setToolsOpen(false), serverId: source.id, connectionEnabled: source.enabled ?? true, allowedToolNames: source.fields["allowedToolNames"], writeAllowedToolNames: source.fields["writeAllowedToolNames"], saving: list.isPending(source.id, "update"), onSave: (fields) => void list.update(source.id, { fields }), useExternalMcpToolsModalEscapeHook: hooks.useExternalMcpToolsModalEscape, useTHook: hooks.useKitT, useExternalMcpDriftCopyHook: hooks.useExternalMcpDriftCopyHook, pickerCollaborators: deps.pickerCollaborators })) : null });
|
|
84
|
+
}
|
|
85
|
+
/** The loading / empty-state / configured-server-list body, split out for the same
|
|
86
|
+
* complexity-budget reason as {@link ExternalMcpAddFormSection} above — the triple-branch
|
|
87
|
+
* loading/empty/list ternary was the parent's deepest nesting. Each configured server is now one
|
|
88
|
+
* {@link ExternalMcpSourceRow}, which owns the per-card `testResult` presence-spread and its own
|
|
89
|
+
* Tools-modal-open state. */
|
|
90
|
+
export function ExternalMcpSourcesSection(props, _optional = {}) {
|
|
91
|
+
const { list, cardHandles, t, tDrift, onRequestRemove } = props;
|
|
92
|
+
if (list.loading) {
|
|
93
|
+
return (_jsx("div", { className: "source-config-list-loading", role: "status", children: t("Loading…") }));
|
|
94
|
+
}
|
|
95
|
+
if (list.sources.length === 0) {
|
|
96
|
+
return (_jsxs("div", { className: "external-mcp-empty", children: [_jsx("p", { className: "external-mcp-empty-title", children: t("No MCP servers configured.") }), _jsx("p", { className: "external-mcp-empty-hint", children: t('Click "Add server" to get started — pick a local command or a hosted server.') })] }));
|
|
97
|
+
}
|
|
98
|
+
return (_jsx("div", { className: "source-config-list-items", children: list.sources.map((source, index) => (_jsx(ExternalMcpSourceRow, { kit: props.kit, hooks: props.hooks, deps: props.deps, source: source, cardHandle: cardHandles[index], list: list, tDrift: tDrift, onRequestRemove: onRequestRemove }, source.id))) }));
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=ExternalMcpSourceRow.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { AdminExternalMcpServer, AdminExternalMcpServerInput } from "@jini-ai/core/contracts/site/cms-external-mcp";
|
|
2
|
+
import type { useExternalMcp, ExternalMcpController } from "./use-external-mcp.hooks.js";
|
|
3
|
+
type SourceConfigItem = Awaited<ReturnType<ExternalMcpController["dependencies"]["port"]["fetchSources"]>>[number];
|
|
4
|
+
export declare function toItem({ server, deps }: {
|
|
5
|
+
server: AdminExternalMcpServer;
|
|
6
|
+
deps: Parameters<typeof useExternalMcp>[0]["deps"];
|
|
7
|
+
}, { locale }?: {
|
|
8
|
+
locale?: string;
|
|
9
|
+
}): SourceConfigItem;
|
|
10
|
+
export declare function describeStoredCredentials({ server, deps }: {
|
|
11
|
+
server: AdminExternalMcpServer;
|
|
12
|
+
deps: Parameters<typeof useExternalMcp>[0]["deps"];
|
|
13
|
+
}, { locale }?: {
|
|
14
|
+
locale?: string;
|
|
15
|
+
}): string | undefined;
|
|
16
|
+
/** The `static_env` access-token half of a save, or nothing for any other auth mode — the store only
|
|
17
|
+
* reads these for a `static_env` row. Both are omit-when-blank: a blank token means "keep the sealed
|
|
18
|
+
* one" (the `env` rule), and a blank variable name resolves to the stored name server-side either way,
|
|
19
|
+
* so omitting it keeps every other mode's write body byte-identical to before this field existed.
|
|
20
|
+
* @complexity O(1). */
|
|
21
|
+
export declare function toAccessTokenWriteBody({ fields, deps }: {
|
|
22
|
+
fields: Record<string, string>;
|
|
23
|
+
deps: Parameters<typeof useExternalMcp>[0]["deps"];
|
|
24
|
+
}, _optional?: {}): Pick<AdminExternalMcpServerInput, "accessToken" | "accessTokenEnvName">;
|
|
25
|
+
/** `fields[key] ?? ""` as a named helper — same rationale as `MenuEditor.tsx`'s `orEmpty`:
|
|
26
|
+
* ESLint's cyclomatic-complexity rule counts each `??` as its own branch, and
|
|
27
|
+
* {@link toOAuthWriteBody}/{@link toWriteBody} each default many fields this way. Naming it moves
|
|
28
|
+
* the count out of both functions' own scope without changing what either produces — every field
|
|
29
|
+
* still falls back to the same `""` for the same absent value it did before. */
|
|
30
|
+
export declare function fieldOrEmpty({ fields, key }: {
|
|
31
|
+
fields: Record<string, string>;
|
|
32
|
+
key: string;
|
|
33
|
+
}, _options?: {}): string;
|
|
34
|
+
/** `{ expectedVersion }` from the item this tab last loaded or saved, so a save from an old screen is refused. @complexity O(1). */
|
|
35
|
+
export declare function expectedVersionOf({ item }: {
|
|
36
|
+
item: SourceConfigItem | undefined;
|
|
37
|
+
}, _options?: {}): {
|
|
38
|
+
expectedVersion?: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Builds the write body from a field map, omitting `env`/`oauth.clientSecret` when blank.
|
|
42
|
+
*
|
|
43
|
+
* `command`/`url` are both always sent regardless of transport — harmless, since the store's own
|
|
44
|
+
* `resolveTransportTarget` reads only the one that matches `transport` and ignores the other, and
|
|
45
|
+
* sending both unconditionally is simpler than a transport-keyed omission that would buy nothing.
|
|
46
|
+
*
|
|
47
|
+
* @complexity O(1).
|
|
48
|
+
* @overallScore 100
|
|
49
|
+
*/
|
|
50
|
+
export declare function toWriteBody({ fields, enabled, deps }: {
|
|
51
|
+
fields: Record<string, string>;
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
deps: Parameters<typeof useExternalMcp>[0]["deps"];
|
|
54
|
+
}, { label }?: {
|
|
55
|
+
label?: string;
|
|
56
|
+
}): AdminExternalMcpServerInput;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=external-mcp-form.rules.d.ts.map
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The real transport behind Settings → External MCP, replacing the empty in-memory fake that
|
|
3
|
+
* tab mounted while the host had no config store.
|
|
4
|
+
*
|
|
5
|
+
* ## Why field rendering is NOT driven by a fixed `SourceFieldSpec[]` here anymore
|
|
6
|
+
*
|
|
7
|
+
* Earlier versions of this file exported a single static `MCP_FIELD_SPECS` array and the host
|
|
8
|
+
* mounted `@jini-ai/ui`'s assembled `ExternalMcpTab` directly against it. That stopped being viable
|
|
9
|
+
* once a server could be `stdio` OR `streamable_http`, with credentials `none`/`static_env`/`oauth`:
|
|
10
|
+
* a static spec list has no way to hide `url`/`command` or the OAuth block depending on what the
|
|
11
|
+
* operator is currently choosing, and showing every field for every combination unconditionally is
|
|
12
|
+
* exactly the "here are all the fields, figure out which apply" experience this tab exists to avoid.
|
|
13
|
+
* `../rules.ts`'s `buildExternalMcpFieldSpecs(values)` now computes the visible/required field set
|
|
14
|
+
* from the draft's current values, and `../components/ExternalMcpSettingsPanel.tsx` — the host's own
|
|
15
|
+
* replacement for `ExternalMcpTab` — recomputes it live as the operator types. This hook stays
|
|
16
|
+
* unchanged in shape (still a `SourceConfigDependencies` port), it just no longer also hands back one
|
|
17
|
+
* frozen spec list.
|
|
18
|
+
*
|
|
19
|
+
* ## The env field never round-trips a value
|
|
20
|
+
*
|
|
21
|
+
* `fetchSources` cannot populate `env`: no route returns a stored env value, deliberately. So the
|
|
22
|
+
* field always arrives blank, and {@link toWriteBody} omits `env` entirely when it is still blank.
|
|
23
|
+
*
|
|
24
|
+
* That asymmetry is the safe direction and is chosen on purpose. If blank meant "clear", then every
|
|
25
|
+
* enable/disable toggle and every label edit would silently wipe the operator's credentials —
|
|
26
|
+
* exactly the failure the store's `undefined`-vs-`""` distinction exists to prevent. The cost is
|
|
27
|
+
* that clearing credentials from the card alone is not expressible; removing and re-adding the
|
|
28
|
+
* server is. Losing a token by accident is much worse than needing two steps to discard one.
|
|
29
|
+
* `oauthClientSecret` follows the identical rule, for the identical reason — no read model ever
|
|
30
|
+
* returns a stored client secret either.
|
|
31
|
+
*/
|
|
32
|
+
/** Joins stored argv back into the one-line field the operator edits, double-quoting any argument
|
|
33
|
+
* that contains whitespace or is empty — the one quoting form the server's `parseArgs` reads — so a
|
|
34
|
+
* re-save (e.g. toggling `enabled`) splits it back into the same arguments instead of breaking a path
|
|
35
|
+
* like `C:\\Users\\John Smith\\...` in two or dropping an empty argument. @complexity O(n) in the
|
|
36
|
+
* total arg length. */
|
|
37
|
+
function joinArgs(args) {
|
|
38
|
+
return args.map((arg) => (arg === "" || /\s/.test(arg) ? `"${arg}"` : arg)).join(" ");
|
|
39
|
+
}
|
|
40
|
+
/** The OAuth half of an item's form fields. Everything but the client secret round-trips the stored view. */
|
|
41
|
+
function oauthItemFields({ server }, _options = {}) {
|
|
42
|
+
return {
|
|
43
|
+
// The rest of the OAuth block is NOT secret (a client id travels in the authorization URL by
|
|
44
|
+
// design, same as the store's own doc comment on this), so it round-trips the real stored
|
|
45
|
+
// value — only `oauthClientSecret` stays blank, matching `env`.
|
|
46
|
+
oauthProviderId: server.oauth.providerId ?? "",
|
|
47
|
+
oauthGrant: server.oauth.grant ?? "",
|
|
48
|
+
oauthClientId: server.oauth.clientId ?? "",
|
|
49
|
+
oauthClientSecret: "",
|
|
50
|
+
oauthScopes: server.oauth.scopes.join(" "),
|
|
51
|
+
oauthTokenEnvName: server.oauth.tokenEnvName ?? "",
|
|
52
|
+
// Read-only: drives the row's Connect button. `toWriteBody` never sends it.
|
|
53
|
+
oauthStatus: server.oauth.status,
|
|
54
|
+
// The store's `ExternalMcpOAuthView` does not carry a connection's own endpoints back —
|
|
55
|
+
// `providerId` is enough to identify a registered one, and a connection with its own
|
|
56
|
+
// endpoints has no other read model for them today. Left blank rather than guessed; an
|
|
57
|
+
// operator editing a custom-endpoint connection re-enters them, the same disclosed gap
|
|
58
|
+
// `env`/`oauthClientSecret` already accept for secret-shaped fields (this one isn't secret,
|
|
59
|
+
// it just isn't surfaced yet — a future `oauthEndpoints` field on the view would close it).
|
|
60
|
+
oauthAuthorizationEndpoint: "",
|
|
61
|
+
oauthTokenEndpoint: "",
|
|
62
|
+
oauthDeviceAuthorizationEndpoint: "",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function toItem({ server, deps }, { locale = "en" } = {}) {
|
|
66
|
+
return {
|
|
67
|
+
id: server.serverId,
|
|
68
|
+
label: server.label,
|
|
69
|
+
enabled: server.enabled,
|
|
70
|
+
fields: {
|
|
71
|
+
builtIn: server.builtIn ? "true" : "false",
|
|
72
|
+
// The basis for the next save (`expectedVersion`); never rendered, like `builtIn`.
|
|
73
|
+
version: String(server.version),
|
|
74
|
+
id: server.serverId,
|
|
75
|
+
transport: server.transport,
|
|
76
|
+
command: server.command,
|
|
77
|
+
url: server.url ?? "",
|
|
78
|
+
args: joinArgs(server.args),
|
|
79
|
+
allowedToolNames: server.allowedToolNames.join(", "),
|
|
80
|
+
// The operator's second, write-authorization list — same join convention as
|
|
81
|
+
// `allowedToolNames` immediately above, and round-tripped the same way (never blanked, unlike
|
|
82
|
+
// `env`/`oauthClientSecret`: the store returns this list in the clear, so there is nothing to
|
|
83
|
+
// protect by omitting it).
|
|
84
|
+
writeAllowedToolNames: server.writeAllowedToolNames.join(", "),
|
|
85
|
+
authMode: server.authMode,
|
|
86
|
+
// Never populated — see this file's header. The names are surfaced in `statusMessage` instead,
|
|
87
|
+
// so an operator can still see which variables are set.
|
|
88
|
+
env: "",
|
|
89
|
+
...oauthItemFields({ server }),
|
|
90
|
+
// Write-only, exactly like `oauthClientSecret`: the store seals it and no read model returns it,
|
|
91
|
+
// so it always arrives blank and {@link toAccessTokenWriteBody} treats blank as "keep".
|
|
92
|
+
accessToken: "",
|
|
93
|
+
// A NAME, not a secret — round-trips the real stored value like `oauthTokenEnvName` does.
|
|
94
|
+
accessTokenEnvName: server.accessTokenEnvName ?? "",
|
|
95
|
+
},
|
|
96
|
+
...includeIfDefined({ key: "statusMessage", value: describeStoredCredentials({ server, deps }, { locale }) }),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** The card's "what is stored" line: env variable NAMES and whether an access token is held — never
|
|
100
|
+
* a value. `undefined` when neither is stored, so the card shows no status line at all.
|
|
101
|
+
* @complexity O(n) in the env variable count. */
|
|
102
|
+
function accessTokenHintSuffix({ server, locale, deps }, _options = {}) {
|
|
103
|
+
return server.accessTokenHint ? ` (${deps.formatCredentialHint({ hint: server.accessTokenHint, locale })})` : "";
|
|
104
|
+
}
|
|
105
|
+
export function describeStoredCredentials({ server, deps }, { locale = "en" } = {}) {
|
|
106
|
+
const parts = [
|
|
107
|
+
...(server.envNames.length > 0 ? [deps.formatCredentialHints({ hints: server.envTokenHints, locale }) || `Credentials set: ${server.envNames.join(", ")}`] : []),
|
|
108
|
+
...(server.hasAccessToken ? [deps.credentialText({ id: 'set', locale }) + accessTokenHintSuffix({ server, locale, deps })] : []),
|
|
109
|
+
];
|
|
110
|
+
return parts.length > 0 ? parts.join(" · ") : undefined;
|
|
111
|
+
}
|
|
112
|
+
/** The `static_env` access-token half of a save, or nothing for any other auth mode — the store only
|
|
113
|
+
* reads these for a `static_env` row. Both are omit-when-blank: a blank token means "keep the sealed
|
|
114
|
+
* one" (the `env` rule), and a blank variable name resolves to the stored name server-side either way,
|
|
115
|
+
* so omitting it keeps every other mode's write body byte-identical to before this field existed.
|
|
116
|
+
* @complexity O(1). */
|
|
117
|
+
export function toAccessTokenWriteBody({ fields, deps }, _optional = {}) {
|
|
118
|
+
if (deps.resolveExternalMcpEffectiveAuthMode(fields) !== "static_env")
|
|
119
|
+
return {};
|
|
120
|
+
return {
|
|
121
|
+
...(fieldOrEmpty({ fields, key: "accessToken" }) === "" ? {} : { accessToken: fieldOrEmpty({ fields, key: "accessToken" }) }),
|
|
122
|
+
...omitIfBlank({ key: "accessTokenEnvName", value: fieldOrEmpty({ fields, key: "accessTokenEnvName" }) }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** `fields[key] ?? ""` as a named helper — same rationale as `MenuEditor.tsx`'s `orEmpty`:
|
|
126
|
+
* ESLint's cyclomatic-complexity rule counts each `??` as its own branch, and
|
|
127
|
+
* {@link toOAuthWriteBody}/{@link toWriteBody} each default many fields this way. Naming it moves
|
|
128
|
+
* the count out of both functions' own scope without changing what either produces — every field
|
|
129
|
+
* still falls back to the same `""` for the same absent value it did before. */
|
|
130
|
+
export function fieldOrEmpty({ fields, key }, _options = {}) {
|
|
131
|
+
return fields[key] ?? "";
|
|
132
|
+
}
|
|
133
|
+
/** `value.trim() === "" ? {} : { [key]: value }` as a named helper. The store reads the PRESENCE
|
|
134
|
+
* of these keys (not just their value) to decide whether a save touched OAuth identity or a
|
|
135
|
+
* tri-state field like `env` — see {@link toOAuthWriteBody}'s own doc — so the omit-when-blank
|
|
136
|
+
* convention must stay byte-for-byte the same; this only moves each call site's ternary branch
|
|
137
|
+
* out of the caller's own complexity count. */
|
|
138
|
+
function omitIfBlank({ key, value }, _options = {}) {
|
|
139
|
+
return (value.trim() === "" ? {} : { [key]: value });
|
|
140
|
+
}
|
|
141
|
+
/** `value === undefined ? {} : { [key]: value }` as a named helper — same rationale as
|
|
142
|
+
* {@link omitIfBlank}, for the two fields (`label`, `oauth`) whose tri-state is "was this
|
|
143
|
+
* argument passed at all", not "is this string blank". */
|
|
144
|
+
function includeIfDefined({ key, value }, _options = {}) {
|
|
145
|
+
return (value === undefined ? {} : { [key]: value });
|
|
146
|
+
}
|
|
147
|
+
/** Builds the OAuth block for a save, or `undefined` when the draft's effective auth mode isn't
|
|
148
|
+
* `oauth` — matching the store's own `resolveOAuthFields`, which ignores the whole block outside
|
|
149
|
+
* that mode. `grant`/`clientId`/`scopes`/`tokenEnvName` are sent as-is: {@link toItem} round-trips
|
|
150
|
+
* their real stored value, so the store's own `firstTrimmed` precedence resolves them correctly
|
|
151
|
+
* whether or not the operator touched them. `providerId` and the three endpoint fields are
|
|
152
|
+
* omit-when-blank instead — the same convention `clientSecret` already uses — because the store
|
|
153
|
+
* reads their PRESENCE, not their value, to decide whether this save touched the connection's OAuth
|
|
154
|
+
* identity (`resolveOAuthEndpoints`). Endpoints are never round-tripped by {@link toItem} today, so
|
|
155
|
+
* sending them as an always-present blank string made every save look like an identity change and
|
|
156
|
+
* silently destroyed the stored token, refresh token, and DCR-minted client secret.
|
|
157
|
+
* @complexity O(1). */
|
|
158
|
+
function toOAuthWriteBody({ fields, deps }, _optional = {}) {
|
|
159
|
+
if (deps.resolveExternalMcpEffectiveAuthMode(fields) !== "oauth")
|
|
160
|
+
return undefined;
|
|
161
|
+
return {
|
|
162
|
+
...omitIfBlank({ key: "providerId", value: fieldOrEmpty({ fields, key: "oauthProviderId" }) }),
|
|
163
|
+
grant: fieldOrEmpty({ fields, key: "oauthGrant" }),
|
|
164
|
+
clientId: fieldOrEmpty({ fields, key: "oauthClientId" }),
|
|
165
|
+
scopes: fieldOrEmpty({ fields, key: "oauthScopes" }),
|
|
166
|
+
tokenEnvName: fieldOrEmpty({ fields, key: "oauthTokenEnvName" }),
|
|
167
|
+
...omitIfBlank({ key: "authorizationEndpoint", value: fieldOrEmpty({ fields, key: "oauthAuthorizationEndpoint" }) }),
|
|
168
|
+
...omitIfBlank({ key: "tokenEndpoint", value: fieldOrEmpty({ fields, key: "oauthTokenEndpoint" }) }),
|
|
169
|
+
...omitIfBlank({ key: "deviceAuthorizationEndpoint", value: fieldOrEmpty({ fields, key: "oauthDeviceAuthorizationEndpoint" }) }),
|
|
170
|
+
...omitIfBlank({ key: "clientSecret", value: fieldOrEmpty({ fields, key: "oauthClientSecret" }) }),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** `{ expectedVersion }` from the item this tab last loaded or saved, so a save from an old screen is refused. @complexity O(1). */
|
|
174
|
+
export function expectedVersionOf({ item }, _options = {}) {
|
|
175
|
+
const version = Number(item?.fields.version);
|
|
176
|
+
return Number.isSafeInteger(version) ? { expectedVersion: version } : {};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Builds the write body from a field map, omitting `env`/`oauth.clientSecret` when blank.
|
|
180
|
+
*
|
|
181
|
+
* `command`/`url` are both always sent regardless of transport — harmless, since the store's own
|
|
182
|
+
* `resolveTransportTarget` reads only the one that matches `transport` and ignores the other, and
|
|
183
|
+
* sending both unconditionally is simpler than a transport-keyed omission that would buy nothing.
|
|
184
|
+
*
|
|
185
|
+
* @complexity O(1).
|
|
186
|
+
* @overallScore 100
|
|
187
|
+
*/
|
|
188
|
+
export function toWriteBody({ fields, enabled, deps }, { label } = {}) {
|
|
189
|
+
const oauth = toOAuthWriteBody({ fields, deps });
|
|
190
|
+
return {
|
|
191
|
+
...includeIfDefined({ key: "label", value: label }),
|
|
192
|
+
transport: fields.transport || "stdio",
|
|
193
|
+
enabled,
|
|
194
|
+
command: fieldOrEmpty({ fields, key: "command" }),
|
|
195
|
+
url: fieldOrEmpty({ fields, key: "url" }),
|
|
196
|
+
args: fieldOrEmpty({ fields, key: "args" }),
|
|
197
|
+
allowedToolNames: fieldOrEmpty({ fields, key: "allowedToolNames" }),
|
|
198
|
+
// Resent in full on every save, same as `allowedToolNames` just above — NOT tri-state like
|
|
199
|
+
// `env` below, because the store always returns this list in the clear and the tab can always
|
|
200
|
+
// resend it. The server's own C-006 check rejects a name here absent from `allowedToolNames`.
|
|
201
|
+
writeAllowedToolNames: fieldOrEmpty({ fields, key: "writeAllowedToolNames" }),
|
|
202
|
+
authMode: deps.resolveExternalMcpEffectiveAuthMode(fields),
|
|
203
|
+
// Blank means "untouched", never "clear" — see this file's header.
|
|
204
|
+
...omitIfBlank({ key: "env", value: fieldOrEmpty({ fields, key: "env" }) }),
|
|
205
|
+
...toAccessTokenWriteBody({ fields, deps }),
|
|
206
|
+
...includeIfDefined({ key: "oauth", value: oauth }),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=external-mcp-form.rules.js.map
|