@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
@@ -0,0 +1,321 @@
1
+ import { sha256Base64UrlSync, sha256HexSync, timingSafeEqualText, } from "./internal/cryptography/index.js";
2
+ import { storageConditionalBatch, } from '@lostgradient/storage';
3
+ const encoder = new TextEncoder();
4
+ const decoder = new TextDecoder();
5
+ const encode = (value) => encoder.encode(JSON.stringify(value));
6
+ const key = (kind, value) => `oauth:${kind}:${sha256HexSync(value)}`;
7
+ const equal = (left, right) => timingSafeEqualText(left, right);
8
+ export class OAuthStore {
9
+ storage;
10
+ constructor(storage) {
11
+ this.storage = storage;
12
+ const capabilities = storage.capabilities();
13
+ if (capabilities.readAfterWrite !== 'linearizable' ||
14
+ !capabilities.conditionalBatch ||
15
+ typeof storage.conditionalBatch !== 'function') {
16
+ throw new Error('OAuth storage requires linearizable reads and conditional batches');
17
+ }
18
+ }
19
+ usesStorage(storage) {
20
+ return this.storage === storage;
21
+ }
22
+ async registerClient(client) {
23
+ const clientKey = key('client', client.clientId);
24
+ return storageConditionalBatch(this.storage, [{ key: clientKey, expectedValue: null }], [{ type: 'put', key: clientKey, value: encode(client) }]);
25
+ }
26
+ async getClient(id) {
27
+ const value = await this.storage.get(key('client', id));
28
+ return value ? JSON.parse(decoder.decode(value)) : null;
29
+ }
30
+ async createConsent(id, consent) {
31
+ const consentKey = key('consent', id);
32
+ return storageConditionalBatch(this.storage, [{ key: consentKey, expectedValue: null }], [
33
+ {
34
+ type: 'put',
35
+ key: consentKey,
36
+ value: encode({
37
+ ...consent,
38
+ csrf: key('csrf', consent.csrf),
39
+ binding: key('binding', consent.binding),
40
+ }),
41
+ },
42
+ ]);
43
+ }
44
+ async getConsent(id, binding) {
45
+ const value = await this.storage.get(key('consent', id));
46
+ if (!value)
47
+ return null;
48
+ const consent = JSON.parse(decoder.decode(value));
49
+ return this.matchesConsent(consent, binding) ? consent : null;
50
+ }
51
+ async denyConsent(id, binding, sessionCondition) {
52
+ binding = { ...binding };
53
+ sessionCondition = sessionCondition && {
54
+ key: sessionCondition.key,
55
+ expectedValue: sessionCondition.expectedValue?.slice() ?? null,
56
+ deadline: sessionCondition.deadline,
57
+ };
58
+ const consentKey = key('consent', id);
59
+ const value = await this.storage.get(consentKey);
60
+ if (!value || !this.matchesConsent(JSON.parse(decoder.decode(value)), binding))
61
+ return false;
62
+ return storageConditionalBatch(this.storage, [{ key: consentKey, expectedValue: value }, ...(sessionCondition ? [sessionCondition] : [])], [{ type: 'delete', key: consentKey }], sessionCondition?.deadline);
63
+ }
64
+ matchesConsent(consent, binding) {
65
+ return (consent.expiresAt > Date.now() &&
66
+ consent.issuer === binding.issuer &&
67
+ consent.client === binding.client &&
68
+ consent.subject === binding.subject &&
69
+ equal(consent.binding, key('binding', binding.binding)) &&
70
+ equal(consent.csrf, key('csrf', binding.csrf)));
71
+ }
72
+ async approveConsent(id, binding, approval, sessionCondition) {
73
+ binding = { ...binding };
74
+ approval = { ...approval, scopes: [...approval.scopes] };
75
+ sessionCondition = sessionCondition && {
76
+ key: sessionCondition.key,
77
+ expectedValue: sessionCondition.expectedValue?.slice() ?? null,
78
+ deadline: sessionCondition.deadline,
79
+ };
80
+ const consentKey = key('consent', id);
81
+ const value = await this.storage.get(consentKey);
82
+ if (!value)
83
+ return false;
84
+ const consent = JSON.parse(decoder.decode(value));
85
+ if (!this.matchesConsent(consent, binding) ||
86
+ approval.subject !== consent.subject ||
87
+ approval.tenant !== consent.tenant ||
88
+ approval.resource !== consent.resource ||
89
+ approval.scopes.length !== consent.scopes.length ||
90
+ approval.scopes.some((scope, index) => scope !== consent.scopes[index]))
91
+ return false;
92
+ const grantKey = key('grant', approval.grantId);
93
+ const codeKey = key('code', approval.code);
94
+ const { code: _code, ...authority } = approval;
95
+ const grant = {
96
+ ...authority,
97
+ issuer: consent.issuer,
98
+ client: binding.client,
99
+ active: true,
100
+ approvedAt: Date.now(),
101
+ };
102
+ const code = {
103
+ grantId: approval.grantId,
104
+ client: binding.client,
105
+ redirect: consent.redirect,
106
+ challenge: consent.challenge,
107
+ expiresAt: consent.expiresAt,
108
+ };
109
+ return storageConditionalBatch(this.storage, [
110
+ { key: consentKey, expectedValue: value },
111
+ { key: grantKey, expectedValue: null },
112
+ { key: codeKey, expectedValue: null },
113
+ ...(sessionCondition ? [sessionCondition] : []),
114
+ ], [
115
+ { type: 'delete', key: consentKey },
116
+ { type: 'put', key: grantKey, value: encode(grant) },
117
+ { type: 'put', key: codeKey, value: encode(code) },
118
+ ], sessionCondition?.deadline);
119
+ }
120
+ async getGrant(id) {
121
+ const value = await this.storage.get(key('grant', id));
122
+ if (!value)
123
+ return null;
124
+ const grant = JSON.parse(decoder.decode(value));
125
+ return { ...grant, approvedAt: grant.approvedAt ?? null };
126
+ }
127
+ async listGrants(identity) {
128
+ identity = { ...identity };
129
+ const grants = [];
130
+ for await (const [, value] of this.storage.scan('oauth:grant:')) {
131
+ const grant = JSON.parse(decoder.decode(value));
132
+ if (grant.active &&
133
+ grant.issuer === identity.issuer &&
134
+ grant.tenant === identity.tenant &&
135
+ grant.subject === identity.subject)
136
+ grants.push({ ...grant, approvedAt: grant.approvedAt ?? null });
137
+ }
138
+ return grants;
139
+ }
140
+ async revokeOwnedGrant(id, identity) {
141
+ identity = { ...identity };
142
+ const grantKey = key('grant', id);
143
+ for (;;) {
144
+ const value = await this.storage.get(grantKey);
145
+ if (!value)
146
+ return false;
147
+ const grant = JSON.parse(decoder.decode(value));
148
+ if (grant.issuer !== identity.issuer ||
149
+ grant.tenant !== identity.tenant ||
150
+ grant.subject !== identity.subject)
151
+ return false;
152
+ if (!grant.active)
153
+ return true;
154
+ if (await storageConditionalBatch(this.storage, [{ key: grantKey, expectedValue: value }], [{ type: 'put', key: grantKey, value: encode({ ...grant, active: false }) }]))
155
+ return true;
156
+ }
157
+ }
158
+ async getCode(id) {
159
+ const value = await this.storage.get(key('code', id));
160
+ return value ? JSON.parse(decoder.decode(value)) : null;
161
+ }
162
+ async exchange(input) {
163
+ input = { ...input };
164
+ const codeKey = key('code', input.code);
165
+ const codeBytes = await this.storage.get(codeKey);
166
+ if (!codeBytes)
167
+ return false;
168
+ const code = JSON.parse(decoder.decode(codeBytes));
169
+ if (code.client !== input.client ||
170
+ code.redirect !== input.redirect ||
171
+ code.expiresAt <= Date.now() ||
172
+ !Number.isFinite(input.accessExpiresAt) ||
173
+ input.accessExpiresAt <= Date.now() ||
174
+ (input.refresh !== null &&
175
+ (!Number.isFinite(input.refreshExpiresAt) || input.refreshExpiresAt <= Date.now())) ||
176
+ !/^[A-Za-z0-9._~-]{43,128}$/.test(input.verifier) ||
177
+ !equal(sha256Base64UrlSync(input.verifier), code.challenge))
178
+ return false;
179
+ const grantKey = key('grant', code.grantId);
180
+ const grantBytes = await this.storage.get(grantKey);
181
+ if (!grantBytes)
182
+ return false;
183
+ const grant = JSON.parse(decoder.decode(grantBytes));
184
+ if (!grant.active || grant.issuer !== input.issuer || grant.resource !== input.resource)
185
+ return false;
186
+ const accessKey = key('access', input.access);
187
+ const refreshKey = input.refresh === null ? null : key('refresh', input.refresh);
188
+ const credential = {
189
+ grantId: code.grantId,
190
+ expiresAt: input.accessExpiresAt,
191
+ scopes: grant.scopes,
192
+ spent: false,
193
+ accessKey,
194
+ };
195
+ return storageConditionalBatch(this.storage, [
196
+ { key: codeKey, expectedValue: codeBytes },
197
+ { key: grantKey, expectedValue: grantBytes },
198
+ { key: accessKey, expectedValue: null },
199
+ ...(refreshKey ? [{ key: refreshKey, expectedValue: null }] : []),
200
+ ], [
201
+ { type: 'delete', key: codeKey },
202
+ { type: 'put', key: accessKey, value: encode(credential) },
203
+ ...(refreshKey
204
+ ? [
205
+ {
206
+ type: 'put',
207
+ key: refreshKey,
208
+ value: encode({ ...credential, expiresAt: input.refreshExpiresAt }),
209
+ },
210
+ ]
211
+ : []),
212
+ ]);
213
+ }
214
+ async getAccess(token) {
215
+ const bytes = await this.storage.get(key('access', token));
216
+ if (!bytes)
217
+ return null;
218
+ const credential = JSON.parse(decoder.decode(bytes));
219
+ const grant = await this.getGrant(credential.grantId);
220
+ if (!grant?.active || credential.expiresAt <= Date.now())
221
+ return null;
222
+ return { ...grant, scopes: credential.scopes, expiresAt: credential.expiresAt };
223
+ }
224
+ async getRefreshGrant(token) {
225
+ const bytes = await this.storage.get(key('refresh', token));
226
+ if (!bytes)
227
+ return null;
228
+ const credential = JSON.parse(decoder.decode(bytes));
229
+ const grant = await this.getGrant(credential.grantId);
230
+ return grant ? { ...grant, scopes: credential.scopes } : null;
231
+ }
232
+ async revokeToken(token, issuer, client) {
233
+ for (const kind of ['access', 'refresh']) {
234
+ const bytes = await this.storage.get(key(kind, token));
235
+ if (!bytes)
236
+ continue;
237
+ const credential = JSON.parse(decoder.decode(bytes));
238
+ const grant = await this.getGrant(credential.grantId);
239
+ if (grant?.issuer === issuer && grant.client === client)
240
+ await this.revokeGrant(credential.grantId);
241
+ return;
242
+ }
243
+ }
244
+ async revokeGrant(id) {
245
+ const grantKey = key('grant', id);
246
+ for (;;) {
247
+ const value = await this.storage.get(grantKey);
248
+ if (!value)
249
+ return false;
250
+ const grant = JSON.parse(decoder.decode(value));
251
+ if (!grant.active)
252
+ return false;
253
+ if (await storageConditionalBatch(this.storage, [{ key: grantKey, expectedValue: value }], [{ type: 'put', key: grantKey, value: encode({ ...grant, active: false }) }]))
254
+ return true;
255
+ }
256
+ }
257
+ async rotate(input) {
258
+ input = { ...input, scopes: [...input.scopes] };
259
+ const refreshKey = key('refresh', input.refresh);
260
+ for (;;) {
261
+ const refreshBytes = await this.storage.get(refreshKey);
262
+ if (!refreshBytes)
263
+ return 'invalid';
264
+ const prior = JSON.parse(decoder.decode(refreshBytes));
265
+ const grantKey = key('grant', prior.grantId);
266
+ const grantBytes = await this.storage.get(grantKey);
267
+ if (!grantBytes)
268
+ return 'invalid';
269
+ const grant = JSON.parse(decoder.decode(grantBytes));
270
+ if (!grant.active ||
271
+ grant.issuer !== input.issuer ||
272
+ grant.client !== input.client ||
273
+ grant.resource !== input.resource)
274
+ return 'invalid';
275
+ if (prior.spent) {
276
+ if (await storageConditionalBatch(this.storage, [
277
+ { key: refreshKey, expectedValue: refreshBytes },
278
+ { key: grantKey, expectedValue: grantBytes },
279
+ ], [{ type: 'put', key: grantKey, value: encode({ ...grant, active: false }) }]))
280
+ return 'replay_revoked';
281
+ continue;
282
+ }
283
+ if (prior.expiresAt <= Date.now() ||
284
+ !Number.isFinite(input.accessExpiresAt) ||
285
+ input.accessExpiresAt <= Date.now() ||
286
+ !Number.isFinite(input.refreshExpiresAt) ||
287
+ input.refreshExpiresAt <= Date.now())
288
+ return 'invalid';
289
+ if (input.scopes.some((scope) => !prior.scopes.includes(scope) || !grant.scopes.includes(scope)))
290
+ return 'scope_rejected';
291
+ const accessKey = key('access', input.access);
292
+ const nextRefreshKey = key('refresh', input.nextRefresh);
293
+ const next = {
294
+ grantId: prior.grantId,
295
+ expiresAt: input.accessExpiresAt,
296
+ scopes: [...input.scopes],
297
+ spent: false,
298
+ accessKey,
299
+ };
300
+ if (await storageConditionalBatch(this.storage, [
301
+ { key: refreshKey, expectedValue: refreshBytes },
302
+ { key: grantKey, expectedValue: grantBytes },
303
+ { key: accessKey, expectedValue: null },
304
+ { key: nextRefreshKey, expectedValue: null },
305
+ ], [
306
+ { type: 'put', key: refreshKey, value: encode({ ...prior, spent: true }) },
307
+ { type: 'delete', key: prior.accessKey },
308
+ { type: 'put', key: accessKey, value: encode(next) },
309
+ {
310
+ type: 'put',
311
+ key: nextRefreshKey,
312
+ value: encode({ ...next, expiresAt: input.refreshExpiresAt }),
313
+ },
314
+ ]))
315
+ return 'rotated';
316
+ const current = await this.storage.get(refreshKey);
317
+ if (current && decoder.decode(current) === decoder.decode(refreshBytes))
318
+ return 'invalid';
319
+ }
320
+ }
321
+ }
package/package.json CHANGED
@@ -1,125 +1,51 @@
1
1
  {
2
- "name": "@lostgradient/mcp",
3
- "version": "0.2.5",
4
- "description": "A Model Context Protocol server engine: registries, scope vocabularies, and an OAuth-ready request boundary.",
5
- "license": "MIT",
6
- "author": "Steve Kinney <hello@stevekinney.net>",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/stevekinney/protokit.git",
10
- "directory": "packages/mcp"
11
- },
12
- "homepage": "https://github.com/stevekinney/protokit/tree/main/packages/mcp#readme",
13
- "bugs": "https://github.com/stevekinney/protokit/issues",
14
- "type": "module",
15
- "sideEffects": false,
16
- "files": [
17
- "dist",
18
- "!dist/**/*.test.*",
19
- "!dist/**/*.map",
20
- "README.md"
21
- ],
22
- "publishConfig": {
23
- "access": "public"
24
- },
25
- "exports": {
26
- ".": {
27
- "types": "./dist/index.d.ts",
28
- "import": "./dist/index.js",
29
- "default": "./dist/index.js"
30
- },
31
- "./logger": {
32
- "types": "./dist/logger.d.ts",
33
- "import": "./dist/logger.js",
34
- "default": "./dist/logger.js"
35
- },
36
- "./env": {
37
- "types": "./dist/env.d.ts",
38
- "import": "./dist/env.js",
39
- "default": "./dist/env.js"
40
- },
41
- "./metrics": {
42
- "types": "./dist/metrics.d.ts",
43
- "import": "./dist/metrics.js",
44
- "default": "./dist/metrics.js"
45
- },
46
- "./environment-schema": {
47
- "types": "./dist/environment-schema.d.ts",
48
- "import": "./dist/environment-schema.js",
49
- "default": "./dist/environment-schema.js"
50
- },
51
- "./version": {
52
- "types": "./dist/version.d.ts",
53
- "import": "./dist/version.js",
54
- "default": "./dist/version.js"
55
- },
56
- "./oauth": {
57
- "types": "./dist/oauth/index.d.ts",
58
- "import": "./dist/oauth/index.js",
59
- "default": "./dist/oauth/index.js"
60
- },
61
- "./oauth/stores": {
62
- "types": "./dist/oauth/stores.d.ts",
63
- "import": "./dist/oauth/stores.js",
64
- "default": "./dist/oauth/stores.js"
65
- },
66
- "./oauth/testing": {
67
- "types": "./dist/oauth/testing/index.d.ts",
68
- "import": "./dist/oauth/testing/index.js",
69
- "default": "./dist/oauth/testing/index.js"
70
- },
71
- "./oauth/postgres": {
72
- "types": "./dist/oauth/postgres/index.d.ts",
73
- "import": "./dist/oauth/postgres/index.js",
74
- "default": "./dist/oauth/postgres/index.js"
75
- },
76
- "./oauth/client-metadata-documents": {
77
- "types": "./dist/oauth/client-metadata-documents.d.ts",
78
- "import": "./dist/oauth/client-metadata-documents.js",
79
- "default": "./dist/oauth/client-metadata-documents.js"
80
- },
81
- "./rate-limit": {
82
- "types": "./dist/rate-limit/index.d.ts",
83
- "import": "./dist/rate-limit/index.js",
84
- "default": "./dist/rate-limit/index.js"
85
- },
86
- "./http": {
87
- "types": "./dist/http/index.d.ts",
88
- "import": "./dist/http/index.js",
89
- "default": "./dist/http/index.js"
90
- },
91
- "./sveltekit": {
92
- "types": "./dist/sveltekit-mount.d.ts",
93
- "import": "./dist/sveltekit-mount.js",
94
- "default": "./dist/sveltekit-mount.js"
95
- },
96
- "./package.json": "./package.json"
97
- },
98
- "scripts": {
99
- "build": "bun run build.ts",
100
- "lint": "eslint src/",
101
- "test": "LOG_LEVEL=info NODE_ENV=test MCP_SERVER_NAME=protokit-mcp-server DATABASE_URL=postgresql://test:test@localhost/test bun test --path-ignore-patterns='src/oauth/postgres/index.test.ts'",
102
- "test:postgres": "LOG_LEVEL=info NODE_ENV=test MCP_SERVER_NAME=protokit-mcp-server DATABASE_URL=postgresql://protokit:protokit@localhost:5432/protokit_test bun test src/oauth/postgres/index.test.ts",
103
- "test:conformance": "NODE_ENV=test MCP_SERVER_NAME=protokit-mcp-server MCP_CONFORMANCE_PORT=3137 bun ./src/conformance-server.ts",
104
- "typecheck": "tsc --noEmit",
105
- "verify:cimd-runtime": "bun run build && bun run verify-cimd-runtime.ts && node --experimental-strip-types verify-cimd-runtime.ts",
106
- "verify:package": "bun run verify-package.ts"
107
- },
108
- "dependencies": {
109
- "@modelcontextprotocol/client": "^2.0.0",
110
- "@modelcontextprotocol/core": "^2.0.0",
111
- "@modelcontextprotocol/ext-apps": "^1.7.5",
112
- "@modelcontextprotocol/node": "^2.0.0",
113
- "@modelcontextprotocol/server": "^2.0.0",
114
- "drizzle-orm": "^0.45.2",
115
- "pino": "^10.3.1",
116
- "zod": "^4.4.3"
117
- },
118
- "devDependencies": {
119
- "@types/node": "^26.2.0",
120
- "@types/pg": "^8.16.0",
121
- "pg": "^8.16.3",
122
- "pino-pretty": "^13.1.3",
123
- "typescript": "6.0.3"
124
- }
125
- }
2
+ "name": "@lostgradient/mcp",
3
+ "version": "0.3.0",
4
+ "description": "The MCP OAuth issuer and protected HTTP handler for Fetch applications.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/stevekinney/corvidae.git",
11
+ "directory": "packages/mcp"
12
+ },
13
+ "engines": {
14
+ "node": ">=22",
15
+ "bun": ">=1.4.0"
16
+ },
17
+ "exports": {
18
+ "./http": {
19
+ "types": "./dist/http.d.ts",
20
+ "default": "./dist/http.js"
21
+ },
22
+ "./oauth": {
23
+ "types": "./dist/oauth/index.d.ts",
24
+ "default": "./dist/oauth/index.js"
25
+ },
26
+ "./oauth/postgres": {
27
+ "types": "./dist/oauth/postgres.d.ts",
28
+ "default": "./dist/oauth/postgres.js"
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "@lostgradient/storage": "0.1.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@lostgradient/storage-postgres": "0.1.0",
36
+ "@types/pg": "^8.15.5",
37
+ "pg": "^8.11.0",
38
+ "zod": "^4.6.6"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@lostgradient/storage-postgres": {
42
+ "optional": true
43
+ },
44
+ "@types/pg": {
45
+ "optional": true
46
+ },
47
+ "pg": {
48
+ "optional": true
49
+ }
50
+ }
51
+ }
@@ -1,73 +0,0 @@
1
- // src/rate-limit/sliding-window-rate-limiter.ts
2
- import { randomUUID } from "node:crypto";
3
-
4
- class SlidingWindowRateLimiter {
5
- nowProvider;
6
- constructor(nowProvider = () => Date.now()) {
7
- this.nowProvider = nowProvider;
8
- }
9
- async consume(input) {
10
- const nowMilliseconds = this.nowProvider();
11
- const windowMilliseconds = input.windowSeconds * 1000;
12
- const result = await input.atomicStore.consume({
13
- key: input.key,
14
- nowMilliseconds,
15
- windowMilliseconds,
16
- maximumRequests: input.maximumRequests,
17
- member: `${nowMilliseconds}-${randomUUID()}`
18
- });
19
- return {
20
- allowed: result.allowed,
21
- retryAfterSeconds: result.allowed ? 0 : Math.max(1, Math.ceil(result.retryAfterMilliseconds / 1000)),
22
- remainingRequests: result.remainingRequests
23
- };
24
- }
25
- async peek(input) {
26
- return input.atomicStore.peek({
27
- key: input.key,
28
- nowMilliseconds: this.nowProvider(),
29
- windowMilliseconds: input.windowSeconds * 1000
30
- });
31
- }
32
- }
33
-
34
- // src/rate-limit/request-rate-limiter.ts
35
- class RequestRateLimiter {
36
- configuration;
37
- storeProvider;
38
- #limiter;
39
- constructor(configuration, storeProvider, nowProvider) {
40
- this.configuration = configuration;
41
- this.storeProvider = storeProvider;
42
- this.#limiter = new SlidingWindowRateLimiter(nowProvider);
43
- }
44
- async consume(category, identifier) {
45
- const categoryConfiguration = this.configuration.categories[category];
46
- return this.#limiter.consume({
47
- key: this.buildKey(category, identifier),
48
- ...categoryConfiguration,
49
- atomicStore: await this.storeProvider()
50
- });
51
- }
52
- async peek(category, identifier) {
53
- return this.#limiter.peek({
54
- key: this.buildKey(category, identifier),
55
- windowSeconds: this.configuration.categories[category].windowSeconds,
56
- atomicStore: await this.storeProvider()
57
- });
58
- }
59
- buildKey(category, identifier) {
60
- const namespace = this.configuration.keyNamespace;
61
- return namespace ? `rate_limit:${namespace}:${category}:${identifier}` : `rate_limit:${category}:${identifier}`;
62
- }
63
- }
64
-
65
- // src/rate-limit/rate-limit-response.ts
66
- function createRateLimitedResponse(retryAfterSeconds, headers) {
67
- return Response.json({ error: "rate_limited", error_description: "Too many requests" }, {
68
- status: 429,
69
- headers: { ...headers ?? {}, "Retry-After": String(retryAfterSeconds) }
70
- });
71
- }
72
-
73
- export { SlidingWindowRateLimiter, RequestRateLimiter, createRateLimitedResponse };
@@ -1,28 +0,0 @@
1
- import {
2
- mcpServerEnvironmentSchema
3
- } from "./chunk-xcf742mf.js";
4
-
5
- // src/env.ts
6
- import { z } from "zod";
7
- var mcpServerEnvironmentObject = z.object(mcpServerEnvironmentSchema);
8
- function parseMcpServerEnvironment(env) {
9
- if (env.SKIP_ENV_VALIDATION) {
10
- throw new Error("SKIP_ENV_VALIDATION is not supported. Supply a real environment instead — see .env.example.");
11
- }
12
- const presentEntries = Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== undefined && entry[1] !== ""));
13
- if (!presentEntries.MCP_SERVER_NAME) {
14
- throw new Error("MCP_SERVER_NAME is required. Set the explicit server name advertised to MCP clients.");
15
- }
16
- const environment = mcpServerEnvironmentObject.parse(presentEntries);
17
- if (environment.NODE_ENV === "production" && environment.LOG_CONTENT_DIAGNOSTICS_UNTIL) {
18
- throw new Error("LOG_CONTENT_DIAGNOSTICS_UNTIL is not supported in production. Raw prompt content logging cannot run in production.");
19
- }
20
- return environment;
21
- }
22
- var cachedEnvironment;
23
- function getEnvironment() {
24
- cachedEnvironment ??= parseMcpServerEnvironment(process.env);
25
- return cachedEnvironment;
26
- }
27
-
28
- export { parseMcpServerEnvironment, getEnvironment };