@super_studio/ecforce-ai-agent-server 0.2.0-canary.5 → 1.0.0-canary.8

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.
Files changed (64) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutProperties.cjs +15 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutProperties.mjs +15 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutPropertiesLoose.cjs +14 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectWithoutPropertiesLoose.mjs +13 -0
  9. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
  10. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  11. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
  12. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  13. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
  14. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  15. package/dist/index.cjs +7 -0
  16. package/dist/index.d.cts +3 -0
  17. package/dist/index.d.mts +3 -0
  18. package/dist/index.mjs +3 -1056
  19. package/dist/lib/constants.cjs +6 -0
  20. package/dist/lib/constants.mjs +6 -0
  21. package/dist/lib/constants.mjs.map +1 -0
  22. package/dist/lib/jwt.cjs +64 -0
  23. package/dist/lib/jwt.mjs +64 -0
  24. package/dist/lib/jwt.mjs.map +1 -0
  25. package/dist/mcp-auth.cjs +52 -0
  26. package/dist/mcp-auth.d.cts +38 -0
  27. package/dist/mcp-auth.d.cts.map +1 -0
  28. package/dist/mcp-auth.d.mts +38 -0
  29. package/dist/mcp-auth.d.mts.map +1 -0
  30. package/dist/mcp-auth.mjs +44 -129
  31. package/dist/mcp-auth.mjs.map +1 -0
  32. package/dist/sdk/__generated__/index.cjs +524 -0
  33. package/dist/sdk/__generated__/index.d.cts +1648 -0
  34. package/dist/sdk/__generated__/index.d.cts.map +1 -0
  35. package/dist/sdk/__generated__/index.d.mts +1648 -0
  36. package/dist/sdk/__generated__/index.d.mts.map +1 -0
  37. package/dist/sdk/__generated__/index.mjs +523 -0
  38. package/dist/sdk/__generated__/index.mjs.map +1 -0
  39. package/dist/sdk/index.cjs +21 -0
  40. package/dist/sdk/index.d.cts +22 -0
  41. package/dist/sdk/index.d.cts.map +1 -0
  42. package/dist/sdk/index.d.mts +22 -0
  43. package/dist/sdk/index.d.mts.map +1 -0
  44. package/dist/sdk/index.mjs +22 -0
  45. package/dist/sdk/index.mjs.map +1 -0
  46. package/package.json +14 -20
  47. package/dist/chunk-FWCSY2DS.mjs +0 -37
  48. package/dist/chunk-ORMEWXMH.js +0 -37
  49. package/dist/index.d.ts +0 -2
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/index.js +0 -1057
  52. package/dist/lib/constants.d.ts +0 -2
  53. package/dist/lib/constants.d.ts.map +0 -1
  54. package/dist/lib/jwt.d.ts +0 -37
  55. package/dist/lib/jwt.d.ts.map +0 -1
  56. package/dist/mcp-auth.d.ts +0 -35
  57. package/dist/mcp-auth.d.ts.map +0 -1
  58. package/dist/mcp-auth.js +0 -136
  59. package/dist/sdk/__generated__/index.d.ts +0 -1636
  60. package/dist/sdk/__generated__/index.d.ts.map +0 -1
  61. package/dist/sdk/generate.d.ts +0 -2
  62. package/dist/sdk/generate.d.ts.map +0 -1
  63. package/dist/sdk/index.d.ts +0 -19
  64. package/dist/sdk/index.d.ts.map +0 -1
