@didit-protocol/mcp-server 5.1.36 → 5.1.51
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 +201 -29
- package/dist/app-api-key.d.ts +5 -0
- package/dist/app-api-key.d.ts.map +1 -0
- package/dist/app-api-key.js +108 -0
- package/dist/app-api-key.js.map +1 -0
- package/dist/auth/cached-verifier.d.ts +38 -0
- package/dist/auth/cached-verifier.d.ts.map +1 -0
- package/dist/auth/cached-verifier.js +82 -0
- package/dist/auth/cached-verifier.js.map +1 -0
- package/dist/auth/introspection-verifier.d.ts +12 -0
- package/dist/auth/introspection-verifier.d.ts.map +1 -1
- package/dist/auth/introspection-verifier.js +40 -14
- package/dist/auth/introspection-verifier.js.map +1 -1
- package/dist/chatgpt-app.d.ts +1 -0
- package/dist/chatgpt-app.d.ts.map +1 -1
- package/dist/chatgpt-app.js +2 -0
- package/dist/chatgpt-app.js.map +1 -1
- package/dist/config.d.ts +12 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +55 -8
- package/dist/config.js.map +1 -1
- package/dist/device-login.d.ts +98 -0
- package/dist/device-login.d.ts.map +1 -0
- package/dist/device-login.js +455 -0
- package/dist/device-login.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +61 -5
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +595 -47
- package/dist/index.js.map +1 -1
- package/dist/investigator-agent.d.ts +4 -0
- package/dist/investigator-agent.d.ts.map +1 -0
- package/dist/investigator-agent.js +10 -0
- package/dist/investigator-agent.js.map +1 -0
- package/dist/login-cli.d.ts +6 -0
- package/dist/login-cli.d.ts.map +1 -0
- package/dist/login-cli.js +47 -0
- package/dist/login-cli.js.map +1 -0
- package/dist/mcp-modern.d.ts +1 -0
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +1 -1
- package/dist/mcp-modern.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +29 -4
- package/dist/permissions.js.map +1 -1
- package/dist/privileged-tools.d.ts +1 -0
- package/dist/privileged-tools.d.ts.map +1 -1
- package/dist/privileged-tools.js +2 -1
- package/dist/privileged-tools.js.map +1 -1
- package/dist/schema/feature-config-schema.json +941 -28
- package/dist/security.d.ts +9 -8
- package/dist/security.d.ts.map +1 -1
- package/dist/security.js +11 -3
- package/dist/security.js.map +1 -1
- package/dist/signature-download.d.ts +31 -0
- package/dist/signature-download.d.ts.map +1 -0
- package/dist/signature-download.js +122 -0
- package/dist/signature-download.js.map +1 -0
- package/dist/tools/auth.d.ts +2 -0
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +114 -14
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/billing.d.ts +33 -2
- package/dist/tools/billing.d.ts.map +1 -1
- package/dist/tools/billing.js +252 -12
- package/dist/tools/billing.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +37 -0
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/investigator.d.ts +19 -0
- package/dist/tools/investigator.d.ts.map +1 -0
- package/dist/tools/investigator.js +449 -0
- package/dist/tools/investigator.js.map +1 -0
- package/dist/tools/members.d.ts +8 -0
- package/dist/tools/members.d.ts.map +1 -1
- package/dist/tools/members.js +73 -4
- package/dist/tools/members.js.map +1 -1
- package/dist/tools/observability.d.ts +6 -0
- package/dist/tools/observability.d.ts.map +1 -1
- package/dist/tools/observability.js +11 -3
- package/dist/tools/observability.js.map +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +89 -5
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/session-explain-levers.d.ts +6 -0
- package/dist/tools/session-explain-levers.d.ts.map +1 -1
- package/dist/tools/session-explain-levers.js +40 -7
- package/dist/tools/session-explain-levers.js.map +1 -1
- package/dist/tools/sessions.d.ts +24 -0
- package/dist/tools/sessions.d.ts.map +1 -1
- package/dist/tools/sessions.js +196 -2
- package/dist/tools/sessions.js.map +1 -1
- package/dist/tools/settings.d.ts.map +1 -1
- package/dist/tools/settings.js +3 -1
- package/dist/tools/settings.js.map +1 -1
- package/dist/tools/standalone.d.ts +5 -0
- package/dist/tools/standalone.d.ts.map +1 -1
- package/dist/tools/standalone.js +18 -2
- package/dist/tools/standalone.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applicationApiKeyHeaders = applicationApiKeyHeaders;
|
|
4
|
+
exports.applicationApiKey = applicationApiKey;
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const security_1 = require("./security");
|
|
7
|
+
// The application API key behind the standalone phone OTP endpoints.
|
|
8
|
+
//
|
|
9
|
+
// `POST /phone/send/` and `POST /phone/check/` are public product APIs, not console
|
|
10
|
+
// endpoints. Their only permission class is `IsValidClient` (service-didit-verification
|
|
11
|
+
// `core/permissions.py:183`), which accepts an introspected credential carrying NO
|
|
12
|
+
// `identifier`: an application `x-api-key`. A user Bearer always carries one
|
|
13
|
+
// (service-didit-auth `authorizations/processors/tokens.py:265`), so it is refused there.
|
|
14
|
+
//
|
|
15
|
+
// The other standalone tools reach their APIs through the console's user-Bearer proxy
|
|
16
|
+
// (`/organization/{org}/application/{app}/apis/<check>/`, gated on `create:sessions`),
|
|
17
|
+
// but that proxy registers only aml, id-verification, poa, kyb/*, phone-risk,
|
|
18
|
+
// email-risk, ip-risk and fraud-check (`applications/urls.py:1486-1573`): there is no
|
|
19
|
+
// `…/apis/phone/send/` or `…/apis/phone/check/`, and both answer 404 on staging and
|
|
20
|
+
// production. The application API key is therefore the only credential that works.
|
|
21
|
+
//
|
|
22
|
+
// The MCP reads it the two supported ways the auth service hands it to a user:
|
|
23
|
+
// 1. The console's application read, `GET /organizations/{org}/applications/{app}`
|
|
24
|
+
// (`organizations/views/application.py:86`): `read:applications` to read it at all,
|
|
25
|
+
// and `client_secret` is blanked unless the role holds `create:sessions`
|
|
26
|
+
// (`organizations/serializers/applications.py:100`), the same permission every other
|
|
27
|
+
// standalone tool needs. It only takes console-client tokens, which MCP sign-ins are.
|
|
28
|
+
// 2. When that read is refused outright (a local `didit_account_login` token is minted for
|
|
29
|
+
// the user's own application, not the console), the membership read
|
|
30
|
+
// `GET /organizations/me/{org}/applications/{app}/` returns it as `api_key`
|
|
31
|
+
// (`organizations/views/me.py:68`) to organization owners and admins only (`me.py:286`).
|
|
32
|
+
// That read checks the grant's organizations but not its scopes, so a sign-in refused
|
|
33
|
+
// for its scopes never falls back to it: the key stays behind the user's consent.
|
|
34
|
+
// Both blank a live application's key for a console browser session while staging's
|
|
35
|
+
// LIVE_PRIMARY_SECRET_REVEAL_ONLY is on (`organizations/services/secret_step_up.py:204`);
|
|
36
|
+
// MCP tokens are not console sessions and keep it.
|
|
37
|
+
//
|
|
38
|
+
// The key is a live secret. It is never cached in module state, never returned to a
|
|
39
|
+
// caller, never logged (audit-log.ts records argument keys and a digest only) and never
|
|
40
|
+
// interpolated into an error message.
|
|
41
|
+
// The auth service's refusal when an MCP sign-in's consented scopes do not cover the request
|
|
42
|
+
// (service-didit-auth `core/permissions.py:312`). The application read needs the
|
|
43
|
+
// `applications` resource, which only didit:management grants (`authorizations/config/mcp_scopes.py:50`).
|
|
44
|
+
const MCP_SCOPE_REFUSAL = /token's scope does not permit this action/;
|
|
45
|
+
/** Request headers for a public product API that authenticates with the application API key. */
|
|
46
|
+
async function applicationApiKeyHeaders() {
|
|
47
|
+
return { "Content-Type": "application/json", "x-api-key": await applicationApiKey() };
|
|
48
|
+
}
|
|
49
|
+
/** The resolved application's API key, read fresh on every call. */
|
|
50
|
+
async function applicationApiKey() {
|
|
51
|
+
const org = (0, security_1.pathSegment)((0, config_1.resolveOrganizationId)(), "organization_id");
|
|
52
|
+
const app = (0, security_1.pathSegment)((0, config_1.resolveApplicationId)(), "application_id");
|
|
53
|
+
let key;
|
|
54
|
+
try {
|
|
55
|
+
// The console detail route is declared WITHOUT a trailing slash (APPEND_SLASH only adds one).
|
|
56
|
+
const application = await (0, config_1.apiRequest)(`/organizations/${org}/applications/${app}`, {
|
|
57
|
+
baseUrl: config_1.DIDIT_AUTH_BASE_URL,
|
|
58
|
+
});
|
|
59
|
+
key = application?.client_secret;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!isForbidden(error))
|
|
63
|
+
throw error;
|
|
64
|
+
if (MCP_SCOPE_REFUSAL.test(error.shape.message)) {
|
|
65
|
+
throw new security_1.DiditError({
|
|
66
|
+
...error.shape,
|
|
67
|
+
code: "missing_scope",
|
|
68
|
+
hint: "These tools send the code with the application's API key, and reading it needs the " +
|
|
69
|
+
"didit:management scope, which this sign-in was not granted. Sign in to the Didit MCP " +
|
|
70
|
+
"connector again with didit:management as well as didit:verification.",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
key = await ownerOrAdminApplicationKey(`/organizations/me/${org}/applications/${app}/`);
|
|
74
|
+
}
|
|
75
|
+
if (typeof key !== "string" || !key.trim()) {
|
|
76
|
+
throw new security_1.DiditError({
|
|
77
|
+
code: "missing_scope",
|
|
78
|
+
message: "Didit returned no API key for this application to your sign-in.",
|
|
79
|
+
hint: "These tools send the code with the application's API key, which Didit only shows to a role " +
|
|
80
|
+
"holding create:sessions (Owner, Admin and Developer have it). A console browser session cannot " +
|
|
81
|
+
"read a live application's key where the console hides it: sign in through the Didit MCP " +
|
|
82
|
+
"connector instead.",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return key;
|
|
86
|
+
}
|
|
87
|
+
async function ownerOrAdminApplicationKey(path) {
|
|
88
|
+
try {
|
|
89
|
+
const application = await (0, config_1.apiRequest)(path, { baseUrl: config_1.DIDIT_AUTH_BASE_URL });
|
|
90
|
+
return application?.api_key;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// Say which roles can read the key instead of the generic "may require a different role".
|
|
94
|
+
if (isForbidden(error)) {
|
|
95
|
+
throw new security_1.DiditError({
|
|
96
|
+
...error.shape,
|
|
97
|
+
hint: "These tools send the code with the application's API key, and this sign-in cannot read it. " +
|
|
98
|
+
"Through the Didit MCP connector it needs a role with create:sessions (Owner, Admin or " +
|
|
99
|
+
"Developer); with a local didit_account_login token, an organization owner or admin.",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function isForbidden(error) {
|
|
106
|
+
return error instanceof security_1.DiditError && error.shape.status === 403;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=app-api-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-api-key.js","sourceRoot":"","sources":["../src/app-api-key.ts"],"names":[],"mappings":";;AA4CA,4DAEC;AAGD,8CAuCC;AAxFD,qCAAwG;AACxG,yCAAqD;AAErD,qEAAqE;AACrE,EAAE;AACF,oFAAoF;AACpF,wFAAwF;AACxF,mFAAmF;AACnF,6EAA6E;AAC7E,0FAA0F;AAC1F,EAAE;AACF,sFAAsF;AACtF,uFAAuF;AACvF,8EAA8E;AAC9E,sFAAsF;AACtF,oFAAoF;AACpF,mFAAmF;AACnF,EAAE;AACF,+EAA+E;AAC/E,qFAAqF;AACrF,yFAAyF;AACzF,8EAA8E;AAC9E,0FAA0F;AAC1F,2FAA2F;AAC3F,6FAA6F;AAC7F,yEAAyE;AACzE,iFAAiF;AACjF,8FAA8F;AAC9F,2FAA2F;AAC3F,uFAAuF;AACvF,oFAAoF;AACpF,0FAA0F;AAC1F,mDAAmD;AACnD,EAAE;AACF,oFAAoF;AACpF,wFAAwF;AACxF,sCAAsC;AAEtC,6FAA6F;AAC7F,iFAAiF;AACjF,0GAA0G;AAC1G,MAAM,iBAAiB,GAAG,2CAA2C,CAAC;AAEtE,gGAAgG;AACzF,KAAK,UAAU,wBA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AiG;gBACjG,0FAA0F;gBAC1F,oBAAoB;SACvB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,KAAK,UAAU,0BAA0B,CAAC,IAAY;IACpD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,IAAA,mBAAU,EAAC,IAAI,EAAE,EAAE,OAAO,EAAE,4BAAmB,EAAE,CAAC,CAAC;QAE7E,OAAO,WAAW,EAAE,OAAO,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0FAA0F;QAC1F,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,qBAAU,CAAC;gBACnB,GAAG,KAAK,CAAC,KAAK;gBACd,IAAI,EACF,6FAA6F;oBAC7F,wFAAwF;oBACxF,qFAAqF;aACxF,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,qBAAU,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { OAuthTokenVerifier } from "@modelcontextprotocol/sdk/server/auth/provider.js";
|
|
2
|
+
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Remembers an ACCEPTED access token for a short while, so a burst of MCP
|
|
5
|
+
* requests from one client costs one introspection instead of one per request.
|
|
6
|
+
*
|
|
7
|
+
* Why: the hosted MCP is stateless, so every JSON-RPC message (`initialize`,
|
|
8
|
+
* `notifications/initialized`, `tools/list`, each tool call) is its own
|
|
9
|
+
* authenticated POST, and each POST introspected the token at
|
|
10
|
+
* service-didit-auth. In production on 2026-11-03 that introspection took
|
|
11
|
+
* p50 ~1.7 s around the busy 10-minute marks (about 0.05 s otherwise), and
|
|
12
|
+
* every MCP request waited on it. Ask Didit's tool listing (three such
|
|
13
|
+
* requests for a new connection) then ran past its 4 s budget on both
|
|
14
|
+
* attempts 27 times on 2 and 3 November, and the user got a turn without
|
|
15
|
+
* Didit tools.
|
|
16
|
+
*
|
|
17
|
+
* - Only successes are cached. A rejected token, and an auth service that did
|
|
18
|
+
* not answer, are never remembered: the next request asks again.
|
|
19
|
+
* - An entry lives at most `ttlMs`, and never past the token's own expiry.
|
|
20
|
+
* - Revocation lag is bounded by `ttlMs`: a revoked token can keep reaching the
|
|
21
|
+
* MCP for at most that long, and every Didit API call a tool makes still
|
|
22
|
+
* re-checks the token at the API itself.
|
|
23
|
+
* - Concurrent requests for one token share a single in-flight introspection.
|
|
24
|
+
* - Keys are SHA-256 hashes, so the process never keeps raw tokens as keys,
|
|
25
|
+
* and the map is bounded (oldest entry out first).
|
|
26
|
+
*/
|
|
27
|
+
export declare class CachingTokenVerifier implements OAuthTokenVerifier {
|
|
28
|
+
private readonly inner;
|
|
29
|
+
private readonly ttlMs;
|
|
30
|
+
private readonly maxEntries;
|
|
31
|
+
private readonly now;
|
|
32
|
+
private readonly entries;
|
|
33
|
+
private readonly inflight;
|
|
34
|
+
constructor(inner: OAuthTokenVerifier, ttlMs: number, maxEntries?: number, now?: () => number);
|
|
35
|
+
verifyAccessToken(token: string): Promise<AuthInfo>;
|
|
36
|
+
private remember;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=cached-verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached-verifier.d.ts","sourceRoot":"","sources":["../../src/auth/cached-verifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,oBAAqB,YAAW,kBAAkB;IAK3D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4D;IACpF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;gBAG9C,KAAK,EAAE,kBAAkB,EACzB,KAAK,EAAE,MAAM,EACb,UAAU,SAAQ,EAClB,GAAG,GAAE,MAAM,MAAiB;IAGzC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAsBzD,OAAO,CAAC,QAAQ;CAYjB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachingTokenVerifier = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
/**
|
|
6
|
+
* Remembers an ACCEPTED access token for a short while, so a burst of MCP
|
|
7
|
+
* requests from one client costs one introspection instead of one per request.
|
|
8
|
+
*
|
|
9
|
+
* Why: the hosted MCP is stateless, so every JSON-RPC message (`initialize`,
|
|
10
|
+
* `notifications/initialized`, `tools/list`, each tool call) is its own
|
|
11
|
+
* authenticated POST, and each POST introspected the token at
|
|
12
|
+
* service-didit-auth. In production on 2026-11-03 that introspection took
|
|
13
|
+
* p50 ~1.7 s around the busy 10-minute marks (about 0.05 s otherwise), and
|
|
14
|
+
* every MCP request waited on it. Ask Didit's tool listing (three such
|
|
15
|
+
* requests for a new connection) then ran past its 4 s budget on both
|
|
16
|
+
* attempts 27 times on 2 and 3 November, and the user got a turn without
|
|
17
|
+
* Didit tools.
|
|
18
|
+
*
|
|
19
|
+
* - Only successes are cached. A rejected token, and an auth service that did
|
|
20
|
+
* not answer, are never remembered: the next request asks again.
|
|
21
|
+
* - An entry lives at most `ttlMs`, and never past the token's own expiry.
|
|
22
|
+
* - Revocation lag is bounded by `ttlMs`: a revoked token can keep reaching the
|
|
23
|
+
* MCP for at most that long, and every Didit API call a tool makes still
|
|
24
|
+
* re-checks the token at the API itself.
|
|
25
|
+
* - Concurrent requests for one token share a single in-flight introspection.
|
|
26
|
+
* - Keys are SHA-256 hashes, so the process never keeps raw tokens as keys,
|
|
27
|
+
* and the map is bounded (oldest entry out first).
|
|
28
|
+
*/
|
|
29
|
+
class CachingTokenVerifier {
|
|
30
|
+
constructor(inner, ttlMs, maxEntries = 5000, now = Date.now) {
|
|
31
|
+
this.inner = inner;
|
|
32
|
+
this.ttlMs = ttlMs;
|
|
33
|
+
this.maxEntries = maxEntries;
|
|
34
|
+
this.now = now;
|
|
35
|
+
this.entries = new Map();
|
|
36
|
+
this.inflight = new Map();
|
|
37
|
+
}
|
|
38
|
+
async verifyAccessToken(token) {
|
|
39
|
+
if (this.ttlMs <= 0)
|
|
40
|
+
return this.inner.verifyAccessToken(token);
|
|
41
|
+
const key = (0, node_crypto_1.createHash)("sha256").update(token).digest("hex");
|
|
42
|
+
const hit = this.entries.get(key);
|
|
43
|
+
if (hit && hit.expiresAt > this.now())
|
|
44
|
+
return copyOf(hit.info);
|
|
45
|
+
if (hit)
|
|
46
|
+
this.entries.delete(key);
|
|
47
|
+
const pending = this.inflight.get(key);
|
|
48
|
+
if (pending)
|
|
49
|
+
return copyOf(await pending);
|
|
50
|
+
const verifying = this.inner.verifyAccessToken(token);
|
|
51
|
+
this.inflight.set(key, verifying);
|
|
52
|
+
try {
|
|
53
|
+
const info = await verifying;
|
|
54
|
+
this.remember(key, info);
|
|
55
|
+
return copyOf(info);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
this.inflight.delete(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
remember(key, info) {
|
|
62
|
+
const now = this.now();
|
|
63
|
+
const tokenExpiry = typeof info.expiresAt === "number" ? info.expiresAt * 1000 : Infinity;
|
|
64
|
+
const expiresAt = Math.min(now + this.ttlMs, tokenExpiry);
|
|
65
|
+
if (expiresAt <= now)
|
|
66
|
+
return;
|
|
67
|
+
while (this.entries.size >= this.maxEntries) {
|
|
68
|
+
const oldest = this.entries.keys().next().value;
|
|
69
|
+
if (oldest === undefined)
|
|
70
|
+
break;
|
|
71
|
+
this.entries.delete(oldest);
|
|
72
|
+
}
|
|
73
|
+
this.entries.set(key, { info, expiresAt });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.CachingTokenVerifier = CachingTokenVerifier;
|
|
77
|
+
/** Each request gets its own object, so a handler that edits its AuthInfo can
|
|
78
|
+
* never change what a later request of the same token sees. */
|
|
79
|
+
function copyOf(info) {
|
|
80
|
+
return { ...info, scopes: [...info.scopes], ...(info.extra && { extra: { ...info.extra } }) };
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=cached-verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached-verifier.js","sourceRoot":"","sources":["../../src/auth/cached-verifier.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAIzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,oBAAoB;IAI/B,YACmB,KAAyB,EACzB,KAAa,EACb,aAAa,IAAK,EAClB,MAAoB,IAAI,CAAC,GAAG;QAH5B,UAAK,GAAL,KAAK,CAAoB;QACzB,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAQ;QAClB,QAAG,GAAH,GAAG,CAAyB;QAP9B,YAAO,GAAG,IAAI,GAAG,EAAiD,CAAC;QACnE,aAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IAO9D,CAAC;IAEJ,KAAK,CAAC,iBAAiB,CAAC,KAAa;QACnC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAEhE,MAAM,GAAG,GAAG,IAAA,wBAAU,EAAC,QAAQ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,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,SAAS,IAAI,GAAG;YAAE,OAAO;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAChD,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF;AA7CD,oDA6CC;AAED;+DAC+D;AAC/D,SAAS,MAAM,CAAC,IAAc;IAC5B,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -11,6 +11,18 @@ import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class IntrospectionTokenVerifier implements OAuthTokenVerifier {
|
|
13
13
|
private readonly basic;
|
|
14
|
+
/**
|
|
15
|
+
* The introspection answer, or null when the auth service SAID the token is not valid (a 4xx
|
|
16
|
+
* other than 429).
|
|
17
|
+
*
|
|
18
|
+
* An auth service that does not answer is not an invalid token. Until 2026-11-04 a timeout, a
|
|
19
|
+
* network error or a 5xx became `invalid_token` (401), and the assistant told the user "your
|
|
20
|
+
* Didit session has expired, sign in again" in the middle of a workflow build (local first-try
|
|
21
|
+
* run of the staging demo prompt: "Introspection request failed: TimeoutError"). It is retried
|
|
22
|
+
* once and, if the service still does not answer, reported as a server error (500), which the
|
|
23
|
+
* caller can retry, never as a reason to sign in again.
|
|
24
|
+
*/
|
|
25
|
+
private introspect;
|
|
14
26
|
verifyAccessToken(token: string): Promise<AuthInfo>;
|
|
15
27
|
}
|
|
16
28
|
//# sourceMappingURL=introspection-verifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"introspection-verifier.d.ts","sourceRoot":"","sources":["../../src/auth/introspection-verifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"introspection-verifier.d.ts","sourceRoot":"","sources":["../../src/auth/introspection-verifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAgB/E;;;;;;;;GAQG;AACH,qBAAa,0BAA2B,YAAW,kBAAkB;IACnE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkG;IAExH;;;;;;;;;;OAUG;YACW,UAAU;IAwBlB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAwC1D"}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IntrospectionTokenVerifier = void 0;
|
|
4
4
|
const errors_js_1 = require("@modelcontextprotocol/sdk/server/auth/errors.js");
|
|
5
5
|
const config_1 = require("../config");
|
|
6
|
+
/** Attempts at the auth service per verification: one retry for a timeout, a network error, a 429 or a 5xx. */
|
|
7
|
+
const INTROSPECTION_ATTEMPTS = 2;
|
|
6
8
|
/**
|
|
7
9
|
* RFC 7662 token-introspection verifier — the correct path for service-didit-auth,
|
|
8
10
|
* whose OIDC authorization-code flow issues opaque access tokens. Mirrors the contract
|
|
@@ -16,24 +18,48 @@ class IntrospectionTokenVerifier {
|
|
|
16
18
|
constructor() {
|
|
17
19
|
this.basic = "Basic " + Buffer.from(`${config_1.MCP_OAUTH_CLIENT_ID}:${config_1.MCP_OAUTH_CLIENT_SECRET}`).toString("base64");
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The introspection answer, or null when the auth service SAID the token is not valid (a 4xx
|
|
23
|
+
* other than 429).
|
|
24
|
+
*
|
|
25
|
+
* An auth service that does not answer is not an invalid token. Until 2026-11-04 a timeout, a
|
|
26
|
+
* network error or a 5xx became `invalid_token` (401), and the assistant told the user "your
|
|
27
|
+
* Didit session has expired, sign in again" in the middle of a workflow build (local first-try
|
|
28
|
+
* run of the staging demo prompt: "Introspection request failed: TimeoutError"). It is retried
|
|
29
|
+
* once and, if the service still does not answer, reported as a server error (500), which the
|
|
30
|
+
* caller can retry, never as a reason to sign in again.
|
|
31
|
+
*/
|
|
32
|
+
async introspect(body) {
|
|
33
|
+
let failure = "";
|
|
34
|
+
for (let attempt = 1; attempt <= INTROSPECTION_ATTEMPTS; attempt++) {
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(config_1.MCP_OAUTH_INTROSPECT_URL, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: { "Content-Type": "application/json", Authorization: this.basic, [config_1.AGENT_HEADER]: config_1.AGENT_HEADER_VALUE },
|
|
39
|
+
body: JSON.stringify(body),
|
|
40
|
+
signal: AbortSignal.timeout(8000),
|
|
41
|
+
});
|
|
42
|
+
if (res.ok)
|
|
43
|
+
return (await res.json());
|
|
44
|
+
// service-didit-auth answers a token it refuses with a 4xx, not only with
|
|
45
|
+
// `active: false`: AuthenticationFailed("Invalid token") / deleted or disabled
|
|
46
|
+
// user is a 401 (authorizations/views/tokens.py). A 429 is the service
|
|
47
|
+
// throttling, not a verdict on the token, so it is retried like a 5xx.
|
|
48
|
+
if (res.status < 500 && res.status !== 429)
|
|
49
|
+
return null;
|
|
50
|
+
failure = `HTTP ${res.status}`;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
failure = String(err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new errors_js_1.ServerError(`Token introspection unavailable: ${failure}`);
|
|
57
|
+
}
|
|
19
58
|
async verifyAccessToken(token) {
|
|
20
59
|
const body = { token };
|
|
21
60
|
if (config_1.MCP_DEFAULT_ORG)
|
|
22
61
|
body.requested_org = config_1.MCP_DEFAULT_ORG;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const res = await fetch(config_1.MCP_OAUTH_INTROSPECT_URL, {
|
|
26
|
-
method: "POST",
|
|
27
|
-
headers: { "Content-Type": "application/json", Authorization: this.basic },
|
|
28
|
-
body: JSON.stringify(body),
|
|
29
|
-
signal: AbortSignal.timeout(8000),
|
|
30
|
-
});
|
|
31
|
-
if (res.ok)
|
|
32
|
-
data = (await res.json());
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
throw new errors_js_1.InvalidTokenError(`Introspection request failed: ${String(err)}`);
|
|
36
|
-
}
|
|
62
|
+
const data = await this.introspect(body);
|
|
37
63
|
// RFC 7662: `active` is REQUIRED and authoritative. Treat anything other than an
|
|
38
64
|
// explicit true (including a response that omits the field) as inactive.
|
|
39
65
|
if (!data || data.active !== true) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"introspection-verifier.js","sourceRoot":"","sources":["../../src/auth/introspection-verifier.ts"],"names":[],"mappings":";;;AAEA,+
|
|
1
|
+
{"version":3,"file":"introspection-verifier.js","sourceRoot":"","sources":["../../src/auth/introspection-verifier.ts"],"names":[],"mappings":";;;AAEA,+EAAiG;AAEjG,sCAQmB;AAEnB,+GAA+G;AAC/G,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAa,0BAA0B;IAAvC;QACmB,UAAK,GAAG,QAAQ,G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,IAAI,CAAC,OAAO;gBAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,uFAAuF;gBACvF,0FAA0F;gBAC1F,aAAa,EAAE,IAAI,CAAC,QAAQ,KAAK,IAAI;gBACrC,eAAe,EAAE,IAAI,CAAC,eAAe,KAAK,IAAI;aAC/C;SACF,CAAC;IACJ,CAAC;CACF;AA9ED,gEA8EC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IACzF,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzE,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/chatgpt-app.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare function widgetToolMeta(_profile: CatalogProfile, _name: string):
|
|
|
31
31
|
export declare function widgetTools(_profile: CatalogProfile): Record<string, unknown>[];
|
|
32
32
|
export declare function stdioCatalogProfile(): CatalogProfile;
|
|
33
33
|
export declare function mountDomainChallenge(_app: Express): void;
|
|
34
|
+
export declare function mountWidgetFonts(_app: Express): void;
|
|
34
35
|
export interface ProfileEndpoint {
|
|
35
36
|
path: string;
|
|
36
37
|
profile: CatalogProfile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatgpt-app.d.ts","sourceRoot":"","sources":["../src/chatgpt-app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAQ9E,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC1B,I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GAAG,IAAI,CAAG;AAE5D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAG;AAExD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,GAAG,CAAC;CAClB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE;IAAE,aAAa,EAAE,aAAa,CAAC;IAAC,iBAAiB,EAAE,GAAG,CAAC;IAAC,eAAe,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5F,eAAe,GAAG,SAAS,CAE7B"}
|
package/dist/chatgpt-app.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.widgetToolMeta = widgetToolMeta;
|
|
|
12
12
|
exports.widgetTools = widgetTools;
|
|
13
13
|
exports.stdioCatalogProfile = stdioCatalogProfile;
|
|
14
14
|
exports.mountDomainChallenge = mountDomainChallenge;
|
|
15
|
+
exports.mountWidgetFonts = mountWidgetFonts;
|
|
15
16
|
exports.mountProfileEndpoint = mountProfileEndpoint;
|
|
16
17
|
function applyCatalogProfile(tools, _profile) {
|
|
17
18
|
return [...tools];
|
|
@@ -46,6 +47,7 @@ function stdioCatalogProfile() {
|
|
|
46
47
|
return "full";
|
|
47
48
|
}
|
|
48
49
|
function mountDomainChallenge(_app) { }
|
|
50
|
+
function mountWidgetFonts(_app) { }
|
|
49
51
|
function mountProfileEndpoint(_app, _options) {
|
|
50
52
|
return undefined;
|
|
51
53
|
}
|
package/dist/chatgpt-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatgpt-app.js","sourceRoot":"","sources":["../src/chatgpt-app.ts"],"names":[],"mappings":";;;AAiBA,kDAEC;AAED,gDAEC;AAED,sDAMC;AAKD,8CAEC;AAED,oDAEC;AAED,kDAEC;AAED,gDAEC;AAED,wCAEC;AAED,kCAEC;AAED,kDAEC;AAED,oDAA4D;
|
|
1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,CAAC,IAAa,IAAS,CAAC;AAE5D,SAAgB,gBAAgB,CAAC,IAAa,IAAS,CAAC;AAQxD,SAAgB,oBAAoB,CAClC,IAAa,EACb,QAA6F;IAE7F,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -10,12 +10,14 @@ export declare function permissionMode(): "shadow" | "enforce" | "off";
|
|
|
10
10
|
export declare const DIDIT_AUTH_BASE_URL: string;
|
|
11
11
|
export declare const DIDIT_API_BASE_URL: string;
|
|
12
12
|
export declare const MCP_PORT: number;
|
|
13
|
+
export declare const MCP_PAYMENTS_PATH = "/mcp/payments";
|
|
13
14
|
export declare const MCP_RESOURCE_URI: string;
|
|
14
15
|
export declare const MCP_OAUTH_CLIENT_ID: string;
|
|
15
16
|
export declare const MCP_OAUTH_CLIENT_SECRET: string;
|
|
16
17
|
export declare const MCP_TOKEN_VERIFY_MODE: string;
|
|
17
18
|
export declare const MCP_OAUTH_INTROSPECT_URL: string;
|
|
18
19
|
export declare const MCP_DEFAULT_ORG: string;
|
|
20
|
+
export declare const MCP_INTROSPECTION_CACHE_TTL_MS: number;
|
|
19
21
|
export declare const MCP_PUBLIC_DISCOVERY: boolean;
|
|
20
22
|
export declare const MCP_DEFAULT_APP: string;
|
|
21
23
|
export declare const MCP_AUTHORIZATION_SERVER_ORIGIN: string;
|
|
@@ -33,7 +35,8 @@ export declare const MCP_SCOPES_SUPPORTED: string[];
|
|
|
33
35
|
* so every tool authenticates as that user WITHOUT any tool-signature change. In stdio
|
|
34
36
|
* mode the same Bearer is supplied via the DIDIT_ACCESS_TOKEN env var. There is NO
|
|
35
37
|
* API-key mode — every tool targets the user-scoped console endpoints, which only
|
|
36
|
-
* authorize a Bearer token (an x-api-key is rejected).
|
|
38
|
+
* authorize a Bearer token (an x-api-key is rejected). The phone OTP pair is the one
|
|
39
|
+
* exception: it reads the application's key with that Bearer (app-api-key.ts).
|
|
37
40
|
*/
|
|
38
41
|
export interface RequestCredentials {
|
|
39
42
|
accessToken?: string;
|
|
@@ -41,6 +44,9 @@ export interface RequestCredentials {
|
|
|
41
44
|
applicationId?: string;
|
|
42
45
|
/** Tool being dispatched — sent as User-Agent so the backend audit log attributes the request. */
|
|
43
46
|
toolName?: string;
|
|
47
|
+
/** Where the user acted from, sent to the Investigator as X-Didit-Actor-Via: "copilot" when the
|
|
48
|
+
* console assistant said so on the MCP request, otherwise "mcp". */
|
|
49
|
+
actorVia?: "copilot" | "mcp";
|
|
44
50
|
}
|
|
45
51
|
export declare const requestContext: AsyncLocalStorage<RequestCredentials>;
|
|
46
52
|
/**
|
|
@@ -74,12 +80,15 @@ export declare function orgPath(resource: string, opts?: {
|
|
|
74
80
|
* there attributed to its tool without any backend change.
|
|
75
81
|
*/
|
|
76
82
|
export declare function userAgent(): string;
|
|
83
|
+
/** Sent on every backend request the MCP server makes (apiRequest and the other Didit-bound fetches). */
|
|
84
|
+
export declare const AGENT_HEADER = "X-Didit-Agent";
|
|
85
|
+
export declare const AGENT_HEADER_VALUE = "mcp";
|
|
77
86
|
export declare function getHeaders(): Record<string, string>;
|
|
78
87
|
export declare function getMultipartHeaders(): Record<string, string>;
|
|
79
88
|
export declare function getAuthHeaders(accessToken: string): Record<string, string>;
|
|
80
89
|
export interface ApiRequestOptions {
|
|
81
|
-
/** Preserve the original
|
|
82
|
-
responseType?: "pdf";
|
|
90
|
+
/** Preserve the original file bytes (PDF or PNG) instead of decoding them as text. */
|
|
91
|
+
responseType?: "pdf" | "png";
|
|
83
92
|
method?: string;
|
|
84
93
|
/** JSON request body. */
|
|
85
94
|
json?: any;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAW7C,eAAO,MAAM,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5D;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK1E;AAQD,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,YAAY,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,oHAAoH;IACpH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC,CAgEzF;AA4BD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,EACtD,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAChC,QAAQ,CAcV;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAKlF"}
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestContext = exports.MCP_SCOPES_SUPPORTED = exports.DIDIT_OIDC_REGISTRATION_URL = exports.DIDIT_OIDC_TOKEN_URL = exports.DIDIT_OIDC_AUTHORIZE_URL = exports.DIDIT_JWKS_URL = exports.DIDIT_OIDC_DISCOVERY_URL = exports.DIDIT_AUTH_ISSUER = exports.MCP_AUTHORIZATION_SERVER_ORIGIN = exports.MCP_DEFAULT_APP = exports.MCP_PUBLIC_DISCOVERY = exports.MCP_DEFAULT_ORG = exports.MCP_OAUTH_INTROSPECT_URL = exports.MCP_TOKEN_VERIFY_MODE = exports.MCP_OAUTH_CLIENT_SECRET = exports.MCP_OAUTH_CLIENT_ID = exports.MCP_RESOURCE_URI = exports.MCP_PORT = exports.DIDIT_API_BASE_URL = exports.DIDIT_AUTH_BASE_URL = exports.SERVER_VERSION = void 0;
|
|
3
|
+
exports.AGENT_HEADER_VALUE = exports.AGENT_HEADER = exports.requestContext = exports.MCP_SCOPES_SUPPORTED = exports.DIDIT_OIDC_REGISTRATION_URL = exports.DIDIT_OIDC_TOKEN_URL = exports.DIDIT_OIDC_AUTHORIZE_URL = exports.DIDIT_JWKS_URL = exports.DIDIT_OIDC_DISCOVERY_URL = exports.DIDIT_AUTH_ISSUER = exports.MCP_AUTHORIZATION_SERVER_ORIGIN = exports.MCP_DEFAULT_APP = exports.MCP_PUBLIC_DISCOVERY = exports.MCP_INTROSPECTION_CACHE_TTL_MS = exports.MCP_DEFAULT_ORG = exports.MCP_OAUTH_INTROSPECT_URL = exports.MCP_TOKEN_VERIFY_MODE = exports.MCP_OAUTH_CLIENT_SECRET = exports.MCP_OAUTH_CLIENT_ID = exports.MCP_RESOURCE_URI = exports.MCP_PAYMENTS_PATH = exports.MCP_PORT = exports.DIDIT_API_BASE_URL = exports.DIDIT_AUTH_BASE_URL = exports.SERVER_VERSION = void 0;
|
|
4
4
|
exports.permissionMode = permissionMode;
|
|
5
5
|
exports.resolveOrganizationId = resolveOrganizationId;
|
|
6
6
|
exports.resolveApplicationId = resolveApplicationId;
|
|
@@ -43,6 +43,8 @@ exports.DIDIT_API_BASE_URL = process.env.DIDIT_API_BASE_URL || "https://verifica
|
|
|
43
43
|
exports.MCP_PORT = parseInt(process.env.MCP_PORT || "3000", 10);
|
|
44
44
|
// The RFC 8707 / RFC 9728 resource identifier for this MCP server.
|
|
45
45
|
// It must match the actual Streamable HTTP transport endpoint.
|
|
46
|
+
// Unlisted hosted endpoint that also offers didit_org_top_up (agent payments); see http.ts.
|
|
47
|
+
exports.MCP_PAYMENTS_PATH = "/mcp/payments";
|
|
46
48
|
exports.MCP_RESOURCE_URI = process.env.MCP_RESOURCE_URI || "https://mcp.didit.me/mcp";
|
|
47
49
|
// The dedicated OAuth client registered in service-didit-auth for the MCP.
|
|
48
50
|
exports.MCP_OAUTH_CLIENT_ID = process.env.MCP_OAUTH_CLIENT_ID || "";
|
|
@@ -57,6 +59,16 @@ exports.MCP_TOKEN_VERIFY_MODE = (process.env.MCP_TOKEN_VERIFY_MODE || "introspec
|
|
|
57
59
|
exports.MCP_OAUTH_INTROSPECT_URL = process.env.MCP_OAUTH_INTROSPECT_URL || "https://apx.didit.me/auth/v2/introspect/";
|
|
58
60
|
// Optional: for single-org MCP deployments, the org to scope introspection to.
|
|
59
61
|
exports.MCP_DEFAULT_ORG = process.env.MCP_DEFAULT_ORG || "";
|
|
62
|
+
// How long an accepted token is remembered before it is introspected again (auth/cached-verifier.ts).
|
|
63
|
+
// Every MCP request is its own authenticated POST; 0 introspects every one of them.
|
|
64
|
+
// A mistyped or negative value falls back to the default rather than turning the cache off.
|
|
65
|
+
exports.MCP_INTROSPECTION_CACHE_TTL_MS = nonNegativeMs(process.env.MCP_INTROSPECTION_CACHE_TTL_MS, 60000);
|
|
66
|
+
function nonNegativeMs(raw, fallback) {
|
|
67
|
+
if (raw === undefined || raw.trim() === "")
|
|
68
|
+
return fallback;
|
|
69
|
+
const value = Number(raw);
|
|
70
|
+
return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
71
|
+
}
|
|
60
72
|
// "Mixed auth" (MCP 2026-07-28 + RFC 9728): serve the PROTOCOL-NEGOTIATION surface without a
|
|
61
73
|
// Bearer, and keep every tool behind OAuth exactly as before. `initialize`, its notification,
|
|
62
74
|
// and `server/discover` return only the server name, version, capabilities and supported
|
|
@@ -126,6 +138,7 @@ function orgPath(resource, opts = {}) {
|
|
|
126
138
|
* Auth headers for the Didit APIs. The MCP always authenticates as a Didit user via a
|
|
127
139
|
* Bearer access token (from the OAuth flow in hosted mode, or DIDIT_ACCESS_TOKEN in stdio
|
|
128
140
|
* mode). There is no API-key path — the user-scoped console endpoints reject x-api-key.
|
|
141
|
+
* Only the phone OTP pair passes its own x-api-key headers (app-api-key.ts).
|
|
129
142
|
*/
|
|
130
143
|
function authHeaders() {
|
|
131
144
|
const ctx = exports.requestContext.getStore();
|
|
@@ -149,6 +162,9 @@ function userAgent() {
|
|
|
149
162
|
const tool = exports.requestContext.getStore()?.toolName;
|
|
150
163
|
return `didit-mcp-server/${exports.SERVER_VERSION}${tool ? ` tool/${tool}` : ""}`;
|
|
151
164
|
}
|
|
165
|
+
/** Sent on every backend request the MCP server makes (apiRequest and the other Didit-bound fetches). */
|
|
166
|
+
exports.AGENT_HEADER = "X-Didit-Agent";
|
|
167
|
+
exports.AGENT_HEADER_VALUE = "mcp";
|
|
152
168
|
function getHeaders() {
|
|
153
169
|
return { "Content-Type": "application/json", ...authHeaders() };
|
|
154
170
|
}
|
|
@@ -162,6 +178,11 @@ function getAuthHeaders(accessToken) {
|
|
|
162
178
|
Authorization: `Bearer ${accessToken}`,
|
|
163
179
|
};
|
|
164
180
|
}
|
|
181
|
+
/** Binary bodies apiRequest returns as bytes: the content type and file signature both have to match. */
|
|
182
|
+
const BINARY_RESPONSES = {
|
|
183
|
+
pdf: { contentType: "application/pdf", magic: Buffer.from("%PDF-", "ascii"), label: "PDF report" },
|
|
184
|
+
png: { contentType: "image/png", magic: Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), label: "PNG image" },
|
|
185
|
+
};
|
|
165
186
|
/**
|
|
166
187
|
* Single entry point for every Didit HTTP call. Centralizes auth headers, query
|
|
167
188
|
* building, 204 handling, and — importantly — error handling: a non-2xx response
|
|
@@ -178,8 +199,10 @@ async function apiRequest(path, opts = {}) {
|
|
|
178
199
|
}
|
|
179
200
|
}
|
|
180
201
|
const resolvedHeaders = headers ?? (form ? getMultipartHeaders() : getHeaders());
|
|
181
|
-
|
|
182
|
-
|
|
202
|
+
// X-Didit-Agent marks every request as agent-originated: the backend refuses settings changes
|
|
203
|
+
// that carry it (the agent top-up switch is a person's decision). Last, so a caller cannot drop it.
|
|
204
|
+
const init = { method, headers: { "User-Agent": userAgent(), ...resolvedHeaders, [exports.AGENT_HEADER]: exports.AGENT_HEADER_VALUE } };
|
|
205
|
+
if (opts.responseType) {
|
|
183
206
|
init.redirect = "error";
|
|
184
207
|
init.signal = AbortSignal.timeout(60000);
|
|
185
208
|
}
|
|
@@ -190,13 +213,14 @@ async function apiRequest(path, opts = {}) {
|
|
|
190
213
|
init.body = JSON.stringify(json);
|
|
191
214
|
}
|
|
192
215
|
const res = await fetch(url.toString(), init);
|
|
193
|
-
if (res.ok && opts.responseType
|
|
194
|
-
|
|
195
|
-
|
|
216
|
+
if (res.ok && opts.responseType) {
|
|
217
|
+
const binary = BINARY_RESPONSES[opts.responseType];
|
|
218
|
+
if (res.headers.get("content-type")?.split(";")[0].trim().toLowerCase() !== binary.contentType) {
|
|
219
|
+
throw new Error(`Didit did not return a ${binary.label}.`);
|
|
196
220
|
}
|
|
197
221
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
198
|
-
if (bytes.subarray(0,
|
|
199
|
-
throw new Error(
|
|
222
|
+
if (!bytes.subarray(0, binary.magic.length).equals(binary.magic)) {
|
|
223
|
+
throw new Error(`Didit returned an invalid ${binary.label}.`);
|
|
200
224
|
}
|
|
201
225
|
return bytes;
|
|
202
226
|
}
|
|
@@ -221,10 +245,33 @@ async function apiRequest(path, opts = {}) {
|
|
|
221
245
|
field: parsed.field,
|
|
222
246
|
allowed: parsed.allowed,
|
|
223
247
|
status: res.status,
|
|
248
|
+
...backendAction(body),
|
|
224
249
|
});
|
|
225
250
|
}
|
|
226
251
|
return body;
|
|
227
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* A refusal the backend answers with its own machine code and a `next_step` (action, url,
|
|
255
|
+
* description) - the agent top-up route does - keeps both, unchanged, so the model can hand the
|
|
256
|
+
* person the console link. Bodies without them add nothing.
|
|
257
|
+
*/
|
|
258
|
+
function backendAction(body) {
|
|
259
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
260
|
+
return {};
|
|
261
|
+
// 403 `sso_required` (service-didit-auth): the account's organization enforces SSO. Its machine code
|
|
262
|
+
// is under `error`, with the organization named beside it.
|
|
263
|
+
if (body.error === "sso_required") {
|
|
264
|
+
const text = (value) => (typeof value === "string" && value ? value.slice(0, 200) : undefined);
|
|
265
|
+
const name = text(body.organization_name);
|
|
266
|
+
const slug = text(body.organization_slug);
|
|
267
|
+
return { backend_code: "sso_required", ...(name || slug ? { sso_organization: { name, slug } } : {}) };
|
|
268
|
+
}
|
|
269
|
+
const nextStep = body.next_step && typeof body.next_step === "object" && !Array.isArray(body.next_step) ? body.next_step : undefined;
|
|
270
|
+
return {
|
|
271
|
+
...(typeof body.code === "string" && body.code ? { backend_code: body.code } : {}),
|
|
272
|
+
...(nextStep ? { next_step: nextStep } : {}),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
228
275
|
/**
|
|
229
276
|
* Build a multipart/form-data body from file inputs and optional scalar fields.
|
|
230
277
|
* Shared by the standalone image endpoints and branding customization. Each
|