@introspection-ai/recipes 0.18.0 → 0.19.0
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/dist/inspect.d.ts +1 -0
- package/dist/inspect.d.ts.map +1 -1
- package/dist/inspect.js +3 -0
- package/dist/inspect.js.map +1 -1
- package/dist/mcp-chunks/{auth-command-ZLGYIEUY.js → auth-command-3K7V3VCW.js} +31 -35
- package/dist/mcp-chunks/call-arguments-TX3F2TEE.js +15 -0
- package/dist/mcp-chunks/{call-command-LKTKSYTH.js → call-command-OFPHPFM5.js} +36 -34
- package/dist/mcp-chunks/chunk-2FSDGCHW.js +3299 -0
- package/dist/mcp-chunks/{chunk-BV56DXPW.js → chunk-2JHHONW4.js} +1 -1
- package/dist/mcp-chunks/chunk-2MEHGB7D.js +63 -0
- package/dist/mcp-chunks/chunk-3IZQW4H4.js +929 -0
- package/dist/mcp-chunks/{chunk-MZ2NARG7.js → chunk-54EWGONA.js} +5 -5
- package/dist/mcp-chunks/{chunk-LQQEYD76.js → chunk-55JIHDU3.js} +1 -1
- package/dist/mcp-chunks/chunk-64EP2BVO.js +39 -0
- package/dist/mcp-chunks/{chunk-LS7PMWSR.js → chunk-6D6KPSXN.js} +1 -1
- package/dist/mcp-chunks/{chunk-2XL7MG7R.js → chunk-7A63PAGP.js} +15 -9
- package/dist/mcp-chunks/chunk-7DH57OKF.js +28 -0
- package/dist/mcp-chunks/{chunk-BTLAWHTA.js → chunk-7RDLPFIO.js} +2 -2
- package/dist/mcp-chunks/chunk-C2PQFLWS.js +422 -0
- package/dist/mcp-chunks/chunk-CA5WFJZA.js +197 -0
- package/dist/mcp-chunks/{chunk-LNH5LAJD.js → chunk-CNDY7WB4.js} +2 -2
- package/dist/mcp-chunks/{chunk-UKYNQGNE.js → chunk-DEUU7WSN.js} +34 -8
- package/dist/mcp-chunks/{chunk-LKIBAYKU.js → chunk-DXPHJFSA.js} +25 -35
- package/dist/mcp-chunks/{chunk-J6LYIZXN.js → chunk-E6RVTWJY.js} +1 -1
- package/dist/mcp-chunks/{chunk-7FHEBT5G.js → chunk-E6T37ED6.js} +18 -13
- package/dist/mcp-chunks/chunk-ETWN4IIA.js +57 -0
- package/dist/mcp-chunks/{chunk-YVZKMV5H.js → chunk-F3LL4EBL.js} +1 -1
- package/dist/mcp-chunks/chunk-FWP4RACK.js +42 -0
- package/dist/mcp-chunks/{chunk-6W5QFASN.js → chunk-GFYTST6N.js} +1 -1
- package/dist/mcp-chunks/{chunk-TEUKFFQL.js → chunk-GIF7LOYU.js} +2 -2
- package/dist/mcp-chunks/{chunk-QXJUA3ND.js → chunk-GSZOK5TS.js} +828 -7
- package/dist/mcp-chunks/chunk-H7F5RZXS.js +26 -0
- package/dist/mcp-chunks/{chunk-ECIVB7P4.js → chunk-HAO6PL7Z.js} +2 -37
- package/dist/mcp-chunks/{chunk-WQJZMCJN.js → chunk-HTZ2URXW.js} +5 -3
- package/dist/mcp-chunks/{chunk-BWHIA4PC.js → chunk-JAKI24KR.js} +1 -1
- package/dist/mcp-chunks/{chunk-PWYFKGKG.js → chunk-KSGYBW3F.js} +180 -89
- package/dist/mcp-chunks/{chunk-SJCCBNZ4.js → chunk-KSMY7PXI.js} +1 -1
- package/dist/mcp-chunks/{chunk-2U4BSDC4.js → chunk-L4VKBFYI.js} +48 -29
- package/dist/mcp-chunks/{chunk-LEZSACDE.js → chunk-LICH4Q7A.js} +4 -4
- package/dist/mcp-chunks/{chunk-PIIYJR44.js → chunk-LNSUME65.js} +29 -33
- package/dist/mcp-chunks/{chunk-D3MRAZ6H.js → chunk-LWVFSQYX.js} +13974 -15562
- package/dist/mcp-chunks/{chunk-7KA2VJVZ.js → chunk-NCXEJ35U.js} +10 -5
- package/dist/mcp-chunks/{chunk-5QOSCSQB.js → chunk-NZOIX6XW.js} +2 -2
- package/dist/mcp-chunks/{chunk-XANPGTLI.js → chunk-P3RN22HQ.js} +11 -4
- package/dist/mcp-chunks/{chunk-IABRYROW.js → chunk-PKOJCYNA.js} +3 -3
- package/dist/mcp-chunks/{chunk-BNV3TPE4.js → chunk-QJACOI2W.js} +5 -13
- package/dist/mcp-chunks/{chunk-UNKB4SBV.js → chunk-RBVYCKCD.js} +2 -2
- package/dist/mcp-chunks/{chunk-DHBE7UBH.js → chunk-SB2UUURE.js} +12 -42
- package/dist/mcp-chunks/{chunk-4SQKWYFF.js → chunk-SFREPU3D.js} +1 -1
- package/dist/mcp-chunks/{chunk-BZIQOWE6.js → chunk-SRZZQ6TL.js} +35 -36
- package/dist/mcp-chunks/{chunk-M3TPODXI.js → chunk-UENXT3NE.js} +1 -1
- package/dist/mcp-chunks/chunk-UHOKCTZT.js +37 -0
- package/dist/mcp-chunks/{chunk-E22DYOW5.js → chunk-WWO5WGH5.js} +5 -5
- package/dist/mcp-chunks/{chunk-6XCZGU3G.js → chunk-WXBPMFSN.js} +149 -192
- package/dist/mcp-chunks/{chunk-XQK2JSW4.js → chunk-XRGLP3Z2.js} +14 -2
- package/dist/mcp-chunks/{chunk-L7NTQVYN.js → chunk-XTL4MHFH.js} +28 -10
- package/dist/mcp-chunks/{chunk-N46NEFAF.js → chunk-XUF6KARU.js} +1 -1
- package/dist/mcp-chunks/{chunk-WD6BOD24.js → chunk-YCYSQA5V.js} +23 -4
- package/dist/mcp-chunks/chunk-YPJ5EHXR.js +17394 -0
- package/dist/mcp-chunks/{chunk-NRAJX5E4.js → chunk-YSPT6F7K.js} +3 -3
- package/dist/mcp-chunks/{chunk-7UDVSOOF.js → chunk-YTKRAHO6.js} +54 -46
- package/dist/mcp-chunks/chunk-ZBFZ5UFE.js +67 -0
- package/dist/mcp-chunks/{cli-UV4QJZZM.js → cli-E4P6SZLQ.js} +89 -76
- package/dist/mcp-chunks/client-2EJC4PLL.js +18 -0
- package/dist/mcp-chunks/{config-command-NLAGKID5.js → config-command-MWF3RHPQ.js} +38 -59
- package/dist/mcp-chunks/daemon-command-6CJ26MKI.js +33 -0
- package/dist/mcp-chunks/{dist-LK3SHAMX.js → dist-ZIPUENTM.js} +527 -469
- package/dist/mcp-chunks/{emit-ts-command-VBXVXO6V.js → emit-ts-command-GOVJJ64A.js} +16 -13
- package/dist/mcp-chunks/{generate-cli-runner-6CAZZA3P.js → generate-cli-runner-L5OQIMEY.js} +242 -247
- package/dist/mcp-chunks/{inspect-cli-command-3ZORTOR7.js → inspect-cli-command-7OMMREPE.js} +10 -9
- package/dist/mcp-chunks/{launch-YKRXHXJI.js → launch-BWXPLPB7.js} +1 -1
- package/dist/mcp-chunks/{lifecycle-XVKRHPH3.js → lifecycle-B5UC65PT.js} +1 -1
- package/dist/mcp-chunks/{list-command-2MEGGNFQ.js → list-command-ZO4HVFQK.js} +74 -43
- package/dist/mcp-chunks/{output-utils-NKESLAJ6.js → output-utils-M3TJ2N4M.js} +3 -3
- package/dist/mcp-chunks/{prompt-B1Yc1NPt-VGOTWJMN.js → prompt-CH6TK0bC-C7OTKGRD.js} +1 -3
- package/dist/mcp-chunks/{record-command-YXHTTTT5.js → record-command-VD3HUQIC.js} +5 -4
- package/dist/mcp-chunks/replay-command-AX6IN7YD.js +42 -0
- package/dist/mcp-chunks/{resource-command-OO4NYF5C.js → resource-command-JEZ2DW2G.js} +10 -10
- package/dist/mcp-chunks/{result-utils-MOHHLNM7.js → result-utils-3YHYGS45.js} +4 -4
- package/dist/mcp-chunks/runtime-HSYVOME7.js +37 -0
- package/dist/mcp-chunks/{runtime-wrapper-RPWDIDBF.js → runtime-wrapper-UREU7GC3.js} +7 -3
- package/dist/mcp-chunks/serve-command-M47YZ6JN.js +16018 -0
- package/dist/mcp-chunks/{timeouts-W2XWCCXR.js → timeouts-THZRYP4B.js} +3 -1
- package/dist/mcp-chunks/{vault-command-PIYIUEZL.js → vault-command-53P7MLCB.js} +7 -6
- package/dist/mcp-chunks/webapi-PHEQZQKH.js +3316 -0
- package/dist/mcp-client.js +11 -1
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-daemon-client.d.ts.map +1 -1
- package/dist/mcp-daemon-client.js +3 -0
- package/dist/mcp-daemon-client.js.map +1 -1
- package/dist/mcp-daemon-protocol.d.ts +6 -0
- package/dist/mcp-daemon-protocol.d.ts.map +1 -1
- package/dist/mcp-daemon-protocol.js.map +1 -1
- package/dist/mcp-daemon.js +43 -22
- package/dist/mcp-daemon.js.map +1 -1
- package/dist/mcp-run-worker.js +29 -22
- package/dist/mcp-trace-context.d.ts +6 -0
- package/dist/mcp-trace-context.d.ts.map +1 -0
- package/dist/mcp-trace-context.js +31 -0
- package/dist/mcp-trace-context.js.map +1 -0
- package/dist/model-binding.d.ts.map +1 -1
- package/dist/model-binding.js +8 -4
- package/dist/model-binding.js.map +1 -1
- package/dist/pi-extension.d.ts.map +1 -1
- package/dist/pi-extension.js +12 -0
- package/dist/pi-extension.js.map +1 -1
- package/dist/recipe/resolve.d.ts +2 -0
- package/dist/recipe/resolve.d.ts.map +1 -1
- package/dist/recipe/resolve.js +2 -1
- package/dist/recipe/resolve.js.map +1 -1
- package/dist/recipe-agent.d.ts +5 -2
- package/dist/recipe-agent.d.ts.map +1 -1
- package/dist/recipe-agent.js +20 -4
- package/dist/recipe-agent.js.map +1 -1
- package/dist/recipe-model.d.ts +7 -1
- package/dist/recipe-model.d.ts.map +1 -1
- package/dist/recipe-model.js +89 -20
- package/dist/recipe-model.js.map +1 -1
- package/dist/recipe-session.d.ts +14 -0
- package/dist/recipe-session.d.ts.map +1 -0
- package/dist/recipe-session.js +181 -0
- package/dist/recipe-session.js.map +1 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +23 -1
- package/dist/session.js.map +1 -1
- package/docs/agent-composition.md +46 -22
- package/docs/pi-extension.md +9 -3
- package/docs/recipe-format.md +41 -5
- package/package.json +7 -7
- package/vendor/introspection-recipe-check/darwin-arm64/introspection-recipe-check +0 -0
- package/vendor/introspection-recipe-check/darwin-x64/introspection-recipe-check +0 -0
- package/vendor/introspection-recipe-check/linux-arm64/introspection-recipe-check +0 -0
- package/vendor/introspection-recipe-check/linux-x64/introspection-recipe-check +0 -0
- package/vendor/introspection-recipe-check/linux-x64-musl/introspection-recipe-check +0 -0
- package/vendor/introspection-recipe-check/win32-x64/introspection-recipe-check.exe +0 -0
- package/dist/mcp-chunks/call-arguments-LU3W6D3K.js +0 -13
- package/dist/mcp-chunks/chunk-HKRJ6O36.js +0 -1076
- package/dist/mcp-chunks/chunk-NNOEGEUZ.js +0 -17273
- package/dist/mcp-chunks/chunk-P3PSC54P.js +0 -869
- package/dist/mcp-chunks/chunk-TATVT5IT.js +0 -194
- package/dist/mcp-chunks/chunk-YHQUTU6L.js +0 -571
- package/dist/mcp-chunks/client-S7RQUG5U.js +0 -13
- package/dist/mcp-chunks/daemon-command-U242Z6VY.js +0 -26
- package/dist/mcp-chunks/replay-command-25HJ6AQU.js +0 -85
- package/dist/mcp-chunks/runtime-5WJ3G25Y.js +0 -33
- package/dist/mcp-chunks/serve-command-DHXJZMMN.js +0 -3302
|
@@ -1,869 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
LATEST_PROTOCOL_VERSION,
|
|
4
|
-
NEVER,
|
|
5
|
-
ZodIssueCode,
|
|
6
|
-
any,
|
|
7
|
-
array,
|
|
8
|
-
boolean,
|
|
9
|
-
coerce_exports,
|
|
10
|
-
literal,
|
|
11
|
-
looseObject,
|
|
12
|
-
number,
|
|
13
|
-
object,
|
|
14
|
-
string,
|
|
15
|
-
url
|
|
16
|
-
} from "./chunk-D3MRAZ6H.js";
|
|
17
|
-
|
|
18
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
|
|
19
|
-
function resourceUrlFromServerUrl(url2) {
|
|
20
|
-
const resourceURL = typeof url2 === "string" ? new URL(url2) : new URL(url2.href);
|
|
21
|
-
resourceURL.hash = "";
|
|
22
|
-
return resourceURL;
|
|
23
|
-
}
|
|
24
|
-
function checkResourceAllowed({ requestedResource, configuredResource }) {
|
|
25
|
-
const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
|
|
26
|
-
const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
|
|
27
|
-
if (requested.origin !== configured.origin) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (requested.pathname.length < configured.pathname.length) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : requested.pathname + "/";
|
|
34
|
-
const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : configured.pathname + "/";
|
|
35
|
-
return requestedPath.startsWith(configuredPath);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// node_modules/.pnpm/pkce-challenge@5.0.1/node_modules/pkce-challenge/dist/index.node.js
|
|
39
|
-
var crypto;
|
|
40
|
-
crypto = globalThis.crypto?.webcrypto ?? // Node.js [18-16] REPL
|
|
41
|
-
globalThis.crypto ?? // Node.js >18
|
|
42
|
-
import("node:crypto").then((m) => m.webcrypto);
|
|
43
|
-
async function getRandomValues(size) {
|
|
44
|
-
return (await crypto).getRandomValues(new Uint8Array(size));
|
|
45
|
-
}
|
|
46
|
-
async function random(size) {
|
|
47
|
-
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
48
|
-
const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % mask.length;
|
|
49
|
-
let result = "";
|
|
50
|
-
while (result.length < size) {
|
|
51
|
-
const randomBytes = await getRandomValues(size - result.length);
|
|
52
|
-
for (const randomByte of randomBytes) {
|
|
53
|
-
if (randomByte < evenDistCutoff) {
|
|
54
|
-
result += mask[randomByte % mask.length];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
async function generateVerifier(length) {
|
|
61
|
-
return await random(length);
|
|
62
|
-
}
|
|
63
|
-
async function generateChallenge(code_verifier) {
|
|
64
|
-
const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
65
|
-
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
66
|
-
}
|
|
67
|
-
async function pkceChallenge(length) {
|
|
68
|
-
if (!length)
|
|
69
|
-
length = 43;
|
|
70
|
-
if (length < 43 || length > 128) {
|
|
71
|
-
throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
72
|
-
}
|
|
73
|
-
const verifier = await generateVerifier(length);
|
|
74
|
-
const challenge = await generateChallenge(verifier);
|
|
75
|
-
return {
|
|
76
|
-
code_verifier: verifier,
|
|
77
|
-
code_challenge: challenge
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
|
|
82
|
-
var SafeUrlSchema = url().superRefine((val, ctx) => {
|
|
83
|
-
if (!URL.canParse(val)) {
|
|
84
|
-
ctx.addIssue({
|
|
85
|
-
code: ZodIssueCode.custom,
|
|
86
|
-
message: "URL must be parseable",
|
|
87
|
-
fatal: true
|
|
88
|
-
});
|
|
89
|
-
return NEVER;
|
|
90
|
-
}
|
|
91
|
-
}).refine((url2) => {
|
|
92
|
-
const u = new URL(url2);
|
|
93
|
-
return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
|
|
94
|
-
}, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
|
|
95
|
-
var OAuthProtectedResourceMetadataSchema = looseObject({
|
|
96
|
-
resource: string().url(),
|
|
97
|
-
authorization_servers: array(SafeUrlSchema).optional(),
|
|
98
|
-
jwks_uri: string().url().optional(),
|
|
99
|
-
scopes_supported: array(string()).optional(),
|
|
100
|
-
bearer_methods_supported: array(string()).optional(),
|
|
101
|
-
resource_signing_alg_values_supported: array(string()).optional(),
|
|
102
|
-
resource_name: string().optional(),
|
|
103
|
-
resource_documentation: string().optional(),
|
|
104
|
-
resource_policy_uri: string().url().optional(),
|
|
105
|
-
resource_tos_uri: string().url().optional(),
|
|
106
|
-
tls_client_certificate_bound_access_tokens: boolean().optional(),
|
|
107
|
-
authorization_details_types_supported: array(string()).optional(),
|
|
108
|
-
dpop_signing_alg_values_supported: array(string()).optional(),
|
|
109
|
-
dpop_bound_access_tokens_required: boolean().optional()
|
|
110
|
-
});
|
|
111
|
-
var OAuthMetadataSchema = looseObject({
|
|
112
|
-
issuer: string(),
|
|
113
|
-
authorization_endpoint: SafeUrlSchema,
|
|
114
|
-
token_endpoint: SafeUrlSchema,
|
|
115
|
-
registration_endpoint: SafeUrlSchema.optional(),
|
|
116
|
-
scopes_supported: array(string()).optional(),
|
|
117
|
-
response_types_supported: array(string()),
|
|
118
|
-
response_modes_supported: array(string()).optional(),
|
|
119
|
-
grant_types_supported: array(string()).optional(),
|
|
120
|
-
token_endpoint_auth_methods_supported: array(string()).optional(),
|
|
121
|
-
token_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
122
|
-
service_documentation: SafeUrlSchema.optional(),
|
|
123
|
-
revocation_endpoint: SafeUrlSchema.optional(),
|
|
124
|
-
revocation_endpoint_auth_methods_supported: array(string()).optional(),
|
|
125
|
-
revocation_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
126
|
-
introspection_endpoint: string().optional(),
|
|
127
|
-
introspection_endpoint_auth_methods_supported: array(string()).optional(),
|
|
128
|
-
introspection_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
129
|
-
code_challenge_methods_supported: array(string()).optional(),
|
|
130
|
-
client_id_metadata_document_supported: boolean().optional()
|
|
131
|
-
});
|
|
132
|
-
var OpenIdProviderMetadataSchema = looseObject({
|
|
133
|
-
issuer: string(),
|
|
134
|
-
authorization_endpoint: SafeUrlSchema,
|
|
135
|
-
token_endpoint: SafeUrlSchema,
|
|
136
|
-
userinfo_endpoint: SafeUrlSchema.optional(),
|
|
137
|
-
jwks_uri: SafeUrlSchema,
|
|
138
|
-
registration_endpoint: SafeUrlSchema.optional(),
|
|
139
|
-
scopes_supported: array(string()).optional(),
|
|
140
|
-
response_types_supported: array(string()),
|
|
141
|
-
response_modes_supported: array(string()).optional(),
|
|
142
|
-
grant_types_supported: array(string()).optional(),
|
|
143
|
-
acr_values_supported: array(string()).optional(),
|
|
144
|
-
subject_types_supported: array(string()),
|
|
145
|
-
id_token_signing_alg_values_supported: array(string()),
|
|
146
|
-
id_token_encryption_alg_values_supported: array(string()).optional(),
|
|
147
|
-
id_token_encryption_enc_values_supported: array(string()).optional(),
|
|
148
|
-
userinfo_signing_alg_values_supported: array(string()).optional(),
|
|
149
|
-
userinfo_encryption_alg_values_supported: array(string()).optional(),
|
|
150
|
-
userinfo_encryption_enc_values_supported: array(string()).optional(),
|
|
151
|
-
request_object_signing_alg_values_supported: array(string()).optional(),
|
|
152
|
-
request_object_encryption_alg_values_supported: array(string()).optional(),
|
|
153
|
-
request_object_encryption_enc_values_supported: array(string()).optional(),
|
|
154
|
-
token_endpoint_auth_methods_supported: array(string()).optional(),
|
|
155
|
-
token_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
156
|
-
display_values_supported: array(string()).optional(),
|
|
157
|
-
claim_types_supported: array(string()).optional(),
|
|
158
|
-
claims_supported: array(string()).optional(),
|
|
159
|
-
service_documentation: string().optional(),
|
|
160
|
-
claims_locales_supported: array(string()).optional(),
|
|
161
|
-
ui_locales_supported: array(string()).optional(),
|
|
162
|
-
claims_parameter_supported: boolean().optional(),
|
|
163
|
-
request_parameter_supported: boolean().optional(),
|
|
164
|
-
request_uri_parameter_supported: boolean().optional(),
|
|
165
|
-
require_request_uri_registration: boolean().optional(),
|
|
166
|
-
op_policy_uri: SafeUrlSchema.optional(),
|
|
167
|
-
op_tos_uri: SafeUrlSchema.optional(),
|
|
168
|
-
client_id_metadata_document_supported: boolean().optional()
|
|
169
|
-
});
|
|
170
|
-
var OpenIdProviderDiscoveryMetadataSchema = object({
|
|
171
|
-
...OpenIdProviderMetadataSchema.shape,
|
|
172
|
-
...OAuthMetadataSchema.pick({
|
|
173
|
-
code_challenge_methods_supported: true
|
|
174
|
-
}).shape
|
|
175
|
-
});
|
|
176
|
-
var OAuthTokensSchema = object({
|
|
177
|
-
access_token: string(),
|
|
178
|
-
id_token: string().optional(),
|
|
179
|
-
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
180
|
-
token_type: string(),
|
|
181
|
-
expires_in: coerce_exports.number().optional(),
|
|
182
|
-
scope: string().optional(),
|
|
183
|
-
refresh_token: string().optional()
|
|
184
|
-
}).strip();
|
|
185
|
-
var OAuthErrorResponseSchema = object({
|
|
186
|
-
error: string(),
|
|
187
|
-
error_description: string().optional(),
|
|
188
|
-
error_uri: string().optional()
|
|
189
|
-
});
|
|
190
|
-
var OptionalSafeUrlSchema = SafeUrlSchema.optional().or(literal("").transform(() => void 0));
|
|
191
|
-
var OAuthClientMetadataSchema = object({
|
|
192
|
-
redirect_uris: array(SafeUrlSchema),
|
|
193
|
-
token_endpoint_auth_method: string().optional(),
|
|
194
|
-
grant_types: array(string()).optional(),
|
|
195
|
-
response_types: array(string()).optional(),
|
|
196
|
-
client_name: string().optional(),
|
|
197
|
-
client_uri: SafeUrlSchema.optional(),
|
|
198
|
-
logo_uri: OptionalSafeUrlSchema,
|
|
199
|
-
scope: string().optional(),
|
|
200
|
-
contacts: array(string()).optional(),
|
|
201
|
-
tos_uri: OptionalSafeUrlSchema,
|
|
202
|
-
policy_uri: string().optional(),
|
|
203
|
-
jwks_uri: SafeUrlSchema.optional(),
|
|
204
|
-
jwks: any().optional(),
|
|
205
|
-
software_id: string().optional(),
|
|
206
|
-
software_version: string().optional(),
|
|
207
|
-
software_statement: string().optional()
|
|
208
|
-
}).strip();
|
|
209
|
-
var OAuthClientInformationSchema = object({
|
|
210
|
-
client_id: string(),
|
|
211
|
-
client_secret: string().optional(),
|
|
212
|
-
client_id_issued_at: number().optional(),
|
|
213
|
-
client_secret_expires_at: number().optional()
|
|
214
|
-
}).strip();
|
|
215
|
-
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
216
|
-
var OAuthClientRegistrationErrorSchema = object({
|
|
217
|
-
error: string(),
|
|
218
|
-
error_description: string().optional()
|
|
219
|
-
}).strip();
|
|
220
|
-
var OAuthTokenRevocationRequestSchema = object({
|
|
221
|
-
token: string(),
|
|
222
|
-
token_type_hint: string().optional()
|
|
223
|
-
}).strip();
|
|
224
|
-
|
|
225
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
|
|
226
|
-
var OAuthError = class extends Error {
|
|
227
|
-
constructor(message, errorUri) {
|
|
228
|
-
super(message);
|
|
229
|
-
this.errorUri = errorUri;
|
|
230
|
-
this.name = this.constructor.name;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Converts the error to a standard OAuth error response object
|
|
234
|
-
*/
|
|
235
|
-
toResponseObject() {
|
|
236
|
-
const response = {
|
|
237
|
-
error: this.errorCode,
|
|
238
|
-
error_description: this.message
|
|
239
|
-
};
|
|
240
|
-
if (this.errorUri) {
|
|
241
|
-
response.error_uri = this.errorUri;
|
|
242
|
-
}
|
|
243
|
-
return response;
|
|
244
|
-
}
|
|
245
|
-
get errorCode() {
|
|
246
|
-
return this.constructor.errorCode;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var InvalidRequestError = class extends OAuthError {
|
|
250
|
-
};
|
|
251
|
-
InvalidRequestError.errorCode = "invalid_request";
|
|
252
|
-
var InvalidClientError = class extends OAuthError {
|
|
253
|
-
};
|
|
254
|
-
InvalidClientError.errorCode = "invalid_client";
|
|
255
|
-
var InvalidGrantError = class extends OAuthError {
|
|
256
|
-
};
|
|
257
|
-
InvalidGrantError.errorCode = "invalid_grant";
|
|
258
|
-
var UnauthorizedClientError = class extends OAuthError {
|
|
259
|
-
};
|
|
260
|
-
UnauthorizedClientError.errorCode = "unauthorized_client";
|
|
261
|
-
var UnsupportedGrantTypeError = class extends OAuthError {
|
|
262
|
-
};
|
|
263
|
-
UnsupportedGrantTypeError.errorCode = "unsupported_grant_type";
|
|
264
|
-
var InvalidScopeError = class extends OAuthError {
|
|
265
|
-
};
|
|
266
|
-
InvalidScopeError.errorCode = "invalid_scope";
|
|
267
|
-
var AccessDeniedError = class extends OAuthError {
|
|
268
|
-
};
|
|
269
|
-
AccessDeniedError.errorCode = "access_denied";
|
|
270
|
-
var ServerError = class extends OAuthError {
|
|
271
|
-
};
|
|
272
|
-
ServerError.errorCode = "server_error";
|
|
273
|
-
var TemporarilyUnavailableError = class extends OAuthError {
|
|
274
|
-
};
|
|
275
|
-
TemporarilyUnavailableError.errorCode = "temporarily_unavailable";
|
|
276
|
-
var UnsupportedResponseTypeError = class extends OAuthError {
|
|
277
|
-
};
|
|
278
|
-
UnsupportedResponseTypeError.errorCode = "unsupported_response_type";
|
|
279
|
-
var UnsupportedTokenTypeError = class extends OAuthError {
|
|
280
|
-
};
|
|
281
|
-
UnsupportedTokenTypeError.errorCode = "unsupported_token_type";
|
|
282
|
-
var InvalidTokenError = class extends OAuthError {
|
|
283
|
-
};
|
|
284
|
-
InvalidTokenError.errorCode = "invalid_token";
|
|
285
|
-
var MethodNotAllowedError = class extends OAuthError {
|
|
286
|
-
};
|
|
287
|
-
MethodNotAllowedError.errorCode = "method_not_allowed";
|
|
288
|
-
var TooManyRequestsError = class extends OAuthError {
|
|
289
|
-
};
|
|
290
|
-
TooManyRequestsError.errorCode = "too_many_requests";
|
|
291
|
-
var InvalidClientMetadataError = class extends OAuthError {
|
|
292
|
-
};
|
|
293
|
-
InvalidClientMetadataError.errorCode = "invalid_client_metadata";
|
|
294
|
-
var InsufficientScopeError = class extends OAuthError {
|
|
295
|
-
};
|
|
296
|
-
InsufficientScopeError.errorCode = "insufficient_scope";
|
|
297
|
-
var InvalidTargetError = class extends OAuthError {
|
|
298
|
-
};
|
|
299
|
-
InvalidTargetError.errorCode = "invalid_target";
|
|
300
|
-
var OAUTH_ERRORS = {
|
|
301
|
-
[InvalidRequestError.errorCode]: InvalidRequestError,
|
|
302
|
-
[InvalidClientError.errorCode]: InvalidClientError,
|
|
303
|
-
[InvalidGrantError.errorCode]: InvalidGrantError,
|
|
304
|
-
[UnauthorizedClientError.errorCode]: UnauthorizedClientError,
|
|
305
|
-
[UnsupportedGrantTypeError.errorCode]: UnsupportedGrantTypeError,
|
|
306
|
-
[InvalidScopeError.errorCode]: InvalidScopeError,
|
|
307
|
-
[AccessDeniedError.errorCode]: AccessDeniedError,
|
|
308
|
-
[ServerError.errorCode]: ServerError,
|
|
309
|
-
[TemporarilyUnavailableError.errorCode]: TemporarilyUnavailableError,
|
|
310
|
-
[UnsupportedResponseTypeError.errorCode]: UnsupportedResponseTypeError,
|
|
311
|
-
[UnsupportedTokenTypeError.errorCode]: UnsupportedTokenTypeError,
|
|
312
|
-
[InvalidTokenError.errorCode]: InvalidTokenError,
|
|
313
|
-
[MethodNotAllowedError.errorCode]: MethodNotAllowedError,
|
|
314
|
-
[TooManyRequestsError.errorCode]: TooManyRequestsError,
|
|
315
|
-
[InvalidClientMetadataError.errorCode]: InvalidClientMetadataError,
|
|
316
|
-
[InsufficientScopeError.errorCode]: InsufficientScopeError,
|
|
317
|
-
[InvalidTargetError.errorCode]: InvalidTargetError
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
|
|
321
|
-
var UnauthorizedError = class extends Error {
|
|
322
|
-
constructor(message) {
|
|
323
|
-
super(message ?? "Unauthorized");
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
function isClientAuthMethod(method) {
|
|
327
|
-
return ["client_secret_basic", "client_secret_post", "none"].includes(method);
|
|
328
|
-
}
|
|
329
|
-
var AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
|
|
330
|
-
var AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
|
|
331
|
-
function selectClientAuthMethod(clientInformation, supportedMethods) {
|
|
332
|
-
const hasClientSecret = clientInformation.client_secret !== void 0;
|
|
333
|
-
if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && (supportedMethods.length === 0 || supportedMethods.includes(clientInformation.token_endpoint_auth_method))) {
|
|
334
|
-
return clientInformation.token_endpoint_auth_method;
|
|
335
|
-
}
|
|
336
|
-
if (supportedMethods.length === 0) {
|
|
337
|
-
return hasClientSecret ? "client_secret_basic" : "none";
|
|
338
|
-
}
|
|
339
|
-
if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
|
|
340
|
-
return "client_secret_basic";
|
|
341
|
-
}
|
|
342
|
-
if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
|
|
343
|
-
return "client_secret_post";
|
|
344
|
-
}
|
|
345
|
-
if (supportedMethods.includes("none")) {
|
|
346
|
-
return "none";
|
|
347
|
-
}
|
|
348
|
-
return hasClientSecret ? "client_secret_post" : "none";
|
|
349
|
-
}
|
|
350
|
-
function applyClientAuthentication(method, clientInformation, headers, params) {
|
|
351
|
-
const { client_id, client_secret } = clientInformation;
|
|
352
|
-
switch (method) {
|
|
353
|
-
case "client_secret_basic":
|
|
354
|
-
applyBasicAuth(client_id, client_secret, headers);
|
|
355
|
-
return;
|
|
356
|
-
case "client_secret_post":
|
|
357
|
-
applyPostAuth(client_id, client_secret, params);
|
|
358
|
-
return;
|
|
359
|
-
case "none":
|
|
360
|
-
applyPublicAuth(client_id, params);
|
|
361
|
-
return;
|
|
362
|
-
default:
|
|
363
|
-
throw new Error(`Unsupported client authentication method: ${method}`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function applyBasicAuth(clientId, clientSecret, headers) {
|
|
367
|
-
if (!clientSecret) {
|
|
368
|
-
throw new Error("client_secret_basic authentication requires a client_secret");
|
|
369
|
-
}
|
|
370
|
-
const credentials = btoa(`${clientId}:${clientSecret}`);
|
|
371
|
-
headers.set("Authorization", `Basic ${credentials}`);
|
|
372
|
-
}
|
|
373
|
-
function applyPostAuth(clientId, clientSecret, params) {
|
|
374
|
-
params.set("client_id", clientId);
|
|
375
|
-
if (clientSecret) {
|
|
376
|
-
params.set("client_secret", clientSecret);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
function applyPublicAuth(clientId, params) {
|
|
380
|
-
params.set("client_id", clientId);
|
|
381
|
-
}
|
|
382
|
-
async function parseErrorResponse(input) {
|
|
383
|
-
const statusCode = input instanceof Response ? input.status : void 0;
|
|
384
|
-
const body = input instanceof Response ? await input.text() : input;
|
|
385
|
-
try {
|
|
386
|
-
const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
|
|
387
|
-
const { error, error_description, error_uri } = result;
|
|
388
|
-
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
389
|
-
return new errorClass(error_description || "", error_uri);
|
|
390
|
-
} catch (error) {
|
|
391
|
-
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error}. Raw body: ${body}`;
|
|
392
|
-
return new ServerError(errorMessage);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
async function auth(provider, options) {
|
|
396
|
-
try {
|
|
397
|
-
return await authInternal(provider, options);
|
|
398
|
-
} catch (error) {
|
|
399
|
-
if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
|
|
400
|
-
await provider.invalidateCredentials?.("all");
|
|
401
|
-
return await authInternal(provider, options);
|
|
402
|
-
} else if (error instanceof InvalidGrantError) {
|
|
403
|
-
await provider.invalidateCredentials?.("tokens");
|
|
404
|
-
return await authInternal(provider, options);
|
|
405
|
-
}
|
|
406
|
-
throw error;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
410
|
-
const cachedState = await provider.discoveryState?.();
|
|
411
|
-
let resourceMetadata;
|
|
412
|
-
let authorizationServerUrl;
|
|
413
|
-
let metadata;
|
|
414
|
-
let effectiveResourceMetadataUrl = resourceMetadataUrl;
|
|
415
|
-
if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
|
|
416
|
-
effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
|
|
417
|
-
}
|
|
418
|
-
if (cachedState?.authorizationServerUrl) {
|
|
419
|
-
authorizationServerUrl = cachedState.authorizationServerUrl;
|
|
420
|
-
resourceMetadata = cachedState.resourceMetadata;
|
|
421
|
-
metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
422
|
-
if (!resourceMetadata) {
|
|
423
|
-
try {
|
|
424
|
-
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
|
|
425
|
-
} catch {
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
|
|
429
|
-
await provider.saveDiscoveryState?.({
|
|
430
|
-
authorizationServerUrl: String(authorizationServerUrl),
|
|
431
|
-
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
432
|
-
resourceMetadata,
|
|
433
|
-
authorizationServerMetadata: metadata
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
|
|
438
|
-
authorizationServerUrl = serverInfo.authorizationServerUrl;
|
|
439
|
-
metadata = serverInfo.authorizationServerMetadata;
|
|
440
|
-
resourceMetadata = serverInfo.resourceMetadata;
|
|
441
|
-
await provider.saveDiscoveryState?.({
|
|
442
|
-
authorizationServerUrl: String(authorizationServerUrl),
|
|
443
|
-
resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
|
|
444
|
-
resourceMetadata,
|
|
445
|
-
authorizationServerMetadata: metadata
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
449
|
-
const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
450
|
-
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
451
|
-
if (!clientInformation) {
|
|
452
|
-
if (authorizationCode !== void 0) {
|
|
453
|
-
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
454
|
-
}
|
|
455
|
-
const supportsUrlBasedClientId = metadata?.client_id_metadata_document_supported === true;
|
|
456
|
-
const clientMetadataUrl = provider.clientMetadataUrl;
|
|
457
|
-
if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) {
|
|
458
|
-
throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`);
|
|
459
|
-
}
|
|
460
|
-
const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl;
|
|
461
|
-
if (shouldUseUrlBasedClientId) {
|
|
462
|
-
clientInformation = {
|
|
463
|
-
client_id: clientMetadataUrl
|
|
464
|
-
};
|
|
465
|
-
await provider.saveClientInformation?.(clientInformation);
|
|
466
|
-
} else {
|
|
467
|
-
if (!provider.saveClientInformation) {
|
|
468
|
-
throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
469
|
-
}
|
|
470
|
-
const fullInformation = await registerClient(authorizationServerUrl, {
|
|
471
|
-
metadata,
|
|
472
|
-
clientMetadata: provider.clientMetadata,
|
|
473
|
-
scope: resolvedScope,
|
|
474
|
-
fetchFn
|
|
475
|
-
});
|
|
476
|
-
await provider.saveClientInformation(fullInformation);
|
|
477
|
-
clientInformation = fullInformation;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
const nonInteractiveFlow = !provider.redirectUrl;
|
|
481
|
-
if (authorizationCode !== void 0 || nonInteractiveFlow) {
|
|
482
|
-
const tokens2 = await fetchToken(provider, authorizationServerUrl, {
|
|
483
|
-
metadata,
|
|
484
|
-
resource,
|
|
485
|
-
authorizationCode,
|
|
486
|
-
fetchFn
|
|
487
|
-
});
|
|
488
|
-
await provider.saveTokens(tokens2);
|
|
489
|
-
return "AUTHORIZED";
|
|
490
|
-
}
|
|
491
|
-
const tokens = await provider.tokens();
|
|
492
|
-
if (tokens?.refresh_token) {
|
|
493
|
-
try {
|
|
494
|
-
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
495
|
-
metadata,
|
|
496
|
-
clientInformation,
|
|
497
|
-
refreshToken: tokens.refresh_token,
|
|
498
|
-
resource,
|
|
499
|
-
addClientAuthentication: provider.addClientAuthentication,
|
|
500
|
-
fetchFn
|
|
501
|
-
});
|
|
502
|
-
await provider.saveTokens(newTokens);
|
|
503
|
-
return "AUTHORIZED";
|
|
504
|
-
} catch (error) {
|
|
505
|
-
if (!(error instanceof OAuthError) || error instanceof ServerError) {
|
|
506
|
-
} else {
|
|
507
|
-
throw error;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const state = provider.state ? await provider.state() : void 0;
|
|
512
|
-
const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, {
|
|
513
|
-
metadata,
|
|
514
|
-
clientInformation,
|
|
515
|
-
state,
|
|
516
|
-
redirectUrl: provider.redirectUrl,
|
|
517
|
-
scope: resolvedScope,
|
|
518
|
-
resource
|
|
519
|
-
});
|
|
520
|
-
await provider.saveCodeVerifier(codeVerifier);
|
|
521
|
-
await provider.redirectToAuthorization(authorizationUrl);
|
|
522
|
-
return "REDIRECT";
|
|
523
|
-
}
|
|
524
|
-
function isHttpsUrl(value) {
|
|
525
|
-
if (!value)
|
|
526
|
-
return false;
|
|
527
|
-
try {
|
|
528
|
-
const url2 = new URL(value);
|
|
529
|
-
return url2.protocol === "https:" && url2.pathname !== "/";
|
|
530
|
-
} catch {
|
|
531
|
-
return false;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
535
|
-
const defaultResource = resourceUrlFromServerUrl(serverUrl);
|
|
536
|
-
if (provider.validateResourceURL) {
|
|
537
|
-
return await provider.validateResourceURL(defaultResource, resourceMetadata?.resource);
|
|
538
|
-
}
|
|
539
|
-
if (!resourceMetadata) {
|
|
540
|
-
return void 0;
|
|
541
|
-
}
|
|
542
|
-
if (!checkResourceAllowed({ requestedResource: defaultResource, configuredResource: resourceMetadata.resource })) {
|
|
543
|
-
throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`);
|
|
544
|
-
}
|
|
545
|
-
return new URL(resourceMetadata.resource);
|
|
546
|
-
}
|
|
547
|
-
function extractWWWAuthenticateParams(res) {
|
|
548
|
-
const authenticateHeader = res.headers.get("WWW-Authenticate");
|
|
549
|
-
if (!authenticateHeader) {
|
|
550
|
-
return {};
|
|
551
|
-
}
|
|
552
|
-
const [type, scheme] = authenticateHeader.split(" ");
|
|
553
|
-
if (type.toLowerCase() !== "bearer" || !scheme) {
|
|
554
|
-
return {};
|
|
555
|
-
}
|
|
556
|
-
const resourceMetadataMatch = extractFieldFromWwwAuth(res, "resource_metadata") || void 0;
|
|
557
|
-
let resourceMetadataUrl;
|
|
558
|
-
if (resourceMetadataMatch) {
|
|
559
|
-
try {
|
|
560
|
-
resourceMetadataUrl = new URL(resourceMetadataMatch);
|
|
561
|
-
} catch {
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
const scope = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
565
|
-
const error = extractFieldFromWwwAuth(res, "error") || void 0;
|
|
566
|
-
return {
|
|
567
|
-
resourceMetadataUrl,
|
|
568
|
-
scope,
|
|
569
|
-
error
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
function extractFieldFromWwwAuth(response, fieldName) {
|
|
573
|
-
const wwwAuthHeader = response.headers.get("WWW-Authenticate");
|
|
574
|
-
if (!wwwAuthHeader) {
|
|
575
|
-
return null;
|
|
576
|
-
}
|
|
577
|
-
const pattern = new RegExp(`${fieldName}=(?:"([^"]+)"|([^\\s,]+))`);
|
|
578
|
-
const match = wwwAuthHeader.match(pattern);
|
|
579
|
-
if (match) {
|
|
580
|
-
return match[1] || match[2];
|
|
581
|
-
}
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
585
|
-
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
586
|
-
protocolVersion: opts?.protocolVersion,
|
|
587
|
-
metadataUrl: opts?.resourceMetadataUrl
|
|
588
|
-
});
|
|
589
|
-
if (!response || response.status === 404) {
|
|
590
|
-
await response?.body?.cancel();
|
|
591
|
-
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
592
|
-
}
|
|
593
|
-
if (!response.ok) {
|
|
594
|
-
await response.body?.cancel();
|
|
595
|
-
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
|
|
596
|
-
}
|
|
597
|
-
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
598
|
-
}
|
|
599
|
-
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
600
|
-
try {
|
|
601
|
-
return await fetchFn(url2, { headers });
|
|
602
|
-
} catch (error) {
|
|
603
|
-
if (error instanceof TypeError) {
|
|
604
|
-
if (headers) {
|
|
605
|
-
return fetchWithCorsRetry(url2, void 0, fetchFn);
|
|
606
|
-
} else {
|
|
607
|
-
return void 0;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
throw error;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
614
|
-
if (pathname.endsWith("/")) {
|
|
615
|
-
pathname = pathname.slice(0, -1);
|
|
616
|
-
}
|
|
617
|
-
return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
|
|
618
|
-
}
|
|
619
|
-
async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
|
|
620
|
-
const headers = {
|
|
621
|
-
"MCP-Protocol-Version": protocolVersion
|
|
622
|
-
};
|
|
623
|
-
return await fetchWithCorsRetry(url2, headers, fetchFn);
|
|
624
|
-
}
|
|
625
|
-
function shouldAttemptFallback(response, pathname) {
|
|
626
|
-
return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
|
|
627
|
-
}
|
|
628
|
-
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
629
|
-
const issuer = new URL(serverUrl);
|
|
630
|
-
const protocolVersion = opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION;
|
|
631
|
-
let url2;
|
|
632
|
-
if (opts?.metadataUrl) {
|
|
633
|
-
url2 = new URL(opts.metadataUrl);
|
|
634
|
-
} else {
|
|
635
|
-
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
636
|
-
url2 = new URL(wellKnownPath, opts?.metadataServerUrl ?? issuer);
|
|
637
|
-
url2.search = issuer.search;
|
|
638
|
-
}
|
|
639
|
-
let response = await tryMetadataDiscovery(url2, protocolVersion, fetchFn);
|
|
640
|
-
if (!opts?.metadataUrl && shouldAttemptFallback(response, issuer.pathname)) {
|
|
641
|
-
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
642
|
-
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
643
|
-
}
|
|
644
|
-
return response;
|
|
645
|
-
}
|
|
646
|
-
function buildDiscoveryUrls(authorizationServerUrl) {
|
|
647
|
-
const url2 = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
|
|
648
|
-
const hasPath = url2.pathname !== "/";
|
|
649
|
-
const urlsToTry = [];
|
|
650
|
-
if (!hasPath) {
|
|
651
|
-
urlsToTry.push({
|
|
652
|
-
url: new URL("/.well-known/oauth-authorization-server", url2.origin),
|
|
653
|
-
type: "oauth"
|
|
654
|
-
});
|
|
655
|
-
urlsToTry.push({
|
|
656
|
-
url: new URL(`/.well-known/openid-configuration`, url2.origin),
|
|
657
|
-
type: "oidc"
|
|
658
|
-
});
|
|
659
|
-
return urlsToTry;
|
|
660
|
-
}
|
|
661
|
-
let pathname = url2.pathname;
|
|
662
|
-
if (pathname.endsWith("/")) {
|
|
663
|
-
pathname = pathname.slice(0, -1);
|
|
664
|
-
}
|
|
665
|
-
urlsToTry.push({
|
|
666
|
-
url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url2.origin),
|
|
667
|
-
type: "oauth"
|
|
668
|
-
});
|
|
669
|
-
urlsToTry.push({
|
|
670
|
-
url: new URL(`/.well-known/openid-configuration${pathname}`, url2.origin),
|
|
671
|
-
type: "oidc"
|
|
672
|
-
});
|
|
673
|
-
urlsToTry.push({
|
|
674
|
-
url: new URL(`${pathname}/.well-known/openid-configuration`, url2.origin),
|
|
675
|
-
type: "oidc"
|
|
676
|
-
});
|
|
677
|
-
return urlsToTry;
|
|
678
|
-
}
|
|
679
|
-
async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
|
|
680
|
-
const headers = {
|
|
681
|
-
"MCP-Protocol-Version": protocolVersion,
|
|
682
|
-
Accept: "application/json"
|
|
683
|
-
};
|
|
684
|
-
const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
|
|
685
|
-
for (const { url: endpointUrl, type } of urlsToTry) {
|
|
686
|
-
const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
|
|
687
|
-
if (!response) {
|
|
688
|
-
continue;
|
|
689
|
-
}
|
|
690
|
-
if (!response.ok) {
|
|
691
|
-
await response.body?.cancel();
|
|
692
|
-
if (response.status >= 400 && response.status < 500) {
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
696
|
-
}
|
|
697
|
-
if (type === "oauth") {
|
|
698
|
-
return OAuthMetadataSchema.parse(await response.json());
|
|
699
|
-
} else {
|
|
700
|
-
return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return void 0;
|
|
704
|
-
}
|
|
705
|
-
async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
706
|
-
let resourceMetadata;
|
|
707
|
-
let authorizationServerUrl;
|
|
708
|
-
try {
|
|
709
|
-
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
|
|
710
|
-
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
711
|
-
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
712
|
-
}
|
|
713
|
-
} catch {
|
|
714
|
-
}
|
|
715
|
-
if (!authorizationServerUrl) {
|
|
716
|
-
authorizationServerUrl = String(new URL("/", serverUrl));
|
|
717
|
-
}
|
|
718
|
-
const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
|
|
719
|
-
return {
|
|
720
|
-
authorizationServerUrl,
|
|
721
|
-
authorizationServerMetadata,
|
|
722
|
-
resourceMetadata
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
726
|
-
let authorizationUrl;
|
|
727
|
-
if (metadata) {
|
|
728
|
-
authorizationUrl = new URL(metadata.authorization_endpoint);
|
|
729
|
-
if (!metadata.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) {
|
|
730
|
-
throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`);
|
|
731
|
-
}
|
|
732
|
-
if (metadata.code_challenge_methods_supported && !metadata.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) {
|
|
733
|
-
throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`);
|
|
734
|
-
}
|
|
735
|
-
} else {
|
|
736
|
-
authorizationUrl = new URL("/authorize", authorizationServerUrl);
|
|
737
|
-
}
|
|
738
|
-
const challenge = await pkceChallenge();
|
|
739
|
-
const codeVerifier = challenge.code_verifier;
|
|
740
|
-
const codeChallenge = challenge.code_challenge;
|
|
741
|
-
authorizationUrl.searchParams.set("response_type", AUTHORIZATION_CODE_RESPONSE_TYPE);
|
|
742
|
-
authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
|
|
743
|
-
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
744
|
-
authorizationUrl.searchParams.set("code_challenge_method", AUTHORIZATION_CODE_CHALLENGE_METHOD);
|
|
745
|
-
authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
|
|
746
|
-
if (state) {
|
|
747
|
-
authorizationUrl.searchParams.set("state", state);
|
|
748
|
-
}
|
|
749
|
-
if (scope) {
|
|
750
|
-
authorizationUrl.searchParams.set("scope", scope);
|
|
751
|
-
}
|
|
752
|
-
if (scope?.includes("offline_access")) {
|
|
753
|
-
authorizationUrl.searchParams.append("prompt", "consent");
|
|
754
|
-
}
|
|
755
|
-
if (resource) {
|
|
756
|
-
authorizationUrl.searchParams.set("resource", resource.href);
|
|
757
|
-
}
|
|
758
|
-
return { authorizationUrl, codeVerifier };
|
|
759
|
-
}
|
|
760
|
-
function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) {
|
|
761
|
-
return new URLSearchParams({
|
|
762
|
-
grant_type: "authorization_code",
|
|
763
|
-
code: authorizationCode,
|
|
764
|
-
code_verifier: codeVerifier,
|
|
765
|
-
redirect_uri: String(redirectUri)
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) {
|
|
769
|
-
const tokenUrl = metadata?.token_endpoint ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
770
|
-
const headers = new Headers({
|
|
771
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
772
|
-
Accept: "application/json"
|
|
773
|
-
});
|
|
774
|
-
if (resource) {
|
|
775
|
-
tokenRequestParams.set("resource", resource.href);
|
|
776
|
-
}
|
|
777
|
-
if (addClientAuthentication) {
|
|
778
|
-
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
|
|
779
|
-
} else if (clientInformation) {
|
|
780
|
-
const supportedMethods = metadata?.token_endpoint_auth_methods_supported ?? [];
|
|
781
|
-
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
782
|
-
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
783
|
-
}
|
|
784
|
-
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
785
|
-
method: "POST",
|
|
786
|
-
headers,
|
|
787
|
-
body: tokenRequestParams
|
|
788
|
-
});
|
|
789
|
-
if (!response.ok) {
|
|
790
|
-
throw await parseErrorResponse(response);
|
|
791
|
-
}
|
|
792
|
-
return OAuthTokensSchema.parse(await response.json());
|
|
793
|
-
}
|
|
794
|
-
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
795
|
-
const tokenRequestParams = new URLSearchParams({
|
|
796
|
-
grant_type: "refresh_token",
|
|
797
|
-
refresh_token: refreshToken
|
|
798
|
-
});
|
|
799
|
-
const tokens = await executeTokenRequest(authorizationServerUrl, {
|
|
800
|
-
metadata,
|
|
801
|
-
tokenRequestParams,
|
|
802
|
-
clientInformation,
|
|
803
|
-
addClientAuthentication,
|
|
804
|
-
resource,
|
|
805
|
-
fetchFn
|
|
806
|
-
});
|
|
807
|
-
return { refresh_token: refreshToken, ...tokens };
|
|
808
|
-
}
|
|
809
|
-
async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
|
|
810
|
-
const scope = provider.clientMetadata.scope;
|
|
811
|
-
let tokenRequestParams;
|
|
812
|
-
if (provider.prepareTokenRequest) {
|
|
813
|
-
tokenRequestParams = await provider.prepareTokenRequest(scope);
|
|
814
|
-
}
|
|
815
|
-
if (!tokenRequestParams) {
|
|
816
|
-
if (!authorizationCode) {
|
|
817
|
-
throw new Error("Either provider.prepareTokenRequest() or authorizationCode is required");
|
|
818
|
-
}
|
|
819
|
-
if (!provider.redirectUrl) {
|
|
820
|
-
throw new Error("redirectUrl is required for authorization_code flow");
|
|
821
|
-
}
|
|
822
|
-
const codeVerifier = await provider.codeVerifier();
|
|
823
|
-
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
824
|
-
}
|
|
825
|
-
const clientInformation = await provider.clientInformation();
|
|
826
|
-
return executeTokenRequest(authorizationServerUrl, {
|
|
827
|
-
metadata,
|
|
828
|
-
tokenRequestParams,
|
|
829
|
-
clientInformation: clientInformation ?? void 0,
|
|
830
|
-
addClientAuthentication: provider.addClientAuthentication,
|
|
831
|
-
resource,
|
|
832
|
-
fetchFn
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
async function registerClient(authorizationServerUrl, { metadata, clientMetadata, scope, fetchFn }) {
|
|
836
|
-
let registrationUrl;
|
|
837
|
-
if (metadata) {
|
|
838
|
-
if (!metadata.registration_endpoint) {
|
|
839
|
-
throw new Error("Incompatible auth server: does not support dynamic client registration");
|
|
840
|
-
}
|
|
841
|
-
registrationUrl = new URL(metadata.registration_endpoint);
|
|
842
|
-
} else {
|
|
843
|
-
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
844
|
-
}
|
|
845
|
-
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
846
|
-
method: "POST",
|
|
847
|
-
headers: {
|
|
848
|
-
"Content-Type": "application/json"
|
|
849
|
-
},
|
|
850
|
-
body: JSON.stringify({
|
|
851
|
-
...clientMetadata,
|
|
852
|
-
...scope !== void 0 ? { scope } : {}
|
|
853
|
-
})
|
|
854
|
-
});
|
|
855
|
-
if (!response.ok) {
|
|
856
|
-
throw await parseErrorResponse(response);
|
|
857
|
-
}
|
|
858
|
-
return OAuthClientInformationFullSchema.parse(await response.json());
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
export {
|
|
862
|
-
resourceUrlFromServerUrl,
|
|
863
|
-
checkResourceAllowed,
|
|
864
|
-
UnauthorizedError,
|
|
865
|
-
auth,
|
|
866
|
-
extractWWWAuthenticateParams,
|
|
867
|
-
discoverOAuthServerInfo,
|
|
868
|
-
refreshAuthorization
|
|
869
|
-
};
|