managed-deepagents 0.6.2-dev.20 → 0.6.2-dev.21
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 +12 -9
- package/dist/agent-auth.d.ts +11 -0
- package/dist/agent-auth.d.ts.map +1 -1
- package/dist/agent-auth.js +58 -0
- package/dist/agent-auth.js.map +1 -1
- package/dist/channels/manifest.d.ts +5 -1
- package/dist/channels/manifest.d.ts.map +1 -1
- package/dist/connections.d.ts +87 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/{credentials.js → connections.js} +107 -99
- package/dist/connections.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +7 -5
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +63 -44
- package/dist/connectors/mcp/index.js.map +1 -1
- package/dist/connectors/mcp/schema.d.ts.map +1 -1
- package/dist/connectors/mcp/schema.js +5 -3
- package/dist/connectors/mcp/schema.js.map +1 -1
- package/dist/connectors/mcp/types.d.ts +10 -8
- package/dist/connectors/mcp/types.d.ts.map +1 -1
- package/dist/credential-gate.d.ts +13 -12
- package/dist/credential-gate.d.ts.map +1 -1
- package/dist/credential-gate.js +52 -31
- package/dist/credential-gate.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/credentials.d.ts +0 -95
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js.map +0 -1
|
@@ -1,58 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `connections.get(...)` — read a managed connection from a tool.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* current caller, always backed by an OAuth grant. Resolution reads Agent Auth
|
|
8
|
-
* on every await and never caches.
|
|
4
|
+
* `{ type: "agent" }` resolves shared workspace material on the connection row.
|
|
5
|
+
* `{ type: "user" }` resolves per-caller grants (OAuth or opaque). Resolution
|
|
6
|
+
* reads Agent Auth on every await and never caches.
|
|
9
7
|
*
|
|
10
|
-
* `mda dev`
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* an actionable error. Both scopes work normally against a deployment.
|
|
8
|
+
* `mda dev` substitutes local values for agent opaque secrets via `MDA_DEV_*`.
|
|
9
|
+
* User-owned connections need a deployment; opaque user grants use the same
|
|
10
|
+
* pre-run gate as OAuth.
|
|
14
11
|
*/
|
|
15
12
|
import { AGENT_AUTH_TIMEOUT_MS, AgentAuth, CredentialAuthorizationRequiredError, CredentialStoreError, } from "./agent-auth.js";
|
|
16
13
|
import { buildRuntimeIdentity, resolveRuntimeConfigurable, } from "./runtime/identity-runtime.js";
|
|
17
14
|
export { AGENT_AUTH_TIMEOUT_MS, AgentAuthUnknownProviderError, CredentialAuthorizationRequiredError, CredentialStoreError, } from "./agent-auth.js";
|
|
18
|
-
const
|
|
15
|
+
const CONNECTION_REFERENCE = Symbol("managed-deepagents.connection");
|
|
19
16
|
const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
20
17
|
const MAX_SLUG_LENGTH = 64;
|
|
21
18
|
const DEFAULT_LANGSMITH_ENDPOINT = "https://api.smith.langchain.com";
|
|
22
19
|
const DEV_CREDENTIAL_PREFIX = "MDA_DEV_";
|
|
23
|
-
|
|
24
|
-
* A user-owned credential is an OAuth grant held per caller against the
|
|
25
|
-
* deployment, and `mda dev` has no deployment to hold one.
|
|
26
|
-
*/
|
|
27
|
-
function localUserCredentialUnsupported(slug) {
|
|
20
|
+
function localUserConnectionUnsupported(slug) {
|
|
28
21
|
const localHint = slug
|
|
29
|
-
? `set ${
|
|
22
|
+
? `set ${agentConnectionEnvKey(slug)}`
|
|
30
23
|
: "set the corresponding MDA_DEV_<slug> variable";
|
|
31
|
-
return ("user-
|
|
32
|
-
"deploy with `mda deploy` to exercise this
|
|
24
|
+
return ("user-owned connections need a deployment, so they do not resolve in `mda dev`: " +
|
|
25
|
+
"deploy with `mda deploy` to exercise this connection, or declare it as " +
|
|
33
26
|
`{ type: "agent" } and ${localHint} for local runs`);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
const CREDENTIAL_KIND = { agent: "secret", user: "oauth2" };
|
|
37
|
-
export class CredentialNotFoundError extends Error {
|
|
28
|
+
export class ConnectionNotFoundError extends Error {
|
|
38
29
|
slug;
|
|
39
30
|
ownerType;
|
|
40
31
|
constructor(slug, ownerType) {
|
|
41
|
-
super(`no ${ownerType}
|
|
42
|
-
this.name = "
|
|
32
|
+
super(`no ${ownerType} connection is set for slug ${JSON.stringify(slug)}`);
|
|
33
|
+
this.name = "ConnectionNotFoundError";
|
|
43
34
|
this.slug = slug;
|
|
44
35
|
this.ownerType = ownerType;
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
/** @deprecated Use {@link ConnectionNotFoundError}. */
|
|
39
|
+
export class CredentialNotFoundError extends ConnectionNotFoundError {
|
|
40
|
+
constructor(slug, ownerType) {
|
|
41
|
+
super(slug, ownerType);
|
|
42
|
+
this.name = "CredentialNotFoundError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class ConnectionReference {
|
|
52
46
|
slug;
|
|
53
47
|
owner;
|
|
54
48
|
accessor;
|
|
55
|
-
[
|
|
49
|
+
[CONNECTION_REFERENCE] = true;
|
|
56
50
|
constructor(slug, owner, accessor) {
|
|
57
51
|
this.slug = slug;
|
|
58
52
|
this.owner = owner;
|
|
@@ -64,13 +58,17 @@ export class CredentialReference {
|
|
|
64
58
|
.then(onfulfilled, onrejected);
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
|
-
export function
|
|
68
|
-
return (value instanceof
|
|
61
|
+
export function isConnectionReference(value) {
|
|
62
|
+
return (value instanceof ConnectionReference ||
|
|
69
63
|
(typeof value === "object" &&
|
|
70
64
|
value !== null &&
|
|
71
|
-
|
|
65
|
+
CONNECTION_REFERENCE in value));
|
|
66
|
+
}
|
|
67
|
+
/** @deprecated Use {@link isConnectionReference}. */
|
|
68
|
+
export function isCredentialReference(value) {
|
|
69
|
+
return isConnectionReference(value);
|
|
72
70
|
}
|
|
73
|
-
export class
|
|
71
|
+
export class AgentAuthConnectionStore {
|
|
74
72
|
env;
|
|
75
73
|
fetchImpl;
|
|
76
74
|
timeoutMs;
|
|
@@ -80,18 +78,16 @@ export class AgentAuthCredentialStore {
|
|
|
80
78
|
this.timeoutMs = timeoutMs;
|
|
81
79
|
}
|
|
82
80
|
async fetch(request) {
|
|
83
|
-
// `mda dev` has no deployment to resolve against, so local values stand in
|
|
84
|
-
// for agent secrets and a user grant has nothing to stand in for.
|
|
85
81
|
if (this.env.MDA_LOCAL_DEV === "1") {
|
|
86
82
|
if (request.owner.type === "user") {
|
|
87
|
-
throw new CredentialStoreError(
|
|
83
|
+
throw new CredentialStoreError(localUserConnectionUnsupported(request.slug));
|
|
88
84
|
}
|
|
89
|
-
const value = this.env[
|
|
85
|
+
const value = this.env[agentConnectionEnvKey(request.slug)];
|
|
90
86
|
if (value !== undefined && value.trim()) {
|
|
91
87
|
return value;
|
|
92
88
|
}
|
|
93
|
-
throw new CredentialStoreError(`local agent
|
|
94
|
-
`set ${
|
|
89
|
+
throw new CredentialStoreError(`local agent connection ${JSON.stringify(request.slug)} is not configured; ` +
|
|
90
|
+
`set ${agentConnectionEnvKey(request.slug)}`);
|
|
95
91
|
}
|
|
96
92
|
const config = resolveAgentAuthConfig(this.env);
|
|
97
93
|
const ownerId = resolveOwnerId(request.owner, request.identity, config.deploymentId);
|
|
@@ -102,32 +98,48 @@ export class AgentAuthCredentialStore {
|
|
|
102
98
|
apiKey: config.apiKey,
|
|
103
99
|
workspaceId: config.workspaceId,
|
|
104
100
|
}, this.fetchImpl, this.timeoutMs);
|
|
101
|
+
const row = await client.findWorkspaceConnection(request.slug);
|
|
102
|
+
if (!row) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
105
|
if (request.owner.type === "user") {
|
|
106
|
-
|
|
106
|
+
if (row.ownerPolicy !== "user") {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
if (row.kind === "secret") {
|
|
110
|
+
return await client.readUserSecret(request.slug);
|
|
111
|
+
}
|
|
112
|
+
if (row.kind === "oauth2") {
|
|
113
|
+
return await client.readUserAccessToken(request.slug);
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
107
116
|
}
|
|
108
|
-
|
|
109
|
-
ownerType: "agent",
|
|
110
|
-
ownerId,
|
|
111
|
-
kind: CREDENTIAL_KIND.agent,
|
|
112
|
-
slug: request.slug,
|
|
113
|
-
});
|
|
114
|
-
if (!credentialId)
|
|
117
|
+
if (row.ownerPolicy !== "agent") {
|
|
115
118
|
return undefined;
|
|
116
|
-
|
|
119
|
+
}
|
|
120
|
+
if (row.kind === "secret") {
|
|
121
|
+
return await client.readSecret(row.connectionId);
|
|
122
|
+
}
|
|
123
|
+
if (row.kind === "oauth2") {
|
|
124
|
+
return await client.readConnectionAccessToken(row.connectionId);
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
117
127
|
}
|
|
118
128
|
}
|
|
119
|
-
|
|
129
|
+
/** @deprecated Use {@link AgentAuthConnectionStore}. */
|
|
130
|
+
export const AgentAuthCredentialStore = AgentAuthConnectionStore;
|
|
131
|
+
export class Connections {
|
|
120
132
|
store;
|
|
121
|
-
constructor(store = new
|
|
133
|
+
constructor(store = new AgentAuthConnectionStore()) {
|
|
122
134
|
this.store = store;
|
|
123
135
|
}
|
|
124
136
|
get(slug, owner) {
|
|
125
|
-
return new
|
|
137
|
+
return new ConnectionReference(normalizeSlug(slug), normalizeOwner(owner), this);
|
|
126
138
|
}
|
|
127
139
|
async resolve(slug, owner) {
|
|
128
140
|
const configurable = resolveRuntimeConfigurable(undefined);
|
|
129
141
|
if (!configurable) {
|
|
130
|
-
throw new Error("
|
|
142
|
+
throw new Error("connections.get(...) must be awaited inside a run: resolve a connection in a tool or middleware, not at import time");
|
|
131
143
|
}
|
|
132
144
|
const value = await this.store.fetch({
|
|
133
145
|
slug,
|
|
@@ -137,57 +149,53 @@ export class Credentials {
|
|
|
137
149
|
if (value === undefined) {
|
|
138
150
|
throw owner.type === "user"
|
|
139
151
|
? new CredentialAuthorizationRequiredError([slug])
|
|
140
|
-
: new
|
|
152
|
+
: new ConnectionNotFoundError(slug, owner.type);
|
|
141
153
|
}
|
|
142
154
|
return value;
|
|
143
155
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Read an agent-owned secret outside a run.
|
|
146
|
-
*
|
|
147
|
-
* Connector declarations are loaded once per deployment, before any caller
|
|
148
|
-
* exists. An agent-owned secret is deployment-scoped, so it is the one lookup
|
|
149
|
-
* that carries no caller and can be resolved there.
|
|
150
|
-
*/
|
|
151
156
|
async resolveDeploymentSecret(slug) {
|
|
152
157
|
const value = await this.store.fetch({
|
|
153
158
|
slug,
|
|
154
159
|
owner: { type: "agent" },
|
|
155
160
|
});
|
|
156
161
|
if (value === undefined) {
|
|
157
|
-
throw new
|
|
162
|
+
throw new ConnectionNotFoundError(slug, "agent");
|
|
158
163
|
}
|
|
159
164
|
return value;
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
|
-
/**
|
|
163
|
-
export
|
|
167
|
+
/** @deprecated Use {@link Connections}. */
|
|
168
|
+
export const Credentials = Connections;
|
|
169
|
+
export function agentConnectionEnvKey(slug) {
|
|
164
170
|
return `${DEV_CREDENTIAL_PREFIX}${normalizeSlug(slug)
|
|
165
171
|
.toUpperCase()
|
|
166
172
|
.replaceAll("-", "_")}`;
|
|
167
173
|
}
|
|
174
|
+
/** @deprecated Use {@link agentConnectionEnvKey}. */
|
|
175
|
+
export const agentCredentialEnvKey = agentConnectionEnvKey;
|
|
168
176
|
function normalizeSlug(slug) {
|
|
169
177
|
if (typeof slug !== "string") {
|
|
170
|
-
throw new TypeError("
|
|
178
|
+
throw new TypeError("connection slug must be a string");
|
|
171
179
|
}
|
|
172
180
|
const canonical = slug.trim();
|
|
173
181
|
if (!canonical ||
|
|
174
182
|
canonical.length > MAX_SLUG_LENGTH ||
|
|
175
183
|
!SLUG_PATTERN.test(canonical)) {
|
|
176
|
-
throw new TypeError(`
|
|
184
|
+
throw new TypeError(`connection slug ${JSON.stringify(slug)} is invalid: use lowercase letters, digits, and single hyphens, at most ${MAX_SLUG_LENGTH} characters`);
|
|
177
185
|
}
|
|
178
186
|
return canonical;
|
|
179
187
|
}
|
|
180
188
|
function normalizeOwner(owner) {
|
|
181
189
|
if (!owner || typeof owner !== "object") {
|
|
182
|
-
throw new TypeError('
|
|
190
|
+
throw new TypeError('connection owner is required: pass { type: "agent" } or { type: "user" }');
|
|
183
191
|
}
|
|
184
192
|
const keys = Object.keys(owner);
|
|
185
193
|
if (keys.some((key) => key !== "type" && key !== "id")) {
|
|
186
|
-
throw new TypeError("
|
|
194
|
+
throw new TypeError("connection owner has an unknown key");
|
|
187
195
|
}
|
|
188
196
|
if (owner.type === "agent") {
|
|
189
197
|
if ("id" in owner) {
|
|
190
|
-
throw new TypeError('
|
|
198
|
+
throw new TypeError('connection owner "id" is not accepted for { type: "agent" }');
|
|
191
199
|
}
|
|
192
200
|
return { type: "agent" };
|
|
193
201
|
}
|
|
@@ -195,48 +203,35 @@ function normalizeOwner(owner) {
|
|
|
195
203
|
if (owner.id === undefined)
|
|
196
204
|
return { type: "user" };
|
|
197
205
|
if (typeof owner.id !== "string" || !owner.id.trim()) {
|
|
198
|
-
throw new TypeError('
|
|
206
|
+
throw new TypeError('connection owner "id" must be a non-empty string');
|
|
199
207
|
}
|
|
200
208
|
return { type: "user", id: owner.id.trim() };
|
|
201
209
|
}
|
|
202
|
-
throw new TypeError("
|
|
210
|
+
throw new TypeError("connection owner type is not supported");
|
|
203
211
|
}
|
|
204
|
-
/**
|
|
205
|
-
* The `owner_id` a lookup is keyed by: the caller for a user, else the
|
|
206
|
-
* deployment. Shared with the credential gate so a declared owner is checked
|
|
207
|
-
* the same way wherever it is resolved.
|
|
208
|
-
*/
|
|
209
212
|
export function resolveOwnerId(owner, identity, deploymentId) {
|
|
210
213
|
if (owner.type === "user") {
|
|
211
214
|
const authenticated = identity?.user.id;
|
|
212
215
|
if (!authenticated) {
|
|
213
|
-
throw new CredentialStoreError("user
|
|
216
|
+
throw new CredentialStoreError("user connections require an authenticated user principal");
|
|
214
217
|
}
|
|
215
218
|
if (owner.id !== undefined && owner.id !== authenticated) {
|
|
216
|
-
throw new CredentialStoreError("user
|
|
219
|
+
throw new CredentialStoreError("user connection owner id must match the authenticated principal");
|
|
217
220
|
}
|
|
218
221
|
return authenticated;
|
|
219
222
|
}
|
|
220
223
|
if (!deploymentId) {
|
|
221
|
-
throw new CredentialStoreError("
|
|
224
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
222
225
|
}
|
|
223
226
|
return deploymentId;
|
|
224
227
|
}
|
|
225
|
-
/**
|
|
226
|
-
* The Agent Auth binding for one caller.
|
|
227
|
-
*
|
|
228
|
-
* `credentials.get` and the pre-run credential gate both resolve their owner id
|
|
229
|
-
* here, so a slug addresses the same Agent Auth row on either path.
|
|
230
|
-
*/
|
|
231
228
|
export function resolveAgentAuthContext(identity, env = process.env) {
|
|
232
|
-
// Only the user-credential gate resolves a context, so a local run can say
|
|
233
|
-
// why rather than reporting a missing deployment variable.
|
|
234
229
|
if (env.MDA_LOCAL_DEV === "1") {
|
|
235
|
-
throw new CredentialStoreError(
|
|
230
|
+
throw new CredentialStoreError(localUserConnectionUnsupported());
|
|
236
231
|
}
|
|
237
232
|
const config = resolveAgentAuthConfig(env);
|
|
238
233
|
if (!config.deploymentId) {
|
|
239
|
-
throw new CredentialStoreError("
|
|
234
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
240
235
|
}
|
|
241
236
|
return {
|
|
242
237
|
baseUrl: config.baseUrl,
|
|
@@ -249,21 +244,19 @@ export function resolveAgentAuthContext(identity, env = process.env) {
|
|
|
249
244
|
function resolveAgentAuthConfig(env) {
|
|
250
245
|
const apiKey = env.LANGSMITH_API_KEY?.trim();
|
|
251
246
|
if (!apiKey) {
|
|
252
|
-
throw new CredentialStoreError("
|
|
247
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_API_KEY is not set");
|
|
248
|
+
}
|
|
249
|
+
const workspaceId = env.LANGSMITH_WORKSPACE_ID?.trim();
|
|
250
|
+
if (!workspaceId) {
|
|
251
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_WORKSPACE_ID is not set");
|
|
253
252
|
}
|
|
254
253
|
return {
|
|
255
254
|
baseUrl: resolveAgentAuthBaseUrl(env),
|
|
256
255
|
apiKey,
|
|
257
256
|
deploymentId: env.LANGSMITH_HOST_PROJECT_ID?.trim() || undefined,
|
|
258
|
-
workspaceId
|
|
257
|
+
workspaceId,
|
|
259
258
|
};
|
|
260
259
|
}
|
|
261
|
-
/**
|
|
262
|
-
* Agent Auth is served by the LangSmith API.
|
|
263
|
-
*
|
|
264
|
-
* Rejects a URL that carries a path, query, or userinfo, so a misconfigured
|
|
265
|
-
* endpoint cannot send the API key at a different service.
|
|
266
|
-
*/
|
|
267
260
|
export function resolveAgentAuthBaseUrl(env = process.env) {
|
|
268
261
|
const raw = env.LANGSMITH_ENDPOINT?.trim() || DEFAULT_LANGSMITH_ENDPOINT;
|
|
269
262
|
let parsed;
|
|
@@ -284,5 +277,20 @@ export function resolveAgentAuthBaseUrl(env = process.env) {
|
|
|
284
277
|
}
|
|
285
278
|
return parsed.origin;
|
|
286
279
|
}
|
|
287
|
-
export const
|
|
288
|
-
|
|
280
|
+
export const connections = new Connections();
|
|
281
|
+
let credentialsDeprecationLogged = false;
|
|
282
|
+
function warnCredentialsDeprecated() {
|
|
283
|
+
if (credentialsDeprecationLogged) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
credentialsDeprecationLogged = true;
|
|
287
|
+
process.emitWarning("credentials.get is deprecated; use connections.get", "DeprecationWarning");
|
|
288
|
+
}
|
|
289
|
+
/** @deprecated Use {@link connections}. */
|
|
290
|
+
export const credentials = {
|
|
291
|
+
get(slug, owner) {
|
|
292
|
+
warnCredentialsDeprecated();
|
|
293
|
+
return connections.get(slug, owner);
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
//# sourceMappingURL=connections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../src/connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,oCAAoC,EACpC,oBAAoB,GAErB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,oCAAoC,EACpC,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAuBzB,MAAM,oBAAoB,GAAG,MAAM,CAAC,+BAA+B,CAAC,CAAC;AACrE,MAAM,YAAY,GAAG,4BAA4B,CAAC;AAClD,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,0BAA0B,GAAG,iCAAiC,CAAC;AACrE,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAEzC,SAAS,8BAA8B,CAAC,IAAa;IACnD,MAAM,SAAS,GAAG,IAAI;QACpB,CAAC,CAAC,OAAO,qBAAqB,CAAC,IAAI,CAAC,EAAE;QACtC,CAAC,CAAC,+CAA+C,CAAC;IACpD,OAAO,CACL,iFAAiF;QACjF,yEAAyE;QACzE,yBAAyB,SAAS,iBAAiB,CACpD,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACvC,IAAI,CAAS;IACb,SAAS,CAA0B;IAE5C,YAAY,IAAY,EAAE,SAAkC;QAC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
* ```ts
|
|
20
20
|
* // connectors/mcp.ts
|
|
21
|
-
* import { connectors,
|
|
21
|
+
* import { connectors, connections } from "managed-deepagents";
|
|
22
22
|
*
|
|
23
23
|
* export const connector = connectors.mcp({
|
|
24
24
|
* mcpServers: {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* notion: {
|
|
30
30
|
* transport: "http",
|
|
31
31
|
* url: "https://mcp.notion.com/mcp",
|
|
32
|
-
*
|
|
32
|
+
* connection: connections.get("notion", { type: "user" }),
|
|
33
33
|
* },
|
|
34
34
|
* },
|
|
35
35
|
* });
|
|
@@ -51,17 +51,19 @@ export declare function clearManagedMcpToolsCacheForTests(connectors?: McpServer
|
|
|
51
51
|
/**
|
|
52
52
|
* The credential gate's view of the declared MCP connectors.
|
|
53
53
|
*
|
|
54
|
-
* One consumer per declaration that names a user-owned
|
|
54
|
+
* One consumer per declaration that names a user-owned connection; a
|
|
55
55
|
* declaration that needs no grant never reaches the gate.
|
|
56
56
|
*/
|
|
57
57
|
export declare function mcpCredentialConsumers(connectors: readonly unknown[] | undefined): CredentialConsumer[];
|
|
58
58
|
/**
|
|
59
|
-
* Load tools for user-
|
|
59
|
+
* Load tools for user-connection servers, once the gate has confirmed the
|
|
60
60
|
* caller's grants.
|
|
61
61
|
*
|
|
62
62
|
* Not process-cached here: the Authorization header is per caller, so the gate
|
|
63
63
|
* owns both the cache and closing the returned transport.
|
|
64
64
|
*/
|
|
65
|
-
export declare function
|
|
65
|
+
export declare function loadUserConnectionMcpTools(connectors: McpServersDefinition, accessTokens: ReadonlyMap<string, string>): Promise<LoadedCredentialTools>;
|
|
66
|
+
/** @deprecated Use {@link loadUserConnectionMcpTools}. */
|
|
67
|
+
export declare const loadUserCredentialMcpTools: typeof loadUserConnectionMcpTools;
|
|
66
68
|
export declare const mcpConnector: (config: McpServersConfig) => McpServersDefinition;
|
|
67
69
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connectors/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAUH,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAGrB,MAAM,YAAY,CAAC;AAEpB,mBAAmB,YAAY,CAAC;AAkBhC;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,oBAAoB,GAC/B,OAAO,CAAC,OAAO,EAAE,CAAC,CAWpB;AAED,yDAAyD;AACzD,wBAAgB,iCAAiC,CAC/C,UAAU,CAAC,EAAE,oBAAoB,GAChC,IAAI,CAMN;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,GACzC,kBAAkB,EAAE,CAuBtB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connectors/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAUH,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAGrB,MAAM,YAAY,CAAC;AAEpB,mBAAmB,YAAY,CAAC;AAkBhC;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,oBAAoB,GAC/B,OAAO,CAAC,OAAO,EAAE,CAAC,CAWpB;AAED,yDAAyD;AACzD,wBAAgB,iCAAiC,CAC/C,UAAU,CAAC,EAAE,oBAAoB,GAChC,IAAI,CAMN;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,GACzC,kBAAkB,EAAE,CAuBtB;AA2ED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,oBAAoB,EAChC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,qBAAqB,CAAC,CAyBhC;AAED,0DAA0D;AAC1D,eAAO,MAAM,0BAA0B,mCAA6B,CAAC;AAsKrE,eAAO,MAAM,YAAY,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,oBAOrD,CAAC"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
20
|
* // connectors/mcp.ts
|
|
21
|
-
* import { connectors,
|
|
21
|
+
* import { connectors, connections } from "managed-deepagents";
|
|
22
22
|
*
|
|
23
23
|
* export const connector = connectors.mcp({
|
|
24
24
|
* mcpServers: {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* notion: {
|
|
30
30
|
* transport: "http",
|
|
31
31
|
* url: "https://mcp.notion.com/mcp",
|
|
32
|
-
*
|
|
32
|
+
* connection: connections.get("notion", { type: "user" }),
|
|
33
33
|
* },
|
|
34
34
|
* },
|
|
35
35
|
* });
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
*/
|
|
38
38
|
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
|
|
39
39
|
import { defineExtension } from "../../extension.js";
|
|
40
|
-
import {
|
|
40
|
+
import { connections, isConnectionReference, } from "../../connections.js";
|
|
41
41
|
import { mcpServersConfig } from "./schema.js";
|
|
42
42
|
import { selectTools } from "../tool-selection.js";
|
|
43
43
|
/**
|
|
@@ -50,8 +50,8 @@ import { selectTools } from "../tool-selection.js";
|
|
|
50
50
|
* the in-flight promise also dedupes concurrent first runs for the same
|
|
51
51
|
* connector. Multiple `connectors.mcp(...)` modules each get their own entry.
|
|
52
52
|
*
|
|
53
|
-
* An agent-owned
|
|
54
|
-
* secret takes a redeploy. Servers with a user-owned
|
|
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
55
|
* entirely; the credential gate loads those per caller.
|
|
56
56
|
*/
|
|
57
57
|
const cachedTools = new Map();
|
|
@@ -85,7 +85,7 @@ export function clearManagedMcpToolsCacheForTests(connectors) {
|
|
|
85
85
|
/**
|
|
86
86
|
* The credential gate's view of the declared MCP connectors.
|
|
87
87
|
*
|
|
88
|
-
* One consumer per declaration that names a user-owned
|
|
88
|
+
* One consumer per declaration that names a user-owned connection; a
|
|
89
89
|
* declaration that needs no grant never reaches the gate.
|
|
90
90
|
*/
|
|
91
91
|
export function mcpCredentialConsumers(connectors) {
|
|
@@ -97,72 +97,89 @@ export function mcpCredentialConsumers(connectors) {
|
|
|
97
97
|
continue;
|
|
98
98
|
}
|
|
99
99
|
const definition = connector;
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
100
|
+
const userConnections = userConnectionReferences(definition);
|
|
101
|
+
if (userConnections.length === 0) {
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
104
|
out.push({
|
|
105
105
|
declaration: definition,
|
|
106
|
-
credentials,
|
|
107
|
-
load: (accessTokens) =>
|
|
106
|
+
credentials: userConnections,
|
|
107
|
+
load: (accessTokens) => loadUserConnectionMcpTools(definition, accessTokens),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
return out;
|
|
111
111
|
}
|
|
112
112
|
/** The declared references themselves: the gate checks their owner. */
|
|
113
|
-
function
|
|
113
|
+
function userConnectionReferences(connectors) {
|
|
114
114
|
const bySlug = new Map();
|
|
115
115
|
for (const server of Object.values(connectors.mcpServers)) {
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
bySlug.set(
|
|
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.mcpServers)) {
|
|
126
|
+
const connection = server.connection;
|
|
127
|
+
if (isConnectionReference(connection) &&
|
|
128
|
+
connection.owner.type === "agent") {
|
|
129
|
+
bySlug.set(connection.slug, connection);
|
|
119
130
|
}
|
|
120
131
|
}
|
|
121
132
|
return [...bySlug.values()];
|
|
122
133
|
}
|
|
123
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();
|
|
124
141
|
return {
|
|
125
142
|
name,
|
|
126
143
|
provider: "mcp",
|
|
127
144
|
autoReply: false,
|
|
128
145
|
requiredPermissions: [],
|
|
129
146
|
requiredEnv: [],
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
userConnections: userSlugs,
|
|
148
|
+
agentConnections: agentSlugs,
|
|
149
|
+
userCredentials: userSlugs,
|
|
133
150
|
providerConfig: {},
|
|
134
151
|
};
|
|
135
152
|
}
|
|
136
153
|
async function createClientAndLoadTools(connectors) {
|
|
137
|
-
const { eager,
|
|
138
|
-
if (
|
|
139
|
-
|
|
154
|
+
const { eager, userConnection } = partitionMcpServers(connectors.mcpServers);
|
|
155
|
+
if (userConnection.length > 0) {
|
|
156
|
+
warnDeferredUserConnectionServers(userConnection);
|
|
140
157
|
}
|
|
141
158
|
if (Object.keys(eager).length === 0) {
|
|
142
159
|
return [];
|
|
143
160
|
}
|
|
144
|
-
const { tools } = await loadToolsFromServers(connectors, await
|
|
161
|
+
const { tools } = await loadToolsFromServers(connectors, await withAgentConnections(eager));
|
|
145
162
|
return tools;
|
|
146
163
|
}
|
|
147
164
|
/**
|
|
148
|
-
* Load tools for user-
|
|
165
|
+
* Load tools for user-connection servers, once the gate has confirmed the
|
|
149
166
|
* caller's grants.
|
|
150
167
|
*
|
|
151
168
|
* Not process-cached here: the Authorization header is per caller, so the gate
|
|
152
169
|
* owns both the cache and closing the returned transport.
|
|
153
170
|
*/
|
|
154
|
-
export async function
|
|
155
|
-
const {
|
|
171
|
+
export async function loadUserConnectionMcpTools(connectors, accessTokens) {
|
|
172
|
+
const { userConnection } = partitionMcpServers(connectors.mcpServers);
|
|
156
173
|
const connectable = {};
|
|
157
|
-
for (const name of
|
|
174
|
+
for (const name of userConnection) {
|
|
158
175
|
const server = connectors.mcpServers[name];
|
|
159
|
-
const
|
|
160
|
-
if (!server || !
|
|
176
|
+
const connection = server?.connection;
|
|
177
|
+
if (!server || !isConnectionReference(connection)) {
|
|
161
178
|
continue;
|
|
162
179
|
}
|
|
163
|
-
const accessToken = accessTokens.get(
|
|
180
|
+
const accessToken = accessTokens.get(connection.slug);
|
|
164
181
|
if (!accessToken) {
|
|
165
|
-
throw new Error(`MCP user
|
|
182
|
+
throw new Error(`MCP user connection "${connection.slug}" has no access token`);
|
|
166
183
|
}
|
|
167
184
|
connectable[name] = withBearer(server, accessToken);
|
|
168
185
|
}
|
|
@@ -172,13 +189,15 @@ export async function loadUserCredentialMcpTools(connectors, accessTokens) {
|
|
|
172
189
|
const { tools, client } = await loadToolsFromServers(connectors, connectable);
|
|
173
190
|
return { tools, close: () => client.close() };
|
|
174
191
|
}
|
|
175
|
-
/**
|
|
176
|
-
|
|
192
|
+
/** @deprecated Use {@link loadUserConnectionMcpTools}. */
|
|
193
|
+
export const loadUserCredentialMcpTools = loadUserConnectionMcpTools;
|
|
194
|
+
/** Resolve each agent-owned connection into a static bearer header. */
|
|
195
|
+
async function withAgentConnections(servers) {
|
|
177
196
|
const out = {};
|
|
178
197
|
for (const [name, server] of Object.entries(servers)) {
|
|
179
|
-
const
|
|
180
|
-
out[name] =
|
|
181
|
-
? withBearer(server, await
|
|
198
|
+
const connection = server.connection;
|
|
199
|
+
out[name] = isConnectionReference(connection)
|
|
200
|
+
? withBearer(server, await connections.resolveDeploymentSecret(connection.slug))
|
|
182
201
|
: server;
|
|
183
202
|
}
|
|
184
203
|
return out;
|
|
@@ -190,31 +209,31 @@ function withBearer(server, token) {
|
|
|
190
209
|
headers: { ...headers, Authorization: `Bearer ${token}` },
|
|
191
210
|
};
|
|
192
211
|
}
|
|
193
|
-
function
|
|
194
|
-
return (
|
|
195
|
-
server.
|
|
212
|
+
function usesUserConnection(server) {
|
|
213
|
+
return (isConnectionReference(server.connection) &&
|
|
214
|
+
server.connection.owner.type === "user");
|
|
196
215
|
}
|
|
197
216
|
function partitionMcpServers(servers) {
|
|
198
217
|
const eager = {};
|
|
199
|
-
const
|
|
218
|
+
const userConnection = [];
|
|
200
219
|
for (const [name, server] of Object.entries(servers)) {
|
|
201
|
-
if (
|
|
202
|
-
|
|
220
|
+
if (usesUserConnection(server)) {
|
|
221
|
+
userConnection.push(name);
|
|
203
222
|
}
|
|
204
223
|
else {
|
|
205
224
|
eager[name] = server;
|
|
206
225
|
}
|
|
207
226
|
}
|
|
208
|
-
return { eager,
|
|
227
|
+
return { eager, userConnection };
|
|
209
228
|
}
|
|
210
|
-
function
|
|
229
|
+
function warnDeferredUserConnectionServers(serverNames) {
|
|
211
230
|
console.warn(`[managed-deepagents] MCP server(s) ${serverNames.join(", ")} declare ` +
|
|
212
|
-
`a user
|
|
231
|
+
`a user connection; tools load after the pre-run credential gate ` +
|
|
213
232
|
`confirms grants for the caller.`);
|
|
214
233
|
}
|
|
215
234
|
function stripManagedToolSelection(servers) {
|
|
216
235
|
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
|
|
217
|
-
const { includeTools: _includeTools, excludeTools: _excludeTools,
|
|
236
|
+
const { includeTools: _includeTools, excludeTools: _excludeTools, connection: _connection, ...clientConfig } = server;
|
|
218
237
|
return [name, clientConfig];
|
|
219
238
|
}));
|
|
220
239
|
}
|