@@ -0,0 +1,6 @@
1
+
2
+ //#region src/lib/constants.ts
3
+ const API_ENDPOINT = "http://localhost:4043";
4
+
5
+ //#endregion
6
+ exports.API_ENDPOINT = API_ENDPOINT;
@@ -0,0 +1,6 @@
1
+ //#region src/lib/constants.ts
2
+ const API_ENDPOINT = "http://localhost:4043";
3
+
4
+ //#endregion
5
+ export { API_ENDPOINT };
6
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/lib/constants.ts"],"sourcesContent":["export const API_ENDPOINT = \"http://localhost:4043\";\n"],"mappings":";AAAA,MAAa,eAAe"}
@@ -0,0 +1,64 @@
1
+ let _panva_hkdf = require("@panva/hkdf");
2
+ let jose = require("jose");
3
+
4
+ //#region src/lib/jwt.ts
5
+ /**
6
+ * このロジックは最新(@auth/core@0.37.2)のAuth.jsのjwt.tsからコピーされました。
7
+ */
8
+ const DEFAULT_MAX_AGE = 720 * 60 * 60;
9
+ const now = () => Date.now() / 1e3 | 0;
10
+ const alg = "dir";
11
+ const enc = "A256CBC-HS512";
12
+ /** Issues a JWT. By default, the JWT is encrypted using "A256CBC-HS512". */
13
+ async function encode(params) {
14
+ const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
15
+ const encryptionSecret = await getDerivedEncryptionKey(enc, (Array.isArray(secret) ? secret : [secret])[0], salt);
16
+ const thumbprint = await (0, jose.calculateJwkThumbprint)({
17
+ kty: "oct",
18
+ k: jose.base64url.encode(encryptionSecret)
19
+ }, `sha${encryptionSecret.byteLength << 3}`);
20
+ return await new jose.EncryptJWT(token).setProtectedHeader({
21
+ alg,
22
+ enc,
23
+ kid: thumbprint
24
+ }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(crypto.randomUUID()).encrypt(encryptionSecret);
25
+ }
26
+ /** Decodes an Auth.js issued JWT. */
27
+ async function decode(params) {
28
+ const { token, secret, salt } = params;
29
+ const secrets = Array.isArray(secret) ? secret : [secret];
30
+ if (!token) return null;
31
+ const { payload } = await (0, jose.jwtDecrypt)(token, async ({ kid, enc: enc$1 }) => {
32
+ for (const secret$1 of secrets) {
33
+ const encryptionSecret = await getDerivedEncryptionKey(enc$1, secret$1, salt);
34
+ if (kid === void 0) return encryptionSecret;
35
+ if (kid === await (0, jose.calculateJwkThumbprint)({
36
+ kty: "oct",
37
+ k: jose.base64url.encode(encryptionSecret)
38
+ }, `sha${encryptionSecret.byteLength << 3}`)) return encryptionSecret;
39
+ }
40
+ throw new Error("no matching decryption secret");
41
+ }, {
42
+ clockTolerance: 15,
43
+ keyManagementAlgorithms: [alg],
44
+ contentEncryptionAlgorithms: [enc, "A256GCM"]
45
+ });
46
+ return payload;
47
+ }
48
+ async function getDerivedEncryptionKey(enc$1, keyMaterial, salt) {
49
+ let length;
50
+ switch (enc$1) {
51
+ case "A256CBC-HS512":
52
+ length = 64;
53
+ break;
54
+ case "A256GCM":
55
+ length = 32;
56
+ break;
57
+ default: throw new Error("Unsupported JWT Content Encryption Algorithm");
58
+ }
59
+ return await (0, _panva_hkdf.hkdf)("sha256", keyMaterial, salt, `Auth.js Generated Encryption Key (${salt})`, length);
60
+ }
61
+
62
+ //#endregion
63
+ exports.decode = decode;
64
+ exports.encode = encode;
@@ -0,0 +1,64 @@
1
+ import { hkdf } from "@panva/hkdf";
2
+ import { EncryptJWT, base64url, calculateJwkThumbprint, jwtDecrypt } from "jose";
3
+
4
+ //#region src/lib/jwt.ts
5
+ /**
6
+ * このロジックは最新(@auth/core@0.37.2)のAuth.jsのjwt.tsからコピーされました。
7
+ */
8
+ const DEFAULT_MAX_AGE = 720 * 60 * 60;
9
+ const now = () => Date.now() / 1e3 | 0;
10
+ const alg = "dir";
11
+ const enc = "A256CBC-HS512";
12
+ /** Issues a JWT. By default, the JWT is encrypted using "A256CBC-HS512". */
13
+ async function encode(params) {
14
+ const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
15
+ const encryptionSecret = await getDerivedEncryptionKey(enc, (Array.isArray(secret) ? secret : [secret])[0], salt);
16
+ const thumbprint = await calculateJwkThumbprint({
17
+ kty: "oct",
18
+ k: base64url.encode(encryptionSecret)
19
+ }, `sha${encryptionSecret.byteLength << 3}`);
20
+ return await new EncryptJWT(token).setProtectedHeader({
21
+ alg,
22
+ enc,
23
+ kid: thumbprint
24
+ }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(crypto.randomUUID()).encrypt(encryptionSecret);
25
+ }
26
+ /** Decodes an Auth.js issued JWT. */
27
+ async function decode(params) {
28
+ const { token, secret, salt } = params;
29
+ const secrets = Array.isArray(secret) ? secret : [secret];
30
+ if (!token) return null;
31
+ const { payload } = await jwtDecrypt(token, async ({ kid, enc: enc$1 }) => {
32
+ for (const secret$1 of secrets) {
33
+ const encryptionSecret = await getDerivedEncryptionKey(enc$1, secret$1, salt);
34
+ if (kid === void 0) return encryptionSecret;
35
+ if (kid === await calculateJwkThumbprint({
36
+ kty: "oct",
37
+ k: base64url.encode(encryptionSecret)
38
+ }, `sha${encryptionSecret.byteLength << 3}`)) return encryptionSecret;
39
+ }
40
+ throw new Error("no matching decryption secret");
41
+ }, {
42
+ clockTolerance: 15,
43
+ keyManagementAlgorithms: [alg],
44
+ contentEncryptionAlgorithms: [enc, "A256GCM"]
45
+ });
46
+ return payload;
47
+ }
48
+ async function getDerivedEncryptionKey(enc$1, keyMaterial, salt) {
49
+ let length;
50
+ switch (enc$1) {
51
+ case "A256CBC-HS512":
52
+ length = 64;
53
+ break;
54
+ case "A256GCM":
55
+ length = 32;
56
+ break;
57
+ default: throw new Error("Unsupported JWT Content Encryption Algorithm");
58
+ }
59
+ return await hkdf("sha256", keyMaterial, salt, `Auth.js Generated Encryption Key (${salt})`, length);
60
+ }
61
+
62
+ //#endregion
63
+ export { decode, encode };
64
+ //# sourceMappingURL=jwt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.mjs","names":["secret","enc","length: number"],"sources":["../../src/lib/jwt.ts"],"sourcesContent":["/**\n * このロジックは最新(@auth/core@0.37.2)のAuth.jsのjwt.tsからコピーされました。\n */\n\nimport { hkdf } from \"@panva/hkdf\";\nimport {\n base64url,\n calculateJwkThumbprint,\n EncryptJWT,\n jwtDecrypt,\n} from \"jose\";\n\nconst DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days\n\nconst now = () => (Date.now() / 1000) | 0;\n\nconst alg = \"dir\";\nconst enc = \"A256CBC-HS512\";\ntype Digest = Parameters<typeof calculateJwkThumbprint>[1];\n\n/** Issues a JWT. By default, the JWT is encrypted using \"A256CBC-HS512\". */\nexport async function encode<Payload = object>(\n params: JWTEncodeParams<Payload>,\n) {\n const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;\n const secrets = Array.isArray(secret) ? secret : [secret];\n const encryptionSecret = await getDerivedEncryptionKey(\n enc,\n secrets[0]!,\n salt,\n );\n\n const thumbprint = await calculateJwkThumbprint(\n { kty: \"oct\", k: base64url.encode(encryptionSecret) },\n `sha${encryptionSecret.byteLength << 3}` as Digest,\n );\n // @ts-expect-error `jose` allows any object as payload.\n return await new EncryptJWT(token)\n .setProtectedHeader({ alg, enc, kid: thumbprint })\n .setIssuedAt()\n .setExpirationTime(now() + maxAge)\n .setJti(crypto.randomUUID())\n .encrypt(encryptionSecret);\n}\n\n/** Decodes an Auth.js issued JWT. */\nexport async function decode<Payload = object>(\n params: JWTDecodeParams,\n): Promise<Payload | null> {\n const { token, secret, salt } = params;\n const secrets = Array.isArray(secret) ? secret : [secret];\n if (!token) {\n return null;\n }\n const { payload } = await jwtDecrypt(\n token,\n async ({ kid, enc }) => {\n for (const secret of secrets) {\n const encryptionSecret = await getDerivedEncryptionKey(\n enc,\n secret,\n salt,\n );\n if (kid === undefined) {\n return encryptionSecret;\n }\n\n const thumbprint = await calculateJwkThumbprint(\n { kty: \"oct\", k: base64url.encode(encryptionSecret) },\n `sha${encryptionSecret.byteLength << 3}` as Digest,\n );\n if (kid === thumbprint) {\n return encryptionSecret;\n }\n }\n\n throw new Error(\"no matching decryption secret\");\n },\n {\n clockTolerance: 15,\n keyManagementAlgorithms: [alg],\n contentEncryptionAlgorithms: [enc, \"A256GCM\"],\n },\n );\n return payload as Payload;\n}\n\nasync function getDerivedEncryptionKey(\n enc: string,\n keyMaterial: Parameters<typeof hkdf>[1],\n salt: Parameters<typeof hkdf>[2],\n) {\n let length: number;\n switch (enc) {\n case \"A256CBC-HS512\":\n length = 64;\n break;\n case \"A256GCM\":\n length = 32;\n break;\n default:\n throw new Error(\"Unsupported JWT Content Encryption Algorithm\");\n }\n return await hkdf(\n \"sha256\",\n keyMaterial,\n salt,\n `Auth.js Generated Encryption Key (${salt})`,\n length,\n );\n}\n\nexport interface JWTEncodeParams<Payload = object> {\n /**\n * The maximum age of the Auth.js issued JWT in seconds.\n *\n * @default 30 * 24 * 60 * 60 // 30 days\n */\n maxAge?: number;\n /** Used in combination with `secret`, to derive the encryption secret for JWTs. */\n salt: string;\n /** Used in combination with `salt`, to derive the encryption secret for JWTs. */\n secret: string | string[];\n /** The JWT payload. */\n token?: Payload;\n}\n\nexport interface JWTDecodeParams {\n /** Used in combination with `secret`, to derive the encryption secret for JWTs. */\n salt: string;\n /**\n * Used in combination with `salt`, to derive the encryption secret for JWTs.\n *\n * @note\n * You can also pass an array of secrets, in which case the first secret that successfully\n * decrypts the JWT will be used. This is useful for rotating secrets without invalidating existing sessions.\n * The newer secret should be added to the start of the array, which will be used for all new sessions.\n */\n secret: string | string[];\n /** The Auth.js issued JWT to be decoded */\n token?: string;\n}\n"],"mappings":";;;;;;;AAYA,MAAM,kBAAkB,MAAU,KAAK;AAEvC,MAAM,YAAa,KAAK,KAAK,GAAG,MAAQ;AAExC,MAAM,MAAM;AACZ,MAAM,MAAM;;AAIZ,eAAsB,OACpB,QACA;CACA,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,SAAS,iBAAiB,SAAS;CAE/D,MAAM,mBAAmB,MAAM,wBAC7B,MAFc,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EAG/C,IACR,KACD;CAED,MAAM,aAAa,MAAM,uBACvB;EAAE,KAAK;EAAO,GAAG,UAAU,OAAO,iBAAiB;EAAE,EACrD,MAAM,iBAAiB,cAAc,IACtC;AAED,QAAO,MAAM,IAAI,WAAW,MAAM,CAC/B,mBAAmB;EAAE;EAAK;EAAK,KAAK;EAAY,CAAC,CACjD,aAAa,CACb,kBAAkB,KAAK,GAAG,OAAO,CACjC,OAAO,OAAO,YAAY,CAAC,CAC3B,QAAQ,iBAAiB;;;AAI9B,eAAsB,OACpB,QACyB;CACzB,MAAM,EAAE,OAAO,QAAQ,SAAS;CAChC,MAAM,UAAU,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO;AACzD,KAAI,CAAC,MACH,QAAO;CAET,MAAM,EAAE,YAAY,MAAM,WACxB,OACA,OAAO,EAAE,KAAK,iBAAU;AACtB,OAAK,MAAMA,YAAU,SAAS;GAC5B,MAAM,mBAAmB,MAAM,wBAC7BC,OACAD,UACA,KACD;AACD,OAAI,QAAQ,OACV,QAAO;AAOT,OAAI,QAJe,MAAM,uBACvB;IAAE,KAAK;IAAO,GAAG,UAAU,OAAO,iBAAiB;IAAE,EACrD,MAAM,iBAAiB,cAAc,IACtC,CAEC,QAAO;;AAIX,QAAM,IAAI,MAAM,gCAAgC;IAElD;EACE,gBAAgB;EAChB,yBAAyB,CAAC,IAAI;EAC9B,6BAA6B,CAAC,KAAK,UAAU;EAC9C,CACF;AACD,QAAO;;AAGT,eAAe,wBACb,OACA,aACA,MACA;CACA,IAAIE;AACJ,SAAQD,OAAR;EACE,KAAK;AACH,YAAS;AACT;EACF,KAAK;AACH,YAAS;AACT;EACF,QACE,OAAM,IAAI,MAAM,+CAA+C;;AAEnE,QAAO,MAAM,KACX,UACA,aACA,MACA,qCAAqC,KAAK,IAC1C,OACD"}
@@ -0,0 +1,52 @@
1
+ const require_jwt = require('./lib/jwt.cjs');
2
+
3
+ //#region src/mcp-auth.ts
4
+ const DEFAULT_MAX_AGE = 600;
5
+ const DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
6
+ /**
7
+ * Uses Auth.js JWT encoding/decoding.
8
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
9
+ */
10
+ async function createMCPToken(payload, options) {
11
+ var _options$maxAge, _options$secret, _options$salt;
12
+ const maxAge = (_options$maxAge = options === null || options === void 0 ? void 0 : options.maxAge) !== null && _options$maxAge !== void 0 ? _options$maxAge : DEFAULT_MAX_AGE;
13
+ const secret = (_options$secret = options === null || options === void 0 ? void 0 : options.secret) !== null && _options$secret !== void 0 ? _options$secret : process.env.MCP_TOKEN_SECRET;
14
+ const salt = (_options$salt = options === null || options === void 0 ? void 0 : options.salt) !== null && _options$salt !== void 0 ? _options$salt : DEFAULT_SALT;
15
+ if (!secret || !salt) throw new Error("Secret or salt is not set");
16
+ return {
17
+ token: await require_jwt.encode({
18
+ token: payload,
19
+ secret,
20
+ salt,
21
+ maxAge
22
+ }),
23
+ expiresAt: new Date(Date.now() + maxAge * 1e3)
24
+ };
25
+ }
26
+ /**
27
+ * Uses Auth.js JWT encoding/decoding.
28
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
29
+ */
30
+ async function decodeMCPToken(token, options) {
31
+ var _options$secret2, _options$salt2;
32
+ const secret = (_options$secret2 = options === null || options === void 0 ? void 0 : options.secret) !== null && _options$secret2 !== void 0 ? _options$secret2 : process.env.MCP_TOKEN_SECRET;
33
+ const salt = (_options$salt2 = options === null || options === void 0 ? void 0 : options.salt) !== null && _options$salt2 !== void 0 ? _options$salt2 : DEFAULT_SALT;
34
+ if (!secret || !salt) throw new Error("Secret or salt is not set");
35
+ const decoded = await require_jwt.decode({
36
+ token,
37
+ secret,
38
+ salt
39
+ });
40
+ if (!decoded) throw new Error("Invalid token");
41
+ return decoded;
42
+ }
43
+ function getMcpToken(req) {
44
+ const mcpToken = req.headers.get("X-MCP-Token");
45
+ if (!mcpToken || typeof mcpToken !== "string") throw new Error("Unauthorized");
46
+ return mcpToken;
47
+ }
48
+
49
+ //#endregion
50
+ exports.createMCPToken = createMCPToken;
51
+ exports.decodeMCPToken = decodeMCPToken;
52
+ exports.getMcpToken = getMcpToken;
@@ -0,0 +1,38 @@
1
+ //#region src/mcp-auth.d.ts
2
+ /**
3
+ * 共通のMCPトークンのペイロード。
4
+ * すべてのapps(cdp, ma, bi)はこのトークンの形になります。
5
+ */
6
+ type MCPTokenPayload = {
7
+ source: string;
8
+ user: {
9
+ id: string;
10
+ name: string;
11
+ email: string;
12
+ projectId: string;
13
+ };
14
+ };
15
+ /**
16
+ * Uses Auth.js JWT encoding/decoding.
17
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
18
+ */
19
+ declare function createMCPToken(payload: MCPTokenPayload, options?: {
20
+ secret?: string;
21
+ salt?: string;
22
+ maxAge?: number;
23
+ }): Promise<{
24
+ token: string;
25
+ expiresAt: Date;
26
+ }>;
27
+ /**
28
+ * Uses Auth.js JWT encoding/decoding.
29
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
30
+ */
31
+ declare function decodeMCPToken(token: string, options?: {
32
+ secret?: string;
33
+ salt?: string;
34
+ }): Promise<MCPTokenPayload>;
35
+ declare function getMcpToken(req: Request): string;
36
+ //#endregion
37
+ export { MCPTokenPayload, createMCPToken, decodeMCPToken, getMcpToken };
38
+ //# sourceMappingURL=mcp-auth.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth.d.cts","names":[],"sources":["../src/mcp-auth.ts"],"sourcesContent":[],"mappings":";;AAMA;AAiBA;;KAjBY,eAAA;EAuBT,MAAA,EAAA,MAAA;EAAA,IAAA,EAAA;IAwBmB,EAAA,EAAA,MAAA;IAuBN,IAAA,EAAA,MAAW;;;;;;;;;iBArDL,cAAA,UACX;;;;IAKR;;;;;;;;iBAwBmB,cAAA;;;IAMnB,QAAQ;iBAiBK,WAAA,MAAiB"}
@@ -0,0 +1,38 @@
1
+ //#region src/mcp-auth.d.ts
2
+ /**
3
+ * 共通のMCPトークンのペイロード。
4
+ * すべてのapps(cdp, ma, bi)はこのトークンの形になります。
5
+ */
6
+ type MCPTokenPayload = {
7
+ source: string;
8
+ user: {
9
+ id: string;
10
+ name: string;
11
+ email: string;
12
+ projectId: string;
13
+ };
14
+ };
15
+ /**
16
+ * Uses Auth.js JWT encoding/decoding.
17
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
18
+ */
19
+ declare function createMCPToken(payload: MCPTokenPayload, options?: {
20
+ secret?: string;
21
+ salt?: string;
22
+ maxAge?: number;
23
+ }): Promise<{
24
+ token: string;
25
+ expiresAt: Date;
26
+ }>;
27
+ /**
28
+ * Uses Auth.js JWT encoding/decoding.
29
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
30
+ */
31
+ declare function decodeMCPToken(token: string, options?: {
32
+ secret?: string;
33
+ salt?: string;
34
+ }): Promise<MCPTokenPayload>;
35
+ declare function getMcpToken(req: Request): string;
36
+ //#endregion
37
+ export { MCPTokenPayload, createMCPToken, decodeMCPToken, getMcpToken };
38
+ //# sourceMappingURL=mcp-auth.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth.d.mts","names":[],"sources":["../src/mcp-auth.ts"],"sourcesContent":[],"mappings":";;AAMA;AAiBA;;KAjBY,eAAA;EAuBT,MAAA,EAAA,MAAA;EAAA,IAAA,EAAA;IAwBmB,EAAA,EAAA,MAAA;IAuBN,IAAA,EAAA,MAAW;;;;;;;;;iBArDL,cAAA,UACX;;;;IAKR;;;;;;;;iBAwBmB,cAAA;;;IAMnB,QAAQ;iBAiBK,WAAA,MAAiB"}
package/dist/mcp-auth.mjs CHANGED
@@ -1,136 +1,51 @@
1
- import "./chunk-FWCSY2DS.mjs";
1
+ import { decode, encode } from "./lib/jwt.mjs";
2
2
 
3
- // src/lib/jwt.ts
4
- import { hkdf } from "@panva/hkdf";
5
- import {
6
- base64url,
7
- calculateJwkThumbprint,
8
- EncryptJWT,
9
- jwtDecrypt
10
- } from "jose";
11
- var DEFAULT_MAX_AGE = 30 * 24 * 60 * 60;
12
- var now = () => Date.now() / 1e3 | 0;
13
- var alg = "dir";
14
- var enc = "A256CBC-HS512";
15
- async function encode(params) {
16
- const { token = {}, secret, maxAge = DEFAULT_MAX_AGE, salt } = params;
17
- const secrets = Array.isArray(secret) ? secret : [secret];
18
- const encryptionSecret = await getDerivedEncryptionKey(
19
- enc,
20
- secrets[0],
21
- salt
22
- );
23
- const thumbprint = await calculateJwkThumbprint(
24
- { kty: "oct", k: base64url.encode(encryptionSecret) },
25
- `sha${encryptionSecret.byteLength << 3}`
26
- );
27
- return await new EncryptJWT(token).setProtectedHeader({ alg, enc, kid: thumbprint }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(crypto.randomUUID()).encrypt(encryptionSecret);
28
- }
29
- async function decode(params) {
30
- const { token, secret, salt } = params;
31
- const secrets = Array.isArray(secret) ? secret : [secret];
32
- if (!token) {
33
- return null;
34
- }
35
- const { payload } = await jwtDecrypt(
36
- token,
37
- async ({ kid, enc: enc2 }) => {
38
- for (const secret2 of secrets) {
39
- const encryptionSecret = await getDerivedEncryptionKey(
40
- enc2,
41
- secret2,
42
- salt
43
- );
44
- if (kid === void 0) {
45
- return encryptionSecret;
46
- }
47
- const thumbprint = await calculateJwkThumbprint(
48
- { kty: "oct", k: base64url.encode(encryptionSecret) },
49
- `sha${encryptionSecret.byteLength << 3}`
50
- );
51
- if (kid === thumbprint) {
52
- return encryptionSecret;
53
- }
54
- }
55
- throw new Error("no matching decryption secret");
56
- },
57
- {
58
- clockTolerance: 15,
59
- keyManagementAlgorithms: [alg],
60
- contentEncryptionAlgorithms: [enc, "A256GCM"]
61
- }
62
- );
63
- return payload;
64
- }
65
- async function getDerivedEncryptionKey(enc2, keyMaterial, salt) {
66
- let length;
67
- switch (enc2) {
68
- case "A256CBC-HS512":
69
- length = 64;
70
- break;
71
- case "A256GCM":
72
- length = 32;
73
- break;
74
- default:
75
- throw new Error("Unsupported JWT Content Encryption Algorithm");
76
- }
77
- return await hkdf(
78
- "sha256",
79
- keyMaterial,
80
- salt,
81
- `Auth.js Generated Encryption Key (${salt})`,
82
- length
83
- );
84
- }
85
-
86
- // src/mcp-auth.ts
87
- var DEFAULT_MAX_AGE2 = 60 * 10;
88
- var DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
3
+ //#region src/mcp-auth.ts
4
+ const DEFAULT_MAX_AGE = 600;
5
+ const DEFAULT_SALT = process.env.STAGE === "local" ? "dev" : process.env.STAGE;
6
+ /**
7
+ * Uses Auth.js JWT encoding/decoding.
8
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
9
+ */
89
10
  async function createMCPToken(payload, options) {
90
- var _a, _b, _c;
91
- const maxAge = (_a = options == null ? void 0 : options.maxAge) != null ? _a : DEFAULT_MAX_AGE2;
92
- const secret = (_b = options == null ? void 0 : options.secret) != null ? _b : process.env.MCP_TOKEN_SECRET;
93
- const salt = (_c = options == null ? void 0 : options.salt) != null ? _c : DEFAULT_SALT;
94
- if (!secret || !salt) {
95
- throw new Error("Secret or salt is not set");
96
- }
97
- const token = await encode({
98
- token: payload,
99
- secret,
100
- salt,
101
- maxAge
102
- });
103
- return {
104
- token,
105
- expiresAt: new Date(Date.now() + maxAge * 1e3)
106
- };
11
+ var _options$maxAge, _options$secret, _options$salt;
12
+ const maxAge = (_options$maxAge = options === null || options === void 0 ? void 0 : options.maxAge) !== null && _options$maxAge !== void 0 ? _options$maxAge : DEFAULT_MAX_AGE;
13
+ const secret = (_options$secret = options === null || options === void 0 ? void 0 : options.secret) !== null && _options$secret !== void 0 ? _options$secret : process.env.MCP_TOKEN_SECRET;
14
+ const salt = (_options$salt = options === null || options === void 0 ? void 0 : options.salt) !== null && _options$salt !== void 0 ? _options$salt : DEFAULT_SALT;
15
+ if (!secret || !salt) throw new Error("Secret or salt is not set");
16
+ return {
17
+ token: await encode({
18
+ token: payload,
19
+ secret,
20
+ salt,
21
+ maxAge
22
+ }),
23
+ expiresAt: new Date(Date.now() + maxAge * 1e3)
24
+ };
107
25
  }
26
+ /**
27
+ * Uses Auth.js JWT encoding/decoding.
28
+ * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts
29
+ */
108
30
  async function decodeMCPToken(token, options) {
109
- var _a, _b;
110
- const secret = (_a = options == null ? void 0 : options.secret) != null ? _a : process.env.MCP_TOKEN_SECRET;
111
- const salt = (_b = options == null ? void 0 : options.salt) != null ? _b : DEFAULT_SALT;
112
- if (!secret || !salt) {
113
- throw new Error("Secret or salt is not set");
114
- }
115
- const decoded = await decode({
116
- token,
117
- secret,
118
- salt
119
- });
120
- if (!decoded) {
121
- throw new Error("Invalid token");
122
- }
123
- return decoded;
31
+ var _options$secret2, _options$salt2;
32
+ const secret = (_options$secret2 = options === null || options === void 0 ? void 0 : options.secret) !== null && _options$secret2 !== void 0 ? _options$secret2 : process.env.MCP_TOKEN_SECRET;
33
+ const salt = (_options$salt2 = options === null || options === void 0 ? void 0 : options.salt) !== null && _options$salt2 !== void 0 ? _options$salt2 : DEFAULT_SALT;
34
+ if (!secret || !salt) throw new Error("Secret or salt is not set");
35
+ const decoded = await decode({
36
+ token,
37
+ secret,
38
+ salt
39
+ });
40
+ if (!decoded) throw new Error("Invalid token");
41
+ return decoded;
124
42
  }
125
43
  function getMcpToken(req) {
126
- const mcpToken = req.headers.get("X-MCP-Token");
127
- if (!mcpToken || typeof mcpToken !== "string") {
128
- throw new Error("Unauthorized");
129
- }
130
- return mcpToken;
44
+ const mcpToken = req.headers.get("X-MCP-Token");
45
+ if (!mcpToken || typeof mcpToken !== "string") throw new Error("Unauthorized");
46
+ return mcpToken;
131
47
  }
132
- export {
133
- createMCPToken,
134
- decodeMCPToken,
135
- getMcpToken
136
- };
48
+
49
+ //#endregion
50
+ export { createMCPToken, decodeMCPToken, getMcpToken };
51
+ //# sourceMappingURL=mcp-auth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth.mjs","names":[],"sources":["../src/mcp-auth.ts"],"sourcesContent":["import { decode, encode } from \"./lib/jwt\";\n\n/**\n * 共通のMCPトークンのペイロード。\n * すべてのapps(cdp, ma, bi)はこのトークンの形になります。\n */\nexport type MCPTokenPayload = {\n source: string;\n user: {\n id: string;\n name: string;\n email: string;\n projectId: string;\n };\n};\n\nconst DEFAULT_MAX_AGE = 60 * 10; // 10 minutes\nconst DEFAULT_SALT = process.env.STAGE === \"local\" ? \"dev\" : process.env.STAGE;\n\n/**\n * Uses Auth.js JWT encoding/decoding.\n * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts\n */\nexport async function createMCPToken(\n payload: MCPTokenPayload,\n options?: {\n secret?: string;\n salt?: string;\n maxAge?: number;\n },\n) {\n const maxAge = options?.maxAge ?? DEFAULT_MAX_AGE;\n const secret = options?.secret ?? process.env.MCP_TOKEN_SECRET;\n const salt = options?.salt ?? DEFAULT_SALT;\n if (!secret || !salt) {\n throw new Error(\"Secret or salt is not set\");\n }\n const token = await encode<MCPTokenPayload>({\n token: payload,\n secret,\n salt,\n maxAge,\n });\n return {\n token,\n expiresAt: new Date(Date.now() + maxAge * 1000),\n };\n}\n\n/**\n * Uses Auth.js JWT encoding/decoding.\n * @see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts\n */\nexport async function decodeMCPToken(\n token: string,\n options?: {\n secret?: string;\n salt?: string;\n },\n): Promise<MCPTokenPayload> {\n const secret = options?.secret ?? process.env.MCP_TOKEN_SECRET;\n const salt = options?.salt ?? DEFAULT_SALT;\n if (!secret || !salt) {\n throw new Error(\"Secret or salt is not set\");\n }\n const decoded = await decode<MCPTokenPayload>({\n token,\n secret,\n salt,\n });\n if (!decoded) {\n throw new Error(\"Invalid token\");\n }\n return decoded;\n}\n\nexport function getMcpToken(req: Request) {\n const mcpToken = req.headers.get(\"X-MCP-Token\");\n if (!mcpToken || typeof mcpToken !== \"string\") {\n throw new Error(\"Unauthorized\");\n }\n return mcpToken;\n}\n"],"mappings":";;;AAgBA,MAAM,kBAAkB;AACxB,MAAM,eAAe,QAAQ,IAAI,UAAU,UAAU,QAAQ,QAAQ,IAAI;;;;;AAMzE,eAAsB,eACpB,SACA,SAKA;;CACA,MAAM,8EAAS,QAAS,mEAAU;CAClC,MAAM,8EAAS,QAAS,mEAAU,QAAQ,IAAI;CAC9C,MAAM,0EAAO,QAAS,6DAAQ;AAC9B,KAAI,CAAC,UAAU,CAAC,KACd,OAAM,IAAI,MAAM,4BAA4B;AAQ9C,QAAO;EACL,OAPY,MAAM,OAAwB;GAC1C,OAAO;GACP;GACA;GACA;GACD,CAAC;EAGA,WAAW,IAAI,KAAK,KAAK,KAAK,GAAG,SAAS,IAAK;EAChD;;;;;;AAOH,eAAsB,eACpB,OACA,SAI0B;;CAC1B,MAAM,+EAAS,QAAS,qEAAU,QAAQ,IAAI;CAC9C,MAAM,2EAAO,QAAS,+DAAQ;AAC9B,KAAI,CAAC,UAAU,CAAC,KACd,OAAM,IAAI,MAAM,4BAA4B;CAE9C,MAAM,UAAU,MAAM,OAAwB;EAC5C;EACA;EACA;EACD,CAAC;AACF,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,gBAAgB;AAElC,QAAO;;AAGT,SAAgB,YAAY,KAAc;CACxC,MAAM,WAAW,IAAI,QAAQ,IAAI,cAAc;AAC/C,KAAI,CAAC,YAAY,OAAO,aAAa,SACnC,OAAM,IAAI,MAAM,eAAe;AAEjC,QAAO"}