@lostgradient/mcp 0.2.5 → 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.
Files changed (123) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -173
  3. package/dist/http.d.ts +35 -0
  4. package/dist/http.js +251 -0
  5. package/dist/internal/cryptography/encryption.d.ts +108 -0
  6. package/dist/internal/cryptography/encryption.js +241 -0
  7. package/dist/internal/cryptography/hash.d.ts +72 -0
  8. package/dist/internal/cryptography/hash.js +233 -0
  9. package/dist/internal/cryptography/index.d.ts +4 -0
  10. package/dist/internal/cryptography/index.js +2 -0
  11. package/dist/oauth/canonicalize-ip-address.d.ts +0 -6
  12. package/dist/oauth/canonicalize-ip-address.js +113 -0
  13. package/dist/oauth/client-metadata-documents.d.ts +2 -22
  14. package/dist/oauth/client-metadata-documents.js +205 -19
  15. package/dist/oauth/index.d.ts +9 -213
  16. package/dist/oauth/index.js +6 -69
  17. package/dist/oauth/issuer.d.ts +103 -0
  18. package/dist/oauth/issuer.js +564 -0
  19. package/dist/oauth/postgres.d.ts +12 -0
  20. package/dist/oauth/postgres.js +76 -0
  21. package/dist/oauth/safe-public-https-fetch.d.ts +3 -5
  22. package/dist/oauth/safe-public-https-fetch.js +114 -0
  23. package/dist/oauth/security-utilities.d.ts +0 -3
  24. package/dist/oauth/security-utilities.js +93 -0
  25. package/dist/oauth-store.d.ts +108 -0
  26. package/dist/oauth-store.js +321 -0
  27. package/package.json +50 -124
  28. package/dist/chunk-3ek3knfm.js +0 -73
  29. package/dist/chunk-3rr24vhh.js +0 -28
  30. package/dist/chunk-6ekjtvcq.js +0 -273
  31. package/dist/chunk-88nhf6xt.js +0 -449
  32. package/dist/chunk-en76akaq.js +0 -1107
  33. package/dist/chunk-k6fm3cmk.js +0 -132
  34. package/dist/chunk-qxwd8est.js +0 -916
  35. package/dist/chunk-rxnyn7tf.js +0 -19
  36. package/dist/chunk-taxyscge.js +0 -67
  37. package/dist/chunk-wsnfttyg.js +0 -4
  38. package/dist/chunk-xcf742mf.js +0 -14
  39. package/dist/conformance-fixture-registration.d.ts +0 -30
  40. package/dist/conformance-server.d.ts +0 -1
  41. package/dist/conformance.d.ts +0 -43
  42. package/dist/env.d.ts +0 -59
  43. package/dist/env.js +0 -9
  44. package/dist/environment-schema.d.ts +0 -29
  45. package/dist/environment-schema.js +0 -6
  46. package/dist/golden-prompts.d.ts +0 -42
  47. package/dist/handler-context.d.ts +0 -16
  48. package/dist/http/authenticate.d.ts +0 -35
  49. package/dist/http/authorization-header.d.ts +0 -5
  50. package/dist/http/grant-revocation-channel.d.ts +0 -24
  51. package/dist/http/handler.d.ts +0 -32
  52. package/dist/http/index.d.ts +0 -27
  53. package/dist/http/index.js +0 -870
  54. package/dist/http/listen-inspection.d.ts +0 -11
  55. package/dist/http/request-context.d.ts +0 -17
  56. package/dist/http/responses.d.ts +0 -13
  57. package/dist/http/serving-layer.d.ts +0 -25
  58. package/dist/http/user-handler-cache.d.ts +0 -37
  59. package/dist/http/user-server-event-bus.d.ts +0 -35
  60. package/dist/index.d.ts +0 -29
  61. package/dist/index.js +0 -616
  62. package/dist/localhost-request-validation.d.ts +0 -2
  63. package/dist/logger.d.ts +0 -59
  64. package/dist/logger.js +0 -18
  65. package/dist/long-running-operation-support.d.ts +0 -34
  66. package/dist/metrics.d.ts +0 -64
  67. package/dist/metrics.js +0 -6
  68. package/dist/oauth/authorize-endpoint.d.ts +0 -5
  69. package/dist/oauth/client-authentication.d.ts +0 -10
  70. package/dist/oauth/discovery-metadata.d.ts +0 -19
  71. package/dist/oauth/endpoint-rate-limits.d.ts +0 -10
  72. package/dist/oauth/endpoint-responses.d.ts +0 -10
  73. package/dist/oauth/network-identity.d.ts +0 -32
  74. package/dist/oauth/pkce-validation.d.ts +0 -2
  75. package/dist/oauth/postgres/client-store.d.ts +0 -12
  76. package/dist/oauth/postgres/code-store.d.ts +0 -14
  77. package/dist/oauth/postgres/database.d.ts +0 -59
  78. package/dist/oauth/postgres/index.d.ts +0 -11
  79. package/dist/oauth/postgres/index.js +0 -616
  80. package/dist/oauth/postgres/schema.d.ts +0 -1476
  81. package/dist/oauth/postgres/token-store.d.ts +0 -16
  82. package/dist/oauth/postgres/transaction-store.d.ts +0 -14
  83. package/dist/oauth/redirect-uri-matching.d.ts +0 -2
  84. package/dist/oauth/registration-endpoint.d.ts +0 -2
  85. package/dist/oauth/request-body.d.ts +0 -14
  86. package/dist/oauth/revocation-endpoint.d.ts +0 -2
  87. package/dist/oauth/scope-utilities.d.ts +0 -15
  88. package/dist/oauth/stores.d.ts +0 -225
  89. package/dist/oauth/stores.js +0 -0
  90. package/dist/oauth/testing/contract-fixtures.d.ts +0 -134
  91. package/dist/oauth/testing/index.d.ts +0 -56
  92. package/dist/oauth/testing/index.js +0 -330
  93. package/dist/oauth/token-endpoint.d.ts +0 -2
  94. package/dist/oauth-scope-configuration.d.ts +0 -3
  95. package/dist/prompts/index.d.ts +0 -5
  96. package/dist/prompts/summarize.d.ts +0 -4
  97. package/dist/rate-limit/in-memory-sliding-window-store.d.ts +0 -3
  98. package/dist/rate-limit/index.d.ts +0 -23
  99. package/dist/rate-limit/index.js +0 -29
  100. package/dist/rate-limit/mcp-concurrency-limiter.d.ts +0 -26
  101. package/dist/rate-limit/rate-limit-response.d.ts +0 -1
  102. package/dist/rate-limit/redis-sliding-window-store.d.ts +0 -2
  103. package/dist/rate-limit/request-rate-limiter.d.ts +0 -10
  104. package/dist/rate-limit/sliding-window-rate-limiter.d.ts +0 -16
  105. package/dist/resources/index.d.ts +0 -4
  106. package/dist/resources/user-profile.d.ts +0 -1
  107. package/dist/scope-vocabulary.d.ts +0 -127
  108. package/dist/scopes.d.ts +0 -49
  109. package/dist/server.d.ts +0 -113
  110. package/dist/supported-scopes.d.ts +0 -25
  111. package/dist/sveltekit-mount-state.d.ts +0 -4
  112. package/dist/sveltekit-mount.d.ts +0 -43
  113. package/dist/sveltekit-mount.js +0 -344
  114. package/dist/template-registry.d.ts +0 -16
  115. package/dist/tool-response.d.ts +0 -100
  116. package/dist/tools/get-user-profile.d.ts +0 -8
  117. package/dist/tools/index.d.ts +0 -16
  118. package/dist/tools/list-audit-events.d.ts +0 -11
  119. package/dist/type-assertions.d.ts +0 -1
  120. package/dist/types/primitives.d.ts +0 -130
  121. package/dist/ui-extension-support.d.ts +0 -20
  122. package/dist/version.d.ts +0 -23
  123. package/dist/version.js +0 -6
