@lostgradient/mcp 0.1.0 → 0.2.1
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 +68 -8
- package/dist/chunk-3ek3knfm.js +73 -0
- package/dist/{chunk-v14p4gng.js → chunk-3rr24vhh.js} +4 -1
- package/dist/chunk-6ekjtvcq.js +273 -0
- package/dist/chunk-7dpts3r9.js +909 -0
- package/dist/chunk-88nhf6xt.js +449 -0
- package/dist/{chunk-psnez3q2.js → chunk-k6fm3cmk.js} +23 -2
- package/dist/chunk-rxnyn7tf.js +19 -0
- package/dist/{chunk-mf3t0afg.js → chunk-wfty87ws.js} +1 -1
- package/dist/{chunk-wmkqd45r.js → chunk-xcf742mf.js} +1 -1
- package/dist/chunk-yf4nw40e.js +1102 -0
- package/dist/conformance.d.ts +43 -0
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/environment-schema.d.ts +1 -1
- package/dist/environment-schema.js +1 -1
- package/dist/http/authenticate.d.ts +35 -0
- package/dist/http/authorization-header.d.ts +5 -0
- package/dist/http/grant-revocation-channel.d.ts +24 -0
- package/dist/http/handler.d.ts +32 -0
- package/dist/http/index.d.ts +27 -0
- package/dist/http/index.js +813 -0
- package/dist/http/request-context.d.ts +17 -0
- package/dist/http/responses.d.ts +11 -0
- package/dist/http/serving-layer.d.ts +18 -0
- package/dist/http/user-handler-cache.d.ts +37 -0
- package/dist/http/user-server-event-bus.d.ts +35 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +230 -940
- package/dist/logger.d.ts +20 -0
- package/dist/logger.js +9 -5
- package/dist/oauth/authorize-endpoint.d.ts +5 -0
- package/dist/oauth/canonicalize-ip-address.d.ts +20 -0
- package/dist/oauth/client-authentication.d.ts +10 -0
- package/dist/oauth/client-metadata-documents.d.ts +52 -0
- package/dist/oauth/client-metadata-documents.js +19 -0
- package/dist/oauth/discovery-metadata.d.ts +19 -0
- package/dist/oauth/endpoint-rate-limits.d.ts +10 -0
- package/dist/oauth/endpoint-responses.d.ts +10 -0
- package/dist/oauth/index.d.ts +214 -0
- package/dist/oauth/index.js +69 -0
- package/dist/oauth/network-identity.d.ts +32 -0
- package/dist/oauth/pkce-validation.d.ts +2 -0
- package/dist/oauth/postgres/client-store.d.ts +12 -0
- package/dist/oauth/postgres/code-store.d.ts +14 -0
- package/dist/oauth/postgres/database.d.ts +18 -0
- package/dist/oauth/postgres/index.d.ts +11 -0
- package/dist/oauth/postgres/index.js +584 -0
- package/dist/oauth/postgres/schema.d.ts +1455 -0
- package/dist/oauth/postgres/token-store.d.ts +16 -0
- package/dist/oauth/postgres/transaction-store.d.ts +14 -0
- package/dist/oauth/redirect-uri-matching.d.ts +2 -0
- package/dist/oauth/registration-endpoint.d.ts +2 -0
- package/dist/oauth/request-body.d.ts +14 -0
- package/dist/oauth/revocation-endpoint.d.ts +2 -0
- package/dist/oauth/safe-public-https-fetch.d.ts +28 -0
- package/dist/oauth/scope-utilities.d.ts +15 -0
- package/dist/oauth/security-utilities.d.ts +8 -0
- package/dist/oauth/stores.d.ts +225 -0
- package/dist/oauth/stores.js +0 -0
- package/dist/oauth/testing/contract-fixtures.d.ts +134 -0
- package/dist/oauth/testing/index.d.ts +56 -0
- package/dist/oauth/testing/index.js +330 -0
- package/dist/oauth/token-endpoint.d.ts +2 -0
- package/dist/oauth-scope-configuration.d.ts +3 -0
- package/dist/rate-limit/in-memory-sliding-window-store.d.ts +3 -0
- package/dist/rate-limit/index.d.ts +23 -0
- package/dist/rate-limit/index.js +29 -0
- package/dist/rate-limit/mcp-concurrency-limiter.d.ts +26 -0
- package/dist/rate-limit/rate-limit-response.d.ts +1 -0
- package/dist/rate-limit/redis-sliding-window-store.d.ts +2 -0
- package/dist/rate-limit/request-rate-limiter.d.ts +10 -0
- package/dist/rate-limit/sliding-window-rate-limiter.d.ts +16 -0
- package/dist/scopes.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/sveltekit-mount-state.d.ts +4 -0
- package/dist/sveltekit-mount.d.ts +43 -0
- package/dist/sveltekit-mount.js +332 -0
- package/dist/tool-response.d.ts +6 -0
- package/dist/types/primitives.d.ts +1 -1
- package/dist/ui-extension-support.d.ts +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +56 -4
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// src/oauth/testing/index.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
function hash(value) {
|
|
4
|
+
return createHash("sha256").update(value).digest("hex");
|
|
5
|
+
}
|
|
6
|
+
function cloneDate(date) {
|
|
7
|
+
return new Date(date);
|
|
8
|
+
}
|
|
9
|
+
function cloneTransaction(record) {
|
|
10
|
+
return {
|
|
11
|
+
...record,
|
|
12
|
+
expiresAt: cloneDate(record.expiresAt),
|
|
13
|
+
consumedAt: record.consumedAt && cloneDate(record.consumedAt),
|
|
14
|
+
createdAt: cloneDate(record.createdAt)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function cloneCode(record) {
|
|
18
|
+
return {
|
|
19
|
+
...record,
|
|
20
|
+
expiresAt: cloneDate(record.expiresAt),
|
|
21
|
+
usedAt: record.usedAt && cloneDate(record.usedAt),
|
|
22
|
+
createdAt: cloneDate(record.createdAt)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function cloneAccessToken(record) {
|
|
26
|
+
return {
|
|
27
|
+
...record,
|
|
28
|
+
expiresAt: cloneDate(record.expiresAt),
|
|
29
|
+
revokedAt: record.revokedAt && cloneDate(record.revokedAt),
|
|
30
|
+
createdAt: cloneDate(record.createdAt)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function cloneRefreshToken(record) {
|
|
34
|
+
return {
|
|
35
|
+
...record,
|
|
36
|
+
expiresAt: cloneDate(record.expiresAt),
|
|
37
|
+
revokedAt: record.revokedAt && cloneDate(record.revokedAt),
|
|
38
|
+
createdAt: cloneDate(record.createdAt)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class InMemoryTransactionStore {
|
|
43
|
+
#records = new Map;
|
|
44
|
+
create(input) {
|
|
45
|
+
const transactionIdHash = hash(input.transactionId);
|
|
46
|
+
this.#records.set(transactionIdHash, {
|
|
47
|
+
record: cloneTransaction({ ...input.record, transactionIdHash }),
|
|
48
|
+
csrfTokenHash: hash(input.csrfToken),
|
|
49
|
+
consentBinding: input.consentBinding
|
|
50
|
+
});
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
consume(transactionId, csrfToken, binding, subjectId) {
|
|
54
|
+
const entry = this.#records.get(hash(transactionId));
|
|
55
|
+
const now = new Date;
|
|
56
|
+
if (!entry || entry.record.consumedAt || entry.record.expiresAt <= now || entry.csrfTokenHash !== hash(csrfToken) || entry.consentBinding !== binding || entry.record.userId !== subjectId)
|
|
57
|
+
return Promise.resolve(null);
|
|
58
|
+
entry.record.consumedAt = now;
|
|
59
|
+
return Promise.resolve(cloneTransaction(entry.record));
|
|
60
|
+
}
|
|
61
|
+
unconsume(transactionId, consumedAt) {
|
|
62
|
+
const entry = this.#records.get(hash(transactionId));
|
|
63
|
+
if (!entry?.record.consumedAt || entry.record.consumedAt.getTime() !== consumedAt.getTime())
|
|
64
|
+
return Promise.resolve(false);
|
|
65
|
+
entry.record.consumedAt = null;
|
|
66
|
+
return Promise.resolve(true);
|
|
67
|
+
}
|
|
68
|
+
deleteByBinding(value) {
|
|
69
|
+
return Promise.resolve(this.#deleteWhere((entry) => entry.consentBinding === value));
|
|
70
|
+
}
|
|
71
|
+
deleteAllForUser(userId) {
|
|
72
|
+
return Promise.resolve(this.#deleteWhere((entry) => entry.record.userId === userId));
|
|
73
|
+
}
|
|
74
|
+
purgeExpired(now) {
|
|
75
|
+
return Promise.resolve(this.#deleteWhere((entry) => entry.record.expiresAt <= now));
|
|
76
|
+
}
|
|
77
|
+
#deleteWhere(predicate) {
|
|
78
|
+
let deleted = 0;
|
|
79
|
+
for (const [key, entry] of this.#records)
|
|
80
|
+
if (predicate(entry)) {
|
|
81
|
+
this.#records.delete(key);
|
|
82
|
+
deleted += 1;
|
|
83
|
+
}
|
|
84
|
+
return deleted;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class InMemoryCodeStore {
|
|
89
|
+
#records = new Map;
|
|
90
|
+
issue(record) {
|
|
91
|
+
this.#records.set(record.codeHash, cloneCode(record));
|
|
92
|
+
return Promise.resolve();
|
|
93
|
+
}
|
|
94
|
+
findByHash(codeHash) {
|
|
95
|
+
const record = this.#records.get(codeHash);
|
|
96
|
+
return Promise.resolve(record ? cloneCode(record) : null);
|
|
97
|
+
}
|
|
98
|
+
consume(codeHash, now) {
|
|
99
|
+
const record = this.#records.get(codeHash);
|
|
100
|
+
if (!record || record.usedAt || record.expiresAt <= now)
|
|
101
|
+
return Promise.resolve(null);
|
|
102
|
+
record.usedAt = cloneDate(now);
|
|
103
|
+
return Promise.resolve(cloneCode(record));
|
|
104
|
+
}
|
|
105
|
+
unconsume(codeHash, usedAt) {
|
|
106
|
+
const record = this.#records.get(codeHash);
|
|
107
|
+
if (!record?.usedAt || record.usedAt.getTime() !== usedAt.getTime())
|
|
108
|
+
return Promise.resolve(false);
|
|
109
|
+
record.usedAt = null;
|
|
110
|
+
return Promise.resolve(true);
|
|
111
|
+
}
|
|
112
|
+
deleteAllForUser(userId) {
|
|
113
|
+
return Promise.resolve(this.#deleteWhere((record) => record.userId === userId));
|
|
114
|
+
}
|
|
115
|
+
purgeExpired(now) {
|
|
116
|
+
return Promise.resolve(this.#deleteWhere((record) => record.expiresAt <= now));
|
|
117
|
+
}
|
|
118
|
+
#deleteWhere(predicate) {
|
|
119
|
+
let deleted = 0;
|
|
120
|
+
for (const [key, record] of this.#records)
|
|
121
|
+
if (predicate(record)) {
|
|
122
|
+
this.#records.delete(key);
|
|
123
|
+
deleted += 1;
|
|
124
|
+
}
|
|
125
|
+
return deleted;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
class InMemoryTokenStore {
|
|
130
|
+
#accessTokens = new Map;
|
|
131
|
+
#refreshTokens = new Map;
|
|
132
|
+
issueAuthorizationGrant(input) {
|
|
133
|
+
this.#accessTokens.set(input.accessToken.accessTokenHash, cloneAccessToken(input.accessToken));
|
|
134
|
+
if (input.refreshToken)
|
|
135
|
+
this.#refreshTokens.set(input.refreshToken.refreshTokenHash, cloneRefreshToken(input.refreshToken));
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
findByHash(tokenHash) {
|
|
139
|
+
const record = this.#accessTokens.get(tokenHash);
|
|
140
|
+
return Promise.resolve(record ? cloneAccessToken(record) : null);
|
|
141
|
+
}
|
|
142
|
+
rotateRefreshToken(input) {
|
|
143
|
+
const prior = this.#refreshTokens.get(input.priorHash);
|
|
144
|
+
if (!prior || prior.clientId !== input.clientId || prior.resource !== input.resource)
|
|
145
|
+
return Promise.resolve({ status: "invalid" });
|
|
146
|
+
if (prior.revokedAt) {
|
|
147
|
+
this.#revokeFamily(prior.familyId, input.createdAt);
|
|
148
|
+
return Promise.resolve({
|
|
149
|
+
status: "replay_revoked",
|
|
150
|
+
userId: prior.userId,
|
|
151
|
+
familyId: prior.familyId
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (prior.expiresAt <= input.createdAt)
|
|
155
|
+
return Promise.resolve({ status: "invalid" });
|
|
156
|
+
if (input.requestedScope && !isScopeSubset(input.requestedScope, prior.scope))
|
|
157
|
+
return Promise.resolve({ status: "scope_rejected" });
|
|
158
|
+
prior.revokedAt = cloneDate(input.createdAt);
|
|
159
|
+
const pairedAccessToken = this.#accessTokens.get(prior.accessTokenHash);
|
|
160
|
+
if (pairedAccessToken)
|
|
161
|
+
pairedAccessToken.revokedAt = cloneDate(input.createdAt);
|
|
162
|
+
const scope = input.requestedScope ?? prior.scope;
|
|
163
|
+
const accessToken = {
|
|
164
|
+
accessTokenHash: input.nextAccessTokenHash,
|
|
165
|
+
clientId: prior.clientId,
|
|
166
|
+
userId: prior.userId,
|
|
167
|
+
scope,
|
|
168
|
+
resource: prior.resource,
|
|
169
|
+
expiresAt: cloneDate(input.accessTokenExpiresAt),
|
|
170
|
+
revokedAt: null,
|
|
171
|
+
createdAt: cloneDate(input.createdAt)
|
|
172
|
+
};
|
|
173
|
+
const refreshToken = {
|
|
174
|
+
refreshTokenHash: input.nextRefreshTokenHash,
|
|
175
|
+
clientId: prior.clientId,
|
|
176
|
+
userId: prior.userId,
|
|
177
|
+
scope,
|
|
178
|
+
resource: prior.resource,
|
|
179
|
+
accessTokenHash: accessToken.accessTokenHash,
|
|
180
|
+
familyId: prior.familyId,
|
|
181
|
+
expiresAt: cloneDate(input.refreshTokenExpiresAt),
|
|
182
|
+
revokedAt: null,
|
|
183
|
+
createdAt: cloneDate(input.createdAt)
|
|
184
|
+
};
|
|
185
|
+
this.#accessTokens.set(accessToken.accessTokenHash, accessToken);
|
|
186
|
+
this.#refreshTokens.set(refreshToken.refreshTokenHash, refreshToken);
|
|
187
|
+
return Promise.resolve({
|
|
188
|
+
status: "rotated",
|
|
189
|
+
accessToken: cloneAccessToken(accessToken),
|
|
190
|
+
refreshToken: cloneRefreshToken(refreshToken)
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
revokeAccessToken(tokenHash, clientId) {
|
|
194
|
+
const token = this.#accessTokens.get(tokenHash);
|
|
195
|
+
if (!token || token.clientId !== clientId)
|
|
196
|
+
return Promise.resolve(false);
|
|
197
|
+
const now = new Date;
|
|
198
|
+
token.revokedAt ??= now;
|
|
199
|
+
for (const refresh of this.#refreshTokens.values())
|
|
200
|
+
if (refresh.accessTokenHash === tokenHash)
|
|
201
|
+
refresh.revokedAt ??= now;
|
|
202
|
+
return Promise.resolve(true);
|
|
203
|
+
}
|
|
204
|
+
revokeRefreshToken(tokenHash, clientId) {
|
|
205
|
+
const token = this.#refreshTokens.get(tokenHash);
|
|
206
|
+
if (!token || token.clientId !== clientId)
|
|
207
|
+
return Promise.resolve({ status: "invalid" });
|
|
208
|
+
const now = new Date;
|
|
209
|
+
if (token.revokedAt) {
|
|
210
|
+
this.#revokeFamily(token.familyId, now);
|
|
211
|
+
return Promise.resolve({
|
|
212
|
+
status: "replay_revoked",
|
|
213
|
+
userId: token.userId,
|
|
214
|
+
familyId: token.familyId
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
token.revokedAt = now;
|
|
218
|
+
const access = this.#accessTokens.get(token.accessTokenHash);
|
|
219
|
+
if (access)
|
|
220
|
+
access.revokedAt ??= now;
|
|
221
|
+
return Promise.resolve({ status: "revoked", userId: token.userId, familyId: token.familyId });
|
|
222
|
+
}
|
|
223
|
+
revokeFamily(familyId) {
|
|
224
|
+
return Promise.resolve(this.#revokeFamily(familyId, new Date));
|
|
225
|
+
}
|
|
226
|
+
deleteAllForUser(userId) {
|
|
227
|
+
let deleted = 0;
|
|
228
|
+
for (const [key, token] of this.#accessTokens)
|
|
229
|
+
if (token.userId === userId) {
|
|
230
|
+
this.#accessTokens.delete(key);
|
|
231
|
+
deleted += 1;
|
|
232
|
+
}
|
|
233
|
+
for (const [key, token] of this.#refreshTokens)
|
|
234
|
+
if (token.userId === userId) {
|
|
235
|
+
this.#refreshTokens.delete(key);
|
|
236
|
+
deleted += 1;
|
|
237
|
+
}
|
|
238
|
+
return Promise.resolve(deleted);
|
|
239
|
+
}
|
|
240
|
+
purgeExpired(now) {
|
|
241
|
+
let deleted = 0;
|
|
242
|
+
for (const [key, token] of this.#accessTokens)
|
|
243
|
+
if (token.expiresAt <= now) {
|
|
244
|
+
this.#accessTokens.delete(key);
|
|
245
|
+
deleted += 1;
|
|
246
|
+
}
|
|
247
|
+
for (const [key, token] of this.#refreshTokens)
|
|
248
|
+
if (token.expiresAt <= now) {
|
|
249
|
+
this.#refreshTokens.delete(key);
|
|
250
|
+
deleted += 1;
|
|
251
|
+
}
|
|
252
|
+
return Promise.resolve(deleted);
|
|
253
|
+
}
|
|
254
|
+
#revokeFamily(familyId, now) {
|
|
255
|
+
let revoked = 0;
|
|
256
|
+
const accessHashes = new Set;
|
|
257
|
+
for (const token of this.#refreshTokens.values())
|
|
258
|
+
if (token.familyId === familyId) {
|
|
259
|
+
if (!token.revokedAt) {
|
|
260
|
+
token.revokedAt = cloneDate(now);
|
|
261
|
+
revoked += 1;
|
|
262
|
+
}
|
|
263
|
+
accessHashes.add(token.accessTokenHash);
|
|
264
|
+
}
|
|
265
|
+
for (const hash2 of accessHashes) {
|
|
266
|
+
const token = this.#accessTokens.get(hash2);
|
|
267
|
+
if (token && !token.revokedAt) {
|
|
268
|
+
token.revokedAt = cloneDate(now);
|
|
269
|
+
revoked += 1;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return revoked;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function isScopeSubset(requested, granted) {
|
|
276
|
+
const grantedScopes = new Set((granted ?? "").split(/\s+/).filter(Boolean));
|
|
277
|
+
return requested.split(/\s+/).filter(Boolean).every((scope) => grantedScopes.has(scope));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
class InMemoryClientStore {
|
|
281
|
+
#records = new Map;
|
|
282
|
+
register(record) {
|
|
283
|
+
if (this.#records.has(record.clientId))
|
|
284
|
+
return Promise.reject(new Error(`Client already registered: ${record.clientId}`));
|
|
285
|
+
this.#records.set(record.clientId, structuredClone(record));
|
|
286
|
+
return Promise.resolve();
|
|
287
|
+
}
|
|
288
|
+
upsert(record) {
|
|
289
|
+
this.#records.set(record.clientId, structuredClone(record));
|
|
290
|
+
return Promise.resolve();
|
|
291
|
+
}
|
|
292
|
+
findById(clientId) {
|
|
293
|
+
const record = this.#records.get(clientId);
|
|
294
|
+
return Promise.resolve(record ? structuredClone(record) : null);
|
|
295
|
+
}
|
|
296
|
+
update(clientId, patch) {
|
|
297
|
+
const record = this.#records.get(clientId);
|
|
298
|
+
if (!record)
|
|
299
|
+
return Promise.resolve();
|
|
300
|
+
this.#records.set(clientId, structuredClone({ ...record, ...patch, clientId }));
|
|
301
|
+
return Promise.resolve();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function createInMemoryOAuthStores() {
|
|
305
|
+
const transactions = new InMemoryTransactionStore;
|
|
306
|
+
const codes = new InMemoryCodeStore;
|
|
307
|
+
const tokens = new InMemoryTokenStore;
|
|
308
|
+
const clients = new InMemoryClientStore;
|
|
309
|
+
return {
|
|
310
|
+
transactions,
|
|
311
|
+
codes,
|
|
312
|
+
tokens,
|
|
313
|
+
clients,
|
|
314
|
+
async deleteAllForUser(userId) {
|
|
315
|
+
const [transactionCount, codeCount, tokenCount] = await Promise.all([
|
|
316
|
+
transactions.deleteAllForUser(userId),
|
|
317
|
+
codes.deleteAllForUser(userId),
|
|
318
|
+
tokens.deleteAllForUser(userId)
|
|
319
|
+
]);
|
|
320
|
+
return { transactions: transactionCount, codes: codeCount, tokens: tokenCount };
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
export {
|
|
325
|
+
InMemoryClientStore,
|
|
326
|
+
InMemoryCodeStore,
|
|
327
|
+
InMemoryTokenStore,
|
|
328
|
+
InMemoryTransactionStore,
|
|
329
|
+
createInMemoryOAuthStores
|
|
330
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { OAuthScopeConfiguration } from './oauth/index.js';
|
|
2
|
+
/** Binds an OAuth supported-scope subset to its vocabulary. */
|
|
3
|
+
export declare function defineOAuthScopeConfiguration<Scope extends string>(configuration: OAuthScopeConfiguration<Scope>): OAuthScopeConfiguration<Scope>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as inMemoryStoreModule from './in-memory-sliding-window-store.js';
|
|
2
|
+
import * as concurrencyModule from './mcp-concurrency-limiter.js';
|
|
3
|
+
import * as responseModule from './rate-limit-response.js';
|
|
4
|
+
import * as redisStoreModule from './redis-sliding-window-store.js';
|
|
5
|
+
import * as requestLimiterModule from './request-rate-limiter.js';
|
|
6
|
+
import * as slidingWindowModule from './sliding-window-rate-limiter.js';
|
|
7
|
+
export declare const attachConcurrencySlotToResponseLifetime: typeof concurrencyModule.attachConcurrencySlotToResponseLifetime;
|
|
8
|
+
export declare const createInMemoryConcurrencySlotStore: typeof concurrencyModule.createInMemoryConcurrencySlotStore;
|
|
9
|
+
export declare const createInMemorySlidingWindowStore: typeof inMemoryStoreModule.createInMemorySlidingWindowStore;
|
|
10
|
+
export declare const createRateLimitedResponse: typeof responseModule.createRateLimitedResponse;
|
|
11
|
+
export declare const createRedisConcurrencySlotStore: typeof concurrencyModule.createRedisConcurrencySlotStore;
|
|
12
|
+
export declare const createRedisSlidingWindowStore: typeof redisStoreModule.createRedisSlidingWindowStore;
|
|
13
|
+
export declare const DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS = 20000;
|
|
14
|
+
export declare const DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS = 60000;
|
|
15
|
+
export declare const inMemorySlidingWindowStore: import("../oauth/index.js").AtomicSlidingWindowStore;
|
|
16
|
+
export declare const McpConcurrencyLimiter: typeof concurrencyModule.McpConcurrencyLimiter;
|
|
17
|
+
export declare const RequestRateLimiter: typeof requestLimiterModule.RequestRateLimiter;
|
|
18
|
+
export declare const SlidingWindowRateLimiter: typeof slidingWindowModule.SlidingWindowRateLimiter;
|
|
19
|
+
export type McpConcurrencyLimiter = InstanceType<typeof concurrencyModule.McpConcurrencyLimiter>;
|
|
20
|
+
export type RequestRateLimiter = InstanceType<typeof requestLimiterModule.RequestRateLimiter>;
|
|
21
|
+
export type SlidingWindowRateLimiter = InstanceType<typeof slidingWindowModule.SlidingWindowRateLimiter>;
|
|
22
|
+
export type { McpConcurrencySlot } from './mcp-concurrency-limiter.js';
|
|
23
|
+
export type { AtomicSlidingWindowStore, ConcurrencySlot, ConcurrencySlotStore, MinimalRedisClient, OAuthRateLimitCategory, RateLimitCategoryConfiguration, RateLimitConfiguration, SlidingWindowRateLimiterResult, } from '../oauth/index.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS,
|
|
3
|
+
DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS,
|
|
4
|
+
McpConcurrencyLimiter,
|
|
5
|
+
RequestRateLimiter,
|
|
6
|
+
SlidingWindowRateLimiter,
|
|
7
|
+
attachConcurrencySlotToResponseLifetime,
|
|
8
|
+
createInMemoryConcurrencySlotStore,
|
|
9
|
+
createInMemorySlidingWindowStore,
|
|
10
|
+
createRateLimitedResponse,
|
|
11
|
+
createRedisConcurrencySlotStore,
|
|
12
|
+
createRedisSlidingWindowStore,
|
|
13
|
+
inMemorySlidingWindowStore
|
|
14
|
+
} from "../chunk-6ekjtvcq.js";
|
|
15
|
+
import"../chunk-3ek3knfm.js";
|
|
16
|
+
export {
|
|
17
|
+
DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS,
|
|
18
|
+
DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS,
|
|
19
|
+
McpConcurrencyLimiter,
|
|
20
|
+
RequestRateLimiter,
|
|
21
|
+
SlidingWindowRateLimiter,
|
|
22
|
+
attachConcurrencySlotToResponseLifetime,
|
|
23
|
+
createInMemoryConcurrencySlotStore,
|
|
24
|
+
createInMemorySlidingWindowStore,
|
|
25
|
+
createRateLimitedResponse,
|
|
26
|
+
createRedisConcurrencySlotStore,
|
|
27
|
+
createRedisSlidingWindowStore,
|
|
28
|
+
inMemorySlidingWindowStore
|
|
29
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ConcurrencySlotStore, MinimalRedisClient } from '../oauth/index.js';
|
|
2
|
+
export declare const DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS = 60000;
|
|
3
|
+
export declare const DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS = 20000;
|
|
4
|
+
export declare function createRedisConcurrencySlotStore(redisClient: MinimalRedisClient, providers?: {
|
|
5
|
+
now?: () => number;
|
|
6
|
+
createId?: () => string;
|
|
7
|
+
}): ConcurrencySlotStore;
|
|
8
|
+
export declare function createInMemoryConcurrencySlotStore(): ConcurrencySlotStore;
|
|
9
|
+
export type McpConcurrencySlot = {
|
|
10
|
+
allowed: boolean;
|
|
11
|
+
/** Renewal cadence derived from the acquired slot's TTL. */
|
|
12
|
+
renewalIntervalMilliseconds: number;
|
|
13
|
+
release(): Promise<void>;
|
|
14
|
+
renew(): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export declare class McpConcurrencyLimiter {
|
|
17
|
+
private readonly store;
|
|
18
|
+
private readonly maximumConcurrent;
|
|
19
|
+
private readonly ttlMilliseconds;
|
|
20
|
+
private readonly onStoreError;
|
|
21
|
+
constructor(store: ConcurrencySlotStore, maximumConcurrent: number, ttlMilliseconds?: number, onStoreError?: (error: unknown, operation: 'release' | 'renew') => void);
|
|
22
|
+
acquire(key: string): Promise<McpConcurrencySlot>;
|
|
23
|
+
}
|
|
24
|
+
export declare function attachConcurrencySlotToResponseLifetime(response: Response, slot: Omit<McpConcurrencySlot, 'renewalIntervalMilliseconds'> & {
|
|
25
|
+
renewalIntervalMilliseconds?: number;
|
|
26
|
+
}, renewalIntervalMilliseconds?: number): Response;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createRateLimitedResponse(retryAfterSeconds: number, headers?: Record<string, string>): Response;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AtomicSlidingWindowStore, OAuthRateLimitCategory, RateLimitConfiguration, SlidingWindowRateLimiterResult } from '../oauth/index.js';
|
|
2
|
+
export declare class RequestRateLimiter {
|
|
3
|
+
#private;
|
|
4
|
+
private readonly configuration;
|
|
5
|
+
private readonly storeProvider;
|
|
6
|
+
constructor(configuration: RateLimitConfiguration, storeProvider: () => AtomicSlidingWindowStore | Promise<AtomicSlidingWindowStore>, nowProvider?: () => number);
|
|
7
|
+
consume(category: OAuthRateLimitCategory, identifier: string): Promise<SlidingWindowRateLimiterResult>;
|
|
8
|
+
peek(category: OAuthRateLimitCategory, identifier: string): Promise<number>;
|
|
9
|
+
private buildKey;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AtomicSlidingWindowStore, SlidingWindowRateLimiterResult } from '../oauth/index.js';
|
|
2
|
+
export declare class SlidingWindowRateLimiter {
|
|
3
|
+
private readonly nowProvider;
|
|
4
|
+
constructor(nowProvider?: () => number);
|
|
5
|
+
consume(input: {
|
|
6
|
+
key: string;
|
|
7
|
+
maximumRequests: number;
|
|
8
|
+
windowSeconds: number;
|
|
9
|
+
atomicStore: AtomicSlidingWindowStore;
|
|
10
|
+
}): Promise<SlidingWindowRateLimiterResult>;
|
|
11
|
+
peek(input: {
|
|
12
|
+
key: string;
|
|
13
|
+
windowSeconds: number;
|
|
14
|
+
atomicStore: AtomicSlidingWindowStore;
|
|
15
|
+
}): Promise<number>;
|
|
16
|
+
}
|
package/dist/scopes.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type McpScope = (typeof templateScopeVocabulary.scopes)[number];
|
|
|
32
32
|
/**
|
|
33
33
|
* The three exports below keep the exact shape every existing caller already
|
|
34
34
|
* imports — `applications/web`'s authorize page renders
|
|
35
|
-
* `mcpScopeDescriptions`,
|
|
35
|
+
* `mcpScopeDescriptions`, the OAuth scope configuration narrows with its injected vocabulary, and
|
|
36
36
|
* `request-limits.ts` sizes a bound against `mcpScopes`. Opening the
|
|
37
37
|
* vocabulary changed how these are derived, not what they are.
|
|
38
38
|
*/
|
package/dist/server.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare function createMcpServer(context: {
|
|
|
96
96
|
/**
|
|
97
97
|
* PROTO-002 / S-11: publishes a `notifications/resources/updated` event
|
|
98
98
|
* scoped to only this context's `userId` (see
|
|
99
|
-
* `
|
|
99
|
+
* `src/http/user-server-event-bus.ts`). Undefined when no
|
|
100
100
|
* event bus is wired for this request (e.g. the standalone conformance
|
|
101
101
|
* server) — `resources/subscribe` still acks, it just never delivers.
|
|
102
102
|
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type SvelteKitMountState = 'available' | 'constructing' | 'live' | 'disposed';
|
|
2
|
+
export declare function getSvelteKitMountState(): SvelteKitMountState;
|
|
3
|
+
export declare function setSvelteKitMountState(state: SvelteKitMountState): void;
|
|
4
|
+
export declare function resetSvelteKitMountStateForTesting(): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { McpRegistry } from './scope-vocabulary.js';
|
|
2
|
+
import { type OAuthDiscoveryConfiguration, type OAuthHostSeams, type OAuthIdentity, type OAuthRequestContext } from './oauth/index.js';
|
|
3
|
+
export type SvelteKitLikeRequestEvent = {
|
|
4
|
+
request: Request;
|
|
5
|
+
url: URL;
|
|
6
|
+
locals: Record<PropertyKey, unknown>;
|
|
7
|
+
getClientAddress(): string;
|
|
8
|
+
};
|
|
9
|
+
export type SvelteKitMcpHandleInput = {
|
|
10
|
+
event: SvelteKitLikeRequestEvent;
|
|
11
|
+
resolve(event: SvelteKitLikeRequestEvent): Response | Promise<Response>;
|
|
12
|
+
};
|
|
13
|
+
export type SvelteKitMcpMount = {
|
|
14
|
+
handle(input: SvelteKitMcpHandleInput): Promise<Response>;
|
|
15
|
+
dispose(): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export type SvelteKitMcpRuntime = {
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
publishGrantRevocation(subjectId: string): Promise<void>;
|
|
21
|
+
handle(context: OAuthRequestContext): Promise<Response>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Records that the host identity handle ran for this request. A null identity
|
|
25
|
+
* is distinct from a handle that was skipped or sequenced after the MCP mount.
|
|
26
|
+
*/
|
|
27
|
+
export declare function primeSvelteKitMcpIdentity(event: SvelteKitLikeRequestEvent, identity: OAuthIdentity | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* Creates one process-wide MCP/OAuth lifecycle for a SvelteKit-compatible
|
|
30
|
+
* handle chain without importing SvelteKit. The host retains ownership of its
|
|
31
|
+
* listener, signals, request draining, and process termination.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createSvelteKitMcpMount<Scope extends string>(input: {
|
|
34
|
+
oauthSeams: OAuthHostSeams<Scope>;
|
|
35
|
+
discoveryConfiguration: OAuthDiscoveryConfiguration;
|
|
36
|
+
registry: McpRegistry<Scope>;
|
|
37
|
+
identityHandleName: string;
|
|
38
|
+
/** Must be true only for a process that persists across requests. */
|
|
39
|
+
longLivedProcess: boolean;
|
|
40
|
+
/** Supplies the host's existing request correlation identifier. */
|
|
41
|
+
getRequestId?(event: SvelteKitLikeRequestEvent): string;
|
|
42
|
+
mcp: SvelteKitMcpRuntime;
|
|
43
|
+
}): Promise<SvelteKitMcpMount>;
|