@lostgradient/mcp 0.2.6 → 0.3.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/LICENSE +1 -1
- package/README.md +15 -173
- package/dist/http.d.ts +35 -0
- package/dist/http.js +251 -0
- package/dist/internal/cryptography/encryption.d.ts +108 -0
- package/dist/internal/cryptography/encryption.js +241 -0
- package/dist/internal/cryptography/hash.d.ts +72 -0
- package/dist/internal/cryptography/hash.js +233 -0
- package/dist/internal/cryptography/index.d.ts +4 -0
- package/dist/internal/cryptography/index.js +2 -0
- package/dist/oauth/canonicalize-ip-address.d.ts +0 -6
- package/dist/oauth/canonicalize-ip-address.js +113 -0
- package/dist/oauth/client-metadata-documents.d.ts +2 -22
- package/dist/oauth/client-metadata-documents.js +205 -19
- package/dist/oauth/index.d.ts +9 -213
- package/dist/oauth/index.js +6 -69
- package/dist/oauth/issuer.d.ts +103 -0
- package/dist/oauth/issuer.js +564 -0
- package/dist/oauth/postgres.d.ts +12 -0
- package/dist/oauth/postgres.js +76 -0
- package/dist/oauth/safe-public-https-fetch.d.ts +3 -5
- package/dist/oauth/safe-public-https-fetch.js +114 -0
- package/dist/oauth/security-utilities.d.ts +0 -3
- package/dist/oauth/security-utilities.js +93 -0
- package/dist/oauth-store.d.ts +108 -0
- package/dist/oauth-store.js +321 -0
- package/package.json +50 -124
- package/dist/chunk-3ek3knfm.js +0 -73
- package/dist/chunk-3rr24vhh.js +0 -28
- package/dist/chunk-5444sx3n.js +0 -916
- package/dist/chunk-6ekjtvcq.js +0 -273
- package/dist/chunk-k6fm3cmk.js +0 -132
- package/dist/chunk-r9atew6b.js +0 -449
- package/dist/chunk-rxnyn7tf.js +0 -19
- package/dist/chunk-taxyscge.js +0 -67
- package/dist/chunk-tkn6m6az.js +0 -1107
- package/dist/chunk-xcf742mf.js +0 -14
- package/dist/chunk-zrrf78wj.js +0 -4
- package/dist/conformance-fixture-registration.d.ts +0 -30
- package/dist/conformance-server.d.ts +0 -1
- package/dist/conformance.d.ts +0 -43
- package/dist/env.d.ts +0 -59
- package/dist/env.js +0 -9
- package/dist/environment-schema.d.ts +0 -29
- package/dist/environment-schema.js +0 -6
- package/dist/golden-prompts.d.ts +0 -42
- package/dist/handler-context.d.ts +0 -16
- package/dist/http/authenticate.d.ts +0 -35
- package/dist/http/authorization-header.d.ts +0 -5
- package/dist/http/grant-revocation-channel.d.ts +0 -24
- package/dist/http/handler.d.ts +0 -32
- package/dist/http/index.d.ts +0 -27
- package/dist/http/index.js +0 -870
- package/dist/http/listen-inspection.d.ts +0 -11
- package/dist/http/request-context.d.ts +0 -17
- package/dist/http/responses.d.ts +0 -13
- package/dist/http/serving-layer.d.ts +0 -25
- package/dist/http/user-handler-cache.d.ts +0 -37
- package/dist/http/user-server-event-bus.d.ts +0 -35
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -616
- package/dist/localhost-request-validation.d.ts +0 -2
- package/dist/logger.d.ts +0 -59
- package/dist/logger.js +0 -18
- package/dist/long-running-operation-support.d.ts +0 -34
- package/dist/metrics.d.ts +0 -64
- package/dist/metrics.js +0 -6
- package/dist/oauth/authorize-endpoint.d.ts +0 -5
- package/dist/oauth/client-authentication.d.ts +0 -10
- package/dist/oauth/discovery-metadata.d.ts +0 -19
- package/dist/oauth/endpoint-rate-limits.d.ts +0 -10
- package/dist/oauth/endpoint-responses.d.ts +0 -10
- package/dist/oauth/network-identity.d.ts +0 -32
- package/dist/oauth/pkce-validation.d.ts +0 -2
- package/dist/oauth/postgres/client-store.d.ts +0 -12
- package/dist/oauth/postgres/code-store.d.ts +0 -14
- package/dist/oauth/postgres/database.d.ts +0 -59
- package/dist/oauth/postgres/index.d.ts +0 -11
- package/dist/oauth/postgres/index.js +0 -616
- package/dist/oauth/postgres/schema.d.ts +0 -1476
- package/dist/oauth/postgres/token-store.d.ts +0 -16
- package/dist/oauth/postgres/transaction-store.d.ts +0 -14
- package/dist/oauth/redirect-uri-matching.d.ts +0 -2
- package/dist/oauth/registration-endpoint.d.ts +0 -2
- package/dist/oauth/request-body.d.ts +0 -14
- package/dist/oauth/revocation-endpoint.d.ts +0 -2
- package/dist/oauth/scope-utilities.d.ts +0 -15
- package/dist/oauth/stores.d.ts +0 -225
- package/dist/oauth/stores.js +0 -0
- package/dist/oauth/testing/contract-fixtures.d.ts +0 -134
- package/dist/oauth/testing/index.d.ts +0 -56
- package/dist/oauth/testing/index.js +0 -330
- package/dist/oauth/token-endpoint.d.ts +0 -2
- package/dist/oauth-scope-configuration.d.ts +0 -3
- package/dist/prompts/index.d.ts +0 -5
- package/dist/prompts/summarize.d.ts +0 -4
- package/dist/rate-limit/in-memory-sliding-window-store.d.ts +0 -3
- package/dist/rate-limit/index.d.ts +0 -23
- package/dist/rate-limit/index.js +0 -29
- package/dist/rate-limit/mcp-concurrency-limiter.d.ts +0 -26
- package/dist/rate-limit/rate-limit-response.d.ts +0 -1
- package/dist/rate-limit/redis-sliding-window-store.d.ts +0 -2
- package/dist/rate-limit/request-rate-limiter.d.ts +0 -10
- package/dist/rate-limit/sliding-window-rate-limiter.d.ts +0 -16
- package/dist/resources/index.d.ts +0 -4
- package/dist/resources/user-profile.d.ts +0 -1
- package/dist/scope-vocabulary.d.ts +0 -127
- package/dist/scopes.d.ts +0 -49
- package/dist/server.d.ts +0 -113
- package/dist/supported-scopes.d.ts +0 -25
- package/dist/sveltekit-mount-state.d.ts +0 -4
- package/dist/sveltekit-mount.d.ts +0 -43
- package/dist/sveltekit-mount.js +0 -344
- package/dist/template-registry.d.ts +0 -16
- package/dist/tool-response.d.ts +0 -100
- package/dist/tools/get-user-profile.d.ts +0 -8
- package/dist/tools/index.d.ts +0 -16
- package/dist/tools/list-audit-events.d.ts +0 -11
- package/dist/type-assertions.d.ts +0 -1
- package/dist/types/primitives.d.ts +0 -130
- package/dist/ui-extension-support.d.ts +0 -20
- package/dist/version.d.ts +0 -23
- package/dist/version.js +0 -6
package/dist/chunk-r9atew6b.js
DELETED
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
engineLogger
|
|
3
|
-
} from "./chunk-k6fm3cmk.js";
|
|
4
|
-
|
|
5
|
-
// src/oauth/client-metadata-documents.ts
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
// src/oauth/security-utilities.ts
|
|
9
|
-
import { timingSafeEqual } from "node:crypto";
|
|
10
|
-
import { isIPv4 as isIPv42, isIPv6 as isIPv62 } from "node:net";
|
|
11
|
-
|
|
12
|
-
// src/oauth/canonicalize-ip-address.ts
|
|
13
|
-
import { isIPv4, isIPv6 } from "node:net";
|
|
14
|
-
function expandIpv6Groups(address) {
|
|
15
|
-
let workingAddress = address;
|
|
16
|
-
const lastColonIndex = workingAddress.lastIndexOf(":");
|
|
17
|
-
const tail = workingAddress.slice(lastColonIndex + 1);
|
|
18
|
-
if (tail.includes(".") && isIPv4(tail)) {
|
|
19
|
-
const octets = tail.split(".").map(Number);
|
|
20
|
-
const highGroup = (octets[0] << 8 | octets[1]).toString(16).padStart(4, "0");
|
|
21
|
-
const lowGroup = (octets[2] << 8 | octets[3]).toString(16).padStart(4, "0");
|
|
22
|
-
workingAddress = `${workingAddress.slice(0, lastColonIndex + 1)}${highGroup}:${lowGroup}`;
|
|
23
|
-
}
|
|
24
|
-
let groups;
|
|
25
|
-
if (workingAddress.includes("::")) {
|
|
26
|
-
const [head, tailPart] = workingAddress.split("::");
|
|
27
|
-
const headGroups = head ? head.split(":").filter(Boolean) : [];
|
|
28
|
-
const tailGroups = tailPart ? tailPart.split(":").filter(Boolean) : [];
|
|
29
|
-
const missingGroupCount = 8 - headGroups.length - tailGroups.length;
|
|
30
|
-
groups = [...headGroups, ...Array(missingGroupCount).fill("0"), ...tailGroups];
|
|
31
|
-
} else {
|
|
32
|
-
groups = workingAddress.split(":");
|
|
33
|
-
}
|
|
34
|
-
return groups.map((group) => group.padStart(4, "0").toLowerCase());
|
|
35
|
-
}
|
|
36
|
-
function compressIpv6Groups(groups) {
|
|
37
|
-
const stripped = groups.map((group) => group.replace(/^0+(?=.)/, ""));
|
|
38
|
-
let bestStart = -1;
|
|
39
|
-
let bestLength = 0;
|
|
40
|
-
let currentStart = -1;
|
|
41
|
-
let currentLength = 0;
|
|
42
|
-
for (let index = 0;index < stripped.length; index += 1) {
|
|
43
|
-
if (stripped[index] === "0") {
|
|
44
|
-
if (currentStart === -1)
|
|
45
|
-
currentStart = index;
|
|
46
|
-
currentLength += 1;
|
|
47
|
-
if (currentLength > bestLength) {
|
|
48
|
-
bestLength = currentLength;
|
|
49
|
-
bestStart = currentStart;
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
currentStart = -1;
|
|
53
|
-
currentLength = 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (bestLength < 2) {
|
|
57
|
-
return stripped.join(":");
|
|
58
|
-
}
|
|
59
|
-
const before = stripped.slice(0, bestStart).join(":");
|
|
60
|
-
const after = stripped.slice(bestStart + bestLength).join(":");
|
|
61
|
-
return `${before}::${after}`;
|
|
62
|
-
}
|
|
63
|
-
function extractIpv4MappedAddress(groups) {
|
|
64
|
-
const isMapped = groups.slice(0, 5).every((group) => group === "0000") && groups[5] === "ffff";
|
|
65
|
-
if (!isMapped)
|
|
66
|
-
return null;
|
|
67
|
-
const highGroup = Number.parseInt(groups[6], 16);
|
|
68
|
-
const lowGroup = Number.parseInt(groups[7], 16);
|
|
69
|
-
return [highGroup >> 8, highGroup & 255, lowGroup >> 8, lowGroup & 255].join(".");
|
|
70
|
-
}
|
|
71
|
-
function stripPort(input) {
|
|
72
|
-
const trimmed = input.trim();
|
|
73
|
-
const bracketedMatch = /^\[([^\]]+)]:\d+$/.exec(trimmed);
|
|
74
|
-
if (bracketedMatch) {
|
|
75
|
-
return bracketedMatch[1];
|
|
76
|
-
}
|
|
77
|
-
if (/^\[[^\]]+]$/.test(trimmed)) {
|
|
78
|
-
return trimmed.slice(1, -1);
|
|
79
|
-
}
|
|
80
|
-
const ipv4WithPortMatch = /^(\d{1,3}(?:\.\d{1,3}){3}):\d+$/.exec(trimmed);
|
|
81
|
-
if (ipv4WithPortMatch) {
|
|
82
|
-
return ipv4WithPortMatch[1];
|
|
83
|
-
}
|
|
84
|
-
return trimmed;
|
|
85
|
-
}
|
|
86
|
-
function canonicalizeIpAddress(input) {
|
|
87
|
-
const withoutPort = stripPort(input);
|
|
88
|
-
const withoutZone = withoutPort.split("%")[0]?.trim().toLowerCase() ?? "";
|
|
89
|
-
if (isIPv4(withoutZone)) {
|
|
90
|
-
return withoutZone;
|
|
91
|
-
}
|
|
92
|
-
if (isIPv6(withoutZone)) {
|
|
93
|
-
const groups = expandIpv6Groups(withoutZone);
|
|
94
|
-
const mappedIpv4 = extractIpv4MappedAddress(groups);
|
|
95
|
-
if (mappedIpv4) {
|
|
96
|
-
return mappedIpv4;
|
|
97
|
-
}
|
|
98
|
-
return compressIpv6Groups(groups);
|
|
99
|
-
}
|
|
100
|
-
return withoutZone;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/oauth/security-utilities.ts
|
|
104
|
-
function ipToBigInt(address) {
|
|
105
|
-
if (isIPv42(address)) {
|
|
106
|
-
return {
|
|
107
|
-
family: 4,
|
|
108
|
-
value: address.split(".").map(Number).reduce((value, octet) => (value << 8n) + BigInt(octet), 0n)
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (!isIPv62(address))
|
|
112
|
-
return null;
|
|
113
|
-
return {
|
|
114
|
-
family: 6,
|
|
115
|
-
value: expandIpv6Groups(address).reduce((value, group) => (value << 16n) + BigInt(Number.parseInt(group, 16)), 0n)
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function parseCidr(cidr) {
|
|
119
|
-
const [address, prefixText, extra] = cidr.split("/");
|
|
120
|
-
if (!address || !prefixText || extra !== undefined || !/^\d+$/.test(prefixText))
|
|
121
|
-
return null;
|
|
122
|
-
const range = ipToBigInt(canonicalizeIpAddress(address));
|
|
123
|
-
if (!range)
|
|
124
|
-
return null;
|
|
125
|
-
const prefixLength = Number.parseInt(prefixText, 10);
|
|
126
|
-
if (prefixLength > (range.family === 4 ? 32 : 128))
|
|
127
|
-
return null;
|
|
128
|
-
return { ...range, prefixLength };
|
|
129
|
-
}
|
|
130
|
-
function isAddressInCidr(address, cidr) {
|
|
131
|
-
const range = parseCidr(cidr);
|
|
132
|
-
const candidate = ipToBigInt(canonicalizeIpAddress(address));
|
|
133
|
-
if (!range || !candidate || candidate.family !== range.family)
|
|
134
|
-
return false;
|
|
135
|
-
if (range.prefixLength === 0)
|
|
136
|
-
return true;
|
|
137
|
-
const shift = BigInt((candidate.family === 4 ? 32 : 128) - range.prefixLength);
|
|
138
|
-
return candidate.value >> shift === range.value >> shift;
|
|
139
|
-
}
|
|
140
|
-
function isValidCidr(cidr) {
|
|
141
|
-
return parseCidr(cidr) !== null;
|
|
142
|
-
}
|
|
143
|
-
function isValidRedirectUri(uri) {
|
|
144
|
-
let parsed;
|
|
145
|
-
try {
|
|
146
|
-
parsed = new URL(uri);
|
|
147
|
-
} catch {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
if (parsed.hash || parsed.username || parsed.password || parsed.hostname.includes("*"))
|
|
151
|
-
return false;
|
|
152
|
-
if (parsed.protocol === "https:")
|
|
153
|
-
return true;
|
|
154
|
-
return parsed.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname);
|
|
155
|
-
}
|
|
156
|
-
var controlCharacterPattern = /[\u0000-\u001F\u007F-\u009F]/;
|
|
157
|
-
var bidiControlCharacterPattern = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/;
|
|
158
|
-
var zeroWidthCharacterPattern = /[\u200B-\u200D\uFEFF]/;
|
|
159
|
-
var latinScriptCharacterPattern = /\p{Script=Latin}/u;
|
|
160
|
-
var confusableWithLatinScriptCharacterPattern = /\p{Script=Cyrillic}|\p{Script=Greek}/u;
|
|
161
|
-
function isValidClientName(name) {
|
|
162
|
-
return Boolean(name) && !controlCharacterPattern.test(name) && !bidiControlCharacterPattern.test(name) && !zeroWidthCharacterPattern.test(name) && !(latinScriptCharacterPattern.test(name) && confusableWithLatinScriptCharacterPattern.test(name));
|
|
163
|
-
}
|
|
164
|
-
function isExactContentType(value, expectedMediaType) {
|
|
165
|
-
if (value === null)
|
|
166
|
-
return false;
|
|
167
|
-
let inQuotes = false;
|
|
168
|
-
for (const character of value) {
|
|
169
|
-
if (character === '"')
|
|
170
|
-
inQuotes = !inQuotes;
|
|
171
|
-
else if (character === "," && !inQuotes)
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
return value.split(";")[0]?.trim().toLowerCase() === expectedMediaType;
|
|
175
|
-
}
|
|
176
|
-
function constantTimeEquals(leftValue, rightValue) {
|
|
177
|
-
const leftBuffer = Buffer.from(leftValue, "utf8");
|
|
178
|
-
const rightBuffer = Buffer.from(rightValue, "utf8");
|
|
179
|
-
if (leftBuffer.length !== rightBuffer.length)
|
|
180
|
-
return false;
|
|
181
|
-
return timingSafeEqual(leftBuffer, rightBuffer);
|
|
182
|
-
}
|
|
183
|
-
function withDeadline(promise, timeoutMilliseconds) {
|
|
184
|
-
return new Promise((resolve, reject) => {
|
|
185
|
-
const timer = setTimeout(() => reject(new Error(`Timed out after ${timeoutMilliseconds}ms`)), timeoutMilliseconds);
|
|
186
|
-
promise.then((value) => {
|
|
187
|
-
clearTimeout(timer);
|
|
188
|
-
resolve(value);
|
|
189
|
-
}, (error) => {
|
|
190
|
-
clearTimeout(timer);
|
|
191
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/oauth/safe-public-https-fetch.ts
|
|
197
|
-
import { lookup as defaultDnsLookup } from "node:dns/promises";
|
|
198
|
-
import { isIPv4 as isIPv43, isIPv6 as isIPv63 } from "node:net";
|
|
199
|
-
var defaultFetchTimeoutMilliseconds = 5000;
|
|
200
|
-
var blockedIpCidrs = [
|
|
201
|
-
"0.0.0.0/8",
|
|
202
|
-
"10.0.0.0/8",
|
|
203
|
-
"100.64.0.0/10",
|
|
204
|
-
"127.0.0.0/8",
|
|
205
|
-
"169.254.0.0/16",
|
|
206
|
-
"172.16.0.0/12",
|
|
207
|
-
"192.0.0.0/24",
|
|
208
|
-
"192.0.2.0/24",
|
|
209
|
-
"192.88.99.0/24",
|
|
210
|
-
"192.168.0.0/16",
|
|
211
|
-
"198.18.0.0/15",
|
|
212
|
-
"198.51.100.0/24",
|
|
213
|
-
"203.0.113.0/24",
|
|
214
|
-
"224.0.0.0/4",
|
|
215
|
-
"240.0.0.0/4",
|
|
216
|
-
"255.255.255.255/32",
|
|
217
|
-
"::1/128",
|
|
218
|
-
"::/128",
|
|
219
|
-
"64:ff9b::/96",
|
|
220
|
-
"::ffff:0:0/96",
|
|
221
|
-
"100::/64",
|
|
222
|
-
"2001:db8::/32",
|
|
223
|
-
"fc00::/7",
|
|
224
|
-
"fe80::/10",
|
|
225
|
-
"ff00::/8"
|
|
226
|
-
];
|
|
227
|
-
function isBlockedIpAddress(address) {
|
|
228
|
-
return blockedIpCidrs.some((cidr) => isAddressInCidr(address, cidr));
|
|
229
|
-
}
|
|
230
|
-
function stripIpv6Brackets(hostname) {
|
|
231
|
-
return hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
class ClientMetadataDocumentFetchError extends Error {
|
|
235
|
-
reason;
|
|
236
|
-
constructor(reason) {
|
|
237
|
-
super(reason);
|
|
238
|
-
this.reason = reason;
|
|
239
|
-
this.name = "ClientMetadataDocumentFetchError";
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
var lookupAll = (hostname, options) => defaultDnsLookup(hostname, options);
|
|
243
|
-
var dnsLookupConcurrencyLimit = 16;
|
|
244
|
-
var outstandingDnsLookupCount = 0;
|
|
245
|
-
var inFlightDnsLookupsByHostname = new Map;
|
|
246
|
-
function boundedCoalescedLookup(hostname, lookupImpl) {
|
|
247
|
-
const inFlight = inFlightDnsLookupsByHostname.get(hostname);
|
|
248
|
-
if (inFlight)
|
|
249
|
-
return inFlight;
|
|
250
|
-
if (outstandingDnsLookupCount >= dnsLookupConcurrencyLimit) {
|
|
251
|
-
return Promise.reject(new Error("DNS lookup concurrency limit exceeded"));
|
|
252
|
-
}
|
|
253
|
-
outstandingDnsLookupCount += 1;
|
|
254
|
-
const lookupPromise = lookupImpl(hostname, { all: true, verbatim: true }).finally(() => {
|
|
255
|
-
outstandingDnsLookupCount -= 1;
|
|
256
|
-
inFlightDnsLookupsByHostname.delete(hostname);
|
|
257
|
-
});
|
|
258
|
-
inFlightDnsLookupsByHostname.set(hostname, lookupPromise);
|
|
259
|
-
return lookupPromise;
|
|
260
|
-
}
|
|
261
|
-
async function assertHostnameIsPubliclyRoutable(hostname, lookupImpl, dnsTimeoutMilliseconds) {
|
|
262
|
-
if (isIPv43(hostname) || isIPv63(hostname)) {
|
|
263
|
-
if (isBlockedIpAddress(hostname)) {
|
|
264
|
-
throw new ClientMetadataDocumentFetchError("blocked_address");
|
|
265
|
-
}
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
let records;
|
|
269
|
-
try {
|
|
270
|
-
records = await withDeadline(boundedCoalescedLookup(hostname, lookupImpl), dnsTimeoutMilliseconds);
|
|
271
|
-
} catch {
|
|
272
|
-
throw new ClientMetadataDocumentFetchError("dns_resolution_failed");
|
|
273
|
-
}
|
|
274
|
-
if (records.length === 0)
|
|
275
|
-
throw new ClientMetadataDocumentFetchError("dns_resolution_failed");
|
|
276
|
-
if (records.some((record) => isBlockedIpAddress(record.address))) {
|
|
277
|
-
throw new ClientMetadataDocumentFetchError("blocked_address");
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
async function safeFetchPublicHttpsUrl(input, options = {}) {
|
|
281
|
-
const url = input instanceof URL ? input : new URL(input);
|
|
282
|
-
if (url.protocol !== "https:")
|
|
283
|
-
throw new ClientMetadataDocumentFetchError("https_required");
|
|
284
|
-
await assertHostnameIsPubliclyRoutable(stripIpv6Brackets(url.hostname), options.lookupImpl ?? lookupAll, options.dnsTimeoutMs ?? defaultFetchTimeoutMilliseconds);
|
|
285
|
-
return (options.fetchImpl ?? fetch)(url, {
|
|
286
|
-
method: "GET",
|
|
287
|
-
redirect: "error",
|
|
288
|
-
headers: options.headers,
|
|
289
|
-
signal: AbortSignal.timeout(options.fetchTimeoutMs ?? defaultFetchTimeoutMilliseconds)
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function resetDnsLookupConcurrencyLimiterForTests() {
|
|
293
|
-
outstandingDnsLookupCount = 0;
|
|
294
|
-
inFlightDnsLookupsByHostname.clear();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// src/oauth/client-metadata-documents.ts
|
|
298
|
-
var cimdMaxResponseBytes = 16 * 1024;
|
|
299
|
-
var cimdCacheTtlMs = 10 * 60 * 1000;
|
|
300
|
-
var cimdCacheMaxEntries = 1000;
|
|
301
|
-
var oauthMaxClientNameLength = 200;
|
|
302
|
-
var oauthMaxGrantTypeCount = 5;
|
|
303
|
-
var oauthMaxRedirectUriCount = 10;
|
|
304
|
-
var oauthMaxRedirectUriLength = 2048;
|
|
305
|
-
var oauthMaxResponseTypeCount = 5;
|
|
306
|
-
function isClientIdMetadataDocumentUrl(clientId) {
|
|
307
|
-
let parsed;
|
|
308
|
-
try {
|
|
309
|
-
parsed = new URL(clientId);
|
|
310
|
-
} catch {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
if (parsed.protocol !== "https:")
|
|
314
|
-
return false;
|
|
315
|
-
if (parsed.hash !== "" || parsed.username !== "" || parsed.password !== "")
|
|
316
|
-
return false;
|
|
317
|
-
if (parsed.pathname === "" || parsed.pathname === "/")
|
|
318
|
-
return false;
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
var applicationTypes = ["web", "native"];
|
|
322
|
-
function documentRedirectUrisMatchApplicationType(redirectUris, applicationType) {
|
|
323
|
-
if (applicationType !== "web")
|
|
324
|
-
return true;
|
|
325
|
-
return redirectUris.every((uri) => new URL(uri).protocol === "https:");
|
|
326
|
-
}
|
|
327
|
-
var clientMetadataDocumentSchema = z.object({
|
|
328
|
-
client_id: z.string().url(),
|
|
329
|
-
client_name: z.string().min(1).max(oauthMaxClientNameLength).refine(isValidClientName, "client_name must not contain control or confusable characters"),
|
|
330
|
-
redirect_uris: z.array(z.string().url().max(oauthMaxRedirectUriLength)).min(1, "At least one redirect URI is required").max(oauthMaxRedirectUriCount).refine((uris) => uris.every(isValidRedirectUri), "Redirect URIs must use HTTPS (or http://localhost for development)"),
|
|
331
|
-
grant_types: z.array(z.string().min(1).max(256).regex(/^[\x21-\x7e]+$/)).max(oauthMaxGrantTypeCount).default(["authorization_code", "refresh_token"]),
|
|
332
|
-
response_types: z.array(z.enum(["code"])).max(oauthMaxResponseTypeCount).default(["code"]),
|
|
333
|
-
token_endpoint_auth_method: z.literal("none").default("none"),
|
|
334
|
-
application_type: z.enum(applicationTypes).optional()
|
|
335
|
-
}).superRefine((data, ctx) => {
|
|
336
|
-
if (!documentRedirectUrisMatchApplicationType(data.redirect_uris, data.application_type)) {
|
|
337
|
-
ctx.addIssue({
|
|
338
|
-
code: "custom",
|
|
339
|
-
message: 'application_type "web" requires every redirect_uri to use HTTPS.',
|
|
340
|
-
path: ["redirect_uris"]
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
var documentCache = new Map;
|
|
345
|
-
function cacheDocument(document, expiresAt) {
|
|
346
|
-
documentCache.delete(document.clientId);
|
|
347
|
-
documentCache.set(document.clientId, { document, expiresAt });
|
|
348
|
-
while (documentCache.size > cimdCacheMaxEntries) {
|
|
349
|
-
const oldestKey = documentCache.keys().next().value;
|
|
350
|
-
if (oldestKey === undefined)
|
|
351
|
-
break;
|
|
352
|
-
documentCache.delete(oldestKey);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
async function readBoundedResponseText(response, maxBytes) {
|
|
356
|
-
const declaredLength = response.headers.get("content-length");
|
|
357
|
-
if (declaredLength !== null) {
|
|
358
|
-
const declaredBytes = Number(declaredLength);
|
|
359
|
-
if (Number.isFinite(declaredBytes) && declaredBytes > maxBytes) {
|
|
360
|
-
throw new ClientMetadataDocumentFetchError("response_too_large");
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (!response.body)
|
|
364
|
-
return "";
|
|
365
|
-
const reader = response.body.getReader();
|
|
366
|
-
const chunks = [];
|
|
367
|
-
let receivedBytes = 0;
|
|
368
|
-
while (true) {
|
|
369
|
-
const { done, value } = await reader.read();
|
|
370
|
-
if (done)
|
|
371
|
-
break;
|
|
372
|
-
receivedBytes += value.byteLength;
|
|
373
|
-
if (receivedBytes > maxBytes) {
|
|
374
|
-
await reader.cancel(new Error("response too large")).catch(() => {});
|
|
375
|
-
throw new ClientMetadataDocumentFetchError("response_too_large");
|
|
376
|
-
}
|
|
377
|
-
chunks.push(value);
|
|
378
|
-
}
|
|
379
|
-
const combined = new Uint8Array(receivedBytes);
|
|
380
|
-
let offset = 0;
|
|
381
|
-
for (const chunk of chunks) {
|
|
382
|
-
combined.set(chunk, offset);
|
|
383
|
-
offset += chunk.byteLength;
|
|
384
|
-
}
|
|
385
|
-
try {
|
|
386
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(combined);
|
|
387
|
-
} catch {
|
|
388
|
-
throw new ClientMetadataDocumentFetchError("invalid_encoding");
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
async function fetchClientIdMetadataDocument(clientId, dependencies = {}) {
|
|
392
|
-
if (!isClientIdMetadataDocumentUrl(clientId))
|
|
393
|
-
return null;
|
|
394
|
-
const now = dependencies.now ?? Date.now;
|
|
395
|
-
const cached = documentCache.get(clientId);
|
|
396
|
-
if (cached && cached.expiresAt > now()) {
|
|
397
|
-
return cached.document;
|
|
398
|
-
}
|
|
399
|
-
const url = new URL(clientId);
|
|
400
|
-
let response;
|
|
401
|
-
try {
|
|
402
|
-
response = await safeFetchPublicHttpsUrl(url, {
|
|
403
|
-
fetchImpl: dependencies.fetchImpl,
|
|
404
|
-
lookupImpl: dependencies.lookupImpl,
|
|
405
|
-
dnsTimeoutMs: dependencies.dnsTimeoutMs,
|
|
406
|
-
headers: { accept: "application/json" }
|
|
407
|
-
});
|
|
408
|
-
} catch (error) {
|
|
409
|
-
engineLogger.warn({ err: error, clientIdHostname: url.hostname }, "Client ID Metadata Document safe fetch failed");
|
|
410
|
-
return null;
|
|
411
|
-
}
|
|
412
|
-
if (!response.ok)
|
|
413
|
-
return null;
|
|
414
|
-
if (!isExactContentType(response.headers.get("content-type"), "application/json"))
|
|
415
|
-
return null;
|
|
416
|
-
let bodyText;
|
|
417
|
-
try {
|
|
418
|
-
bodyText = await readBoundedResponseText(response, cimdMaxResponseBytes);
|
|
419
|
-
} catch (error) {
|
|
420
|
-
engineLogger.warn({ err: error }, "Client ID Metadata Document body rejected");
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
let parsedJson;
|
|
424
|
-
try {
|
|
425
|
-
parsedJson = JSON.parse(bodyText);
|
|
426
|
-
} catch {
|
|
427
|
-
return null;
|
|
428
|
-
}
|
|
429
|
-
const parsed = clientMetadataDocumentSchema.safeParse(parsedJson);
|
|
430
|
-
if (!parsed.success)
|
|
431
|
-
return null;
|
|
432
|
-
if (parsed.data.client_id !== clientId)
|
|
433
|
-
return null;
|
|
434
|
-
const document = {
|
|
435
|
-
clientId,
|
|
436
|
-
clientName: parsed.data.client_name,
|
|
437
|
-
redirectUris: parsed.data.redirect_uris,
|
|
438
|
-
grantTypes: parsed.data.grant_types,
|
|
439
|
-
responseTypes: parsed.data.response_types,
|
|
440
|
-
applicationType: parsed.data.application_type ?? null
|
|
441
|
-
};
|
|
442
|
-
cacheDocument(document, now() + cimdCacheTtlMs);
|
|
443
|
-
return document;
|
|
444
|
-
}
|
|
445
|
-
function clearClientIdMetadataDocumentCacheForTests() {
|
|
446
|
-
documentCache.clear();
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
export { expandIpv6Groups, stripPort, canonicalizeIpAddress, isAddressInCidr, isValidCidr, isValidRedirectUri, isValidClientName, isExactContentType, constantTimeEquals, withDeadline, ClientMetadataDocumentFetchError, safeFetchPublicHttpsUrl, resetDnsLookupConcurrencyLimiterForTests, isClientIdMetadataDocumentUrl, fetchClientIdMetadataDocument, clearClientIdMetadataDocumentCacheForTests };
|
package/dist/chunk-rxnyn7tf.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// src/ui-extension-support.ts
|
|
2
|
-
import { RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
|
|
3
|
-
function hasRegisteredUiExtensionResource(registry) {
|
|
4
|
-
return registry.resources.some((resource) => resource.mimeType === RESOURCE_MIME_TYPE);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// src/supported-scopes.ts
|
|
8
|
-
function getSupportedScopes(registry) {
|
|
9
|
-
const scopes = new Set;
|
|
10
|
-
for (const tool of registry.tools)
|
|
11
|
-
scopes.add(tool.requiredScope);
|
|
12
|
-
for (const resource of registry.resources)
|
|
13
|
-
scopes.add(resource.requiredScope);
|
|
14
|
-
for (const prompt of registry.prompts)
|
|
15
|
-
scopes.add(prompt.requiredScope);
|
|
16
|
-
return [...scopes].sort();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { hasRegisteredUiExtensionResource, getSupportedScopes };
|
package/dist/chunk-taxyscge.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// src/metrics.ts
|
|
2
|
-
var MAX_DURATIONS = 1000;
|
|
3
|
-
function percentile(sorted, p) {
|
|
4
|
-
if (sorted.length === 0)
|
|
5
|
-
return 0;
|
|
6
|
-
const index = Math.ceil(p / 100 * sorted.length) - 1;
|
|
7
|
-
return sorted[Math.max(0, index)];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
class MetricsCollector {
|
|
11
|
-
tools = new Map;
|
|
12
|
-
events = new Map;
|
|
13
|
-
startedAt = Date.now();
|
|
14
|
-
recordToolInvocation(name, durationMs, isError) {
|
|
15
|
-
let entry = this.tools.get(name);
|
|
16
|
-
if (!entry) {
|
|
17
|
-
entry = { invocations: 0, errors: 0, durations: [] };
|
|
18
|
-
this.tools.set(name, entry);
|
|
19
|
-
}
|
|
20
|
-
entry.invocations++;
|
|
21
|
-
if (isError)
|
|
22
|
-
entry.errors++;
|
|
23
|
-
entry.durations.push(durationMs);
|
|
24
|
-
if (entry.durations.length > MAX_DURATIONS) {
|
|
25
|
-
entry.durations = entry.durations.slice(-MAX_DURATIONS);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
recordEvent(category, outcome) {
|
|
29
|
-
let outcomes = this.events.get(category);
|
|
30
|
-
if (!outcomes) {
|
|
31
|
-
outcomes = new Map;
|
|
32
|
-
this.events.set(category, outcomes);
|
|
33
|
-
}
|
|
34
|
-
outcomes.set(outcome, (outcomes.get(outcome) ?? 0) + 1);
|
|
35
|
-
}
|
|
36
|
-
snapshot() {
|
|
37
|
-
const tools = Object.create(null);
|
|
38
|
-
for (const [name, entry] of this.tools) {
|
|
39
|
-
const sorted = [...entry.durations].sort((a, b) => a - b);
|
|
40
|
-
tools[name] = {
|
|
41
|
-
invocations: entry.invocations,
|
|
42
|
-
errors: entry.errors,
|
|
43
|
-
p50: percentile(sorted, 50),
|
|
44
|
-
p95: percentile(sorted, 95),
|
|
45
|
-
p99: percentile(sorted, 99)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const events = {};
|
|
49
|
-
for (const [category, outcomes] of this.events) {
|
|
50
|
-
events[category] = Object.fromEntries(outcomes);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
tools,
|
|
54
|
-
events,
|
|
55
|
-
uptimeSeconds: Math.floor((Date.now() - this.startedAt) / 1000),
|
|
56
|
-
collectedAt: new Date().toISOString()
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
reset() {
|
|
60
|
-
this.tools.clear();
|
|
61
|
-
this.events.clear();
|
|
62
|
-
this.startedAt = Date.now();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
var metricsCollector = new MetricsCollector;
|
|
66
|
-
|
|
67
|
-
export { metricsCollector };
|