@tsed/platform-mcp 8.43.4 → 8.44.1

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.
@@ -39,8 +39,8 @@ export interface McpHttpUpstreamSettings extends McpUpstreamBaseSettings {
39
39
  type: "http" | "sse";
40
40
  url: string;
41
41
  /**
42
- * Headers sent with every upstream request. Values support the `${OAUTH_TOKEN}`, `${OAUTH_CLIENT_ID}`
43
- * and `${OAUTH_SCOPES}` placeholders, replaced with the verified identity of the caller.
42
+ * Headers sent with every upstream request. Values support the `${OAUTH_TOKEN}`, `${OAUTH_CLIENT_ID}`,
43
+ * `${OAUTH_SCOPES}` and `${OAUTH_SUB}` placeholders, replaced with the verified identity of the caller.
44
44
  */
45
45
  headers?: Record<string, string>;
46
46
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-mcp",
3
- "version": "8.43.4",
3
+ "version": "8.44.1",
4
4
  "description": "Model Context Protocol integration for Ts.ED HTTP adapters.",
5
5
  "source": "./src/http/index.ts",
6
6
  "type": "module",
@@ -51,14 +51,14 @@
51
51
  "uuid": ">=11.0.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@tsed/barrels": "8.43.4",
55
- "@tsed/core": "8.43.4",
56
- "@tsed/di": "8.43.4",
57
- "@tsed/exceptions": "8.43.4",
58
- "@tsed/json-mapper": "8.43.4",
59
- "@tsed/platform-http": "8.43.4",
60
- "@tsed/schema": "8.43.4",
61
- "@tsed/typescript": "8.43.4",
54
+ "@tsed/barrels": "8.44.1",
55
+ "@tsed/core": "8.44.1",
56
+ "@tsed/di": "8.44.1",
57
+ "@tsed/exceptions": "8.44.1",
58
+ "@tsed/json-mapper": "8.44.1",
59
+ "@tsed/platform-http": "8.44.1",
60
+ "@tsed/schema": "8.44.1",
61
+ "@tsed/typescript": "8.44.1",
62
62
  "jose": "^6.1.3",
63
63
  "typescript": "6.0.2",
64
64
  "vitest": "4.1.4"
@@ -41,8 +41,8 @@ export interface McpHttpUpstreamSettings extends McpUpstreamBaseSettings {
41
41
  type: "http" | "sse";
42
42
  url: string;
43
43
  /**
44
- * Headers sent with every upstream request. Values support the `${OAUTH_TOKEN}`, `${OAUTH_CLIENT_ID}`
45
- * and `${OAUTH_SCOPES}` placeholders, replaced with the verified identity of the caller.
44
+ * Headers sent with every upstream request. Values support the `${OAUTH_TOKEN}`, `${OAUTH_CLIENT_ID}`,
45
+ * `${OAUTH_SCOPES}` and `${OAUTH_SUB}` placeholders, replaced with the verified identity of the caller.
46
46
  */
47
47
  headers?: Record<string, string>;
48
48
  /**
@@ -64,11 +64,32 @@ describe("resolveUpstream()", () => {
64
64
  });
65
65
  });
66
66
 
67
+ describe("resolveUpstream() with ${OAUTH_SUB}", () => {
68
+ const upstream = {type: "stdio" as const, command: "node", args: ["--user=${OAUTH_SUB}"], env: {USER_ID: "${OAUTH_SUB}"}};
69
+
70
+ it("interpolates the subject exposed in the claims of the caller", () => {
71
+ expect(resolveUpstream(upstream, {...authInfo, extra: {sub: "user-1"}})).toEqual({
72
+ ...upstream,
73
+ args: ["--user=user-1"],
74
+ env: {USER_ID: "user-1"}
75
+ });
76
+ });
77
+
78
+ it.each([
79
+ ["the claims hold no subject", {...authInfo, extra: {}}],
80
+ ["the subject is not a string", {...authInfo, extra: {sub: 42}}],
81
+ ["the caller exposes no claims", authInfo]
82
+ ])("replaces the placeholder with an empty value when %s", (_, info) => {
83
+ expect(resolveUpstream(upstream, info)).toEqual({...upstream, args: ["--user="], env: {USER_ID: ""}});
84
+ });
85
+ });
86
+
67
87
  describe("hasUpstreamPlaceholders()", () => {
68
88
  it("detects placeholders in headers, args and env", () => {
69
89
  expect(hasUpstreamPlaceholders({type: "http", url: "http://localhost", headers: {a: "${OAUTH_TOKEN}"}})).toBe(true);
70
90
  expect(hasUpstreamPlaceholders({type: "stdio", command: "node", args: ["${OAUTH_CLIENT_ID}"]})).toBe(true);
71
91
  expect(hasUpstreamPlaceholders({type: "stdio", command: "node", env: {A: "${OAUTH_SCOPES}"}})).toBe(true);
92
+ expect(hasUpstreamPlaceholders({type: "stdio", command: "node", env: {A: "${OAUTH_SUB}"}})).toBe(true);
72
93
  });
73
94
 
74
95
  it("ignores static definitions", () => {
@@ -2,7 +2,7 @@ import type {AuthInfo} from "@modelcontextprotocol/server";
2
2
  import type {PlatformMcpUpstreamSettings} from "../interfaces/PlatformMcpUpstreamSettings.js";
3
3
  import {hasPlaceholders, interpolate} from "./interpolate.js";
4
4
 
5
- const OAUTH_PLACEHOLDERS = ["OAUTH_TOKEN", "OAUTH_CLIENT_ID", "OAUTH_SCOPES"] as const;
5
+ const OAUTH_PLACEHOLDERS = ["OAUTH_TOKEN", "OAUTH_CLIENT_ID", "OAUTH_SCOPES", "OAUTH_SUB"] as const;
6
6
 
7
7
  function mapValues(record: Record<string, string> | undefined, fn: (value: string) => string) {
8
8
  return record && Object.fromEntries(Object.entries(record).map(([key, value]) => [key, fn(value)]));
@@ -14,6 +14,15 @@ function getValues(upstream: PlatformMcpUpstreamSettings): string[] {
14
14
  : Object.values(upstream.headers || {});
15
15
  }
16
16
 
17
+ /**
18
+ * Reads the subject of the caller from the claims the verifier (or the `preAuth` check) exposes in `extra`.
19
+ */
20
+ function getSubject(authInfo?: AuthInfo) {
21
+ const sub = authInfo?.extra?.sub;
22
+
23
+ return typeof sub === "string" ? sub : undefined;
24
+ }
25
+
17
26
  /**
18
27
  * Tells whether the upstream definition references the identity of the caller.
19
28
  */
@@ -32,7 +41,8 @@ export function resolveUpstream<T extends PlatformMcpUpstreamSettings>(upstream:
32
41
  const variables: Record<(typeof OAUTH_PLACEHOLDERS)[number], string | undefined> = {
33
42
  OAUTH_TOKEN: authInfo?.token,
34
43
  OAUTH_CLIENT_ID: authInfo?.clientId,
35
- OAUTH_SCOPES: authInfo?.scopes?.join(" ")
44
+ OAUTH_SCOPES: authInfo?.scopes?.join(" "),
45
+ OAUTH_SUB: getSubject(authInfo)
36
46
  };
37
47
  const resolve = (value: string) => interpolate(value, variables);
38
48