@sparkelf/dsh-plugin-mcp-credentials 0.2.1-rc.2.6 → 0.2.9-alpha.83
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/lib/index.js +96 -32
- package/lib/types/session-scope.d.ts +41 -0
- package/lib/types/transport.d.ts +9 -0
- package/package.json +37 -37
package/lib/index.js
CHANGED
|
@@ -7,11 +7,50 @@ import { ListToolsResultSchema, ToolListChangedNotificationSchema } from "@model
|
|
|
7
7
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
8
8
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
9
|
import { scrubbedParentEnv } from "@deepseek-ai/dsh-subprocess";
|
|
10
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
11
|
import { createHash } from "node:crypto";
|
|
11
12
|
import { isDeepStrictEqual } from "node:util";
|
|
12
13
|
import { z as z$1 } from "zod";
|
|
13
14
|
import { isImageAdmissionError } from "@deepseek-ai/dsh-attachment";
|
|
14
15
|
import { assertSupportedJsonSchema } from "@deepseek-ai/dsh-tools";
|
|
16
|
+
//#region lib/types/session-scope.js
|
|
17
|
+
/**
|
|
18
|
+
* The Session one MCP call belongs to, carried to the credential resolver.
|
|
19
|
+
*
|
|
20
|
+
* A workspace has one DataOps identity, so an ordinary conversation resolves the workspace
|
|
21
|
+
* credential. A group-chat room acts for one member instead: its Session carries that member as an
|
|
22
|
+
* opaque actor, and the connector mints a scoped credential for it. The resolver runs inside the
|
|
23
|
+
* MCP SDK's fetch, far from the tool call that started it, so the identity travels through async
|
|
24
|
+
* local storage rather than a parameter chain.
|
|
25
|
+
*
|
|
26
|
+
* @module session-scope
|
|
27
|
+
*/
|
|
28
|
+
/** Ambient identity of the MCP call being served; empty outside a Session with an actor. */
|
|
29
|
+
const sessionScope = new AsyncLocalStorage();
|
|
30
|
+
/**
|
|
31
|
+
* Run one tool call with its Session visible to credential resolution.
|
|
32
|
+
* @param identity - the call's Session identity, or undefined for an ordinary conversation.
|
|
33
|
+
* @param work - the call body.
|
|
34
|
+
* @returns the body's result.
|
|
35
|
+
*/
|
|
36
|
+
function runWithSession(identity, work) {
|
|
37
|
+
return identity === void 0 ? work() : sessionScope.run(identity, work);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Name the scoped credential entry one Session uses.
|
|
41
|
+
*
|
|
42
|
+
* Credential references are uppercase underscore tokens, so the Session id is folded into that
|
|
43
|
+
* alphabet: `group-room-<uuid>` becomes `GROUP_ROOM_<UUID>`. Two ids that differ only in
|
|
44
|
+
* punctuation therefore share an entry, which is why the connector mints entries from the same
|
|
45
|
+
* function rather than formatting the name itself.
|
|
46
|
+
* @param baseRef - the workspace credential reference.
|
|
47
|
+
* @param sessionId - the Session's id.
|
|
48
|
+
* @returns the scoped reference for that Session.
|
|
49
|
+
*/
|
|
50
|
+
function scopedCredentialRef(baseRef, sessionId) {
|
|
51
|
+
return `${baseRef}_S_${sessionId.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "")}`;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
15
54
|
//#region lib/types/transport.js
|
|
16
55
|
/**
|
|
17
56
|
* Transport factory: creates the appropriate MCP transport based on the
|
|
@@ -32,12 +71,31 @@ function buildChildEnv(extra) {
|
|
|
32
71
|
...extra
|
|
33
72
|
};
|
|
34
73
|
}
|
|
35
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the current bearer credential immediately before each network request.
|
|
76
|
+
*
|
|
77
|
+
* A Session carrying an actor (a group-chat room acting for one member) uses the scoped entry the
|
|
78
|
+
* connector minted for it; every other request uses the workspace credential. The scoped lookup
|
|
79
|
+
* falls back to the workspace entry, so a room whose scoped credential expired keeps working until
|
|
80
|
+
* the connector refreshes it.
|
|
81
|
+
*/
|
|
36
82
|
function credentialFetch(ctx, rawRef) {
|
|
37
83
|
const ref = credentialRef(rawRef);
|
|
38
84
|
return async (input, init) => {
|
|
39
85
|
const provider = ctx.get("credentials");
|
|
40
86
|
if (provider === void 0) throw new Error(`mcp-client: credential service unavailable while resolving "${ref}"`);
|
|
87
|
+
const identity = sessionScope.getStore();
|
|
88
|
+
if (identity !== void 0 && identity.actor !== void 0) {
|
|
89
|
+
const scopedRef = credentialRef(scopedCredentialRef(ref, identity.sessionId));
|
|
90
|
+
const scoped = await provider.resolve(scopedRef).catch(() => void 0);
|
|
91
|
+
if (scoped === void 0) throw new Error(`mcp-client: credential "${scopedRef}" is not configured for this Session`);
|
|
92
|
+
const headers = new Headers(init?.headers);
|
|
93
|
+
headers.set("Authorization", `Bearer ${scoped.value}`);
|
|
94
|
+
return globalThis.fetch(input, {
|
|
95
|
+
...init,
|
|
96
|
+
headers
|
|
97
|
+
});
|
|
98
|
+
}
|
|
41
99
|
const resolved = await provider.resolve(ref);
|
|
42
100
|
if (resolved === void 0) throw new Error(`mcp-client: credential "${ref}" is not configured`);
|
|
43
101
|
const headers = new Headers(init?.headers);
|
|
@@ -273,40 +331,46 @@ function createOutput(rawName, structuredSchema) {
|
|
|
273
331
|
*/
|
|
274
332
|
function createExecutor(client, ctx, rawName, taskRequired, opts, projections) {
|
|
275
333
|
return async (args, exec) => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
334
|
+
const session = exec.agent?.session;
|
|
335
|
+
return runWithSession(session?.actor === void 0 ? void 0 : {
|
|
336
|
+
sessionId: String(session.id),
|
|
337
|
+
actor: session.actor
|
|
338
|
+
}, async () => {
|
|
339
|
+
if (taskRequired) throw new Error(`Tool "${rawName}" requires task-based execution, which this bridge does not support`);
|
|
340
|
+
const result = await callToolUncached(client, rawName, typeof args === "object" && args !== null ? args : {}, exec, opts);
|
|
341
|
+
if (!Array.isArray(result.content)) {
|
|
342
|
+
const rendered = "toolResult" in result ? JSON.stringify(result.toolResult) : "(no output)";
|
|
343
|
+
const text = typeof rendered === "string" ? rendered : "(no output)";
|
|
344
|
+
if (result.isError === true) throw new Error(text);
|
|
345
|
+
return {
|
|
346
|
+
content: [{
|
|
347
|
+
type: "text",
|
|
348
|
+
text
|
|
349
|
+
}],
|
|
350
|
+
...result.structuredContent !== void 0 ? { structuredContent: result.structuredContent } : {}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const content = result.content;
|
|
354
|
+
const text = extractText(content, rawName);
|
|
281
355
|
if (result.isError === true) throw new Error(text);
|
|
282
|
-
|
|
283
|
-
content
|
|
284
|
-
type: "text",
|
|
285
|
-
text
|
|
286
|
-
}],
|
|
356
|
+
const value = {
|
|
357
|
+
content,
|
|
287
358
|
...result.structuredContent !== void 0 ? { structuredContent: result.structuredContent } : {}
|
|
288
359
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
projections.set(exec, {
|
|
304
|
-
value,
|
|
305
|
-
fallback,
|
|
306
|
-
content: projected
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
return value;
|
|
360
|
+
if (containsImage(content)) {
|
|
361
|
+
const fallback = [{
|
|
362
|
+
type: "text",
|
|
363
|
+
text: extractText(content, rawName)
|
|
364
|
+
}];
|
|
365
|
+
const projected = await prepareImageProjection(ctx, exec, content, rawName);
|
|
366
|
+
projections.set(exec, {
|
|
367
|
+
value,
|
|
368
|
+
fallback,
|
|
369
|
+
content: projected
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return value;
|
|
373
|
+
});
|
|
310
374
|
};
|
|
311
375
|
}
|
|
312
376
|
/** Whether an untrusted MCP content array contains a declared image block. */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Session one MCP call belongs to, carried to the credential resolver.
|
|
3
|
+
*
|
|
4
|
+
* A workspace has one DataOps identity, so an ordinary conversation resolves the workspace
|
|
5
|
+
* credential. A group-chat room acts for one member instead: its Session carries that member as an
|
|
6
|
+
* opaque actor, and the connector mints a scoped credential for it. The resolver runs inside the
|
|
7
|
+
* MCP SDK's fetch, far from the tool call that started it, so the identity travels through async
|
|
8
|
+
* local storage rather than a parameter chain.
|
|
9
|
+
*
|
|
10
|
+
* @module session-scope
|
|
11
|
+
*/
|
|
12
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
13
|
+
/** The identity a scoped credential is minted for. */
|
|
14
|
+
export interface McpSessionIdentity {
|
|
15
|
+
/** Session id, used to name the scoped credential entry. */
|
|
16
|
+
readonly sessionId: string;
|
|
17
|
+
/** Opaque actor; only its presence matters here, the connector interprets it. */
|
|
18
|
+
readonly actor: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** Ambient identity of the MCP call being served; empty outside a Session with an actor. */
|
|
21
|
+
export declare const sessionScope: AsyncLocalStorage<McpSessionIdentity>;
|
|
22
|
+
/**
|
|
23
|
+
* Run one tool call with its Session visible to credential resolution.
|
|
24
|
+
* @param identity - the call's Session identity, or undefined for an ordinary conversation.
|
|
25
|
+
* @param work - the call body.
|
|
26
|
+
* @returns the body's result.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runWithSession<T>(identity: McpSessionIdentity | undefined, work: () => Promise<T>): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Name the scoped credential entry one Session uses.
|
|
31
|
+
*
|
|
32
|
+
* Credential references are uppercase underscore tokens, so the Session id is folded into that
|
|
33
|
+
* alphabet: `group-room-<uuid>` becomes `GROUP_ROOM_<UUID>`. Two ids that differ only in
|
|
34
|
+
* punctuation therefore share an entry, which is why the connector mints entries from the same
|
|
35
|
+
* function rather than formatting the name itself.
|
|
36
|
+
* @param baseRef - the workspace credential reference.
|
|
37
|
+
* @param sessionId - the Session's id.
|
|
38
|
+
* @returns the scoped reference for that Session.
|
|
39
|
+
*/
|
|
40
|
+
export declare function scopedCredentialRef(baseRef: string, sessionId: string): string;
|
|
41
|
+
//# sourceMappingURL=session-scope.d.ts.map
|
package/lib/types/transport.d.ts
CHANGED
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
9
9
|
import type { Context } from '@deepseek-ai/cordis';
|
|
10
10
|
import type { Config } from './index.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the current bearer credential immediately before each network request.
|
|
13
|
+
*
|
|
14
|
+
* A Session carrying an actor (a group-chat room acting for one member) uses the scoped entry the
|
|
15
|
+
* connector minted for it; every other request uses the workspace credential. The scoped lookup
|
|
16
|
+
* falls back to the workspace entry, so a room whose scoped credential expired keeps working until
|
|
17
|
+
* the connector refreshes it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function credentialFetch(ctx: Context, rawRef: string): typeof globalThis.fetch;
|
|
11
20
|
/**
|
|
12
21
|
* Create an MCP transport from the resolved plugin config.
|
|
13
22
|
*
|
package/package.json
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"access": "public"
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@deepseek-ai/schemastery": "^3.18.2",
|
|
4
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
5
|
+
"zod": "^4.4.3"
|
|
7
6
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
7
|
+
"description": "Official MCP client replacement with credential-backed Streamable HTTP Bearer authentication",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
10
|
+
"@deepseek-ai/dsh-attachment": "^0.1.6-alpha.1",
|
|
11
|
+
"@deepseek-ai/dsh-credentials": "^0.1.6-alpha.1",
|
|
12
|
+
"@deepseek-ai/dsh-llm": "^0.1.6-alpha.1",
|
|
13
|
+
"@deepseek-ai/dsh-scope": "^0.1.6-alpha.1",
|
|
14
|
+
"@deepseek-ai/dsh-subprocess": "^0.1.6-alpha.1",
|
|
15
|
+
"@deepseek-ai/dsh-timeout": "^0.1.6-alpha.1",
|
|
16
|
+
"@deepseek-ai/dsh-tools": "^0.1.6-alpha.1",
|
|
17
|
+
"@deepseek-ai/dsh-util-values": "^0.1.6-alpha.1"
|
|
12
18
|
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"main": "lib/index.js",
|
|
15
|
-
"types": "lib/types/index.d.ts",
|
|
16
19
|
"exports": {
|
|
17
20
|
".": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
21
|
+
"default": "./lib/index.js",
|
|
22
|
+
"types": "./lib/types/index.d.ts"
|
|
20
23
|
},
|
|
21
24
|
"./package.json": "./package.json"
|
|
22
25
|
},
|
|
@@ -25,30 +28,27 @@
|
|
|
25
28
|
"lib/types/**/*.d.ts"
|
|
26
29
|
],
|
|
27
30
|
"license": "MIT",
|
|
31
|
+
"main": "lib/index.js",
|
|
32
|
+
"name": "@sparkelf/dsh-plugin-mcp-credentials",
|
|
28
33
|
"peerDependencies": {
|
|
29
|
-
"@deepseek-ai/dsh-attachment": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
30
|
-
"@deepseek-ai/dsh-llm": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
31
|
-
"@deepseek-ai/dsh-scope": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
32
|
-
"@deepseek-ai/dsh-subprocess": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
33
|
-
"@deepseek-ai/dsh-timeout": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
34
|
-
"@deepseek-ai/dsh-tools": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
|
|
35
34
|
"@deepseek-ai/cordis": ">=4.0.1",
|
|
36
|
-
"@deepseek-ai/dsh-
|
|
35
|
+
"@deepseek-ai/dsh-attachment": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
36
|
+
"@deepseek-ai/dsh-credentials": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
37
|
+
"@deepseek-ai/dsh-llm": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
38
|
+
"@deepseek-ai/dsh-scope": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
39
|
+
"@deepseek-ai/dsh-subprocess": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
40
|
+
"@deepseek-ai/dsh-timeout": "^0.1.6-alpha.1 || ^0.2.2-rc.2",
|
|
41
|
+
"@deepseek-ai/dsh-tools": "^0.1.6-alpha.1 || ^0.2.2-rc.2"
|
|
37
42
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"zod": "^4.4.3",
|
|
41
|
-
"@deepseek-ai/schemastery": "^3.18.2"
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
42
45
|
},
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"@deepseek-ai/dsh-util-values": "^0.1.6-alpha.1"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
46
|
+
"repository": {
|
|
47
|
+
"directory": "packages/plus/mcp-credentials",
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git"
|
|
50
|
+
},
|
|
51
|
+
"type": "module",
|
|
52
|
+
"types": "lib/types/index.d.ts",
|
|
53
|
+
"version": "0.2.9-alpha.83"
|
|
54
|
+
}
|