managed-deepagents 0.6.2-dev.11 → 0.6.2-dev.13
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/dist/agent-auth.d.ts +104 -0
- package/dist/agent-auth.d.ts.map +1 -0
- package/dist/agent-auth.js +224 -0
- package/dist/agent-auth.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +29 -89
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +228 -50
- package/dist/connectors/mcp/index.js.map +1 -1
- package/dist/connectors/mcp/schema.d.ts +12 -0
- package/dist/connectors/mcp/schema.d.ts.map +1 -0
- package/dist/connectors/mcp/schema.js +55 -0
- package/dist/connectors/mcp/schema.js.map +1 -0
- package/dist/connectors/mcp/types.d.ts +62 -0
- package/dist/connectors/mcp/types.d.ts.map +1 -0
- package/dist/connectors/mcp/types.js +2 -0
- package/dist/connectors/mcp/types.js.map +1 -0
- package/dist/connectors/tool-selection.d.ts +9 -18
- package/dist/connectors/tool-selection.d.ts.map +1 -1
- package/dist/connectors/tool-selection.js +32 -58
- package/dist/connectors/tool-selection.js.map +1 -1
- package/dist/credential-gate.d.ts +39 -0
- package/dist/credential-gate.d.ts.map +1 -0
- package/dist/credential-gate.js +209 -0
- package/dist/credential-gate.js.map +1 -0
- package/dist/credentials.d.ts +88 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +246 -0
- package/dist/credentials.js.map +1 -0
- package/dist/identity/index.d.ts +1 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/types.d.ts +79 -5
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/auth.d.ts +9 -4
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/http.d.ts +1 -1
- package/dist/runtime/http.d.ts.map +1 -1
- package/dist/runtime/http.js.map +1 -1
- package/dist/runtime/identity-runtime.d.ts +65 -5
- package/dist/runtime/identity-runtime.d.ts.map +1 -1
- package/dist/runtime/identity-runtime.js +148 -0
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +12 -7
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/managed-middleware.d.ts +2 -2
- package/dist/runtime/managed-middleware.js +6 -6
- package/dist/runtime/managed-tools.d.ts +19 -15
- package/dist/runtime/managed-tools.d.ts.map +1 -1
- package/dist/runtime/managed-tools.js +14 -13
- package/dist/runtime/managed-tools.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -2
- package/package.json +7 -7
- package/dist/connectors/mcp/load.d.ts +0 -12
- package/dist/connectors/mcp/load.d.ts.map +0 -1
- package/dist/connectors/mcp/load.js +0 -122
- package/dist/connectors/mcp/load.js.map +0 -1
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
20
|
* // connectors/mcp.ts
|
|
21
|
-
* import { connectors } from "managed-deepagents";
|
|
21
|
+
* import { connectors, credentials } from "managed-deepagents";
|
|
22
22
|
*
|
|
23
23
|
* export const connector = connectors.mcp({
|
|
24
24
|
* mcpServers: {
|
|
@@ -26,69 +26,247 @@
|
|
|
26
26
|
* transport: "http",
|
|
27
27
|
* url: "https://docs.example.com/mcp",
|
|
28
28
|
* },
|
|
29
|
+
* notion: {
|
|
30
|
+
* transport: "http",
|
|
31
|
+
* url: "https://mcp.notion.com/mcp",
|
|
32
|
+
* credential: credentials.get("notion", { type: "user" }),
|
|
33
|
+
* },
|
|
29
34
|
* },
|
|
30
35
|
* });
|
|
31
36
|
* ```
|
|
32
37
|
*/
|
|
33
|
-
import {
|
|
34
|
-
import { checkToolSelectionOverlap, toolSelectionConnectorFields, } from "../tool-selection.js";
|
|
38
|
+
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
|
|
35
39
|
import { defineExtension } from "../../extension.js";
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"or write a normal authored tool instead.";
|
|
40
|
-
const remoteMcpServer = z
|
|
41
|
-
.looseObject({
|
|
42
|
-
// Present only to reject it: a `command` is how a stdio server is spelled.
|
|
43
|
-
command: z.never({ error: STDIO_REJECTION }).optional(),
|
|
44
|
-
transport: z.enum(["http", "sse"], {
|
|
45
|
-
error: (issue) => issue.input === "stdio"
|
|
46
|
-
? STDIO_REJECTION
|
|
47
|
-
: 'must declare a remote transport ("http" or "sse")',
|
|
48
|
-
}),
|
|
49
|
-
url: z
|
|
50
|
-
.string("must be a non-empty URL")
|
|
51
|
-
.refine((url) => url.trim().length > 0, "must be a non-empty URL"),
|
|
52
|
-
headers: z.record(z.string(), z.string()).optional(),
|
|
53
|
-
...toolSelectionConnectorFields,
|
|
54
|
-
})
|
|
55
|
-
.check((ctx) => {
|
|
56
|
-
checkToolSelectionOverlap(ctx, ctx.value);
|
|
57
|
-
});
|
|
40
|
+
import { credentials, isCredentialReference, } from "../../credentials.js";
|
|
41
|
+
import { mcpServersConfig } from "./schema.js";
|
|
42
|
+
import { selectTools } from "../tool-selection.js";
|
|
58
43
|
/**
|
|
59
|
-
*
|
|
44
|
+
* MCP tools loaded per declared connector, cached for the process lifetime.
|
|
60
45
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
46
|
+
* The compiled entry's graph factory runs `compileManagedAgent` on every
|
|
47
|
+
* invocation, but each connector's MCP connection and tool surface are stable
|
|
48
|
+
* for the life of the deployment — so the client is created and its tools
|
|
49
|
+
* loaded once per declaration, and every subsequent run reuses them. Storing
|
|
50
|
+
* the in-flight promise also dedupes concurrent first runs for the same
|
|
51
|
+
* connector. Multiple `connectors.mcp(...)` modules each get their own entry.
|
|
52
|
+
*
|
|
53
|
+
* An agent-owned credential is read into this cache once, so rotating that
|
|
54
|
+
* secret takes a redeploy. Servers with a user-owned credential are omitted
|
|
55
|
+
* entirely; the credential gate loads those per caller.
|
|
65
56
|
*/
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
const cachedTools = new Map();
|
|
58
|
+
/**
|
|
59
|
+
* Load (and cache) the MCP tools for one connector declaration.
|
|
60
|
+
*
|
|
61
|
+
* A failed load is never cached, so a transient connection error on the first
|
|
62
|
+
* run can be retried on the next, but a misconfigured deployment surfaces the
|
|
63
|
+
* error rather than silently starting with no tools.
|
|
64
|
+
*/
|
|
65
|
+
export function loadManagedMcpTools(connectors) {
|
|
66
|
+
const cached = cachedTools.get(connectors);
|
|
67
|
+
if (cached) {
|
|
68
|
+
return cached;
|
|
69
|
+
}
|
|
70
|
+
const loading = createClientAndLoadTools(connectors).catch((error) => {
|
|
71
|
+
cachedTools.delete(connectors);
|
|
72
|
+
throw error;
|
|
73
|
+
});
|
|
74
|
+
cachedTools.set(connectors, loading);
|
|
75
|
+
return loading;
|
|
76
|
+
}
|
|
77
|
+
/** Clear the process-level MCP tool cache. Test-only. */
|
|
78
|
+
export function clearManagedMcpToolsCacheForTests(connectors) {
|
|
79
|
+
if (connectors) {
|
|
80
|
+
cachedTools.delete(connectors);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
cachedTools.clear();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The credential gate's view of the declared MCP connectors.
|
|
87
|
+
*
|
|
88
|
+
* One consumer per declaration that names a user-owned credential; a
|
|
89
|
+
* declaration that needs no grant never reaches the gate.
|
|
90
|
+
*/
|
|
91
|
+
export function mcpCredentialConsumers(connectors) {
|
|
92
|
+
const out = [];
|
|
93
|
+
for (const connector of connectors ?? []) {
|
|
94
|
+
if (!connector ||
|
|
95
|
+
typeof connector !== "object" ||
|
|
96
|
+
connector.kind !== "mcp_servers") {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const definition = connector;
|
|
100
|
+
const credentials = userCredentialReferences(definition);
|
|
101
|
+
if (credentials.length === 0) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
out.push({
|
|
105
|
+
declaration: definition,
|
|
106
|
+
credentials,
|
|
107
|
+
load: (accessTokens) => loadUserCredentialMcpTools(definition, accessTokens),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** The declared references themselves: the gate checks their owner. */
|
|
113
|
+
function userCredentialReferences(connectors) {
|
|
114
|
+
const bySlug = new Map();
|
|
115
|
+
for (const server of Object.values(connectors.mcpServers)) {
|
|
116
|
+
if (usesUserCredential(server)) {
|
|
117
|
+
const credential = server.credential;
|
|
118
|
+
bySlug.set(credential.slug, credential);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return [...bySlug.values()];
|
|
122
|
+
}
|
|
123
|
+
async function createClientAndLoadTools(connectors) {
|
|
124
|
+
const { eager, userCredential } = partitionMcpServers(connectors.mcpServers);
|
|
125
|
+
if (userCredential.length > 0) {
|
|
126
|
+
warnDeferredUserCredentialServers(userCredential);
|
|
127
|
+
}
|
|
128
|
+
if (Object.keys(eager).length === 0) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const { tools } = await loadToolsFromServers(connectors, await withAgentCredentials(eager));
|
|
132
|
+
return tools;
|
|
133
|
+
}
|
|
77
134
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
135
|
+
* Load tools for user-credential servers, once the gate has confirmed the
|
|
136
|
+
* caller's grants.
|
|
80
137
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* installs never pull in `@langchain/mcp-adapters`.
|
|
138
|
+
* Not process-cached here: the Authorization header is per caller, so the gate
|
|
139
|
+
* owns both the cache and closing the returned transport.
|
|
84
140
|
*/
|
|
141
|
+
export async function loadUserCredentialMcpTools(connectors, accessTokens) {
|
|
142
|
+
const { userCredential } = partitionMcpServers(connectors.mcpServers);
|
|
143
|
+
const connectable = {};
|
|
144
|
+
for (const name of userCredential) {
|
|
145
|
+
const server = connectors.mcpServers[name];
|
|
146
|
+
const credential = server?.credential;
|
|
147
|
+
if (!server || !isCredentialReference(credential)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const accessToken = accessTokens.get(credential.slug);
|
|
151
|
+
if (!accessToken) {
|
|
152
|
+
throw new Error(`MCP user credential "${credential.slug}" has no access token`);
|
|
153
|
+
}
|
|
154
|
+
connectable[name] = withBearer(server, accessToken);
|
|
155
|
+
}
|
|
156
|
+
if (Object.keys(connectable).length === 0) {
|
|
157
|
+
return { tools: [], close: async () => { } };
|
|
158
|
+
}
|
|
159
|
+
const { tools, client } = await loadToolsFromServers(connectors, connectable);
|
|
160
|
+
return { tools, close: () => client.close() };
|
|
161
|
+
}
|
|
162
|
+
/** Resolve each agent-owned credential into a static bearer header. */
|
|
163
|
+
async function withAgentCredentials(servers) {
|
|
164
|
+
const out = {};
|
|
165
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
166
|
+
const credential = server.credential;
|
|
167
|
+
out[name] = isCredentialReference(credential)
|
|
168
|
+
? withBearer(server, await credentials.resolveDeploymentSecret(credential.slug))
|
|
169
|
+
: server;
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
function withBearer(server, token) {
|
|
174
|
+
const headers = Object.fromEntries(Object.entries(server.headers ?? {}).filter(([name]) => name.toLowerCase() !== "authorization"));
|
|
175
|
+
return {
|
|
176
|
+
...server,
|
|
177
|
+
headers: { ...headers, Authorization: `Bearer ${token}` },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function usesUserCredential(server) {
|
|
181
|
+
return (isCredentialReference(server.credential) &&
|
|
182
|
+
server.credential.owner.type === "user");
|
|
183
|
+
}
|
|
184
|
+
function partitionMcpServers(servers) {
|
|
185
|
+
const eager = {};
|
|
186
|
+
const userCredential = [];
|
|
187
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
188
|
+
if (usesUserCredential(server)) {
|
|
189
|
+
userCredential.push(name);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
eager[name] = server;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { eager, userCredential };
|
|
196
|
+
}
|
|
197
|
+
function warnDeferredUserCredentialServers(serverNames) {
|
|
198
|
+
console.warn(`[managed-deepagents] MCP server(s) ${serverNames.join(", ")} declare ` +
|
|
199
|
+
`a user credential; tools load after the pre-run credential gate ` +
|
|
200
|
+
`confirms grants for the caller.`);
|
|
201
|
+
}
|
|
202
|
+
function stripManagedToolSelection(servers) {
|
|
203
|
+
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
|
|
204
|
+
const { includeTools: _includeTools, excludeTools: _excludeTools, credential: _credential, ...clientConfig } = server;
|
|
205
|
+
return [name, clientConfig];
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
async function loadToolsFromServers(connectors, connectable) {
|
|
209
|
+
const prefixToolNameWithServerName = connectors.prefixToolNameWithServerName ?? true;
|
|
210
|
+
const client = new MultiServerMCPClient({
|
|
211
|
+
mcpServers: stripManagedToolSelection(connectable),
|
|
212
|
+
prefixToolNameWithServerName,
|
|
213
|
+
throwOnLoadError: connectors.throwOnLoadError ?? true,
|
|
214
|
+
useStandardContentBlocks: connectors.useStandardContentBlocks ?? true,
|
|
215
|
+
onConnectionError: connectors.onConnectionError ?? "throw",
|
|
216
|
+
});
|
|
217
|
+
try {
|
|
218
|
+
const tools = await loadToolsByServer(client, connectable, prefixToolNameWithServerName);
|
|
219
|
+
if (!prefixToolNameWithServerName) {
|
|
220
|
+
assertNoToolNameCollisions(tools);
|
|
221
|
+
}
|
|
222
|
+
return { tools, client };
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
await client.close().catch(() => undefined);
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function loadToolsByServer(client, servers, prefixToolNameWithServerName) {
|
|
230
|
+
const tools = [];
|
|
231
|
+
for (const [serverName, server] of Object.entries(servers)) {
|
|
232
|
+
const serverTools = await client.getTools(serverName);
|
|
233
|
+
tools.push(...filterToolsForServer(serverName, server, serverTools, prefixToolNameWithServerName));
|
|
234
|
+
}
|
|
235
|
+
return tools;
|
|
236
|
+
}
|
|
237
|
+
function filterToolsForServer(serverName, selection, tools, prefixToolNameWithServerName) {
|
|
238
|
+
return selectTools(`MCP server "${serverName}"`, selection, tools, (tool) => {
|
|
239
|
+
const name = tool.name;
|
|
240
|
+
if (typeof name !== "string") {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
const prefix = `${serverName}__`;
|
|
244
|
+
return prefixToolNameWithServerName && name.startsWith(prefix)
|
|
245
|
+
? name.slice(prefix.length)
|
|
246
|
+
: name;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function assertNoToolNameCollisions(tools) {
|
|
250
|
+
const seen = new Set();
|
|
251
|
+
const collisions = new Set();
|
|
252
|
+
for (const tool of tools) {
|
|
253
|
+
const name = tool.name;
|
|
254
|
+
if (typeof name !== "string")
|
|
255
|
+
continue;
|
|
256
|
+
if (seen.has(name))
|
|
257
|
+
collisions.add(name);
|
|
258
|
+
seen.add(name);
|
|
259
|
+
}
|
|
260
|
+
if (collisions.size > 0) {
|
|
261
|
+
throw new Error(`MCP tool name collision: ${[...collisions].sort().join(", ")}. ` +
|
|
262
|
+
"Set `prefixToolNameWithServerName: true` (the default) so each tool is " +
|
|
263
|
+
"namespaced by its server, or rename the conflicting tools.");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
85
266
|
export const mcpConnector = defineExtension("connector", {
|
|
86
267
|
kind: "mcp_servers",
|
|
87
268
|
label: "connectors.mcp",
|
|
88
269
|
args: mcpServersConfig,
|
|
89
|
-
|
|
90
|
-
const { loadManagedMcpTools } = await import("./load.js");
|
|
91
|
-
return loadManagedMcpTools(self);
|
|
92
|
-
},
|
|
270
|
+
tools: (_ctx, self) => loadManagedMcpTools(self),
|
|
93
271
|
});
|
|
94
272
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connectors/mcp/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connectors/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,WAAW,EACX,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAUnD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4C,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAgC;IAEhC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,OAAO,GAAG,wBAAwB,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACnE,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/B,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC;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BAA4B,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC/D,yEAAyE;YACzE,4DAA4D,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GACvB,eAAe,CAAC,WAAW,EAAE;IAC3B,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC;CACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServersConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The MCP connector's arguments.
|
|
5
|
+
*
|
|
6
|
+
* Shape, types, and tool-name lists are the schema's job; the rules that need
|
|
7
|
+
* more than one field — a stdio server, a tool selected and deselected at once
|
|
8
|
+
* — are checks with hand-written messages. Server configs stay loose because
|
|
9
|
+
* `@langchain/mcp-adapters` accepts more per-transport options than MDA models.
|
|
10
|
+
*/
|
|
11
|
+
export declare const mcpServersConfig: z.ZodType<McpServersConfig, McpServersConfig>;
|
|
12
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/connectors/mcp/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA6CnD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,gBAAgB,CAevE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { appendToolSelectionOverlapIssue, optionalToolNameListSchema, } from "../tool-selection.js";
|
|
3
|
+
import { isCredentialReference, } from "../../credentials.js";
|
|
4
|
+
/** Stdio servers are out of scope; the message points at the alternatives. */
|
|
5
|
+
const STDIO_REJECTION = "uses a stdio transport, which is not supported. Managed Deep Agents " +
|
|
6
|
+
"support remote MCP servers over HTTP/SSE only; expose the server over HTTP " +
|
|
7
|
+
"or write a normal authored tool instead.";
|
|
8
|
+
/** Raw MCP tool names, before the managed `{server}__` prefix is applied. */
|
|
9
|
+
const remoteMcpServer = z
|
|
10
|
+
.looseObject({
|
|
11
|
+
/**
|
|
12
|
+
* Present only to reject it: a `command` is how a stdio server is defined,
|
|
13
|
+
* which we don't support.
|
|
14
|
+
*/
|
|
15
|
+
command: z.never({ error: STDIO_REJECTION }).optional(),
|
|
16
|
+
transport: z.enum(["http", "sse"], {
|
|
17
|
+
error: (issue) => issue.input === "stdio"
|
|
18
|
+
? STDIO_REJECTION
|
|
19
|
+
: 'must declare a remote transport ("http" or "sse")',
|
|
20
|
+
}),
|
|
21
|
+
url: z
|
|
22
|
+
.string("must be a non-empty URL")
|
|
23
|
+
.refine((url) => url.trim().length > 0, "must be a non-empty URL"),
|
|
24
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
25
|
+
defaultToolTimeout: z
|
|
26
|
+
.number("defaultToolTimeout must be a positive number")
|
|
27
|
+
.positive("defaultToolTimeout must be a positive number")
|
|
28
|
+
.optional(),
|
|
29
|
+
includeTools: optionalToolNameListSchema,
|
|
30
|
+
excludeTools: optionalToolNameListSchema,
|
|
31
|
+
credential: z
|
|
32
|
+
.custom(isCredentialReference, "must be a credentials.get(slug, owner) reference")
|
|
33
|
+
.optional(),
|
|
34
|
+
})
|
|
35
|
+
.check(appendToolSelectionOverlapIssue);
|
|
36
|
+
/**
|
|
37
|
+
* The MCP connector's arguments.
|
|
38
|
+
*
|
|
39
|
+
* Shape, types, and tool-name lists are the schema's job; the rules that need
|
|
40
|
+
* more than one field — a stdio server, a tool selected and deselected at once
|
|
41
|
+
* — are checks with hand-written messages. Server configs stay loose because
|
|
42
|
+
* `@langchain/mcp-adapters` accepts more per-transport options than MDA models.
|
|
43
|
+
*/
|
|
44
|
+
export const mcpServersConfig = z.object({
|
|
45
|
+
mcpServers: z
|
|
46
|
+
.record(z.string(), remoteMcpServer, {
|
|
47
|
+
error: "must be an object mapping server names to remote MCP server configs",
|
|
48
|
+
})
|
|
49
|
+
.refine((servers) => Object.keys(servers).length > 0, "requires at least one entry"),
|
|
50
|
+
prefixToolNameWithServerName: z.boolean().optional(),
|
|
51
|
+
throwOnLoadError: z.boolean().optional(),
|
|
52
|
+
useStandardContentBlocks: z.boolean().optional(),
|
|
53
|
+
onConnectionError: z.literal("throw").optional(),
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/connectors/mcp/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAE9B,8EAA8E;AAC9E,MAAM,eAAe,GACnB,sEAAsE;IACtE,6EAA6E;IAC7E,0CAA0C,CAAC;AAE7C,6EAA6E;AAC7E,MAAM,eAAe,GAAG,CAAC;KACtB,WAAW,CAAC;IACX;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvD,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;QACjC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,KAAK,CAAC,KAAK,KAAK,OAAO;YACrB,CAAC,CAAC,eAAe;YACjB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C,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ClientConfig, StreamableHTTPConnection } from "@langchain/mcp-adapters";
|
|
2
|
+
import type { Connector } from "../../runtime/connector.js";
|
|
3
|
+
import type { CredentialReference } from "../../credentials.js";
|
|
4
|
+
/** Per-server MCP tool selection. Names are raw, unprefixed MCP tool names. */
|
|
5
|
+
export interface McpToolSelectionConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Raw MCP tool names to expose from this server. Names are matched before any
|
|
8
|
+
* managed `{server}__` prefix is applied.
|
|
9
|
+
*/
|
|
10
|
+
includeTools?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Raw MCP tool names to hide from this server. Names are matched before any
|
|
13
|
+
* managed `{server}__` prefix is applied.
|
|
14
|
+
*/
|
|
15
|
+
excludeTools?: string[];
|
|
16
|
+
}
|
|
17
|
+
/** A user-owned credential reference resolved through Agent Auth at run time. */
|
|
18
|
+
export type McpServerCredential = CredentialReference;
|
|
19
|
+
/** Adapter connection fields MDA forwards, excluding stdio/auth the runtime owns. */
|
|
20
|
+
type AdapterRemoteConnection = Omit<StreamableHTTPConnection, "transport" | "type" | "authProvider">;
|
|
21
|
+
/** Shared remote server options plus MDA-only tool selection and credential mode. */
|
|
22
|
+
export type RemoteMcpServerBaseConfig = AdapterRemoteConnection & McpToolSelectionConfig & {
|
|
23
|
+
/**
|
|
24
|
+
* Bearer credential for this server, declared with `credentials.get(...)`.
|
|
25
|
+
* An agent owner is a deployment-wide secret read once at load; a user
|
|
26
|
+
* owner is the caller's OAuth grant, loaded per caller after the gate.
|
|
27
|
+
*/
|
|
28
|
+
credential?: McpServerCredential;
|
|
29
|
+
};
|
|
30
|
+
/** Streamable HTTP MCP server connection. */
|
|
31
|
+
export type HttpMcpServerConfig = RemoteMcpServerBaseConfig & {
|
|
32
|
+
/** Remote transport. `"http"` selects Streamable HTTP. */
|
|
33
|
+
transport: "http";
|
|
34
|
+
};
|
|
35
|
+
/** Legacy SSE MCP server connection. */
|
|
36
|
+
export type SseMcpServerConfig = RemoteMcpServerBaseConfig & {
|
|
37
|
+
/** Remote transport. `"sse"` selects legacy SSE. */
|
|
38
|
+
transport: "sse";
|
|
39
|
+
};
|
|
40
|
+
/** A remote MCP server connection. Stdio servers are intentionally excluded. */
|
|
41
|
+
export type RemoteMcpServerConfig = HttpMcpServerConfig | SseMcpServerConfig;
|
|
42
|
+
/** {@link MultiServerMCPClient} options MDA exposes on `connectors.mcp`. */
|
|
43
|
+
type McpClientOptions = Pick<ClientConfig, "prefixToolNameWithServerName" | "throwOnLoadError" | "useStandardContentBlocks" | "onConnectionError">;
|
|
44
|
+
/** Configuration accepted by `connectors.mcp`. */
|
|
45
|
+
export interface McpServersConfig extends McpClientOptions {
|
|
46
|
+
/**
|
|
47
|
+
* MCP servers to connect to. Each key is the logical server name MDA uses
|
|
48
|
+
* for validation, tracing metadata, and tool-name prefixing.
|
|
49
|
+
*/
|
|
50
|
+
mcpServers: Record<string, RemoteMcpServerConfig>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The connector exported from a `connectors/` module for MCP. It is a branded
|
|
54
|
+
* managed {@link Connector} whose `tools` hook loads the declared MCP tools at
|
|
55
|
+
* runtime, plus the raw config the loader reads.
|
|
56
|
+
*/
|
|
57
|
+
export interface McpServersDefinition extends McpServersConfig, Connector {
|
|
58
|
+
/** Internal discriminator used by the MDA loader. */
|
|
59
|
+
readonly kind: "mcp_servers";
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/connectors/mcp/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/connectors/mcp/types.ts"],"names":[],"mappings":""}
|
|
@@ -20,27 +20,18 @@ export interface ToolSelection<TTool extends string = string> {
|
|
|
20
20
|
/** Tool names to hide. Applied after {@link ToolSelection.includeTools}. */
|
|
21
21
|
excludeTools?: TTool[];
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Shared authoring options for connectors that load remote tools.
|
|
25
|
-
*/
|
|
26
|
-
export interface ToolSelectionConnectorConfig<TTool extends string = string> extends ToolSelection<TTool> {
|
|
27
|
-
/** Timeout for each tool call (milliseconds on the TypeScript runtime). */
|
|
28
|
-
defaultToolTimeout?: number;
|
|
29
|
-
}
|
|
30
23
|
/** Tool names: non-empty, no duplicates within one list. */
|
|
31
|
-
export declare const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
defaultToolTimeout: z.ZodOptional<z.ZodNumber>;
|
|
35
|
-
};
|
|
36
|
-
/** Shared include/exclude overlap check for connector arg schemas. */
|
|
37
|
-
export declare function checkToolSelectionOverlap(ctx: {
|
|
24
|
+
export declare const optionalToolNameListSchema: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
export declare function appendToolSelectionOverlapIssue(ctx: {
|
|
26
|
+
value: unknown;
|
|
38
27
|
issues: {
|
|
39
|
-
push(issue:
|
|
28
|
+
push: (issue: {
|
|
29
|
+
code: "custom";
|
|
30
|
+
input: unknown;
|
|
31
|
+
message: string;
|
|
32
|
+
}) => void;
|
|
40
33
|
};
|
|
41
|
-
|
|
42
|
-
}, value: ToolSelection): void;
|
|
43
|
-
export declare function toolSelectionConnectorSchema<TArgs, TInput>(extra?: z.ZodRawShape): z.ZodType<TArgs, TInput>;
|
|
34
|
+
}): void;
|
|
44
35
|
/** Read the name a selection matches a loaded tool by. */
|
|
45
36
|
export type ToolNameReader = (tool: unknown) => string | undefined;
|
|
46
37
|
/** Read a loaded tool's own `name`. The default for connectors that don't rename. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-selection.d.ts","sourceRoot":"","sources":["../../src/connectors/tool-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC1D,6DAA6D;IAC7D,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;IACvB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;CACxB;AAED
|
|
1
|
+
{"version":3,"file":"tool-selection.d.ts","sourceRoot":"","sources":["../../src/connectors/tool-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC1D,6DAA6D;IAC7D,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;IACvB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;CACxB;AAED,4DAA4D;AAC5D,eAAO,MAAM,0BAA0B,wCAsB1B,CAAC;AAmBd,wBAAgB,+BAA+B,CAAC,GAAG,EAAE;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE;QACN,IAAI,EAAE,CAAC,KAAK,EAAE;YAAE,IAAI,EAAE,QAAQ,CAAC;YAAC,KAAK,EAAE,OAAO,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,KAAK,IAAI,CAAC;KAC5E,CAAC;CACH,GAAG,IAAI,CAWP;AAED,0DAA0D;AAC1D,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;AAEnE,qFAAqF;AACrF,eAAO,MAAM,QAAQ,EAAE,cAGtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,QAAQ,GAAE,cAAyB,GAClC,OAAO,EAAE,CAwBX"}
|
|
@@ -8,73 +8,47 @@
|
|
|
8
8
|
* silently dropping a tool the agent was meant to have.
|
|
9
9
|
*/
|
|
10
10
|
import { z } from "zod";
|
|
11
|
-
function nonEmpty(field) {
|
|
12
|
-
const message = `${field} must be a non-empty string`;
|
|
13
|
-
return z.string(message).refine((value) => value.trim().length > 0, message);
|
|
14
|
-
}
|
|
15
11
|
/** Tool names: non-empty, no duplicates within one list. */
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
seen.add(name);
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
.optional(),
|
|
33
|
-
excludeTools: z
|
|
34
|
-
.array(nonEmpty("tool name"))
|
|
35
|
-
.check((ctx) => {
|
|
36
|
-
const seen = new Set();
|
|
37
|
-
for (const name of ctx.value) {
|
|
38
|
-
if (seen.has(name)) {
|
|
39
|
-
ctx.issues.push({
|
|
40
|
-
code: "custom",
|
|
41
|
-
input: ctx.value,
|
|
42
|
-
message: `contains duplicate tool name "${name}"`,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
seen.add(name);
|
|
12
|
+
export const optionalToolNameListSchema = z
|
|
13
|
+
.array(z
|
|
14
|
+
.string("tool name must be a non-empty string")
|
|
15
|
+
.refine((name) => name.trim().length > 0, "tool name must be a non-empty string"))
|
|
16
|
+
.check((ctx) => {
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
for (const name of ctx.value) {
|
|
19
|
+
if (seen.has(name)) {
|
|
20
|
+
ctx.issues.push({
|
|
21
|
+
code: "custom",
|
|
22
|
+
input: ctx.value,
|
|
23
|
+
message: `contains duplicate tool name "${name}"`,
|
|
24
|
+
});
|
|
46
25
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
/** Shared include/exclude overlap check for connector arg schemas. */
|
|
55
|
-
export function checkToolSelectionOverlap(ctx, value) {
|
|
56
|
-
const { includeTools, excludeTools } = value;
|
|
26
|
+
seen.add(name);
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.optional();
|
|
30
|
+
function toolSelectionOverlapMessage(selection) {
|
|
31
|
+
const { includeTools, excludeTools } = selection;
|
|
57
32
|
const overlap = (includeTools ?? []).filter((name) => (excludeTools ?? []).includes(name));
|
|
58
|
-
if (overlap.length
|
|
33
|
+
if (overlap.length === 0) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return `selects tool(s) in both \`includeTools\` and \`excludeTools\`: ${[
|
|
37
|
+
...new Set(overlap),
|
|
38
|
+
]
|
|
39
|
+
.sort()
|
|
40
|
+
.join(", ")}`;
|
|
41
|
+
}
|
|
42
|
+
export function appendToolSelectionOverlapIssue(ctx) {
|
|
43
|
+
const message = toolSelectionOverlapMessage(ctx.value);
|
|
44
|
+
if (message) {
|
|
59
45
|
ctx.issues.push({
|
|
60
46
|
code: "custom",
|
|
61
47
|
input: ctx.value,
|
|
62
|
-
message
|
|
63
|
-
...new Set(overlap),
|
|
64
|
-
]
|
|
65
|
-
.sort()
|
|
66
|
-
.join(", ")}`,
|
|
48
|
+
message,
|
|
67
49
|
});
|
|
68
50
|
}
|
|
69
51
|
}
|
|
70
|
-
export function toolSelectionConnectorSchema(extra = {}) {
|
|
71
|
-
return z
|
|
72
|
-
.strictObject({ ...toolSelectionConnectorFields, ...extra })
|
|
73
|
-
.check((ctx) => {
|
|
74
|
-
checkToolSelectionOverlap(ctx, ctx.value);
|
|
75
|
-
})
|
|
76
|
-
.prefault({});
|
|
77
|
-
}
|
|
78
52
|
/** Read a loaded tool's own `name`. The default for connectors that don't rename. */
|
|
79
53
|
export const toolName = (tool) => {
|
|
80
54
|
const name = tool.name;
|