@@ -1,273 +0,0 @@
1
- import {
2
- RequestRateLimiter,
3
- SlidingWindowRateLimiter,
4
- createRateLimitedResponse
5
- } from "./chunk-3ek3knfm.js";
6
-
7
- // src/rate-limit/in-memory-sliding-window-store.ts
8
- function createInMemorySlidingWindowStore() {
9
- const membersByKey = new Map;
10
- const expirationsByKey = new Map;
11
- const pruneExpired = (key, nowMilliseconds, cutoffScore) => {
12
- const expiresAt = expirationsByKey.get(key);
13
- if (expiresAt !== undefined && nowMilliseconds > expiresAt) {
14
- membersByKey.delete(key);
15
- expirationsByKey.delete(key);
16
- return [];
17
- }
18
- const remaining = (membersByKey.get(key) ?? []).filter((entry) => entry.score > cutoffScore);
19
- membersByKey.set(key, remaining);
20
- return remaining;
21
- };
22
- return {
23
- consume: async (input) => {
24
- const existing = pruneExpired(input.key, input.nowMilliseconds, input.nowMilliseconds - input.windowMilliseconds);
25
- if (existing.length >= input.maximumRequests) {
26
- const oldest = existing.reduce((minimum, entry) => entry.score < minimum.score ? entry : minimum);
27
- return {
28
- allowed: false,
29
- retryAfterMilliseconds: Math.max(0, oldest.score + input.windowMilliseconds - input.nowMilliseconds),
30
- remainingRequests: 0
31
- };
32
- }
33
- existing.push({ score: input.nowMilliseconds, member: input.member });
34
- membersByKey.set(input.key, existing);
35
- expirationsByKey.set(input.key, input.nowMilliseconds + input.windowMilliseconds);
36
- return {
37
- allowed: true,
38
- retryAfterMilliseconds: 0,
39
- remainingRequests: Math.max(0, input.maximumRequests - existing.length)
40
- };
41
- },
42
- peek: async (input) => pruneExpired(input.key, input.nowMilliseconds, input.nowMilliseconds - input.windowMilliseconds).length
43
- };
44
- }
45
- var inMemorySlidingWindowStore = createInMemorySlidingWindowStore();
46
-
47
- // src/rate-limit/mcp-concurrency-limiter.ts
48
- import { randomUUID } from "node:crypto";
49
- var DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS = 60000;
50
- var DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS = 20000;
51
- var acquireScript = `
52
- local key = KEYS[1]
53
- local now_ms = tonumber(ARGV[1])
54
- local ttl_ms = tonumber(ARGV[2])
55
- local max_concurrent = tonumber(ARGV[3])
56
- local member = ARGV[4]
57
- redis.call('ZREMRANGEBYSCORE', key, '-inf', now_ms)
58
- local count = redis.call('ZCARD', key)
59
- if count >= max_concurrent then return 0 end
60
- redis.call('ZADD', key, now_ms + ttl_ms, member)
61
- redis.call('PEXPIRE', key, ttl_ms)
62
- return 1
63
- `;
64
- var renewScript = `
65
- local key = KEYS[1]
66
- local now_ms = tonumber(ARGV[1])
67
- local ttl_ms = tonumber(ARGV[2])
68
- local member = ARGV[3]
69
- if redis.call('ZSCORE', key, member) == false then return 0 end
70
- redis.call('ZADD', key, now_ms + ttl_ms, member)
71
- redis.call('PEXPIRE', key, ttl_ms)
72
- return 1
73
- `;
74
- function createRedisConcurrencySlotStore(redisClient, providers = {}) {
75
- const now = providers.now ?? (() => Date.now());
76
- const createId = providers.createId ?? randomUUID;
77
- return {
78
- acquire: async (key, maximumConcurrent, ttlMilliseconds) => {
79
- const slot = { id: createId() };
80
- const reply = await redisClient.eval(acquireScript, {
81
- keys: [key],
82
- arguments: [String(now()), String(ttlMilliseconds), String(maximumConcurrent), slot.id]
83
- });
84
- return reply === 1 ? slot : null;
85
- },
86
- renew: async (key, slot, ttlMilliseconds) => await redisClient.eval(renewScript, {
87
- keys: [key],
88
- arguments: [String(now()), String(ttlMilliseconds), slot.id]
89
- }) === 1,
90
- release: async (key, slot) => {
91
- await redisClient.zRem(key, slot.id);
92
- }
93
- };
94
- }
95
- function createInMemoryConcurrencySlotStore() {
96
- const slotsByKey = new Map;
97
- return {
98
- acquire: async (key, maximumConcurrent) => {
99
- const slots = slotsByKey.get(key) ?? new Set;
100
- if (slots.size >= maximumConcurrent)
101
- return null;
102
- const slot = { id: randomUUID() };
103
- slots.add(slot.id);
104
- slotsByKey.set(key, slots);
105
- return slot;
106
- },
107
- renew: async (key, slot) => slotsByKey.get(key)?.has(slot.id) ?? false,
108
- release: async (key, slot) => {
109
- slotsByKey.get(key)?.delete(slot.id);
110
- }
111
- };
112
- }
113
-
114
- class McpConcurrencyLimiter {
115
- store;
116
- maximumConcurrent;
117
- ttlMilliseconds;
118
- onStoreError;
119
- constructor(store, maximumConcurrent, ttlMilliseconds = DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS, onStoreError = () => {}) {
120
- this.store = store;
121
- this.maximumConcurrent = maximumConcurrent;
122
- this.ttlMilliseconds = ttlMilliseconds;
123
- this.onStoreError = onStoreError;
124
- }
125
- async acquire(key) {
126
- const slot = await this.store.acquire(key, this.maximumConcurrent, this.ttlMilliseconds);
127
- let released = false;
128
- return {
129
- allowed: slot !== null,
130
- renewalIntervalMilliseconds: Math.max(1, Math.floor(this.ttlMilliseconds / 3)),
131
- release: async () => {
132
- if (!slot || released)
133
- return;
134
- released = true;
135
- try {
136
- await this.store.release(key, slot);
137
- } catch (error) {
138
- this.onStoreError(error, "release");
139
- }
140
- },
141
- renew: async () => {
142
- if (!slot || released)
143
- return;
144
- try {
145
- await this.store.renew(key, slot, this.ttlMilliseconds);
146
- } catch (error) {
147
- this.onStoreError(error, "renew");
148
- }
149
- }
150
- };
151
- }
152
- }
153
- function attachConcurrencySlotToResponseLifetime(response, slot, renewalIntervalMilliseconds = slot.renewalIntervalMilliseconds ?? DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS) {
154
- if (!response.body || response.bodyUsed) {
155
- slot.release();
156
- return response;
157
- }
158
- let settled = false;
159
- const renewalTimer = setInterval(() => void slot.renew(), renewalIntervalMilliseconds);
160
- renewalTimer.unref?.();
161
- const settleOnce = () => {
162
- if (settled)
163
- return;
164
- settled = true;
165
- clearInterval(renewalTimer);
166
- slot.release();
167
- };
168
- const sourceReader = response.body.getReader();
169
- const trackedBody = new ReadableStream({
170
- async pull(controller) {
171
- try {
172
- const { done, value } = await sourceReader.read();
173
- if (done) {
174
- controller.close();
175
- settleOnce();
176
- return;
177
- }
178
- controller.enqueue(value);
179
- } catch (error) {
180
- controller.error(error);
181
- settleOnce();
182
- }
183
- },
184
- cancel(reason) {
185
- sourceReader.cancel(reason).catch(() => {});
186
- settleOnce();
187
- }
188
- });
189
- return new Response(trackedBody, {
190
- status: response.status,
191
- statusText: response.statusText,
192
- headers: response.headers
193
- });
194
- }
195
-
196
- // src/rate-limit/redis-sliding-window-store.ts
197
- var consumeScript = `
198
- local key = KEYS[1]
199
- local now = tonumber(ARGV[1])
200
- local window = tonumber(ARGV[2])
201
- local max_requests = tonumber(ARGV[3])
202
- local member = ARGV[4]
203
- redis.call('ZREMRANGEBYSCORE', key, '-inf', now - window)
204
- local count = redis.call('ZCARD', key)
205
- if count >= max_requests then
206
- local oldest = redis.call('ZRANGE', key, 0, 0, 'WITHSCORES')
207
- local retry_after = window
208
- if oldest[2] ~= nil then
209
- retry_after = tonumber(oldest[2]) + window - now
210
- if retry_after < 0 then retry_after = 0 end
211
- end
212
- return {0, retry_after, 0}
213
- end
214
- redis.call('ZADD', key, now, member)
215
- redis.call('PEXPIRE', key, window)
216
- return {1, 0, max_requests - count - 1}
217
- `;
218
- var peekScript = `
219
- local key = KEYS[1]
220
- local now = tonumber(ARGV[1])
221
- local window = tonumber(ARGV[2])
222
- redis.call('ZREMRANGEBYSCORE', key, '-inf', now - window)
223
- return redis.call('ZCARD', key)
224
- `;
225
- function serializeFiniteScriptArgument(value, parameterName) {
226
- if (!Number.isFinite(value)) {
227
- throw new TypeError(`Rate limiter received a non-finite ${parameterName} (${String(value)}). ` + "This indicates missing or unparsed rate-limit configuration, not a Redis fault.");
228
- }
229
- return String(value);
230
- }
231
- function createRedisSlidingWindowStore(redisClient) {
232
- return {
233
- consume: async (input) => {
234
- const reply = await redisClient.eval(consumeScript, {
235
- keys: [input.key],
236
- arguments: [
237
- serializeFiniteScriptArgument(input.nowMilliseconds, "nowMilliseconds"),
238
- serializeFiniteScriptArgument(input.windowMilliseconds, "windowMilliseconds"),
239
- serializeFiniteScriptArgument(input.maximumRequests, "maximumRequests"),
240
- input.member
241
- ]
242
- });
243
- return {
244
- allowed: reply[0] === 1,
245
- retryAfterMilliseconds: Number(reply[1]),
246
- remainingRequests: Number(reply[2])
247
- };
248
- },
249
- peek: async (input) => Number(await redisClient.eval(peekScript, {
250
- keys: [input.key],
251
- arguments: [
252
- serializeFiniteScriptArgument(input.nowMilliseconds, "nowMilliseconds"),
253
- serializeFiniteScriptArgument(input.windowMilliseconds, "windowMilliseconds")
254
- ]
255
- }))
256
- };
257
- }
258
-
259
- // src/rate-limit/index.ts
260
- var attachConcurrencySlotToResponseLifetime2 = attachConcurrencySlotToResponseLifetime;
261
- var createInMemoryConcurrencySlotStore2 = createInMemoryConcurrencySlotStore;
262
- var createInMemorySlidingWindowStore2 = createInMemorySlidingWindowStore;
263
- var createRateLimitedResponse2 = createRateLimitedResponse;
264
- var createRedisConcurrencySlotStore2 = createRedisConcurrencySlotStore;
265
- var createRedisSlidingWindowStore2 = createRedisSlidingWindowStore;
266
- var DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS2 = DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS;
267
- var DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS2 = DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS;
268
- var inMemorySlidingWindowStore2 = inMemorySlidingWindowStore;
269
- var McpConcurrencyLimiter2 = McpConcurrencyLimiter;
270
- var RequestRateLimiter2 = RequestRateLimiter;
271
- var SlidingWindowRateLimiter2 = SlidingWindowRateLimiter;
272
-
273
- export { attachConcurrencySlotToResponseLifetime2 as attachConcurrencySlotToResponseLifetime, createInMemoryConcurrencySlotStore2 as createInMemoryConcurrencySlotStore, createInMemorySlidingWindowStore2 as createInMemorySlidingWindowStore, createRateLimitedResponse2 as createRateLimitedResponse, createRedisConcurrencySlotStore2 as createRedisConcurrencySlotStore, createRedisSlidingWindowStore2 as createRedisSlidingWindowStore, DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS2 as DEFAULT_CONCURRENCY_SLOT_RENEWAL_INTERVAL_MILLISECONDS, DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS2 as DEFAULT_CONCURRENCY_SLOT_TTL_MILLISECONDS, inMemorySlidingWindowStore2 as inMemorySlidingWindowStore, McpConcurrencyLimiter2 as McpConcurrencyLimiter, RequestRateLimiter2 as RequestRateLimiter, SlidingWindowRateLimiter2 as SlidingWindowRateLimiter };