managed-deepagents 0.6.2-dev.30 → 0.6.2-dev.31
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 +28 -3
- package/dist/agent-auth.d.ts.map +1 -1
- package/dist/agent-auth.js +181 -12
- package/dist/agent-auth.js.map +1 -1
- package/dist/channels/manifest.d.ts +4 -2
- package/dist/channels/manifest.d.ts.map +1 -1
- package/dist/channels/trigger/http.js +1 -1
- package/dist/channels/trigger/http.js.map +1 -1
- package/dist/connections.d.ts +74 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/{credentials.js → connections.js} +92 -100
- package/dist/connections.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +5 -5
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +60 -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 +8 -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 +49 -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
|
+
/** `LANGSMITH_ENDPOINT` is missing a usable Agent Auth origin. */
|
|
39
|
+
export class InvalidAgentAuthEndpointError extends CredentialStoreError {
|
|
40
|
+
name = "InvalidAgentAuthEndpointError";
|
|
41
|
+
constructor() {
|
|
42
|
+
super("LangSmith Agent Auth endpoint is not a valid URL (set LANGSMITH_ENDPOINT)");
|
|
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,13 @@ 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));
|
|
72
66
|
}
|
|
73
|
-
export class
|
|
67
|
+
export class AgentAuthConnectionStore {
|
|
74
68
|
env;
|
|
75
69
|
fetchImpl;
|
|
76
70
|
timeoutMs;
|
|
@@ -80,18 +74,16 @@ export class AgentAuthCredentialStore {
|
|
|
80
74
|
this.timeoutMs = timeoutMs;
|
|
81
75
|
}
|
|
82
76
|
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
77
|
if (this.env.MDA_LOCAL_DEV === "1") {
|
|
86
78
|
if (request.owner.type === "user") {
|
|
87
|
-
throw new CredentialStoreError(
|
|
79
|
+
throw new CredentialStoreError(localUserConnectionUnsupported(request.slug));
|
|
88
80
|
}
|
|
89
|
-
const value = this.env[
|
|
81
|
+
const value = this.env[agentConnectionEnvKey(request.slug)];
|
|
90
82
|
if (value !== undefined && value.trim()) {
|
|
91
83
|
return value;
|
|
92
84
|
}
|
|
93
|
-
throw new CredentialStoreError(`local agent
|
|
94
|
-
`set ${
|
|
85
|
+
throw new CredentialStoreError(`local agent connection ${JSON.stringify(request.slug)} is not configured; ` +
|
|
86
|
+
`set ${agentConnectionEnvKey(request.slug)}`);
|
|
95
87
|
}
|
|
96
88
|
const config = resolveAgentAuthConfig(this.env);
|
|
97
89
|
const ownerId = resolveOwnerId(request.owner, request.identity, config.deploymentId);
|
|
@@ -101,33 +93,46 @@ export class AgentAuthCredentialStore {
|
|
|
101
93
|
principalId: ownerId,
|
|
102
94
|
apiKey: config.apiKey,
|
|
103
95
|
workspaceId: config.workspaceId,
|
|
96
|
+
serviceKey: config.serviceKey,
|
|
104
97
|
}, this.fetchImpl, this.timeoutMs);
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
const row = await client.findWorkspaceConnection(request.slug);
|
|
99
|
+
if (!row) {
|
|
100
|
+
return undefined;
|
|
107
101
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
if (request.owner.type === "user") {
|
|
103
|
+
if (row.kind === "secret") {
|
|
104
|
+
return await client.readUserSecret(request.slug);
|
|
105
|
+
}
|
|
106
|
+
if (row.kind === "oauth2") {
|
|
107
|
+
return await client.readUserAccessToken(request.slug);
|
|
108
|
+
}
|
|
115
109
|
return undefined;
|
|
116
|
-
|
|
110
|
+
}
|
|
111
|
+
if (row.kind === "secret") {
|
|
112
|
+
const credentialId = await client.findSecretCredentialId(row, request.slug);
|
|
113
|
+
if (!credentialId) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
return await client.readSecret(credentialId);
|
|
117
|
+
}
|
|
118
|
+
if (row.kind === "oauth2") {
|
|
119
|
+
return await client.readConnectionAccessToken(row.connectionId);
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
|
-
export class
|
|
124
|
+
export class Connections {
|
|
120
125
|
store;
|
|
121
|
-
constructor(store = new
|
|
126
|
+
constructor(store = new AgentAuthConnectionStore()) {
|
|
122
127
|
this.store = store;
|
|
123
128
|
}
|
|
124
129
|
get(slug, owner) {
|
|
125
|
-
return new
|
|
130
|
+
return new ConnectionReference(normalizeSlug(slug), normalizeOwner(owner), this);
|
|
126
131
|
}
|
|
127
132
|
async resolve(slug, owner) {
|
|
128
133
|
const configurable = resolveRuntimeConfigurable(undefined);
|
|
129
134
|
if (!configurable) {
|
|
130
|
-
throw new Error("
|
|
135
|
+
throw new Error("connections.get(...) must be awaited inside a run: resolve a connection in a tool or middleware, not at import time");
|
|
131
136
|
}
|
|
132
137
|
const value = await this.store.fetch({
|
|
133
138
|
slug,
|
|
@@ -137,57 +142,49 @@ export class Credentials {
|
|
|
137
142
|
if (value === undefined) {
|
|
138
143
|
throw owner.type === "user"
|
|
139
144
|
? new CredentialAuthorizationRequiredError([slug])
|
|
140
|
-
: new
|
|
145
|
+
: new ConnectionNotFoundError(slug, owner.type);
|
|
141
146
|
}
|
|
142
147
|
return value;
|
|
143
148
|
}
|
|
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
149
|
async resolveDeploymentSecret(slug) {
|
|
152
150
|
const value = await this.store.fetch({
|
|
153
151
|
slug,
|
|
154
152
|
owner: { type: "agent" },
|
|
155
153
|
});
|
|
156
154
|
if (value === undefined) {
|
|
157
|
-
throw new
|
|
155
|
+
throw new ConnectionNotFoundError(slug, "agent");
|
|
158
156
|
}
|
|
159
157
|
return value;
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
|
-
|
|
163
|
-
export function agentCredentialEnvKey(slug) {
|
|
160
|
+
export function agentConnectionEnvKey(slug) {
|
|
164
161
|
return `${DEV_CREDENTIAL_PREFIX}${normalizeSlug(slug)
|
|
165
162
|
.toUpperCase()
|
|
166
163
|
.replaceAll("-", "_")}`;
|
|
167
164
|
}
|
|
168
165
|
function normalizeSlug(slug) {
|
|
169
166
|
if (typeof slug !== "string") {
|
|
170
|
-
throw new TypeError("
|
|
167
|
+
throw new TypeError("connection slug must be a string");
|
|
171
168
|
}
|
|
172
169
|
const canonical = slug.trim();
|
|
173
170
|
if (!canonical ||
|
|
174
171
|
canonical.length > MAX_SLUG_LENGTH ||
|
|
175
172
|
!SLUG_PATTERN.test(canonical)) {
|
|
176
|
-
throw new TypeError(`
|
|
173
|
+
throw new TypeError(`connection slug ${JSON.stringify(slug)} is invalid: use lowercase letters, digits, and single hyphens, at most ${MAX_SLUG_LENGTH} characters`);
|
|
177
174
|
}
|
|
178
175
|
return canonical;
|
|
179
176
|
}
|
|
180
177
|
function normalizeOwner(owner) {
|
|
181
178
|
if (!owner || typeof owner !== "object") {
|
|
182
|
-
throw new TypeError('
|
|
179
|
+
throw new TypeError('connection owner is required: pass { type: "agent" } or { type: "user" }');
|
|
183
180
|
}
|
|
184
181
|
const keys = Object.keys(owner);
|
|
185
182
|
if (keys.some((key) => key !== "type" && key !== "id")) {
|
|
186
|
-
throw new TypeError("
|
|
183
|
+
throw new TypeError("connection owner has an unknown key");
|
|
187
184
|
}
|
|
188
185
|
if (owner.type === "agent") {
|
|
189
186
|
if ("id" in owner) {
|
|
190
|
-
throw new TypeError('
|
|
187
|
+
throw new TypeError('connection owner "id" is not accepted for { type: "agent" }');
|
|
191
188
|
}
|
|
192
189
|
return { type: "agent" };
|
|
193
190
|
}
|
|
@@ -195,48 +192,35 @@ function normalizeOwner(owner) {
|
|
|
195
192
|
if (owner.id === undefined)
|
|
196
193
|
return { type: "user" };
|
|
197
194
|
if (typeof owner.id !== "string" || !owner.id.trim()) {
|
|
198
|
-
throw new TypeError('
|
|
195
|
+
throw new TypeError('connection owner "id" must be a non-empty string');
|
|
199
196
|
}
|
|
200
197
|
return { type: "user", id: owner.id.trim() };
|
|
201
198
|
}
|
|
202
|
-
throw new TypeError("
|
|
199
|
+
throw new TypeError("connection owner type is not supported");
|
|
203
200
|
}
|
|
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
201
|
export function resolveOwnerId(owner, identity, deploymentId) {
|
|
210
202
|
if (owner.type === "user") {
|
|
211
203
|
const authenticated = identity?.user.id;
|
|
212
204
|
if (!authenticated) {
|
|
213
|
-
throw new CredentialStoreError("user
|
|
205
|
+
throw new CredentialStoreError("user connections require an authenticated user principal");
|
|
214
206
|
}
|
|
215
207
|
if (owner.id !== undefined && owner.id !== authenticated) {
|
|
216
|
-
throw new CredentialStoreError("user
|
|
208
|
+
throw new CredentialStoreError("user connection owner id must match the authenticated principal");
|
|
217
209
|
}
|
|
218
210
|
return authenticated;
|
|
219
211
|
}
|
|
220
212
|
if (!deploymentId) {
|
|
221
|
-
throw new CredentialStoreError("
|
|
213
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
222
214
|
}
|
|
223
215
|
return deploymentId;
|
|
224
216
|
}
|
|
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
217
|
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
218
|
if (env.MDA_LOCAL_DEV === "1") {
|
|
235
|
-
throw new CredentialStoreError(
|
|
219
|
+
throw new CredentialStoreError(localUserConnectionUnsupported());
|
|
236
220
|
}
|
|
237
221
|
const config = resolveAgentAuthConfig(env);
|
|
238
222
|
if (!config.deploymentId) {
|
|
239
|
-
throw new CredentialStoreError("
|
|
223
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
240
224
|
}
|
|
241
225
|
return {
|
|
242
226
|
baseUrl: config.baseUrl,
|
|
@@ -244,34 +228,42 @@ export function resolveAgentAuthContext(identity, env = process.env) {
|
|
|
244
228
|
principalId: resolveOwnerId({ type: "user" }, identity, config.deploymentId),
|
|
245
229
|
apiKey: config.apiKey,
|
|
246
230
|
workspaceId: config.workspaceId,
|
|
231
|
+
serviceKey: config.serviceKey,
|
|
247
232
|
};
|
|
248
233
|
}
|
|
249
234
|
function resolveAgentAuthConfig(env) {
|
|
250
235
|
const apiKey = env.LANGSMITH_API_KEY?.trim();
|
|
251
236
|
if (!apiKey) {
|
|
252
|
-
throw new CredentialStoreError("
|
|
237
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_API_KEY is not set");
|
|
238
|
+
}
|
|
239
|
+
const workspaceId = env.LANGSMITH_WORKSPACE_ID?.trim();
|
|
240
|
+
if (!workspaceId) {
|
|
241
|
+
throw new CredentialStoreError("connections are not configured: LANGSMITH_WORKSPACE_ID is not set");
|
|
253
242
|
}
|
|
254
243
|
return {
|
|
255
244
|
baseUrl: resolveAgentAuthBaseUrl(env),
|
|
256
245
|
apiKey,
|
|
257
246
|
deploymentId: env.LANGSMITH_HOST_PROJECT_ID?.trim() || undefined,
|
|
258
|
-
workspaceId
|
|
247
|
+
workspaceId,
|
|
248
|
+
serviceKey: env.MDA_AGENT_AUTH_SERVICE_KEY?.trim() || undefined,
|
|
259
249
|
};
|
|
260
250
|
}
|
|
261
251
|
/**
|
|
262
|
-
* Agent Auth
|
|
252
|
+
* Origin for Agent Auth HTTP calls from `LANGSMITH_ENDPOINT`.
|
|
263
253
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
254
|
+
* Cloud SaaS revisions omit that reserved name and inject `LANGCHAIN_ENDPOINT`
|
|
255
|
+
* instead; read it as the same setting so we do not default to production.
|
|
266
256
|
*/
|
|
267
257
|
export function resolveAgentAuthBaseUrl(env = process.env) {
|
|
268
|
-
const raw = env.LANGSMITH_ENDPOINT?.trim() ||
|
|
258
|
+
const raw = env.LANGSMITH_ENDPOINT?.trim() ||
|
|
259
|
+
env.LANGCHAIN_ENDPOINT?.trim() ||
|
|
260
|
+
DEFAULT_LANGSMITH_ENDPOINT;
|
|
269
261
|
let parsed;
|
|
270
262
|
try {
|
|
271
263
|
parsed = new URL(raw);
|
|
272
264
|
}
|
|
273
265
|
catch {
|
|
274
|
-
throw new
|
|
266
|
+
throw new InvalidAgentAuthEndpointError();
|
|
275
267
|
}
|
|
276
268
|
if (!["http:", "https:"].includes(parsed.protocol) ||
|
|
277
269
|
!parsed.hostname ||
|
|
@@ -280,9 +272,9 @@ export function resolveAgentAuthBaseUrl(env = process.env) {
|
|
|
280
272
|
(parsed.pathname !== "/" && parsed.pathname !== "") ||
|
|
281
273
|
parsed.search ||
|
|
282
274
|
parsed.hash) {
|
|
283
|
-
throw new
|
|
275
|
+
throw new InvalidAgentAuthEndpointError();
|
|
284
276
|
}
|
|
285
277
|
return parsed.origin;
|
|
286
278
|
}
|
|
287
|
-
export const
|
|
288
|
-
//# sourceMappingURL=
|
|
279
|
+
export const connections = new Connections();
|
|
280
|
+
//# 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;AAazB,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,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QAC9B,0BAA0B,CAAC;IAC7B,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,6BAA6B,EAAE,CAAC;IAC5C,CAAC;IACD,IACE,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC9C,CAAC,MAAM,CAAC,QAAQ;QAChB,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,QAAQ;QACf,CAAC,MAAM,CAAC,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,KAAK,EAAE,CAAC;QACnD,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,IAAI,EACX,CAAC;QACD,MAAM,IAAI,6BAA6B,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,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
|
* });
|
|
@@ -51,17 +51,17 @@ 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
66
|
export declare const mcpConnector: (config: McpServersConfig) => McpServersDefinition;
|
|
67
67
|
//# 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;AA0ED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,oBAAoB,EAChC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,qBAAqB,CAAC,CAyBhC;AAsKD,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,88 @@ 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
|
-
.sort(),
|
|
147
|
+
userConnections: userSlugs,
|
|
148
|
+
agentConnections: agentSlugs,
|
|
133
149
|
providerConfig: {},
|
|
134
150
|
};
|
|
135
151
|
}
|
|
136
152
|
async function createClientAndLoadTools(connectors) {
|
|
137
|
-
const { eager,
|
|
138
|
-
if (
|
|
139
|
-
|
|
153
|
+
const { eager, userConnection } = partitionMcpServers(connectors.mcpServers);
|
|
154
|
+
if (userConnection.length > 0) {
|
|
155
|
+
warnDeferredUserConnectionServers(userConnection);
|
|
140
156
|
}
|
|
141
157
|
if (Object.keys(eager).length === 0) {
|
|
142
158
|
return [];
|
|
143
159
|
}
|
|
144
|
-
const { tools } = await loadToolsFromServers(connectors, await
|
|
160
|
+
const { tools } = await loadToolsFromServers(connectors, await withAgentConnections(eager));
|
|
145
161
|
return tools;
|
|
146
162
|
}
|
|
147
163
|
/**
|
|
148
|
-
* Load tools for user-
|
|
164
|
+
* Load tools for user-connection servers, once the gate has confirmed the
|
|
149
165
|
* caller's grants.
|
|
150
166
|
*
|
|
151
167
|
* Not process-cached here: the Authorization header is per caller, so the gate
|
|
152
168
|
* owns both the cache and closing the returned transport.
|
|
153
169
|
*/
|
|
154
|
-
export async function
|
|
155
|
-
const {
|
|
170
|
+
export async function loadUserConnectionMcpTools(connectors, accessTokens) {
|
|
171
|
+
const { userConnection } = partitionMcpServers(connectors.mcpServers);
|
|
156
172
|
const connectable = {};
|
|
157
|
-
for (const name of
|
|
173
|
+
for (const name of userConnection) {
|
|
158
174
|
const server = connectors.mcpServers[name];
|
|
159
|
-
const
|
|
160
|
-
if (!server || !
|
|
175
|
+
const connection = server?.connection;
|
|
176
|
+
if (!server || !isConnectionReference(connection)) {
|
|
161
177
|
continue;
|
|
162
178
|
}
|
|
163
|
-
const accessToken = accessTokens.get(
|
|
179
|
+
const accessToken = accessTokens.get(connection.slug);
|
|
164
180
|
if (!accessToken) {
|
|
165
|
-
throw new Error(`MCP user
|
|
181
|
+
throw new Error(`MCP user connection "${connection.slug}" has no access token`);
|
|
166
182
|
}
|
|
167
183
|
connectable[name] = withBearer(server, accessToken);
|
|
168
184
|
}
|
|
@@ -172,13 +188,13 @@ export async function loadUserCredentialMcpTools(connectors, accessTokens) {
|
|
|
172
188
|
const { tools, client } = await loadToolsFromServers(connectors, connectable);
|
|
173
189
|
return { tools, close: () => client.close() };
|
|
174
190
|
}
|
|
175
|
-
/** Resolve each agent-owned
|
|
176
|
-
async function
|
|
191
|
+
/** Resolve each agent-owned connection into a static bearer header. */
|
|
192
|
+
async function withAgentConnections(servers) {
|
|
177
193
|
const out = {};
|
|
178
194
|
for (const [name, server] of Object.entries(servers)) {
|
|
179
|
-
const
|
|
180
|
-
out[name] =
|
|
181
|
-
? withBearer(server, await
|
|
195
|
+
const connection = server.connection;
|
|
196
|
+
out[name] = isConnectionReference(connection)
|
|
197
|
+
? withBearer(server, await connections.resolveDeploymentSecret(connection.slug))
|
|
182
198
|
: server;
|
|
183
199
|
}
|
|
184
200
|
return out;
|
|
@@ -190,31 +206,31 @@ function withBearer(server, token) {
|
|
|
190
206
|
headers: { ...headers, Authorization: `Bearer ${token}` },
|
|
191
207
|
};
|
|
192
208
|
}
|
|
193
|
-
function
|
|
194
|
-
return (
|
|
195
|
-
server.
|
|
209
|
+
function usesUserConnection(server) {
|
|
210
|
+
return (isConnectionReference(server.connection) &&
|
|
211
|
+
server.connection.owner.type === "user");
|
|
196
212
|
}
|
|
197
213
|
function partitionMcpServers(servers) {
|
|
198
214
|
const eager = {};
|
|
199
|
-
const
|
|
215
|
+
const userConnection = [];
|
|
200
216
|
for (const [name, server] of Object.entries(servers)) {
|
|
201
|
-
if (
|
|
202
|
-
|
|
217
|
+
if (usesUserConnection(server)) {
|
|
218
|
+
userConnection.push(name);
|
|
203
219
|
}
|
|
204
220
|
else {
|
|
205
221
|
eager[name] = server;
|
|
206
222
|
}
|
|
207
223
|
}
|
|
208
|
-
return { eager,
|
|
224
|
+
return { eager, userConnection };
|
|
209
225
|
}
|
|
210
|
-
function
|
|
226
|
+
function warnDeferredUserConnectionServers(serverNames) {
|
|
211
227
|
console.warn(`[managed-deepagents] MCP server(s) ${serverNames.join(", ")} declare ` +
|
|
212
|
-
`a user
|
|
228
|
+
`a user connection; tools load after the pre-run credential gate ` +
|
|
213
229
|
`confirms grants for the caller.`);
|
|
214
230
|
}
|
|
215
231
|
function stripManagedToolSelection(servers) {
|
|
216
232
|
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
|
|
217
|
-
const { includeTools: _includeTools, excludeTools: _excludeTools,
|
|
233
|
+
const { includeTools: _includeTools, excludeTools: _excludeTools, connection: _connection, ...clientConfig } = server;
|
|
218
234
|
return [name, clientConfig];
|
|
219
235
|
}));
|
|
220
236
|
}
|