@didit-protocol/mcp-server 5.1.51 → 5.1.53
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 +156 -14
- package/dist/account-session.d.ts +46 -0
- package/dist/account-session.d.ts.map +1 -0
- package/dist/account-session.js +262 -0
- package/dist/account-session.js.map +1 -0
- package/dist/api-key-connection.d.ts +77 -0
- package/dist/api-key-connection.d.ts.map +1 -0
- package/dist/api-key-connection.js +170 -0
- package/dist/api-key-connection.js.map +1 -0
- package/dist/app-api-key.d.ts.map +1 -1
- package/dist/app-api-key.js +4 -0
- package/dist/app-api-key.js.map +1 -1
- package/dist/audit-log.d.ts +2 -0
- package/dist/audit-log.d.ts.map +1 -1
- package/dist/audit-log.js +13 -0
- package/dist/audit-log.js.map +1 -1
- package/dist/auth/introspection-verifier.d.ts.map +1 -1
- package/dist/auth/introspection-verifier.js +10 -0
- package/dist/auth/introspection-verifier.js.map +1 -1
- package/dist/compress.d.ts +8 -0
- package/dist/compress.d.ts.map +1 -0
- package/dist/compress.js +90 -0
- package/dist/compress.js.map +1 -0
- package/dist/config.d.ts +12 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +33 -6
- package/dist/config.js.map +1 -1
- package/dist/device-login.d.ts +5 -0
- package/dist/device-login.d.ts.map +1 -1
- package/dist/device-login.js +2 -0
- package/dist/device-login.js.map +1 -1
- package/dist/guidance.d.ts +53 -0
- package/dist/guidance.d.ts.map +1 -0
- package/dist/guidance.js +183 -0
- package/dist/guidance.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +43 -5
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +529 -121
- package/dist/index.js.map +1 -1
- package/dist/internal-tools.d.ts +6 -1
- package/dist/internal-tools.d.ts.map +1 -1
- package/dist/internal-tools.js +3 -2
- package/dist/internal-tools.js.map +1 -1
- package/dist/login-cli.d.ts.map +1 -1
- package/dist/login-cli.js +8 -0
- package/dist/login-cli.js.map +1 -1
- package/dist/mcp-modern.d.ts +9 -5
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +31 -8
- package/dist/mcp-modern.js.map +1 -1
- package/dist/orgapp.d.ts.map +1 -1
- package/dist/orgapp.js +14 -1
- package/dist/orgapp.js.map +1 -1
- package/dist/paging.d.ts +43 -0
- package/dist/paging.d.ts.map +1 -0
- package/dist/paging.js +98 -0
- package/dist/paging.js.map +1 -0
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +1 -0
- package/dist/permissions.js.map +1 -1
- package/dist/privileged-tools.d.ts +5 -1
- package/dist/privileged-tools.d.ts.map +1 -1
- package/dist/privileged-tools.js +2 -2
- package/dist/privileged-tools.js.map +1 -1
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +11 -4
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/billing.d.ts.map +1 -1
- package/dist/tools/billing.js +29 -0
- package/dist/tools/billing.js.map +1 -1
- package/dist/tools/blocklist.d.ts.map +1 -1
- package/dist/tools/blocklist.js +21 -0
- package/dist/tools/blocklist.js.map +1 -1
- package/dist/tools/cases.d.ts.map +1 -1
- package/dist/tools/cases.js +12 -0
- package/dist/tools/cases.js.map +1 -1
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +16 -0
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/discovery.d.ts +50 -0
- package/dist/tools/discovery.d.ts.map +1 -0
- package/dist/tools/discovery.js +522 -0
- package/dist/tools/discovery.js.map +1 -0
- package/dist/tools/docs.d.ts +10 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +137 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/investigator.d.ts.map +1 -1
- package/dist/tools/investigator.js +4 -3
- package/dist/tools/investigator.js.map +1 -1
- package/dist/tools/questionnaires.d.ts +2 -1
- package/dist/tools/questionnaires.d.ts.map +1 -1
- package/dist/tools/questionnaires.js +3 -2
- package/dist/tools/questionnaires.js.map +1 -1
- package/dist/tools/search.d.ts +3 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +20 -6
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/sessions.d.ts +2 -1
- package/dist/tools/sessions.d.ts.map +1 -1
- package/dist/tools/sessions.js +3 -2
- package/dist/tools/sessions.js.map +1 -1
- package/dist/tools/settings.d.ts +4 -0
- package/dist/tools/settings.d.ts.map +1 -1
- package/dist/tools/settings.js +7 -0
- package/dist/tools/settings.js.map +1 -1
- package/dist/tools/transactions.d.ts.map +1 -1
- package/dist/tools/transactions.js +21 -0
- package/dist/tools/transactions.js.map +1 -1
- package/dist/toolsets.d.ts +87 -0
- package/dist/toolsets.d.ts.map +1 -0
- package/dist/toolsets.js +345 -0
- package/dist/toolsets.js.map +1 -0
- package/package.json +8 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-connection.d.ts","sourceRoot":"","sources":["../src/api-key-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAK/E,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE3D;AAmBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAE,MAAmB,GAAG,QAAQ,CAgD5H;AAED,qHAAqH;AACrH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAKrF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CA0BhD,CAAC;AASH,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYtD;AAED,8GAA8G;AAC9G,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,MAAM,GAAG,SAAS,CASpB;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAEjF;AAED,mHAAmH;AACnH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO7E"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERSON_ONLY_TOOLS = void 0;
|
|
4
|
+
exports.looksLikeApiKey = looksLikeApiKey;
|
|
5
|
+
exports.apiKeyAuthInfo = apiKeyAuthInfo;
|
|
6
|
+
exports.apiKeyScopeOf = apiKeyScopeOf;
|
|
7
|
+
exports.personOnlyRefusal = personOnlyRefusal;
|
|
8
|
+
exports.apiKeyScopeRefusal = apiKeyScopeRefusal;
|
|
9
|
+
exports.apiKeyOrganizations = apiKeyOrganizations;
|
|
10
|
+
exports.apiKeyApplication = apiKeyApplication;
|
|
11
|
+
const errors_js_1 = require("@modelcontextprotocol/sdk/server/auth/errors.js");
|
|
12
|
+
const internal_tools_1 = require("./internal-tools");
|
|
13
|
+
/**
|
|
14
|
+
* A Didit access token is a JWT (three dot-separated parts). An API key is URL-safe random text,
|
|
15
|
+
* with or without the `sk_live_` / `sk_test_` marker, and never contains a dot. So the shape
|
|
16
|
+
* alone tells them apart, and each credential costs exactly one introspection.
|
|
17
|
+
*/
|
|
18
|
+
function looksLikeApiKey(credential) {
|
|
19
|
+
return credential.length > 0 && !credential.includes(".");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* How long an accepted key is trusted before the auth service is asked again. The MCP SDK refuses a
|
|
23
|
+
* credential that has no expiry, and a key has none of its own; this one is renewed on every
|
|
24
|
+
* introspection, so it only bounds how long a single answer is reused.
|
|
25
|
+
*/
|
|
26
|
+
const KEY_ANSWER_LIFETIME_S = 3600;
|
|
27
|
+
const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
|
|
28
|
+
/** Epoch seconds of an ISO date or a number of seconds; undefined for anything else. */
|
|
29
|
+
function epochSeconds(value) {
|
|
30
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
31
|
+
return value;
|
|
32
|
+
const parsed = typeof value === "string" ? Date.parse(value) : NaN;
|
|
33
|
+
return Number.isNaN(parsed) ? undefined : Math.floor(parsed / 1000);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The AuthInfo of an accepted API key, from the auth service's introspection answer
|
|
37
|
+
* (service-didit-auth `TokenProcessor.verify_api_key`): `sub` is the application, and `api_key`
|
|
38
|
+
* carries the key's own limits.
|
|
39
|
+
*
|
|
40
|
+
* `scopes` is empty on purpose. The permission pre-check (permissions.ts) compares a person's
|
|
41
|
+
* role permissions; a key has none, and the API enforces the key's own access on every call.
|
|
42
|
+
*/
|
|
43
|
+
function apiKeyAuthInfo(key, data, resource, now = Date.now()) {
|
|
44
|
+
const applicationId = text(data.sub);
|
|
45
|
+
const organizationId = text(data.organization_id);
|
|
46
|
+
if (!applicationId || !organizationId) {
|
|
47
|
+
throw new errors_js_1.InvalidTokenError("The API key could not be matched to an application.");
|
|
48
|
+
}
|
|
49
|
+
const access = (data.api_key && typeof data.api_key === "object" ? data.api_key : {});
|
|
50
|
+
// The API checks the allowlist against the address a request comes from, and through this
|
|
51
|
+
// server that is the server's own address, never the caller's. Say so once, here, instead of
|
|
52
|
+
// letting every tool call fail with an address the person has never seen.
|
|
53
|
+
if (Array.isArray(access.allowed_ips) && access.allowed_ips.length > 0) {
|
|
54
|
+
throw new errors_js_1.InvalidTokenError("This API key is limited to specific IP addresses, so it cannot be used through the hosted MCP server. " +
|
|
55
|
+
"Use a key without an IP limit, or sign in with OAuth.");
|
|
56
|
+
}
|
|
57
|
+
const nowSeconds = Math.floor(now / 1000);
|
|
58
|
+
// `expires_at` is already the earlier of the key's own expiry and, for a secret that was
|
|
59
|
+
// rotated, the end of the old secret's grace period (service-didit-auth `access_payload`).
|
|
60
|
+
const ownExpiry = epochSeconds(access.expires_at);
|
|
61
|
+
const scope = {
|
|
62
|
+
organizationId,
|
|
63
|
+
organizationName: text(data.organization_name),
|
|
64
|
+
applicationId,
|
|
65
|
+
applicationName: text(data.application_name),
|
|
66
|
+
mode: text(data.application_mode),
|
|
67
|
+
keyId: text(access.uuid),
|
|
68
|
+
keyLabel: text(access.label),
|
|
69
|
+
keyPrefix: text(access.prefix),
|
|
70
|
+
primary: access.primary === true,
|
|
71
|
+
restricted: access.scopes !== null && access.scopes !== undefined,
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
token: key,
|
|
75
|
+
clientId: text(data.client_id) ?? "api-key",
|
|
76
|
+
scopes: [],
|
|
77
|
+
expiresAt: Math.min(ownExpiry ?? Infinity, nowSeconds + KEY_ANSWER_LIFETIME_S),
|
|
78
|
+
resource,
|
|
79
|
+
extra: {
|
|
80
|
+
credential: "api_key",
|
|
81
|
+
api_key: scope,
|
|
82
|
+
organization_id: organizationId,
|
|
83
|
+
sub: applicationId,
|
|
84
|
+
is_privileged: false,
|
|
85
|
+
has_2fa_enabled: false,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** The application behind the connection when it authenticated with an API key; undefined for a person's sign-in. */
|
|
90
|
+
function apiKeyScopeOf(authInfo) {
|
|
91
|
+
const extra = authInfo?.extra;
|
|
92
|
+
if (extra?.credential !== "api_key")
|
|
93
|
+
return undefined;
|
|
94
|
+
return extra.api_key;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Tools an API key connection neither lists nor runs.
|
|
98
|
+
*
|
|
99
|
+
* All but the last group act for a MEMBER of an organization, on routes the auth service and the
|
|
100
|
+
* console API only open to a person's sign-in (an application credential is refused there). The
|
|
101
|
+
* list was checked against the API with a real key: every read-only tool that takes no argument
|
|
102
|
+
* was called through an API key connection, and the ones refused by design are here. The download
|
|
103
|
+
* links seal the caller's credential inside the link; a person's token inside one stops working
|
|
104
|
+
* within a day, a key would not.
|
|
105
|
+
*/
|
|
106
|
+
exports.PERSON_ONLY_TOOLS = new Set([
|
|
107
|
+
// Members, roles and API key management (service-didit-auth, a person's sign-in only).
|
|
108
|
+
"didit_org_list_members",
|
|
109
|
+
"didit_org_invite_member",
|
|
110
|
+
"didit_org_update_member",
|
|
111
|
+
"didit_org_remove_member",
|
|
112
|
+
"didit_org_list_roles",
|
|
113
|
+
"didit_org_list_api_keys",
|
|
114
|
+
"didit_org_create_api_key",
|
|
115
|
+
"didit_org_reveal_application_api_key",
|
|
116
|
+
// The audit log and the workflow builder: the API answers a member of the organization only.
|
|
117
|
+
"didit_audit_log_list",
|
|
118
|
+
"didit_workflow_build_graph",
|
|
119
|
+
...internal_tools_1.INTERNAL_PERSON_ONLY_TOOLS,
|
|
120
|
+
// The organization's plan, cards, receipts and billing details (organization-wide console routes).
|
|
121
|
+
"didit_billing_get_plan",
|
|
122
|
+
"didit_billing_quote_plan",
|
|
123
|
+
"didit_billing_list_payment_methods",
|
|
124
|
+
"didit_billing_list_receipts",
|
|
125
|
+
"didit_billing_get_details",
|
|
126
|
+
"didit_billing_update_details",
|
|
127
|
+
// Download links that carry the caller's credential.
|
|
128
|
+
"didit_session_generate_pdf",
|
|
129
|
+
"didit_session_get_signature_evidence",
|
|
130
|
+
"didit_session_get_signed_document",
|
|
131
|
+
"didit_session_get_signature_field_image",
|
|
132
|
+
]);
|
|
133
|
+
const DOWNLOAD_TOOLS = new Set([
|
|
134
|
+
"didit_session_generate_pdf",
|
|
135
|
+
"didit_session_get_signature_evidence",
|
|
136
|
+
"didit_session_get_signed_document",
|
|
137
|
+
"didit_session_get_signature_field_image",
|
|
138
|
+
]);
|
|
139
|
+
/** Why a person-only tool does not run on an API key connection, and what to do instead. */
|
|
140
|
+
function personOnlyRefusal(name) {
|
|
141
|
+
if (DOWNLOAD_TOOLS.has(name)) {
|
|
142
|
+
return (`'${name}' returns a download link, which is only issued to a person's sign-in. With an API key, ` +
|
|
143
|
+
"request the file from the Didit API directly (the same x-api-key), or connect with OAuth.");
|
|
144
|
+
}
|
|
145
|
+
return (`'${name}' acts for a member of the organization, and this connection uses an API key, which is one ` +
|
|
146
|
+
"application and no person. A person does this in the Didit console, or through a connection that signs in with OAuth.");
|
|
147
|
+
}
|
|
148
|
+
/** Why a call that names another organization or application is refused, or undefined when it may proceed. */
|
|
149
|
+
function apiKeyScopeRefusal(scope, organizationId, applicationId) {
|
|
150
|
+
const differs = (asked, own) => asked !== undefined && asked.toLowerCase() !== own.toLowerCase();
|
|
151
|
+
if (!differs(organizationId, scope.organizationId) && !differs(applicationId, scope.applicationId))
|
|
152
|
+
return undefined;
|
|
153
|
+
return (`This connection uses an API key, which acts on one application only: ${scope.applicationId}` +
|
|
154
|
+
`${scope.applicationName ? ` (${scope.applicationName})` : ""} in organization ${scope.organizationId}. ` +
|
|
155
|
+
"Omit organization_id and application_id, or pass these. To work on another application, connect with that application's key.");
|
|
156
|
+
}
|
|
157
|
+
/** The key's organization, as `didit_org_list` answers for a person. */
|
|
158
|
+
function apiKeyOrganizations(scope) {
|
|
159
|
+
return [{ uuid: scope.organizationId, name: scope.organizationName ?? scope.organizationId }];
|
|
160
|
+
}
|
|
161
|
+
/** The key's application, as `didit_org_list_applications` and `didit_org_get_application` answer for a person. */
|
|
162
|
+
function apiKeyApplication(scope) {
|
|
163
|
+
return {
|
|
164
|
+
uuid: scope.applicationId,
|
|
165
|
+
name: scope.applicationName ?? scope.applicationId,
|
|
166
|
+
...(scope.mode ? { mode: scope.mode } : {}),
|
|
167
|
+
organization_id: scope.organizationId,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=api-key-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-connection.js","sourceRoot":"","sources":["../src/api-key-connection.ts"],"names":[],"mappings":";;;AAkDA,0CAEC;AA2BD,wCAgDC;AAGD,sCAKC;AAgDD,8CAYC;AAGD,gDAaC;AAGD,kDAEC;AAGD,8CAOC;AA5MD,+EAAoF;AAEpF,qDAA8D;AAqB9D;;;;GAIG;AACH,SAAgB,eAAe,CAAC,UAAkB;IAChD,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,IAAI,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAErH,wFAAwF;AACxF,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI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,CAAC;QAAE,OAAO,SAAS,CAAC;IAErH,OAAO,CACL,wEAAwE,KAAK,CAAC,aAAa,EAAE;QAC7F,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,EAAE,oBAAoB,KAAK,CAAC,cAAc,IAAI;QACzG,8HAA8H,CAC/H,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,SAAgB,mBAAmB,CAAC,KAAkB;IACpD,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC;AAChG,CAAC;AAED,mHAAmH;AACnH,SAAgB,iBAAiB,CAAC,KAAkB;IAClD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,IAAI,EAAE,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,aAAa;QAClD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,eAAe,EAAE,KAAK,CAAC,cAAc;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-api-key.d.ts","sourceRoot":"","sources":["../src/app-api-key.ts"],"names":[],"mappings":"AA2CA,gGAAgG;AAChG,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEhF;AAED,oEAAoE;AACpE,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"app-api-key.d.ts","sourceRoot":"","sources":["../src/app-api-key.ts"],"names":[],"mappings":"AA2CA,gGAAgG;AAChG,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEhF;AAED,oEAAoE;AACpE,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CA2CzD"}
|
package/dist/app-api-key.js
CHANGED
|
@@ -48,6 +48,10 @@ async function applicationApiKeyHeaders() {
|
|
|
48
48
|
}
|
|
49
49
|
/** The resolved application's API key, read fresh on every call. */
|
|
50
50
|
async function applicationApiKey() {
|
|
51
|
+
// An API key connection already holds its application's key (api-key-connection.ts).
|
|
52
|
+
const own = config_1.requestContext.getStore()?.apiKey;
|
|
53
|
+
if (own)
|
|
54
|
+
return own;
|
|
51
55
|
const org = (0, security_1.pathSegment)((0, config_1.resolveOrganizationId)(), "organization_id");
|
|
52
56
|
const app = (0, security_1.pathSegment)((0, config_1.resolveApplicationId)(), "application_id");
|
|
53
57
|
let key;
|
package/dist/app-api-key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-api-key.js","sourceRoot":"","sources":["../src/app-api-key.ts"],"names":[],"mappings":";;AA4CA,4DAEC;AAGD,
|
|
1
|
+
{"version":3,"file":"app-api-key.js","sourceRoot":"","sources":["../src/app-api-key.ts"],"names":[],"mappings":";;AA4CA,4DAEC;AAGD,8CA2CC;AA5FD,qCAAwH;AACxH,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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AAC;QACD,GAAG,GAAG,MAAM,0BAA0B,CAAC,qBAAqB,GAAG,iBAAiB,GAAG,GAAG,CAAC,CAAC;IAC1F,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,qBAAU,CAAC;YACnB,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,iEAAiE;YAC1E,IAAI,EACF,6FAA6F;gBAC7F,iGAAiG;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"}
|
package/dist/audit-log.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface ToolCallMeta {
|
|
|
6
6
|
hosted: boolean;
|
|
7
7
|
/** Shadow-mode verdict of the permission pre-check (permissions.ts), when it would have denied. */
|
|
8
8
|
permissionCheck?: "would_deny";
|
|
9
|
+
/** The discovery tool the call came through (tools/discovery.ts); `tool` is the tool it ran. */
|
|
10
|
+
via?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface ToolResultLike {
|
|
11
13
|
isError?: boolean;
|
package/dist/audit-log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-log.d.ts","sourceRoot":"","sources":["../src/audit-log.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"audit-log.d.ts","sourceRoot":"","sources":["../src/audit-log.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAI/E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,mGAAmG;IACnG,eAAe,CAAC,EAAE,YAAY,CAAC;IAC/B,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUpD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEhD;AAyDD,yFAAyF;AACzF,wBAAsB,aAAa,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAanH"}
|
package/dist/audit-log.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.auditToolCall = auditToolCall;
|
|
|
9
9
|
// but not the tool name). Argument VALUES are never logged (PII): only their keys and
|
|
10
10
|
// a canonical digest, which is enough to correlate a call with the exact payload.
|
|
11
11
|
const node_crypto_1 = require("node:crypto");
|
|
12
|
+
const api_key_connection_1 = require("./api-key-connection");
|
|
12
13
|
/** Deterministic JSON: object keys sorted recursively, so key order never changes the digest. */
|
|
13
14
|
function canonicalJson(value) {
|
|
14
15
|
if (Array.isArray(value))
|
|
@@ -33,6 +34,16 @@ function extra(authInfo, key) {
|
|
|
33
34
|
const value = authInfo?.extra?.[key];
|
|
34
35
|
return typeof value === "string" ? value : undefined;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* An API key connection (api-key-connection.ts): which key made the call, so it is traceable.
|
|
39
|
+
* A named key by its id; the application's primary key, which has no id, as such. Never the key.
|
|
40
|
+
*/
|
|
41
|
+
function apiKeyFields(authInfo) {
|
|
42
|
+
const key = (0, api_key_connection_1.apiKeyScopeOf)(authInfo);
|
|
43
|
+
if (!key)
|
|
44
|
+
return {};
|
|
45
|
+
return { credential: "api_key", ...(key.keyId ? { api_key_id: key.keyId } : {}), ...(key.primary ? { api_key_primary: true } : {}) };
|
|
46
|
+
}
|
|
36
47
|
function record(meta, startedAt, outcome, errorCode) {
|
|
37
48
|
return {
|
|
38
49
|
time: new Date().toISOString(),
|
|
@@ -46,10 +57,12 @@ function record(meta, startedAt, outcome, errorCode) {
|
|
|
46
57
|
sub: extra(meta.authInfo, "sub"),
|
|
47
58
|
organization_id: extra(meta.authInfo, "organization_id"),
|
|
48
59
|
client_id: meta.authInfo?.clientId,
|
|
60
|
+
...apiKeyFields(meta.authInfo),
|
|
49
61
|
args_digest: argsDigest(meta.args),
|
|
50
62
|
arg_keys: Object.keys(meta.args).sort(),
|
|
51
63
|
...(typeof meta.args.confirm === "boolean" ? { confirm: meta.args.confirm } : {}),
|
|
52
64
|
...(meta.permissionCheck ? { permission_check: meta.permissionCheck } : {}),
|
|
65
|
+
...(meta.via ? { via: meta.via } : {}),
|
|
53
66
|
};
|
|
54
67
|
}
|
|
55
68
|
/** stderr on purpose: over stdio, stdout is the JSON-RPC channel. Never throws. */
|
package/dist/audit-log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-log.js","sourceRoot":"","sources":["../src/audit-log.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"audit-log.js","sourceRoot":"","sources":["../src/audit-log.ts"],"names":[],"mappings":";;AA2BA,sCAUC;AAED,gCAEC;AA0DD,sCAaC;AAhHD,8FAA8F;AAC9F,oFAAoF;AACpF,sFAAsF;AACtF,sFAAsF;AACtF,kFAAkF;AAClF,6CAAyC;AAGzC,6DAAqD;AAkBrD,iGAAiG;AACjG,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC3E,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IAExF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;SAC7D,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;SAClC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAChD,GAAG,C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AACH,CAAC"}
|
|
@@ -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;AAiB/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;CAmD1D"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
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
|
+
const api_key_connection_1 = require("../api-key-connection");
|
|
5
6
|
const config_1 = require("../config");
|
|
6
7
|
/** Attempts at the auth service per verification: one retry for a timeout, a network error, a 429 or a 5xx. */
|
|
7
8
|
const INTROSPECTION_ATTEMPTS = 2;
|
|
@@ -56,6 +57,15 @@ class IntrospectionTokenVerifier {
|
|
|
56
57
|
throw new errors_js_1.ServerError(`Token introspection unavailable: ${failure}`);
|
|
57
58
|
}
|
|
58
59
|
async verifyAccessToken(token) {
|
|
60
|
+
// An application API key instead of a person's token (api-key-connection.ts): the auth
|
|
61
|
+
// service introspects it under `api_key`, and the answer names its application.
|
|
62
|
+
if ((0, api_key_connection_1.looksLikeApiKey)(token)) {
|
|
63
|
+
const answer = await this.introspect({ api_key: token });
|
|
64
|
+
if (!answer || answer.active !== true) {
|
|
65
|
+
throw new errors_js_1.InvalidTokenError("API key is invalid, revoked or expired");
|
|
66
|
+
}
|
|
67
|
+
return (0, api_key_connection_1.apiKeyAuthInfo)(token, answer, new URL(config_1.MCP_RESOURCE_URI));
|
|
68
|
+
}
|
|
59
69
|
const body = { token };
|
|
60
70
|
if (config_1.MCP_DEFAULT_ORG)
|
|
61
71
|
body.requested_org = config_1.MCP_DEFAULT_ORG;
|
|
@@ -1 +1 @@
|
|
|
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,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,4BAAmB,IAAI,gCAAuB,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"introspection-verifier.js","sourceRoot":"","sources":["../../src/auth/introspection-verifier.ts"],"names":[],"mappings":";;;AAEA,+EAAiG;AAEjG,8DAAwE;AACxE,sCAQmB;AAEnB,+GAA+G;AAC/G,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAa,0BAA0B;IAAvC;QACmB,UAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,4BAAmB,IAAI,gCAAuB,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAwF1H,CAAC;IAtFC;;;;;;;;;;OAUG;IACK,KAAK,CAAC,UAAU,CAAC,IAA4B;QACnD,IAAI,OAAO,GAAG,EAAE,C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EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;YAC5B,SAAS,EAAE,GAAG;YACd,QAAQ,EAAE,IAAI,GAAG,CAAC,yBAAgB,CAAC;YACnC,KAAK,EAAE;gBACL,eAAe,EAAE,cAAc;gBAC/B,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,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;AAzFD,gEAyFC;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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RequestHandler } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* The middleware to mount before every route. Which answers are compressed is the library's
|
|
4
|
+
* rule: text types (JSON, event streams, HTML) the client accepts compressed; never a PDF, a
|
|
5
|
+
* PNG or a font, which are compressed already.
|
|
6
|
+
*/
|
|
7
|
+
export declare function compressResponses(): RequestHandler[];
|
|
8
|
+
//# sourceMappingURL=compress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;AA6DxD;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,EAAE,CAEpD"}
|
package/dist/compress.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compressResponses = compressResponses;
|
|
7
|
+
/**
|
|
8
|
+
* Compressed responses for the hosted server.
|
|
9
|
+
*
|
|
10
|
+
* tools/list is the largest answer the server gives: about 350 KB of JSON for the full catalog,
|
|
11
|
+
* sent again on every connection (about 33,000 times a day in production in November 2026,
|
|
12
|
+
* roughly 12 GB a day). It is text that repeats itself, so gzip takes it to about a sixth. A
|
|
13
|
+
* client that sends `Accept-Encoding` gets the smaller answer; one that does not gets exactly
|
|
14
|
+
* the bytes it got before.
|
|
15
|
+
*
|
|
16
|
+
* Two things make this more than mounting the middleware:
|
|
17
|
+
*
|
|
18
|
+
* - `no-transform`. The MCP SDK marks its event streams `Cache-Control: no-cache, no-transform`,
|
|
19
|
+
* and the compressor reads that directive as "never compress". But the directive speaks to
|
|
20
|
+
* intermediaries (RFC 9111, 5.2.2.6): a proxy must not alter what the origin sent. This server
|
|
21
|
+
* is the origin choosing its own content coding, so the directive is hidden from the compressor
|
|
22
|
+
* while it decides and put back before the headers leave. On the wire the answer is compressed
|
|
23
|
+
* AND still tells every proxy to leave it alone. Without this, the event stream path, which is
|
|
24
|
+
* the one every client before the 2026-07-28 protocol uses, is never compressed.
|
|
25
|
+
* - Event streams. A compressor holds bytes back until it has a full block, which would delay an
|
|
26
|
+
* event that is meant to arrive now, so every write to an event stream is flushed at once.
|
|
27
|
+
*/
|
|
28
|
+
const compression_1 = __importDefault(require("compression"));
|
|
29
|
+
const on_headers_1 = __importDefault(require("on-headers"));
|
|
30
|
+
/** Below this an answer is not worth compressing (a health check, a refusal). */
|
|
31
|
+
const THRESHOLD_BYTES = 1024;
|
|
32
|
+
const NO_TRANSFORM = "no-transform";
|
|
33
|
+
/** Responses whose `no-transform` is out of the Cache-Control header while the compressor decides. */
|
|
34
|
+
const hiddenNoTransform = new WeakSet();
|
|
35
|
+
const directivesOf = (res) => String(res.getHeader("Cache-Control") ?? "")
|
|
36
|
+
.split(",")
|
|
37
|
+
.map((directive) => directive.trim())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
/*
|
|
40
|
+
* Header listeners fire in the reverse order they were added (on-headers). The compressor adds
|
|
41
|
+
* its own when its middleware runs, so a listener added AFTER it runs before it, and one added
|
|
42
|
+
* BEFORE it runs after it. That is the whole mechanism: hide, let the compressor decide, restore.
|
|
43
|
+
*/
|
|
44
|
+
/** Mounted before the compressor, so it runs last: the directive goes back on the wire. */
|
|
45
|
+
const restoreNoTransform = (_req, res, next) => {
|
|
46
|
+
(0, on_headers_1.default)(res, () => {
|
|
47
|
+
if (!hiddenNoTransform.has(res))
|
|
48
|
+
return;
|
|
49
|
+
res.setHeader("Cache-Control", [...directivesOf(res), NO_TRANSFORM].join(", "));
|
|
50
|
+
});
|
|
51
|
+
next();
|
|
52
|
+
};
|
|
53
|
+
/** Mounted after the compressor, so it runs first: the compressor decides on the content type alone. */
|
|
54
|
+
const hideNoTransform = (_req, res, next) => {
|
|
55
|
+
(0, on_headers_1.default)(res, () => {
|
|
56
|
+
const directives = directivesOf(res);
|
|
57
|
+
const rest = directives.filter((directive) => directive.toLowerCase() !== NO_TRANSFORM);
|
|
58
|
+
if (rest.length === directives.length)
|
|
59
|
+
return;
|
|
60
|
+
if (rest.length > 0)
|
|
61
|
+
res.setHeader("Cache-Control", rest.join(", "));
|
|
62
|
+
else
|
|
63
|
+
res.removeHeader("Cache-Control");
|
|
64
|
+
hiddenNoTransform.add(res);
|
|
65
|
+
});
|
|
66
|
+
next();
|
|
67
|
+
};
|
|
68
|
+
const isEventStream = (res) => String(res.getHeader("Content-Type") ?? "")
|
|
69
|
+
.toLowerCase()
|
|
70
|
+
.startsWith("text/event-stream");
|
|
71
|
+
/** After the compressor: an event written to an event stream leaves the server now, not with the next block. */
|
|
72
|
+
const flushEventStreams = (_req, res, next) => {
|
|
73
|
+
const write = res.write.bind(res);
|
|
74
|
+
res.write = ((...args) => {
|
|
75
|
+
const accepted = write(...args);
|
|
76
|
+
if (isEventStream(res))
|
|
77
|
+
res.flush();
|
|
78
|
+
return accepted;
|
|
79
|
+
});
|
|
80
|
+
next();
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The middleware to mount before every route. Which answers are compressed is the library's
|
|
84
|
+
* rule: text types (JSON, event streams, HTML) the client accepts compressed; never a PDF, a
|
|
85
|
+
* PNG or a font, which are compressed already.
|
|
86
|
+
*/
|
|
87
|
+
function compressResponses() {
|
|
88
|
+
return [restoreNoTransform, (0, compression_1.default)({ threshold: THRESHOLD_BYTES }), hideNoTransform, flushEventStreams];
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=compress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":";;;;;AAyFA,8CAEC;AA3FD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8DAAsC;AACtC,4DAAmC;AAGnC,iFAAiF;AACjF,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,sGAAsG;AACtG,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAY,CAAC;AAElD,MAAM,YAAY,GAAG,CAAC,GAAa,EAAY,EAAE,CAC/C,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;KACzC,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;KACpC,MAAM,CAA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AC,IAAI,EAAE,CAAC;KACxC,WAAW,EAAE;KACb,UAAU,CAAC,mBAAmB,CAAC,CAAC;AAErC,gHAAgH;AAChH,MAAM,iBAAiB,GAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC5D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAoC,CAAC;IACrE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QAChC,IAAI,aAAa,CAAC,GAAG,CAAC;YAAE,GAAG,CAAC,KAAK,EAAE,CAAC;QAEpC,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAqB,CAAC;IACvB,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,CAAC,kBAAkB,EAAE,IAAA,qBAAW,EAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC;AAC/G,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import type { FileSource } from "./security";
|
|
3
|
+
import type { ApiKeyScope } from "./api-key-connection";
|
|
3
4
|
export declare const SERVER_VERSION: string;
|
|
4
5
|
/**
|
|
5
6
|
* Per-tool permission pre-check (permissions.ts): `shadow` (default) only records what
|
|
@@ -19,6 +20,7 @@ export declare const MCP_OAUTH_INTROSPECT_URL: string;
|
|
|
19
20
|
export declare const MCP_DEFAULT_ORG: string;
|
|
20
21
|
export declare const MCP_INTROSPECTION_CACHE_TTL_MS: number;
|
|
21
22
|
export declare const MCP_PUBLIC_DISCOVERY: boolean;
|
|
23
|
+
export declare const SERVER_FEATURES: readonly string[];
|
|
22
24
|
export declare const MCP_DEFAULT_APP: string;
|
|
23
25
|
export declare const MCP_AUTHORIZATION_SERVER_ORIGIN: string;
|
|
24
26
|
export declare const DIDIT_AUTH_ISSUER: string;
|
|
@@ -29,17 +31,22 @@ export declare const DIDIT_OIDC_TOKEN_URL: string;
|
|
|
29
31
|
export declare const DIDIT_OIDC_REGISTRATION_URL: string;
|
|
30
32
|
export declare const MCP_SCOPES_SUPPORTED: string[];
|
|
31
33
|
/**
|
|
32
|
-
* Per-request credential context. The MCP
|
|
34
|
+
* Per-request credential context. The MCP normally acts as a Didit USER: the OAuth
|
|
33
35
|
* resource-server layer (hosted mode) populates this with the caller's validated user
|
|
34
36
|
* Bearer token (and the org it is scoped to) for the duration of a single tool dispatch,
|
|
35
37
|
* so every tool authenticates as that user WITHOUT any tool-signature change. In stdio
|
|
36
|
-
* mode the same Bearer is supplied via the DIDIT_ACCESS_TOKEN env var.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* mode the same Bearer is supplied via the DIDIT_ACCESS_TOKEN env var.
|
|
39
|
+
*
|
|
40
|
+
* A hosted connection may authenticate with an application API key instead
|
|
41
|
+
* (api-key-connection.ts). Then `apiKey` is set and `accessToken` is not: every request goes
|
|
42
|
+
* out with `x-api-key`, and the connection is the one application in `apiKeyScope`.
|
|
40
43
|
*/
|
|
41
44
|
export interface RequestCredentials {
|
|
42
45
|
accessToken?: string;
|
|
46
|
+
/** The application API key of an API key connection. Never set together with accessToken. */
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
/** The application that key belongs to. */
|
|
49
|
+
apiKeyScope?: ApiKeyScope;
|
|
43
50
|
organizationId?: string;
|
|
44
51
|
applicationId?: string;
|
|
45
52
|
/** Tool being dispatched — sent as User-Agent so the backend audit log attributes the request. */
|
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,i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AE,MAAM,CAAC,CAEnD;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG5D;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;AAyCD;;;;;;;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.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;
|
|
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.SERVER_FEATURES = 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;
|
|
@@ -81,6 +81,20 @@ function nonNegativeMs(raw, fallback) {
|
|
|
81
81
|
// deployment (a gateway-hosted copy, a directory listing) with MCP_PUBLIC_DISCOVERY=true.
|
|
82
82
|
// tools/list and tools/call are NEVER public under this flag - the catalog stays authenticated.
|
|
83
83
|
exports.MCP_PUBLIC_DISCOVERY = process.env.MCP_PUBLIC_DISCOVERY === "true";
|
|
84
|
+
// What this build supports, reported by GET /healthz so a client can adapt to the server it is
|
|
85
|
+
// about to connect to. The console's connect screen offers a read-only connection only where
|
|
86
|
+
// the server lists `read_only`: against a server that predates it the parameter is ignored,
|
|
87
|
+
// and the person would believe a connection is read-only when it is not.
|
|
88
|
+
// `api_key`: the hosted endpoint also takes an application API key in place of a sign-in
|
|
89
|
+
// (api-key-connection.ts), so a client can offer that choice only where it works.
|
|
90
|
+
// Only where tokens are introspected: a deployment that verifies JWTs locally (jwks) cannot accept a key.
|
|
91
|
+
exports.SERVER_FEATURES = [
|
|
92
|
+
"toolsets",
|
|
93
|
+
"read_only",
|
|
94
|
+
"tool_discovery",
|
|
95
|
+
"prompts",
|
|
96
|
+
...(exports.MCP_TOKEN_VERIFY_MODE === "jwks" ? [] : ["api_key"]),
|
|
97
|
+
];
|
|
84
98
|
// Optional: default application for single-app deployments (used when a tool call
|
|
85
99
|
// omits application_id and the user has no unambiguous default).
|
|
86
100
|
exports.MCP_DEFAULT_APP = process.env.MCP_DEFAULT_APP || "";
|
|
@@ -135,13 +149,16 @@ function orgPath(resource, opts = {}) {
|
|
|
135
149
|
return `/organization/${(0, security_1.pathSegment)(resolveOrganizationId(opts.organizationId), "organization_id")}${resource}`;
|
|
136
150
|
}
|
|
137
151
|
/**
|
|
138
|
-
* Auth headers for the Didit APIs
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
152
|
+
* Auth headers for the Didit APIs: the caller's Bearer access token (from the OAuth flow in
|
|
153
|
+
* hosted mode, or DIDIT_ACCESS_TOKEN in stdio mode), or the application API key of an API key
|
|
154
|
+
* connection, sent as `x-api-key` exactly as on a direct API call. The console's
|
|
155
|
+
* application routes accept the application's own key; its organization-wide routes do not,
|
|
156
|
+
* which is why those tools are not offered to such a connection (api-key-connection.ts).
|
|
142
157
|
*/
|
|
143
158
|
function authHeaders() {
|
|
144
159
|
const ctx = exports.requestContext.getStore();
|
|
160
|
+
if (ctx?.apiKey)
|
|
161
|
+
return { "x-api-key": ctx.apiKey };
|
|
145
162
|
if (ctx?.accessToken) {
|
|
146
163
|
const headers = { Authorization: `Bearer ${ctx.accessToken}` };
|
|
147
164
|
// Tells the verification API which authorized org this request acts in
|
|
@@ -241,7 +258,7 @@ async function apiRequest(path, opts = {}) {
|
|
|
241
258
|
throw new security_1.DiditError({
|
|
242
259
|
code: (0, security_1.statusToCode)(res.status),
|
|
243
260
|
message: parsed.message || `Request failed with status ${res.status}.`,
|
|
244
|
-
hint: (0, security_1.statusToHint)(res.status, body),
|
|
261
|
+
hint: apiKeyRefusalHint(res.status) ?? (0, security_1.statusToHint)(res.status, body),
|
|
245
262
|
field: parsed.field,
|
|
246
263
|
allowed: parsed.allowed,
|
|
247
264
|
status: res.status,
|
|
@@ -250,6 +267,16 @@ async function apiRequest(path, opts = {}) {
|
|
|
250
267
|
}
|
|
251
268
|
return body;
|
|
252
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* A 403 on an API key connection (api-key-connection.ts) is about the key, never about a role:
|
|
272
|
+
* the generic hint ("it may require a different role") would send the agent to the wrong fix.
|
|
273
|
+
*/
|
|
274
|
+
function apiKeyRefusalHint(status) {
|
|
275
|
+
if (status !== 403 || !exports.requestContext.getStore()?.apiKey)
|
|
276
|
+
return undefined;
|
|
277
|
+
return ("This connection uses an API key. Either the key's access does not cover this action (a person widens it in the " +
|
|
278
|
+
"Didit console, under the application's API keys), or the action needs a person's sign-in (the console, or an OAuth connection).");
|
|
279
|
+
}
|
|
253
280
|
/**
|
|
254
281
|
* A refusal the backend answers with its own machine code and a `next_step` (action, url,
|
|
255
282
|
* description) - the agent top-up route does - keeps both, unchanged, so the model can hand the
|