@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
package/README.md
CHANGED
|
@@ -185,6 +185,21 @@ confirmation UI/exchanges, and current connection roster. A revocation gate chec
|
|
|
185
185
|
row on every call; the host composes its credential checks, including preset credentials.
|
|
186
186
|
See [API.md](https://github.com/AINSEP/Jini/blob/main/packages/mcp/API.md) for concrete object-argument examples.
|
|
187
187
|
|
|
188
|
+
## Wiring
|
|
189
|
+
|
|
190
|
+
- **Federation runtime** (`createFederationRuntime` from `@jini-ai/mcp/federation`): one per
|
|
191
|
+
process. The host injects `boot` (its attach bound to registry, approval deps and preset
|
|
192
|
+
registry), `resolveConnections` (the stored roster), `resolvePresetConnections`,
|
|
193
|
+
`createReloadCoordinator` (its reload adapter over `createFederationReloadCoordinator`), refusal
|
|
194
|
+
`messages` and a `FederationHostLogger` (the host owns any console prefix/format); optional
|
|
195
|
+
`after`, `onAdmitted`, `beforeReload`. Jini owns single-flight boot, boot-plus-reload accounting,
|
|
196
|
+
connect-failure merging, preset origin stamping on reload and the empty-grant awaiting set.
|
|
197
|
+
- **Roster-change bus** (`createMcpRosterChangeBus` from `@jini-ai/mcp/federation`): the host creates
|
|
198
|
+
ONE bus in a composition module and binds its `on`/`notify`/`reset`. It injects
|
|
199
|
+
`createLoweringError` (the host's safe, actionable error a failed or timed-out tool-access lowering
|
|
200
|
+
rejects with) and may inject `defaultWaitMs` (default 5s). Each runtime registers its reload under a
|
|
201
|
+
stable key (last wins); roster writers call `notify()`, or `notify({ lowered })` to await Stop/cleanup.
|
|
202
|
+
|
|
188
203
|
All test, compiler, build, and pack verification is deferred under the owner directive.
|
|
189
204
|
|
|
190
205
|
## Design decisions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AtomicFileWriterPort, FileLockPort } from '@jini-ai/core/contracts/runtime';
|
|
2
2
|
import { type McpLaunchSpec, type PlanContext } from './install.js';
|
|
3
|
-
/** The host's file effects: Node hosts pass `{ fileLock
|
|
3
|
+
/** The host's file effects: Node hosts pass `{ fileLock, writer }` built by `@jini-ai/node-adapters/fs`' `createFileLockPort` and `createAtomicWriterPort` over platform's functions. */
|
|
4
4
|
export interface OwnedJsonInstallFiles {
|
|
5
5
|
readonly fileLock: FileLockPort;
|
|
6
6
|
readonly writer: Pick<AtomicFileWriterPort, 'writeText' | 'backupOriginalOnce'>;
|
package/dist/client/client.js
CHANGED
|
@@ -181,7 +181,7 @@ function collectPatternCandidates(text, patterns) {
|
|
|
181
181
|
}
|
|
182
182
|
function patternRefs(text, pattern) {
|
|
183
183
|
if (typeof pattern === 'function')
|
|
184
|
-
return pattern(text);
|
|
184
|
+
return pattern({ text });
|
|
185
185
|
// The capture group is required in every pattern, so `m[1]` is always a
|
|
186
186
|
// matched string here (the `!` only satisfies noUncheckedIndexedAccess).
|
|
187
187
|
return Array.from(text.matchAll(pattern), (m) => m[1]);
|
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* references. Each quote is optional on its own, as in the pattern.
|
|
5
5
|
*/
|
|
6
6
|
/** Every `url(...)` reference in `text`, in order, exactly as the pattern's group captured it. */
|
|
7
|
-
export declare function cssUrlRefs(text
|
|
7
|
+
export declare function cssUrlRefs({ text }: {
|
|
8
|
+
text: string;
|
|
9
|
+
}, _optional?: Record<string, never>): string[];
|
|
8
10
|
//# sourceMappingURL=css-url-refs.d.ts.map
|
|
@@ -49,7 +49,7 @@ function refAt(text, start) {
|
|
|
49
49
|
return close < 0 ? null : { ref: text.slice(first, end), end: close };
|
|
50
50
|
}
|
|
51
51
|
/** Every `url(...)` reference in `text`, in order, exactly as the pattern's group captured it. */
|
|
52
|
-
export function cssUrlRefs(text) {
|
|
52
|
+
export function cssUrlRefs({ text }, _optional = {}) {
|
|
53
53
|
const refs = [];
|
|
54
54
|
const opener = /url\(/gi;
|
|
55
55
|
for (let open = opener.exec(text); open; open = opener.exec(text)) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ToolHandler } from '@jini-ai/core';
|
|
2
|
+
import type { ChatDeleteSurfaceDeps } from '@jini-ai/core/contracts/site/daemon-surface-exchanges';
|
|
3
|
+
import type { ExternalMcpAccessSnapshot, ExternalMcpServerRecord, SaveExternalMcpServerInput } from '@jini-ai/core/contracts/hosted-mcp';
|
|
4
|
+
import type { ExternalMcpToolDeps } from './tool-registrations.js';
|
|
5
|
+
/** Access-only proposals name an existing source and cannot alter its endpoint or credentials.
|
|
6
|
+
* @complexity O(k) in the fixed input-key list; no effects.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isExternalMcpAccessInput(input: Record<string, unknown>): boolean;
|
|
9
|
+
/** Configuration cards carry the same fresh person and management checks as access cards.
|
|
10
|
+
* @complexity O(1); two existing authorization reads per card phase. */
|
|
11
|
+
export declare function requireMcpSaveApprover({ routeDeps, surfaces, principalId, id }: {
|
|
12
|
+
routeDeps: ExternalMcpToolDeps;
|
|
13
|
+
surfaces: ChatDeleteSurfaceDeps;
|
|
14
|
+
principalId: string;
|
|
15
|
+
id: string;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
/** Check fixed grants against the proposed source identity, including a human-edited target.
|
|
18
|
+
* @complexity O(a+w+t) in bounded tool lists; no I/O or credential discovery. */
|
|
19
|
+
export declare function requireKnownMcpSave({ routeDeps, record, input }: {
|
|
20
|
+
routeDeps: ExternalMcpToolDeps;
|
|
21
|
+
record: ExternalMcpServerRecord | null;
|
|
22
|
+
input: SaveExternalMcpServerInput;
|
|
23
|
+
}): void;
|
|
24
|
+
/** The connection and access a person reviewed on the card no longer match the stored row.
|
|
25
|
+
* A dedicated identity, separate from bad input (`ToolInputError`/`ExternalMcpValidationError`) and
|
|
26
|
+
* changed authority (`ForbiddenError`), so the card can ask for a new card rather than a field fix.
|
|
27
|
+
* It carries no submitted form data: its only rendering is fixed copy. */
|
|
28
|
+
export declare class ExternalMcpSaveBasisChangedError extends Error {
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
|
31
|
+
/** Re-read the identity and access reviewed by the person before the configuration writer.
|
|
32
|
+
* @complexity O(a+w) snapshot bytes; one existing source-row read, no credential unsealing. */
|
|
33
|
+
export declare function currentMcpSaveRecord({ routeDeps, id, expected }: {
|
|
34
|
+
routeDeps: ExternalMcpToolDeps;
|
|
35
|
+
id: string;
|
|
36
|
+
expected: ExternalMcpAccessSnapshot | null;
|
|
37
|
+
}): Promise<ExternalMcpServerRecord | null>;
|
|
38
|
+
/** Fixed access proposal through the same human-only exchange as other privilege changes.
|
|
39
|
+
* Preparation reads one source; the accepted effect conditionally updates only its access columns.
|
|
40
|
+
* @complexity O(a+w) bounded lists; two permission checks, one preview and one conditional update.
|
|
41
|
+
*/
|
|
42
|
+
export declare function externalMcpAccessHandler({ routeDeps, surfaces }: {
|
|
43
|
+
routeDeps: ExternalMcpToolDeps;
|
|
44
|
+
surfaces: ChatDeleteSurfaceDeps;
|
|
45
|
+
}): ToolHandler;
|
|
46
|
+
//# sourceMappingURL=access-review.d.ts.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { requireInputRecord, requireString, redactSecrets, ToolInputError } from '@jini-ai/core';
|
|
2
|
+
import { adaptLegacyAuthorize } from '@jini-ai/core';
|
|
3
|
+
import { EXTERNAL_MCP_MANAGE_PERMISSION } from './agent-tools.js';
|
|
4
|
+
import { EXTERNAL_MCP_SAVE_TOOL_ID } from './save-form.js';
|
|
5
|
+
import { optionalStringField } from './save-input.js';
|
|
6
|
+
const EXTERNAL_MCP_ENTITY_TYPE = "external-mcp-server";
|
|
7
|
+
/** Access-only proposals name an existing source and cannot alter its endpoint or credentials.
|
|
8
|
+
* @complexity O(k) in the fixed input-key list; no effects.
|
|
9
|
+
*/
|
|
10
|
+
export function isExternalMcpAccessInput(input) {
|
|
11
|
+
const fields = ['id', 'transport', 'enabled', 'allowedToolNames', 'writeAllowedToolNames'];
|
|
12
|
+
return Object.keys(input).every(key => fields.includes(key)) &&
|
|
13
|
+
['enabled', 'allowedToolNames', 'writeAllowedToolNames'].some(key => Object.hasOwn(input, key));
|
|
14
|
+
}
|
|
15
|
+
/** Reuse management authorization both before disclosing the source and immediately before apply. */
|
|
16
|
+
async function authorizeMcpAccess({ routeDeps, principalId, id }) {
|
|
17
|
+
await routeDeps.requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }),
|
|
18
|
+
workspaceId: routeDeps.workspaceId, principalId, permission: EXTERNAL_MCP_MANAGE_PERMISSION }, { entityType: EXTERNAL_MCP_ENTITY_TYPE, entityId: id });
|
|
19
|
+
}
|
|
20
|
+
/** Redact existing credential-bearing endpoint/command shapes before placing them on a card.
|
|
21
|
+
* The unredacted admission fingerprint stays private to the conditional writer.
|
|
22
|
+
* @complexity O(t) source-label/target bytes; no I/O.
|
|
23
|
+
*/
|
|
24
|
+
function externalMcpAccessSubject({ record, id }) {
|
|
25
|
+
const target = record.transport === 'stdio' ? `${record.command ?? ""} ${record.args ?? ""}` : remoteEndpointOrigin({ url: record.url });
|
|
26
|
+
return { label: redactSecrets({ input: record.label ?? id }, { redactPii: false }),
|
|
27
|
+
target: redactSecrets({ input: target }, { redactPii: false }) };
|
|
28
|
+
}
|
|
29
|
+
function remoteEndpointOrigin({ url }, _optional = {}) {
|
|
30
|
+
if (url === null)
|
|
31
|
+
return 'Remote endpoint unavailable.';
|
|
32
|
+
try {
|
|
33
|
+
const parsed = new URL(url);
|
|
34
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.origin : 'Remote endpoint unavailable.';
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return 'Remote endpoint unavailable.';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** New permissions must name tools actually advertised by this exact admitted endpoint.
|
|
41
|
+
* Existing grants may still be removed or disabled without starting optional remote discovery.
|
|
42
|
+
* `refusal` replaces the default copy when the caller knows a more precise, value-free cause.
|
|
43
|
+
* @throws ToolInputError before a card/write if any new name is absent from the identity-bound cache.
|
|
44
|
+
* @complexity O(a+w+t) in bounded proposed/current lists and the existing cached tool names; no I/O.
|
|
45
|
+
*/
|
|
46
|
+
function requireKnownMcpAccess({ routeDeps, record, previous, access }, { refusal } = {}) {
|
|
47
|
+
const enabling = !previous.enabled && access.enabled;
|
|
48
|
+
const newNames = enabling ? [...access.allowedToolNames, ...access.writeAllowedToolNames]
|
|
49
|
+
: [...access.allowedToolNames.filter(name => !previous.allowedToolNames.includes(name)),
|
|
50
|
+
...access.writeAllowedToolNames.filter(name => !previous.writeAllowedToolNames.includes(name))];
|
|
51
|
+
if (newNames.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
const known = routeDeps.externalMcpKnownToolNames?.({ serverId: record.serverId, admissionRevision: routeDeps.externalMcpAccessSnapshot({ record }).admissionRevision });
|
|
54
|
+
const names = new Set(known ?? []);
|
|
55
|
+
if (!newNames.every(name => names.has(name)))
|
|
56
|
+
throw new ToolInputError({ message: refusal ?? routeDeps.unverifiedAccessMessage({ serverId: record.serverId }) });
|
|
57
|
+
}
|
|
58
|
+
/** Configuration cards carry the same fresh person and management checks as access cards.
|
|
59
|
+
* @complexity O(1); two existing authorization reads per card phase. */
|
|
60
|
+
export async function requireMcpSaveApprover({ routeDeps, surfaces, principalId, id }) {
|
|
61
|
+
await authorizeMcpAccess({ routeDeps, principalId, id });
|
|
62
|
+
if (!surfaces.assertAccessApprover)
|
|
63
|
+
throw new ToolInputError({ message: 'This chat cannot verify the person approving the connection. Reopen the chat in your signed-in admin session. Nothing was saved.' });
|
|
64
|
+
await surfaces.assertAccessApprover({ toolId: EXTERNAL_MCP_SAVE_TOOL_ID, principalId });
|
|
65
|
+
}
|
|
66
|
+
/** Check fixed grants against the proposed source identity, including a human-edited target.
|
|
67
|
+
* @complexity O(a+w+t) in bounded tool lists; no I/O or credential discovery. */
|
|
68
|
+
export function requireKnownMcpSave({ routeDeps, record, input }) {
|
|
69
|
+
const access = { enabled: input.enabled, allowedToolNames: routeDeps.parseAllowedToolNames({ raw: input.allowedToolNames }), writeAllowedToolNames: routeDeps.parseWriteAllowedToolNames({ raw: input.writeAllowedToolNames }) };
|
|
70
|
+
if (!record) {
|
|
71
|
+
if (access.allowedToolNames.length + access.writeAllowedToolNames.length > 0)
|
|
72
|
+
throw new routeDeps.ExternalMcpValidationError(routeDeps.unverifiedConnectionMessage, 'allowedToolNames');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const { target, previous, refusal } = mcpSaveBasis({ routeDeps, record, input });
|
|
76
|
+
requireKnownMcpAccess({ routeDeps, record: target, previous, access }, refusal === undefined ? {} : { refusal });
|
|
77
|
+
}
|
|
78
|
+
/** The identity and prior grants a save's proposed access is checked against: the saved row when the
|
|
79
|
+
* target is unchanged, or the edited target with no carried-over grants when the person changed it.
|
|
80
|
+
* @complexity O(b) in bounded command/argument bytes plus one strict grant parse; no I/O. */
|
|
81
|
+
function mcpSaveBasis({ routeDeps, record, input }, _optional = {}) {
|
|
82
|
+
const candidate = mcpSaveTarget({ routeDeps, record, input });
|
|
83
|
+
if (!mcpSaveTargetChanged({ record, candidate }))
|
|
84
|
+
return { target: record, previous: { enabled: record.enabled, ...routeDeps.readExternalMcpToolGrants(record, { strict: true }) } };
|
|
85
|
+
// Fixed copy per transport: the person edited this field, and its submitted value can hold a
|
|
86
|
+
// credential (a capability URL, a token argument), so the refusal names the field, never the value.
|
|
87
|
+
return { target: candidate, previous: { enabled: false, allowedToolNames: [], writeAllowedToolNames: [] },
|
|
88
|
+
refusal: candidate.transport === 'stdio' ? CHANGED_COMMAND_REFUSAL : CHANGED_ADDRESS_REFUSAL };
|
|
89
|
+
}
|
|
90
|
+
/** Whether the edited form points at a different program or address than the saved row.
|
|
91
|
+
* @complexity O(b) in bounded command/argument bytes; no I/O. */
|
|
92
|
+
function mcpSaveTargetChanged({ record, candidate }, _optional = {}) {
|
|
93
|
+
// With `npx` or `node` the arguments choose the program, so they are the target too. Credentials are not.
|
|
94
|
+
const stdioArgsChanged = candidate.transport === 'stdio' && candidate.args !== (record.args ?? '[]');
|
|
95
|
+
return candidate.url !== record.url || candidate.command !== record.command || stdioArgsChanged;
|
|
96
|
+
}
|
|
97
|
+
const CHANGED_ADDRESS_REFUSAL = 'The connection address in this form differs from the saved one, so its allowed tools cannot carry over. Keep the saved address, or save the new address with no allowed tools and choose them after it connects. Nothing was saved.';
|
|
98
|
+
const CHANGED_COMMAND_REFUSAL = 'The command or arguments in this form differ from the saved ones, so its allowed tools cannot carry over. Keep the saved command and arguments, or save the new ones with no allowed tools and choose them after it connects. Nothing was saved.';
|
|
99
|
+
/** The connection and access a person reviewed on the card no longer match the stored row.
|
|
100
|
+
* A dedicated identity, separate from bad input (`ToolInputError`/`ExternalMcpValidationError`) and
|
|
101
|
+
* changed authority (`ForbiddenError`), so the card can ask for a new card rather than a field fix.
|
|
102
|
+
* It carries no submitted form data: its only rendering is fixed copy. */
|
|
103
|
+
export class ExternalMcpSaveBasisChangedError extends Error {
|
|
104
|
+
constructor() {
|
|
105
|
+
super('The reviewed External MCP connection changed before it was saved.');
|
|
106
|
+
this.name = 'ExternalMcpSaveBasisChangedError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Re-read the identity and access reviewed by the person before the configuration writer.
|
|
110
|
+
* @complexity O(a+w) snapshot bytes; one existing source-row read, no credential unsealing. */
|
|
111
|
+
export async function currentMcpSaveRecord({ routeDeps, id, expected }) {
|
|
112
|
+
const current = await routeDeps.externalMcpServerRepo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId: id });
|
|
113
|
+
const snapshot = current ? routeDeps.externalMcpAccessSnapshot({ record: current }) : null;
|
|
114
|
+
if (JSON.stringify(snapshot) !== JSON.stringify(expected))
|
|
115
|
+
throw new ExternalMcpSaveBasisChangedError();
|
|
116
|
+
return current;
|
|
117
|
+
}
|
|
118
|
+
/** Match the store's normalized target without opening or retaining submitted credentials.
|
|
119
|
+
* @complexity O(b) in bounded command/argument bytes; no I/O. */
|
|
120
|
+
function mcpSaveTarget({ routeDeps, record, input }) {
|
|
121
|
+
return { ...record, transport: input.transport,
|
|
122
|
+
url: input.transport === 'streamable_http' ? input.url?.trim() ?? null : null,
|
|
123
|
+
command: input.transport === 'stdio' ? input.command.trim() : null,
|
|
124
|
+
args: JSON.stringify(routeDeps.parseArgs({ raw: input.args })), authMode: input.authMode ?? record.authMode };
|
|
125
|
+
}
|
|
126
|
+
/** Fixed access proposal through the same human-only exchange as other privilege changes.
|
|
127
|
+
* Preparation reads one source; the accepted effect conditionally updates only its access columns.
|
|
128
|
+
* @complexity O(a+w) bounded lists; two permission checks, one preview and one conditional update.
|
|
129
|
+
*/
|
|
130
|
+
export function externalMcpAccessHandler({ routeDeps, surfaces }) {
|
|
131
|
+
return routeDeps.approvalToolHandler({ surfaces,
|
|
132
|
+
prepare: async ({ ctx }) => {
|
|
133
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
134
|
+
const id = requireString({ input, key: 'id' }).trim().toLowerCase();
|
|
135
|
+
await authorizeMcpAccess({ routeDeps, principalId: ctx.principal.id, id });
|
|
136
|
+
const record = await routeDeps.externalMcpServerRepo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId: id });
|
|
137
|
+
if (!record)
|
|
138
|
+
throw new ToolInputError({ message: `The '${id}' connection no longer exists. Request its connection setup before changing access. Nothing was changed.` });
|
|
139
|
+
const transport = optionalStringField({ input, key: 'transport' });
|
|
140
|
+
if (transport !== undefined && transport !== record.transport)
|
|
141
|
+
throw new ToolInputError({ message: `The '${id}' connection uses a different transport. Request its current configuration before changing access. Nothing was changed.` });
|
|
142
|
+
if (input.enabled !== undefined && typeof input.enabled !== 'boolean')
|
|
143
|
+
throw new ToolInputError({ message: "'enabled' must be true or false. Nothing was changed." });
|
|
144
|
+
const previous = { enabled: record.enabled, ...routeDeps.readExternalMcpToolGrants(record, { strict: true }) };
|
|
145
|
+
const allowed = optionalStringField({ input, key: 'allowedToolNames' });
|
|
146
|
+
const write = optionalStringField({ input, key: 'writeAllowedToolNames' });
|
|
147
|
+
const access = { enabled: input.enabled ?? record.enabled,
|
|
148
|
+
allowedToolNames: allowed === undefined ? previous.allowedToolNames : routeDeps.parseAllowedToolNames({ raw: allowed }),
|
|
149
|
+
writeAllowedToolNames: write === undefined ? previous.writeAllowedToolNames : routeDeps.parseWriteAllowedToolNames({ raw: write }) };
|
|
150
|
+
const allowedSet = new Set(access.allowedToolNames);
|
|
151
|
+
if (access.writeAllowedToolNames.some(name => !allowedSet.has(name)))
|
|
152
|
+
throw new ToolInputError({ message: 'Every tool allowed to write must also appear in allowedToolNames. Nothing was changed.' });
|
|
153
|
+
requireKnownMcpAccess({ routeDeps, record, previous, access });
|
|
154
|
+
return { id, ...externalMcpAccessSubject({ record, id }), expected: routeDeps.externalMcpAccessSnapshot({ record }), previous, access };
|
|
155
|
+
},
|
|
156
|
+
describe: ({ ctx, prepared }) => ({ toolId: EXTERNAL_MCP_SAVE_TOOL_ID, errorCode: routeDeps.accessErrorCode,
|
|
157
|
+
title: 'Change this connection’s access?', description: 'Only the listed source and tool grants change. Stored credentials stay in place.',
|
|
158
|
+
details: [{ label: 'Source target', value: prepared.target }], confirmLabel: 'Approve access', access: { resources: [{ id: prepared.id, label: prepared.label,
|
|
159
|
+
scope: { personId: ctx.principal.id, siteId: routeDeps.workspaceId }, revision: prepared.expected.admissionRevision,
|
|
160
|
+
previous: prepared.previous, proposed: prepared.access }] } }),
|
|
161
|
+
run: async ({ ctx, prepared }) => {
|
|
162
|
+
await authorizeMcpAccess({ routeDeps, principalId: ctx.principal.id, id: prepared.id });
|
|
163
|
+
ctx.signal.throwIfAborted();
|
|
164
|
+
await routeDeps.applyExternalMcpAccess({ repo: routeDeps.externalMcpServerRepo, clock: routeDeps.clock,
|
|
165
|
+
workspaceId: routeDeps.workspaceId, serverId: prepared.id, expected: prepared.expected, access: prepared.access, principalId: ctx.principal.id });
|
|
166
|
+
const lowers = !prepared.access.enabled || prepared.previous.allowedToolNames.some(name => !prepared.access.allowedToolNames.includes(name)) ||
|
|
167
|
+
prepared.previous.writeAllowedToolNames.some(name => !prepared.access.writeAllowedToolNames.includes(name));
|
|
168
|
+
if (lowers)
|
|
169
|
+
await routeDeps.notifyExternalMcpRosterChanged({ lowered: { serverIds: [prepared.id] } });
|
|
170
|
+
else
|
|
171
|
+
void routeDeps.notifyExternalMcpRosterChanged();
|
|
172
|
+
return { saved: true, server: { serverId: prepared.id, ...prepared.access } };
|
|
173
|
+
}, }, { flag: 'saved' });
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=access-review.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The External MCP domain's agent-tool catalog (SPEC-016 REQ-22 naming/callability
|
|
3
|
+
* convention — the same shape `features/site-inspection/agent-tools.ts` and every other domain
|
|
4
|
+
* catalog already use).
|
|
5
|
+
*
|
|
6
|
+
* ## Why this domain exists
|
|
7
|
+
*
|
|
8
|
+
* The owner's ask: a non-technical site owner should be able to type "connect me to Higgsfield"
|
|
9
|
+
* into the admin assistant chat and have the agent configure the external MCP server itself,
|
|
10
|
+
* asking only for what it genuinely cannot know. The host's external MCP settings form (the admin form) already lets a human do this by
|
|
11
|
+
* hand; these five tools are the same capability, reachable by the agent.
|
|
12
|
+
*
|
|
13
|
+
* ## Five tools, not one CRUD tool per field
|
|
14
|
+
*
|
|
15
|
+
* - `content_read.external_mcp` — read. What is configured, never a secret value.
|
|
16
|
+
* - `external_mcp_save` — the ONE write tool for both "add a new server" and "update an existing
|
|
17
|
+
* one". Mirrors `saveExternalMcpServer`'s own idempotent-by-id PUT design (the host's
|
|
18
|
+
* external MCP store's own doc: "two routes would be two validators of one contract") — the
|
|
19
|
+
* same reasoning applies one layer up: two tools would be two validators of one contract, and an
|
|
20
|
+
* agent updating a server it just created would have to remember which tool it used the first
|
|
21
|
+
* time. HUMAN-CONFIRMED: this never writes silently. See the host's tool-registrations handler.
|
|
22
|
+
* - `external_mcp_test_connection` — checks an ALREADY-SAVED server's configuration, and may
|
|
23
|
+
* refresh an OAuth grant. Reports whether its configuration resolves cleanly (decrypts, has everything its transport needs, isn't sitting on
|
|
24
|
+
* an expired OAuth grant) — see that tool's own description for exactly what it does and does not
|
|
25
|
+
* check.
|
|
26
|
+
* - `external_mcp_oauth_connect` / `external_mcp_oauth_poll_device` — the two moves the hard
|
|
27
|
+
* constraint "the agent's job ends at handing over one link and then detecting completion"
|
|
28
|
+
* requires: start an authorization and hand back the one thing a human needs (a link, or a device
|
|
29
|
+
* code), and — for the device-code grant specifically, which has no callback of its own — poll it
|
|
30
|
+
* once per call so completion can be detected without inventing a script the model would loop on
|
|
31
|
+
* its own. For the browser-redirect grant, completion is detected simply by calling
|
|
32
|
+
* `content_read.external_mcp` again and reading `oauth.status`.
|
|
33
|
+
*
|
|
34
|
+
* ## What no tool here ever accepts as input
|
|
35
|
+
*
|
|
36
|
+
* `env` (the stdio credential block), `accessToken` and `oauthClientSecret` are absent from every input schema
|
|
37
|
+
* below, on purpose, not by omission. A tool argument is text the model chose to write, and — same
|
|
38
|
+
* as `deployment_propose_custom_provider_credential`'s identical rule — a secret typed into a tool
|
|
39
|
+
* call is a secret written into the conversation transcript. Every secret field is entered by the
|
|
40
|
+
* HUMAN directly into the confirmation form `external_mcp_save` renders; the agent never sees or
|
|
41
|
+
* handles it (see the host's save form). `additionalProperties: false` on `external_mcp_save`'s schema
|
|
42
|
+
* makes an attempt to pass one a loud, rejected call rather than a silently dropped field.
|
|
43
|
+
*/
|
|
44
|
+
import type { AgentToolDefinition as SharedAgentToolDefinition } from "@jini-ai/core";
|
|
45
|
+
import type { ExternalMcpHostCopy } from "./external-mcp-host-copy.js";
|
|
46
|
+
/** Mirrors the `AgentToolSideEffect` union every domain declares its own copy of — see
|
|
47
|
+
* `WirableToolDefinition`'s doc in `@jini-ai/cms/core` for why a shared import is deliberately not
|
|
48
|
+
* used here. */
|
|
49
|
+
export type AgentToolSideEffect = "none" | "mutates-durable-state";
|
|
50
|
+
export type AgentToolDefinition = SharedAgentToolDefinition & {
|
|
51
|
+
sideEffects: AgentToolSideEffect;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The same site-owner-level permission the host's HTTP routes gate on (the host's external MCP route
|
|
55
|
+
* guard) — restated rather than imported because that module lives in the host's routes, a
|
|
56
|
+
* direction this domain does not import from (see the host's tool deps header). Reusing the STRING is
|
|
57
|
+
* what keeps the two gates from drifting, which is the property that module's own doc calls
|
|
58
|
+
* load-bearing: a stored row's `command` is spawned as a real child process at daemon boot, so
|
|
59
|
+
* whoever can write here can execute arbitrary code as the host process — exactly as consequential
|
|
60
|
+
* through a chat message as through a form submission, and the gate must not be weaker for one path
|
|
61
|
+
* than the other.
|
|
62
|
+
*/
|
|
63
|
+
export declare const EXTERNAL_MCP_MANAGE_PERMISSION = "admin.integrations.manage";
|
|
64
|
+
/**
|
|
65
|
+
* Every agent-callable tool this domain exposes. All five are wired — there is no `unwiredToolIds`
|
|
66
|
+
* set in the host's tool registrations, which means any future catalog entry added without a handler is a
|
|
67
|
+
* build failure.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createExternalMcpAgentToolCatalog({ copy }: {
|
|
70
|
+
copy: ExternalMcpHostCopy;
|
|
71
|
+
}, _optional?: {}): readonly AgentToolDefinition[];
|
|
72
|
+
//# sourceMappingURL=agent-tools.d.ts.map
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The External MCP domain's agent-tool catalog (SPEC-016 REQ-22 naming/callability
|
|
3
|
+
* convention — the same shape `features/site-inspection/agent-tools.ts` and every other domain
|
|
4
|
+
* catalog already use).
|
|
5
|
+
*
|
|
6
|
+
* ## Why this domain exists
|
|
7
|
+
*
|
|
8
|
+
* The owner's ask: a non-technical site owner should be able to type "connect me to Higgsfield"
|
|
9
|
+
* into the admin assistant chat and have the agent configure the external MCP server itself,
|
|
10
|
+
* asking only for what it genuinely cannot know. The host's external MCP settings form (the admin form) already lets a human do this by
|
|
11
|
+
* hand; these five tools are the same capability, reachable by the agent.
|
|
12
|
+
*
|
|
13
|
+
* ## Five tools, not one CRUD tool per field
|
|
14
|
+
*
|
|
15
|
+
* - `content_read.external_mcp` — read. What is configured, never a secret value.
|
|
16
|
+
* - `external_mcp_save` — the ONE write tool for both "add a new server" and "update an existing
|
|
17
|
+
* one". Mirrors `saveExternalMcpServer`'s own idempotent-by-id PUT design (the host's
|
|
18
|
+
* external MCP store's own doc: "two routes would be two validators of one contract") — the
|
|
19
|
+
* same reasoning applies one layer up: two tools would be two validators of one contract, and an
|
|
20
|
+
* agent updating a server it just created would have to remember which tool it used the first
|
|
21
|
+
* time. HUMAN-CONFIRMED: this never writes silently. See the host's tool-registrations handler.
|
|
22
|
+
* - `external_mcp_test_connection` — checks an ALREADY-SAVED server's configuration, and may
|
|
23
|
+
* refresh an OAuth grant. Reports whether its configuration resolves cleanly (decrypts, has everything its transport needs, isn't sitting on
|
|
24
|
+
* an expired OAuth grant) — see that tool's own description for exactly what it does and does not
|
|
25
|
+
* check.
|
|
26
|
+
* - `external_mcp_oauth_connect` / `external_mcp_oauth_poll_device` — the two moves the hard
|
|
27
|
+
* constraint "the agent's job ends at handing over one link and then detecting completion"
|
|
28
|
+
* requires: start an authorization and hand back the one thing a human needs (a link, or a device
|
|
29
|
+
* code), and — for the device-code grant specifically, which has no callback of its own — poll it
|
|
30
|
+
* once per call so completion can be detected without inventing a script the model would loop on
|
|
31
|
+
* its own. For the browser-redirect grant, completion is detected simply by calling
|
|
32
|
+
* `content_read.external_mcp` again and reading `oauth.status`.
|
|
33
|
+
*
|
|
34
|
+
* ## What no tool here ever accepts as input
|
|
35
|
+
*
|
|
36
|
+
* `env` (the stdio credential block), `accessToken` and `oauthClientSecret` are absent from every input schema
|
|
37
|
+
* below, on purpose, not by omission. A tool argument is text the model chose to write, and — same
|
|
38
|
+
* as `deployment_propose_custom_provider_credential`'s identical rule — a secret typed into a tool
|
|
39
|
+
* call is a secret written into the conversation transcript. Every secret field is entered by the
|
|
40
|
+
* HUMAN directly into the confirmation form `external_mcp_save` renders; the agent never sees or
|
|
41
|
+
* handles it (see the host's save form). `additionalProperties: false` on `external_mcp_save`'s schema
|
|
42
|
+
* makes an attempt to pass one a loud, rejected call rather than a silently dropped field.
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* The same site-owner-level permission the host's HTTP routes gate on (the host's external MCP route
|
|
46
|
+
* guard) — restated rather than imported because that module lives in the host's routes, a
|
|
47
|
+
* direction this domain does not import from (see the host's tool deps header). Reusing the STRING is
|
|
48
|
+
* what keeps the two gates from drifting, which is the property that module's own doc calls
|
|
49
|
+
* load-bearing: a stored row's `command` is spawned as a real child process at daemon boot, so
|
|
50
|
+
* whoever can write here can execute arbitrary code as the host process — exactly as consequential
|
|
51
|
+
* through a chat message as through a form submission, and the gate must not be weaker for one path
|
|
52
|
+
* than the other.
|
|
53
|
+
*/
|
|
54
|
+
export const EXTERNAL_MCP_MANAGE_PERMISSION = "admin.integrations.manage";
|
|
55
|
+
const EXTERNAL_MCP_TRANSPORTS = ["stdio", "streamable_http"];
|
|
56
|
+
const EXTERNAL_MCP_AUTH_MODES = ["none", "static_env", "oauth"];
|
|
57
|
+
const EXTERNAL_MCP_OAUTH_GRANTS = ["authorization_code", "device_code"];
|
|
58
|
+
const LIST_INPUT_SCHEMA = {
|
|
59
|
+
type: "object",
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: {},
|
|
62
|
+
};
|
|
63
|
+
/** The id/transport/access-list half of `external_mcp_save`'s properties — the part whose text carries host copy. */
|
|
64
|
+
const saveConnectionProperties = ({ copy }) => ({
|
|
65
|
+
id: {
|
|
66
|
+
type: "string",
|
|
67
|
+
minLength: 1,
|
|
68
|
+
maxLength: 64,
|
|
69
|
+
description: `Lowercase letters, digits and dashes. An id that already names a configured server UPDATES it (replacing its stored row, the same PUT semantics ${copy.settingsLocation} itself uses); a new id creates one.`,
|
|
70
|
+
},
|
|
71
|
+
enabled: { type: "boolean", description: "For an existing source, approve turning its access on or off without changing its connection or stored credentials." },
|
|
72
|
+
label: { type: "string", description: "Display name shown in Settings. Optional — defaults to the id." },
|
|
73
|
+
transport: {
|
|
74
|
+
type: "string",
|
|
75
|
+
enum: [...EXTERNAL_MCP_TRANSPORTS],
|
|
76
|
+
description: "Required for connection setup; omit for access-only changes to an existing source. 'stdio' launches a local command as a child process (e.g. an npx-installed MCP server) — for a hosted/remote service reachable over the network, this is almost always 'streamable_http' instead.",
|
|
77
|
+
},
|
|
78
|
+
command: { type: "string", description: "Required when transport is 'stdio'. e.g. 'npx'." },
|
|
79
|
+
args: { type: "string", description: "Space-separated command-line arguments. Only meaningful for 'stdio'." },
|
|
80
|
+
url: { type: "string", description: "Required when transport is 'streamable_http'. The server's absolute https:// URL." },
|
|
81
|
+
allowedToolNames: {
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "Comma-separated remote tool names this connection may call. Nothing runs unless it is listed here — an empty value is a legitimate, meaningful choice (contributes zero tools), not an oversight to flag back to the human.",
|
|
84
|
+
},
|
|
85
|
+
writeAllowedToolNames: {
|
|
86
|
+
type: "string",
|
|
87
|
+
description: `Comma-separated remote tool names SEPARATELY authorized to write (the remote's own readOnlyHint:false is otherwise refused elsewhere). A name here must also be in allowedToolNames, or the save is rejected. For an UPDATE, call ${copy.listToolName} first if you want to preserve an existing connection's write grants — an id that no longer names any row (e.g. recreating one that was deleted) has nothing to prefill from, so leaving this unset there means zero write access, not a carry-over of what used to be granted. An empty value is otherwise a legitimate, meaningful choice (no write access), not an oversight to flag back to the human.`,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
/** The auth half of `external_mcp_save`'s properties: no `copy` wording, and no secret-valued field. */
|
|
91
|
+
const SAVE_AUTH_PROPERTIES = {
|
|
92
|
+
authMode: {
|
|
93
|
+
type: "string",
|
|
94
|
+
enum: [...EXTERNAL_MCP_AUTH_MODES],
|
|
95
|
+
description: "'none' for a server that needs no credentials at all. 'static_env' for one that takes a pasted API key or token (the human types it directly into the confirmation form — never pass a credential value as a tool argument). 'oauth' for a server whose credentials are obtained by a browser sign-in or device code — see external_mcp_oauth_connect.",
|
|
96
|
+
},
|
|
97
|
+
accessTokenEnvName: { type: "string", description: "For stdio + static_env: the environment variable NAME that receives the token entered by the human. Never a credential value." },
|
|
98
|
+
oauthProviderId: {
|
|
99
|
+
type: "string",
|
|
100
|
+
description: "Only meaningful when authMode is 'oauth'. A registered OAuth provider id. Leave unset to instead supply this connection's own endpoints below.",
|
|
101
|
+
},
|
|
102
|
+
oauthGrant: {
|
|
103
|
+
type: "string",
|
|
104
|
+
enum: [...EXTERNAL_MCP_OAUTH_GRANTS],
|
|
105
|
+
description: "Only meaningful when authMode is 'oauth'. 'authorization_code' is an ordinary browser sign-in; 'device_code' is for a server with no way to receive a redirect.",
|
|
106
|
+
},
|
|
107
|
+
oauthClientId: { type: "string", description: "Only meaningful when authMode is 'oauth'. Not secret — it travels in the authorization URL by design." },
|
|
108
|
+
oauthScopes: { type: "string", description: "Only meaningful when authMode is 'oauth'. Space- or comma-separated." },
|
|
109
|
+
oauthTokenEnvName: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description: "Only meaningful when authMode is 'oauth' and transport is 'stdio' — the environment variable name the launched command reads its access token from.",
|
|
112
|
+
},
|
|
113
|
+
oauthAuthorizationEndpoint: { type: "string", description: "Only needed when authMode is 'oauth', the grant is 'authorization_code', and oauthProviderId is unset." },
|
|
114
|
+
oauthTokenEndpoint: { type: "string", description: "Only needed when authMode is 'oauth' and oauthProviderId is unset." },
|
|
115
|
+
oauthDeviceAuthorizationEndpoint: { type: "string", description: "Only needed when authMode is 'oauth', the grant is 'device_code', and oauthProviderId is unset." },
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* `external_mcp_save`'s schema. Every property here is a NON-secret prefill hint — see this file's
|
|
119
|
+
* header for why `env`/`oauthClientSecret` are not, and never will be, properties of this schema.
|
|
120
|
+
*
|
|
121
|
+
* `transport`/`authMode` are required rather than left to default, unlike the admin form (which can
|
|
122
|
+
* default them because a human is looking at a live, reactive UI): the confirmation form this tool
|
|
123
|
+
* renders is generated ONCE per call and cannot change shape after the fact, so the agent must have
|
|
124
|
+
* already worked out which fields even apply — through ordinary conversation — before calling this.
|
|
125
|
+
*/
|
|
126
|
+
const saveInputSchema = ({ copy }) => ({
|
|
127
|
+
type: "object",
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
required: ["id"],
|
|
130
|
+
properties: { ...saveConnectionProperties({ copy }), ...SAVE_AUTH_PROPERTIES },
|
|
131
|
+
});
|
|
132
|
+
const SERVER_ID_INPUT_SCHEMA = {
|
|
133
|
+
type: "object",
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
required: ["id"],
|
|
136
|
+
properties: {
|
|
137
|
+
id: { type: "string", minLength: 1, maxLength: 64, description: "An already-configured server's id." },
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const EXTERNAL_MCP_LIST_TOOL = {
|
|
141
|
+
name: "external_mcp_list",
|
|
142
|
+
description: [
|
|
143
|
+
"Lists this workspace's configured external MCP servers: id, label, transport, auth mode, enabled state, allowed tool names, which environment variable NAMES are set (never their values), and — for an OAuth-authenticated connection — its status ('disconnected' | 'pending' | 'connected' | 'needs_reauth').",
|
|
144
|
+
"Call this before external_mcp_save to check whether an id already exists (and see its current values before proposing an update), and after external_mcp_oauth_connect / external_mcp_oauth_poll_device to detect whether a browser sign-in the human completed has actually landed — that is the ENTIRE mechanism for detecting an authorization_code connect's completion; there is no separate 'wait for it' tool.",
|
|
145
|
+
"Never contains a credential value, a client secret, or an access/refresh token. Has no side effects and can be safely repeated.",
|
|
146
|
+
].join(" "),
|
|
147
|
+
sideEffects: "none",
|
|
148
|
+
authorization: { permission: EXTERNAL_MCP_MANAGE_PERMISSION },
|
|
149
|
+
inputSchema: LIST_INPUT_SCHEMA,
|
|
150
|
+
};
|
|
151
|
+
const EXTERNAL_MCP_TEST_CONNECTION_TOOL = {
|
|
152
|
+
name: "external_mcp_test_connection",
|
|
153
|
+
description: [
|
|
154
|
+
"Checks whether an ALREADY-SAVED external MCP server's configuration resolves cleanly (needs the full gateway: it can store data): its stored credentials decrypt, its transport has what it needs (a command for 'stdio', a URL for 'streamable_http'), and — for an OAuth connection — it is actually authorized rather than 'needs_reauth' or never connected.",
|
|
155
|
+
"This does NOT launch the command or make a network call to the remote server — it reports the same readiness check the daemon itself performs at boot before federating a server, not a live reachability probe. A server that passes this can still fail to actually connect for reasons this call cannot see (a wrong command, a server that is down); a server that fails this is reported with the exact operator-actionable reason.",
|
|
156
|
+
"Only works on a server that has already been saved (via external_mcp_save) — it takes an id, not a draft configuration, and cannot be used to test-run an arbitrary unsaved command.",
|
|
157
|
+
"Returns { ok: true } or { ok: false, reason }. OAuth token resolution may contact the authorization provider and persist a refreshed grant. Use external_mcp_probe_connection to test a hosted endpoint live, or external_mcp_get_admissions to read the assistant's current tool roster.",
|
|
158
|
+
].join(" "),
|
|
159
|
+
sideEffects: "mutates-durable-state",
|
|
160
|
+
authorization: { permission: EXTERNAL_MCP_MANAGE_PERMISSION },
|
|
161
|
+
inputSchema: SERVER_ID_INPUT_SCHEMA,
|
|
162
|
+
};
|
|
163
|
+
const EXTERNAL_MCP_OAUTH_POLL_DEVICE_TOOL = {
|
|
164
|
+
name: "external_mcp_oauth_poll_device",
|
|
165
|
+
description: [
|
|
166
|
+
"Polls a device-code authorization ONCE — call external_mcp_oauth_connect first to start one. Waits for exactly one HTTP round trip and returns immediately; it does not loop or block until the human finishes.",
|
|
167
|
+
"Returns { status: 'connected' } once the human has entered the code and approved it — the connection is authorized and ready to use. Returns { status: 'pending', retryAfterSeconds } while still waiting; call this again after that many seconds, not sooner (the provider will otherwise slow you down further).",
|
|
168
|
+
"Throws once the authorization is DECLINED, EXPIRED, or the provider fails — these are terminal; do not keep polling after one, tell the human and offer to start over with external_mcp_oauth_connect.",
|
|
169
|
+
].join(" "),
|
|
170
|
+
sideEffects: "mutates-durable-state",
|
|
171
|
+
authorization: { permission: EXTERNAL_MCP_MANAGE_PERMISSION },
|
|
172
|
+
inputSchema: SERVER_ID_INPUT_SCHEMA,
|
|
173
|
+
};
|
|
174
|
+
/** `external_mcp_save`: the one write tool; its text and schema name the host's settings screen and read tool. */
|
|
175
|
+
function externalMcpSaveTool({ copy }) {
|
|
176
|
+
return {
|
|
177
|
+
name: "external_mcp_save",
|
|
178
|
+
description: [
|
|
179
|
+
`Proposes creating or updating one external MCP server. Existing-source access-only changes (enabled, allowedToolNames, writeAllowedToolNames) show one fixed approval card and preserve stored credentials. Connection setup shows the human a credential form before anything is written — THIS NEVER SAVES SILENTLY. Call ${copy.listToolName} first if you are updating an existing id, so the human sees accurate current values rather than blanks for anything you did not restate.`,
|
|
180
|
+
"The form the human sees is generated from the fields YOU pass: decide transport and authMode through ordinary conversation before calling this (ask the human, or infer from what they already told you), because the form's shape is fixed once generated and cannot change after the fact.",
|
|
181
|
+
"Never pass a credential, API key, token, or client secret as an argument to this tool — there are no such properties on this schema, and the human types any secret directly into the rendered form, never through you.",
|
|
182
|
+
"Returns one of: { saved: true, server } once the human confirms and the write succeeds; { saved: false, cancelled: true } if the human declines; { saved: false, reason: 'expired' | 'abandoned', note } if nobody answered in time; { saved: false, reason: 'invalid', message, field } if the human's submitted form failed validation (tell them what to fix and call this again).",
|
|
183
|
+
].join(" "),
|
|
184
|
+
sideEffects: "mutates-durable-state",
|
|
185
|
+
authorization: { permission: EXTERNAL_MCP_MANAGE_PERMISSION },
|
|
186
|
+
inputSchema: saveInputSchema({ copy }),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** `external_mcp_oauth_connect`: its completion-detection guidance names the host's read tool. */
|
|
190
|
+
function externalMcpOauthConnectTool({ copy }) {
|
|
191
|
+
return {
|
|
192
|
+
name: "external_mcp_oauth_connect",
|
|
193
|
+
description: [
|
|
194
|
+
"Starts an OAuth authorization for an already-saved, OAuth-authenticated server (authMode 'oauth' — save it with external_mcp_save first).",
|
|
195
|
+
"Returns either { kind: 'redirect_required', authorizationUrl, expiresAt } — hand the human this exact URL to open in their own browser and tell them to sign in there; you cannot complete this step for them — or { kind: 'device_code', userCode, verificationUri, verificationUriComplete, expiresAt, intervalSeconds } — tell the human to open verificationUri (or verificationUriComplete directly) and enter userCode.",
|
|
196
|
+
`Your job ends at handing over that one link or code. For 'redirect_required', detect completion by calling ${copy.listToolName} again after the human says they finished and reading oauth.status ('connected' means it worked). For 'device_code', call external_mcp_oauth_poll_device with the same id — once, not in a tight loop — no sooner than intervalSeconds after this call, and again after each 'pending' response.`,
|
|
197
|
+
"Throws if the server does not exist, is not authMode 'oauth', or the provider could not be reached — these are real failures the human needs to know about, not something to retry silently.",
|
|
198
|
+
].join(" "),
|
|
199
|
+
sideEffects: "mutates-durable-state",
|
|
200
|
+
authorization: { permission: EXTERNAL_MCP_MANAGE_PERMISSION },
|
|
201
|
+
inputSchema: SERVER_ID_INPUT_SCHEMA,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Every agent-callable tool this domain exposes. All five are wired — there is no `unwiredToolIds`
|
|
206
|
+
* set in the host's tool registrations, which means any future catalog entry added without a handler is a
|
|
207
|
+
* build failure.
|
|
208
|
+
*/
|
|
209
|
+
export function createExternalMcpAgentToolCatalog({ copy }, _optional = {}) {
|
|
210
|
+
return [
|
|
211
|
+
EXTERNAL_MCP_LIST_TOOL,
|
|
212
|
+
externalMcpSaveTool({ copy }),
|
|
213
|
+
EXTERNAL_MCP_TEST_CONNECTION_TOOL,
|
|
214
|
+
externalMcpOauthConnectTool({ copy }),
|
|
215
|
+
EXTERNAL_MCP_OAUTH_POLL_DEVICE_TOOL,
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=agent-tools.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Desktop publishes its managed roster ids when starting this site process. No label matching. */
|
|
2
|
+
export declare function readBuiltInExternalMcpServerIds({ env }: {
|
|
3
|
+
env: Record<string, string | undefined>;
|
|
4
|
+
}, _options?: {}): readonly string[];
|
|
5
|
+
export declare function isBuiltInExternalMcpServer({ serverId, ids }: {
|
|
6
|
+
serverId: string;
|
|
7
|
+
ids?: readonly string[] | undefined;
|
|
8
|
+
}, _options?: {}): boolean;
|
|
9
|
+
export declare function describeExternalMcpOwnership<T extends {
|
|
10
|
+
serverId: string;
|
|
11
|
+
}>({ server, ids }: {
|
|
12
|
+
server: T;
|
|
13
|
+
ids?: readonly string[];
|
|
14
|
+
}, _options?: {}): T & {
|
|
15
|
+
builtIn: boolean;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=built-in-connections.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Desktop publishes its managed roster ids when starting this site process. No label matching. */
|
|
2
|
+
export function readBuiltInExternalMcpServerIds({ env }, _options = {}) {
|
|
3
|
+
try {
|
|
4
|
+
const value = JSON.parse(env.JINI_BUILT_IN_MCP_SERVER_IDS ?? "[]");
|
|
5
|
+
return Array.isArray(value) && value.every(id => typeof id === "string") ? value : [];
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function isBuiltInExternalMcpServer({ serverId, ids }, _options = {}) { return ids?.includes(serverId) ?? false; }
|
|
12
|
+
export function describeExternalMcpOwnership({ server, ids }, _options = {}) {
|
|
13
|
+
return { ...server, builtIn: isBuiltInExternalMcpServer({ serverId: server.serverId, ids }) };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=built-in-connections.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The product copy a host passes into the external MCP domain's model-facing text (the setup
|
|
3
|
+
* and operations tool catalogs, and the operations handlers' refusal messages). Type-only: the
|
|
4
|
+
* engine names neither the host's settings screen nor the host's own read tool in text a model
|
|
5
|
+
* reads, so the host supplies them.
|
|
6
|
+
*/
|
|
7
|
+
/** Host product copy for external MCP tool catalogs and messages. */
|
|
8
|
+
export interface ExternalMcpHostCopy {
|
|
9
|
+
/** Where the host's admin form for external MCP servers lives, as the model is told, e.g. "Settings → External MCP". */
|
|
10
|
+
readonly settingsLocation: string;
|
|
11
|
+
/** The host tool the model calls to read configured servers (the catalogs and messages point the model at it). */
|
|
12
|
+
readonly listToolName: string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=external-mcp-host-copy.d.ts.map
|