@sparkelf/dsh-plugin-mcp-credentials 0.2.1-alpha.51 → 0.2.1-alpha.52

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 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,13 +71,21 @@ function buildChildEnv(extra) {
32
71
  ...extra
33
72
  };
34
73
  }
35
- /** Resolve the current bearer credential immediately before each network request. */
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}"`);
41
- const resolved = await provider.resolve(ref);
87
+ const identity = sessionScope.getStore();
88
+ const resolved = (identity === void 0 || identity.actor === void 0 ? void 0 : await provider.resolve(credentialRef(scopedCredentialRef(ref, identity.sessionId))).catch(() => void 0)) ?? await provider.resolve(ref);
42
89
  if (resolved === void 0) throw new Error(`mcp-client: credential "${ref}" is not configured`);
43
90
  const headers = new Headers(init?.headers);
44
91
  headers.set("Authorization", `Bearer ${resolved.value}`);
@@ -273,40 +320,46 @@ function createOutput(rawName, structuredSchema) {
273
320
  */
274
321
  function createExecutor(client, ctx, rawName, taskRequired, opts, projections) {
275
322
  return async (args, exec) => {
276
- if (taskRequired) throw new Error(`Tool "${rawName}" requires task-based execution, which this bridge does not support`);
277
- const result = await callToolUncached(client, rawName, typeof args === "object" && args !== null ? args : {}, exec, opts);
278
- if (!Array.isArray(result.content)) {
279
- const rendered = "toolResult" in result ? JSON.stringify(result.toolResult) : "(no output)";
280
- const text = typeof rendered === "string" ? rendered : "(no output)";
323
+ const session = exec.agent?.session;
324
+ return runWithSession(session?.actor === void 0 ? void 0 : {
325
+ sessionId: String(session.id),
326
+ actor: session.actor
327
+ }, async () => {
328
+ if (taskRequired) throw new Error(`Tool "${rawName}" requires task-based execution, which this bridge does not support`);
329
+ const result = await callToolUncached(client, rawName, typeof args === "object" && args !== null ? args : {}, exec, opts);
330
+ if (!Array.isArray(result.content)) {
331
+ const rendered = "toolResult" in result ? JSON.stringify(result.toolResult) : "(no output)";
332
+ const text = typeof rendered === "string" ? rendered : "(no output)";
333
+ if (result.isError === true) throw new Error(text);
334
+ return {
335
+ content: [{
336
+ type: "text",
337
+ text
338
+ }],
339
+ ...result.structuredContent !== void 0 ? { structuredContent: result.structuredContent } : {}
340
+ };
341
+ }
342
+ const content = result.content;
343
+ const text = extractText(content, rawName);
281
344
  if (result.isError === true) throw new Error(text);
282
- return {
283
- content: [{
284
- type: "text",
285
- text
286
- }],
345
+ const value = {
346
+ content,
287
347
  ...result.structuredContent !== void 0 ? { structuredContent: result.structuredContent } : {}
288
348
  };
289
- }
290
- const content = result.content;
291
- const text = extractText(content, rawName);
292
- if (result.isError === true) throw new Error(text);
293
- const value = {
294
- content,
295
- ...result.structuredContent !== void 0 ? { structuredContent: result.structuredContent } : {}
296
- };
297
- if (containsImage(content)) {
298
- const fallback = [{
299
- type: "text",
300
- text: extractText(content, rawName)
301
- }];
302
- const projected = await prepareImageProjection(ctx, exec, content, rawName);
303
- projections.set(exec, {
304
- value,
305
- fallback,
306
- content: projected
307
- });
308
- }
309
- return value;
349
+ if (containsImage(content)) {
350
+ const fallback = [{
351
+ type: "text",
352
+ text: extractText(content, rawName)
353
+ }];
354
+ const projected = await prepareImageProjection(ctx, exec, content, rawName);
355
+ projections.set(exec, {
356
+ value,
357
+ fallback,
358
+ content: projected
359
+ });
360
+ }
361
+ return value;
362
+ });
310
363
  };
311
364
  }
312
365
  /** 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/package.json CHANGED
@@ -1,25 +1,22 @@
1
1
  {
2
- "dependencies": {
3
- "@deepseek-ai/schemastery": "^3.18.2",
4
- "@modelcontextprotocol/sdk": "^1.12.0",
5
- "zod": "^4.4.3"
6
- },
2
+ "name": "@sparkelf/dsh-plugin-mcp-credentials",
7
3
  "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"
4
+ "version": "0.2.1-alpha.52",
5
+ "publishConfig": {
6
+ "access": "public"
18
7
  },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/plus/mcp-credentials"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
19
16
  "exports": {
20
17
  ".": {
21
- "default": "./lib/index.js",
22
- "types": "./lib/types/index.d.ts"
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
23
20
  },
24
21
  "./package.json": "./package.json"
25
22
  },
@@ -28,27 +25,30 @@
28
25
  "lib/types/**/*.d.ts"
29
26
  ],
30
27
  "license": "MIT",
31
- "main": "lib/index.js",
32
- "name": "@sparkelf/dsh-plugin-mcp-credentials",
33
28
  "peerDependencies": {
34
- "@deepseek-ai/cordis": ">=4.0.1",
35
29
  "@deepseek-ai/dsh-attachment": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
36
- "@deepseek-ai/dsh-credentials": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
37
30
  "@deepseek-ai/dsh-llm": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
38
31
  "@deepseek-ai/dsh-scope": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
39
32
  "@deepseek-ai/dsh-subprocess": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
40
33
  "@deepseek-ai/dsh-timeout": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
41
- "@deepseek-ai/dsh-tools": "^0.1.6-alpha.1 || ^0.2.1-rc.2"
42
- },
43
- "publishConfig": {
44
- "access": "public"
34
+ "@deepseek-ai/dsh-tools": "^0.1.6-alpha.1 || ^0.2.1-rc.2",
35
+ "@deepseek-ai/cordis": ">=4.0.1",
36
+ "@deepseek-ai/dsh-credentials": "^0.1.6-alpha.1 || ^0.2.1-rc.2"
45
37
  },
46
- "repository": {
47
- "directory": "packages/plus/mcp-credentials",
48
- "type": "git",
49
- "url": "git+https://github.com/deepseek-ai/deepseek-harness.git"
38
+ "dependencies": {
39
+ "@modelcontextprotocol/sdk": "^1.12.0",
40
+ "@deepseek-ai/schemastery": "workspace:^",
41
+ "zod": "^4.4.3"
50
42
  },
51
- "type": "module",
52
- "types": "lib/types/index.d.ts",
53
- "version": "0.2.1-alpha.51"
43
+ "devDependencies": {
44
+ "@deepseek-ai/dsh-attachment": "workspace:^",
45
+ "@deepseek-ai/dsh-llm": "workspace:^",
46
+ "@deepseek-ai/dsh-scope": "workspace:^",
47
+ "@deepseek-ai/dsh-subprocess": "workspace:^",
48
+ "@deepseek-ai/dsh-timeout": "workspace:^",
49
+ "@deepseek-ai/dsh-tools": "workspace:^",
50
+ "@deepseek-ai/dsh-util-values": "workspace:^",
51
+ "@deepseek-ai/cordis": "workspace:^",
52
+ "@deepseek-ai/dsh-credentials": "workspace:^"
53
+ }
54
54
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 DeepSeek
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.