managed-deepagents 0.6.2-dev.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -16
- package/dist/agent-auth.d.ts +167 -0
- package/dist/agent-auth.d.ts.map +1 -0
- package/dist/agent-auth.js +520 -0
- package/dist/agent-auth.js.map +1 -0
- package/dist/channels/manifest.d.ts +4 -0
- package/dist/channels/manifest.d.ts.map +1 -1
- package/dist/channels/response-format.d.ts +1 -1
- package/dist/channels/response-format.d.ts.map +1 -1
- package/dist/channels/response-format.js +1 -1
- package/dist/channels/response-format.js.map +1 -1
- package/dist/channels/trigger/http.d.ts +8 -0
- package/dist/channels/trigger/http.d.ts.map +1 -1
- package/dist/channels/trigger/http.js +56 -6
- package/dist/channels/trigger/http.js.map +1 -1
- package/dist/channels/trigger/identity-context.d.ts +47 -0
- package/dist/channels/trigger/identity-context.d.ts.map +1 -0
- package/dist/channels/trigger/identity-context.js +171 -0
- package/dist/channels/trigger/identity-context.js.map +1 -0
- package/dist/channels/trigger/types.d.ts +10 -0
- package/dist/channels/trigger/types.d.ts.map +1 -1
- package/dist/channels/trigger/types.js +5 -0
- package/dist/channels/trigger/types.js.map +1 -1
- package/dist/connection-authorization.d.ts +17 -0
- package/dist/connection-authorization.d.ts.map +1 -0
- package/dist/connection-authorization.js +46 -0
- package/dist/connection-authorization.js.map +1 -0
- package/dist/connections.d.ts +98 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/connections.js +339 -0
- package/dist/connections.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +36 -95
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +266 -57
- package/dist/connectors/mcp/index.js.map +1 -1
- package/dist/connectors/mcp/schema.d.ts +17 -0
- package/dist/connectors/mcp/schema.d.ts.map +1 -0
- package/dist/connectors/mcp/schema.js +122 -0
- package/dist/connectors/mcp/schema.js.map +1 -0
- package/dist/connectors/mcp/types.d.ts +81 -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 +10 -19
- package/dist/connectors/tool-selection.d.ts.map +1 -1
- package/dist/connectors/tool-selection.js +33 -59
- package/dist/connectors/tool-selection.js.map +1 -1
- package/dist/credential-gate.d.ts +28 -0
- package/dist/credential-gate.d.ts.map +1 -0
- package/dist/credential-gate.js +179 -0
- package/dist/credential-gate.js.map +1 -0
- package/dist/extension.d.ts +3 -3
- package/dist/extension.js +2 -2
- 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 +102 -5
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +9 -34
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/ingress/index.d.ts +10 -2
- package/dist/ingress/index.d.ts.map +1 -1
- package/dist/ingress/index.js +18 -9
- package/dist/ingress/index.js.map +1 -1
- package/dist/namespaces.d.ts +12 -29
- package/dist/namespaces.d.ts.map +1 -1
- package/dist/namespaces.js +26 -9
- package/dist/namespaces.js.map +1 -1
- package/dist/runtime/auth.d.ts +76 -5
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js +114 -6
- 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 +164 -0
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +13 -8
- 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/dist/runtime/validated-token.d.ts.map +1 -1
- package/dist/runtime/validated-token.js +23 -0
- package/dist/runtime/validated-token.js.map +1 -1
- package/package.json +8 -8
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The managed
|
|
2
|
+
* The managed MCP declaration primitive.
|
|
3
3
|
*
|
|
4
4
|
* A Managed Deep Agent declares the remote MCP servers whose tools it wants in
|
|
5
|
-
* `
|
|
5
|
+
* `tools/mcp.ts` with `defineMcp(...)`. MDA discovers that
|
|
6
6
|
* declaration, creates the `@langchain/mcp-adapters` client, loads the tools,
|
|
7
7
|
* and adds them to the Deep Agent at runtime — the author never imports the MCP
|
|
8
8
|
* client or calls `getTools()`.
|
|
@@ -17,78 +17,287 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
|
-
* //
|
|
21
|
-
* import {
|
|
20
|
+
* // tools/mcp.ts
|
|
21
|
+
* import { defineMcp, connections } from "managed-deepagents";
|
|
22
22
|
*
|
|
23
|
-
* export const
|
|
24
|
-
*
|
|
23
|
+
* export const mcp = defineMcp({
|
|
24
|
+
* servers: {
|
|
25
25
|
* docs: {
|
|
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
|
+
* connection: connections.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 { connections, isConnectionReference, } from "../../connections.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 `defineMcp(...)` modules each get their own entry.
|
|
52
|
+
*
|
|
53
|
+
* An agent-owned connection is read into this cache once, so rotating that
|
|
54
|
+
* secret takes a redeploy. Servers with a user-owned connection 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 connection; 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 userConnections = userConnectionReferences(definition);
|
|
101
|
+
if (userConnections.length === 0) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
out.push({
|
|
105
|
+
declaration: definition,
|
|
106
|
+
credentials: userConnections,
|
|
107
|
+
load: (accessTokens) => loadUserConnectionMcpTools(definition, accessTokens),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** The declared references themselves: the gate checks their owner. */
|
|
113
|
+
function userConnectionReferences(connectors) {
|
|
114
|
+
const bySlug = new Map();
|
|
115
|
+
for (const server of Object.values(connectors.servers)) {
|
|
116
|
+
if (usesUserConnection(server)) {
|
|
117
|
+
const connection = server.connection;
|
|
118
|
+
bySlug.set(connection.slug, connection);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return [...bySlug.values()];
|
|
122
|
+
}
|
|
123
|
+
function agentConnectionReferences(connectors) {
|
|
124
|
+
const bySlug = new Map();
|
|
125
|
+
for (const server of Object.values(connectors.servers)) {
|
|
126
|
+
const connection = server.connection;
|
|
127
|
+
if (isConnectionReference(connection) &&
|
|
128
|
+
connection.owner.type === "agent") {
|
|
129
|
+
bySlug.set(connection.slug, connection);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...bySlug.values()];
|
|
133
|
+
}
|
|
134
|
+
function mcpRequirements(name, connectors) {
|
|
135
|
+
const userSlugs = userConnectionReferences(connectors)
|
|
136
|
+
.map((connection) => connection.slug)
|
|
137
|
+
.sort();
|
|
138
|
+
const agentSlugs = agentConnectionReferences(connectors)
|
|
139
|
+
.map((connection) => connection.slug)
|
|
140
|
+
.sort();
|
|
141
|
+
return {
|
|
142
|
+
name,
|
|
143
|
+
provider: "mcp",
|
|
144
|
+
autoReply: false,
|
|
145
|
+
requiredPermissions: [],
|
|
146
|
+
requiredEnv: [],
|
|
147
|
+
userConnections: userSlugs,
|
|
148
|
+
agentConnections: agentSlugs,
|
|
149
|
+
providerConfig: {},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async function createClientAndLoadTools(connectors) {
|
|
153
|
+
const { eager, userConnection } = partitionMcpServers(connectors.servers);
|
|
154
|
+
if (userConnection.length > 0) {
|
|
155
|
+
warnDeferredUserConnectionServers(userConnection);
|
|
156
|
+
}
|
|
157
|
+
if (Object.keys(eager).length === 0) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const { tools } = await loadToolsFromServers(connectors, await withAgentConnections(eager));
|
|
161
|
+
return tools;
|
|
162
|
+
}
|
|
77
163
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
164
|
+
* Load tools for user-connection servers, once the gate has confirmed the
|
|
165
|
+
* caller's grants.
|
|
80
166
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* installs never pull in `@langchain/mcp-adapters`.
|
|
167
|
+
* Not process-cached here: the Authorization header is per caller, so the gate
|
|
168
|
+
* owns both the cache and closing the returned transport.
|
|
84
169
|
*/
|
|
85
|
-
export
|
|
170
|
+
export async function loadUserConnectionMcpTools(connectors, accessTokens) {
|
|
171
|
+
const { userConnection } = partitionMcpServers(connectors.servers);
|
|
172
|
+
const connectable = {};
|
|
173
|
+
for (const name of userConnection) {
|
|
174
|
+
const server = connectors.servers[name];
|
|
175
|
+
const connection = server?.connection;
|
|
176
|
+
if (!server || !isConnectionReference(connection)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const accessToken = accessTokens.get(connection.slug);
|
|
180
|
+
if (!accessToken) {
|
|
181
|
+
throw new Error(`MCP user connection "${connection.slug}" has no access token`);
|
|
182
|
+
}
|
|
183
|
+
connectable[name] = withBearer(server, accessToken);
|
|
184
|
+
}
|
|
185
|
+
if (Object.keys(connectable).length === 0) {
|
|
186
|
+
return { tools: [], close: async () => { } };
|
|
187
|
+
}
|
|
188
|
+
const { tools, client } = await loadToolsFromServers(connectors, connectable);
|
|
189
|
+
return { tools, close: () => client.close() };
|
|
190
|
+
}
|
|
191
|
+
/** Resolve each agent-owned connection into a static bearer header. */
|
|
192
|
+
async function withAgentConnections(servers) {
|
|
193
|
+
const out = {};
|
|
194
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
195
|
+
const connection = server.connection;
|
|
196
|
+
out[name] = isConnectionReference(connection)
|
|
197
|
+
? withBearer(server, await connections.resolveDeploymentSecret(connection.slug))
|
|
198
|
+
: server;
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
function withBearer(server, token) {
|
|
203
|
+
const headers = Object.fromEntries(Object.entries(server.headers ?? {}).filter(([name]) => name.toLowerCase() !== "authorization"));
|
|
204
|
+
return {
|
|
205
|
+
...server,
|
|
206
|
+
headers: { ...headers, Authorization: `Bearer ${token}` },
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function usesUserConnection(server) {
|
|
210
|
+
return (isConnectionReference(server.connection) &&
|
|
211
|
+
server.connection.owner.type === "user");
|
|
212
|
+
}
|
|
213
|
+
function partitionMcpServers(servers) {
|
|
214
|
+
const eager = {};
|
|
215
|
+
const userConnection = [];
|
|
216
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
217
|
+
if (usesUserConnection(server)) {
|
|
218
|
+
userConnection.push(name);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
eager[name] = server;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { eager, userConnection };
|
|
225
|
+
}
|
|
226
|
+
function warnDeferredUserConnectionServers(serverNames) {
|
|
227
|
+
console.warn(`[managed-deepagents] MCP server(s) ${serverNames.join(", ")} declare ` +
|
|
228
|
+
`a user connection; tools load after the pre-run credential gate ` +
|
|
229
|
+
`confirms grants for the caller.`);
|
|
230
|
+
}
|
|
231
|
+
function stripManagedToolSelection(servers) {
|
|
232
|
+
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
|
|
233
|
+
const { includeTools: _includeTools, excludeTools: _excludeTools, connection: _connection, ...clientConfig } = server;
|
|
234
|
+
return [name, clientConfig];
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
async function loadToolsFromServers(connectors, connectable) {
|
|
238
|
+
const prefixToolNameWithServerName = connectors.prefixToolNameWithServerName ?? true;
|
|
239
|
+
const client = new MultiServerMCPClient({
|
|
240
|
+
mcpServers: stripManagedToolSelection(connectable),
|
|
241
|
+
prefixToolNameWithServerName,
|
|
242
|
+
throwOnLoadError: connectors.throwOnLoadError ?? true,
|
|
243
|
+
useStandardContentBlocks: connectors.useStandardContentBlocks ?? true,
|
|
244
|
+
onConnectionError: connectors.onConnectionError ?? "throw",
|
|
245
|
+
});
|
|
246
|
+
try {
|
|
247
|
+
const tools = await loadToolsByServer(client, connectable, prefixToolNameWithServerName);
|
|
248
|
+
if (!prefixToolNameWithServerName) {
|
|
249
|
+
assertNoToolNameCollisions(tools);
|
|
250
|
+
}
|
|
251
|
+
return { tools, client };
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
await client.close().catch(() => undefined);
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async function loadToolsByServer(client, servers, prefixToolNameWithServerName) {
|
|
259
|
+
const tools = [];
|
|
260
|
+
for (const [serverName, server] of Object.entries(servers)) {
|
|
261
|
+
const serverTools = await client.getTools(serverName);
|
|
262
|
+
tools.push(...filterToolsForServer(serverName, server, serverTools, prefixToolNameWithServerName));
|
|
263
|
+
}
|
|
264
|
+
return tools;
|
|
265
|
+
}
|
|
266
|
+
function filterToolsForServer(serverName, selection, tools, prefixToolNameWithServerName) {
|
|
267
|
+
return selectTools(`MCP server "${serverName}"`, selection, tools, (tool) => {
|
|
268
|
+
const name = tool.name;
|
|
269
|
+
if (typeof name !== "string") {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
const prefix = `${serverName}__`;
|
|
273
|
+
return prefixToolNameWithServerName && name.startsWith(prefix)
|
|
274
|
+
? name.slice(prefix.length)
|
|
275
|
+
: name;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function assertNoToolNameCollisions(tools) {
|
|
279
|
+
const seen = new Set();
|
|
280
|
+
const collisions = new Set();
|
|
281
|
+
for (const tool of tools) {
|
|
282
|
+
const name = tool.name;
|
|
283
|
+
if (typeof name !== "string")
|
|
284
|
+
continue;
|
|
285
|
+
if (seen.has(name))
|
|
286
|
+
collisions.add(name);
|
|
287
|
+
seen.add(name);
|
|
288
|
+
}
|
|
289
|
+
if (collisions.size > 0) {
|
|
290
|
+
throw new Error(`MCP tool name collision: ${[...collisions].sort().join(", ")}. ` +
|
|
291
|
+
"Set `prefixToolNameWithServerName: true` (the default) so each tool is " +
|
|
292
|
+
"namespaced by its server, or rename the conflicting tools.");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** Declare remote MCP servers whose tools load at agent-graph construction. */
|
|
296
|
+
export const defineMcp = defineExtension("connector", {
|
|
86
297
|
kind: "mcp_servers",
|
|
87
|
-
label: "
|
|
298
|
+
label: "defineMcp",
|
|
88
299
|
args: mcpServersConfig,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return loadManagedMcpTools(self);
|
|
92
|
-
},
|
|
300
|
+
tools: (_ctx, self) => loadManagedMcpTools(self),
|
|
301
|
+
requirements: (name, self) => mcpRequirements(name, self),
|
|
93
302
|
});
|
|
94
303
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connectors/mcp/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"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AC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServersArgs } from "./types.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare const MCP_SERVERS_KEY_DEPRECATION = "mcpServers is deprecated; use servers instead. It will be removed in 0.8.0.";
|
|
5
|
+
/**
|
|
6
|
+
* The MCP connector's arguments.
|
|
7
|
+
*
|
|
8
|
+
* Shape, types, and tool-name lists are the schema's job; the rules that need
|
|
9
|
+
* more than one field — a stdio server, a tool selected and deselected at once
|
|
10
|
+
* — are checks with hand-written messages. Server configs stay loose because
|
|
11
|
+
* `@langchain/mcp-adapters` accepts more per-transport options than MDA models.
|
|
12
|
+
*
|
|
13
|
+
* `mcpServers` is accepted as a deprecated alias of `servers` and is rewritten
|
|
14
|
+
* to `servers` so the stored definition has one key.
|
|
15
|
+
*/
|
|
16
|
+
export declare const mcpServersConfig: z.ZodType<McpServersArgs>;
|
|
17
|
+
//# 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,cAAc,EAAE,MAAM,YAAY,CAAC;AAejD,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,gFACuC,CAAC;AAgEhF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAoDnD,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { appendToolSelectionOverlapIssue, optionalToolNameListSchema, } from "../tool-selection.js";
|
|
3
|
+
import { isConnectionReference, } from "../../connections.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
|
+
const CREDENTIAL_FIELD_REJECTION = 'the "credential" field was removed; use connection: connections.get(slug, owner) instead';
|
|
9
|
+
/** @internal */
|
|
10
|
+
export const MCP_SERVERS_KEY_DEPRECATION = "mcpServers is deprecated; use servers instead. It will be removed in 0.8.0.";
|
|
11
|
+
const SERVERS_MAP_ERROR = "must be an object mapping server names to remote MCP server configs";
|
|
12
|
+
const SERVERS_KEY_CONFLICT = 'use either "servers" or "mcpServers", not both';
|
|
13
|
+
function emitMcpServersKeyDeprecation() {
|
|
14
|
+
if (typeof process !== "undefined" &&
|
|
15
|
+
typeof process.emitWarning === "function") {
|
|
16
|
+
process.emitWarning(MCP_SERVERS_KEY_DEPRECATION, {
|
|
17
|
+
type: "DeprecationWarning",
|
|
18
|
+
code: "MDA_MCP_SERVERS",
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.warn(MCP_SERVERS_KEY_DEPRECATION);
|
|
23
|
+
}
|
|
24
|
+
/** Raw MCP tool names, before the managed `{server}__` prefix is applied. */
|
|
25
|
+
const remoteMcpServer = z
|
|
26
|
+
.looseObject({
|
|
27
|
+
/**
|
|
28
|
+
* Present only to reject it: a `command` is how a stdio server is defined,
|
|
29
|
+
* which we don't support.
|
|
30
|
+
*/
|
|
31
|
+
command: z.never({ error: STDIO_REJECTION }).optional(),
|
|
32
|
+
transport: z.enum(["http", "sse"], {
|
|
33
|
+
error: (issue) => issue.input === "stdio"
|
|
34
|
+
? STDIO_REJECTION
|
|
35
|
+
: 'must declare a remote transport ("http" or "sse")',
|
|
36
|
+
}),
|
|
37
|
+
url: z
|
|
38
|
+
.string("must be a non-empty URL")
|
|
39
|
+
.refine((url) => url.trim().length > 0, "must be a non-empty URL"),
|
|
40
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
41
|
+
defaultToolTimeout: z
|
|
42
|
+
.number("defaultToolTimeout must be a positive number")
|
|
43
|
+
.positive("defaultToolTimeout must be a positive number")
|
|
44
|
+
.optional(),
|
|
45
|
+
includeTools: optionalToolNameListSchema,
|
|
46
|
+
excludeTools: optionalToolNameListSchema,
|
|
47
|
+
credential: z.never({ error: CREDENTIAL_FIELD_REJECTION }).optional(),
|
|
48
|
+
connection: z
|
|
49
|
+
.custom(isConnectionReference, "must be a connections.get(slug, owner) reference")
|
|
50
|
+
.optional(),
|
|
51
|
+
})
|
|
52
|
+
.check(appendToolSelectionOverlapIssue);
|
|
53
|
+
const serverMap = z
|
|
54
|
+
.record(z.string(), remoteMcpServer, {
|
|
55
|
+
error: SERVERS_MAP_ERROR,
|
|
56
|
+
})
|
|
57
|
+
.refine((servers) => Object.keys(servers).length > 0, "requires at least one entry");
|
|
58
|
+
/**
|
|
59
|
+
* The MCP connector's arguments.
|
|
60
|
+
*
|
|
61
|
+
* Shape, types, and tool-name lists are the schema's job; the rules that need
|
|
62
|
+
* more than one field — a stdio server, a tool selected and deselected at once
|
|
63
|
+
* — are checks with hand-written messages. Server configs stay loose because
|
|
64
|
+
* `@langchain/mcp-adapters` accepts more per-transport options than MDA models.
|
|
65
|
+
*
|
|
66
|
+
* `mcpServers` is accepted as a deprecated alias of `servers` and is rewritten
|
|
67
|
+
* to `servers` so the stored definition has one key.
|
|
68
|
+
*/
|
|
69
|
+
export const mcpServersConfig = z
|
|
70
|
+
.object({
|
|
71
|
+
servers: serverMap.optional(),
|
|
72
|
+
mcpServers: serverMap.optional(),
|
|
73
|
+
prefixToolNameWithServerName: z.boolean().optional(),
|
|
74
|
+
throwOnLoadError: z.boolean().optional(),
|
|
75
|
+
useStandardContentBlocks: z.boolean().optional(),
|
|
76
|
+
onConnectionError: z.literal("throw").optional(),
|
|
77
|
+
})
|
|
78
|
+
.check((ctx) => {
|
|
79
|
+
const { servers, mcpServers } = ctx.value;
|
|
80
|
+
if (servers !== undefined && mcpServers !== undefined) {
|
|
81
|
+
ctx.issues.push({
|
|
82
|
+
code: "custom",
|
|
83
|
+
input: ctx.value,
|
|
84
|
+
message: SERVERS_KEY_CONFLICT,
|
|
85
|
+
path: ["mcpServers"],
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (servers === undefined && mcpServers === undefined) {
|
|
90
|
+
ctx.issues.push({
|
|
91
|
+
code: "custom",
|
|
92
|
+
input: ctx.value,
|
|
93
|
+
message: SERVERS_MAP_ERROR,
|
|
94
|
+
path: ["servers"],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
.transform((value) => {
|
|
99
|
+
const servers = value.servers ?? value.mcpServers;
|
|
100
|
+
if (servers === undefined) {
|
|
101
|
+
// The `.check` above reports this; keep the transform total.
|
|
102
|
+
return { servers: {} };
|
|
103
|
+
}
|
|
104
|
+
if (value.mcpServers !== undefined && value.servers === undefined) {
|
|
105
|
+
emitMcpServersKeyDeprecation();
|
|
106
|
+
}
|
|
107
|
+
const args = { servers };
|
|
108
|
+
if (value.prefixToolNameWithServerName !== undefined) {
|
|
109
|
+
args.prefixToolNameWithServerName = value.prefixToolNameWithServerName;
|
|
110
|
+
}
|
|
111
|
+
if (value.throwOnLoadError !== undefined) {
|
|
112
|
+
args.throwOnLoadError = value.throwOnLoadError;
|
|
113
|
+
}
|
|
114
|
+
if (value.useStandardContentBlocks !== undefined) {
|
|
115
|
+
args.useStandardContentBlocks = value.useStandardContentBlocks;
|
|
116
|
+
}
|
|
117
|
+
if (value.onConnectionError !== undefined) {
|
|
118
|
+
args.onConnectionError = value.onConnectionError;
|
|
119
|
+
}
|
|
120
|
+
return args;
|
|
121
|
+
});
|
|
122
|
+
//# 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,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GAAG,KAAK,CAAC,4BAA4B,CAAC;IACzE,CAAC;IACD,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IACjD,CAAC;IACD,IAAI,KAAK,CAAC,wBAAwB,KAAK,SAAS,EAAE,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC,wBAAwB,CAAC;IACjE,CAAC;IACD,IAAI,KAAK,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ClientConfig, StreamableHTTPConnection } from "@langchain/mcp-adapters";
|
|
2
|
+
import type { Connector } from "../../runtime/connector.js";
|
|
3
|
+
import type { ConnectionReference } from "../../connections.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 connection reference resolved through Agent Auth at run time. */
|
|
18
|
+
export type McpServerConnection = ConnectionReference;
|
|
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 connection mode. */
|
|
22
|
+
export type RemoteMcpServerBaseConfig = AdapterRemoteConnection & McpToolSelectionConfig & {
|
|
23
|
+
/**
|
|
24
|
+
* Bearer connection for this server, declared with `connections.get(...)`.
|
|
25
|
+
* An agent owner is a workspace-shared secret read once at load; a user
|
|
26
|
+
* owner is the caller's grant, loaded per caller after the gate.
|
|
27
|
+
*/
|
|
28
|
+
connection?: McpServerConnection;
|
|
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 `defineMcp`. */
|
|
43
|
+
type McpClientOptions = Pick<ClientConfig, "prefixToolNameWithServerName" | "throwOnLoadError" | "useStandardContentBlocks" | "onConnectionError">;
|
|
44
|
+
/** Named remote MCP servers. Each key is the logical server name. */
|
|
45
|
+
export type McpServerMap = Record<string, RemoteMcpServerConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Configuration accepted by `defineMcp`.
|
|
48
|
+
*
|
|
49
|
+
* Prefer `servers`. `mcpServers` is a deprecated alias and will be removed in
|
|
50
|
+
* 0.8.0.
|
|
51
|
+
*/
|
|
52
|
+
export type McpServersConfig = McpClientOptions & ({
|
|
53
|
+
/**
|
|
54
|
+
* MCP servers to connect to. Each key is the logical server name MDA
|
|
55
|
+
* uses for validation, tracing metadata, and tool-name prefixing.
|
|
56
|
+
*/
|
|
57
|
+
servers: McpServerMap;
|
|
58
|
+
mcpServers?: never;
|
|
59
|
+
} | {
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use {@link McpServersConfig} `servers` instead.
|
|
62
|
+
* `mcpServers` will be removed in 0.8.0.
|
|
63
|
+
*/
|
|
64
|
+
mcpServers: McpServerMap;
|
|
65
|
+
servers?: never;
|
|
66
|
+
});
|
|
67
|
+
/** Parsed `defineMcp` arguments stored on the connector. Always `servers`. */
|
|
68
|
+
export interface McpServersArgs extends McpClientOptions {
|
|
69
|
+
servers: McpServerMap;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The connector exported from a `connectors/` module for MCP. It is a branded
|
|
73
|
+
* managed {@link Connector} whose `tools` hook loads the declared MCP tools at
|
|
74
|
+
* runtime, plus the raw config the loader reads.
|
|
75
|
+
*/
|
|
76
|
+
export interface McpServersDefinition extends McpServersArgs, Connector {
|
|
77
|
+
/** Internal discriminator used by the MDA loader. */
|
|
78
|
+
readonly kind: "mcp_servers";
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# 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,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEtD,qFA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