@zgeoff/mcp-auth 0.0.0-stage → 0.1.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 (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -2
  3. package/dist/admin/build-admin.d.ts +4 -0
  4. package/dist/admin/build-client-admin.d.ts +4 -0
  5. package/dist/admin/build-grant-admin.d.ts +3 -0
  6. package/dist/admin/build-passkey-admin.d.ts +3 -0
  7. package/dist/admin/check-redirect-uris.d.ts +1 -0
  8. package/dist/admin/create-enrollment-token.d.ts +2 -0
  9. package/dist/admin/read-client-name.d.ts +1 -0
  10. package/dist/admin/read-sign-in-grants.d.ts +3 -0
  11. package/dist/admin/remove-expired.d.ts +2 -0
  12. package/dist/admin/to-client-view.d.ts +3 -0
  13. package/dist/default-paths.d.ts +18 -0
  14. package/dist/elysia/create-mcp-http-app.d.ts +17 -0
  15. package/dist/elysia/find-bearer-token.d.ts +1 -0
  16. package/dist/elysia/index.d.ts +2 -0
  17. package/dist/elysia/is-beside-prefix.d.ts +1 -0
  18. package/dist/grants/collect-granted-scopes.d.ts +7 -0
  19. package/dist/grants/read-access-payload.d.ts +9 -0
  20. package/dist/grants/read-client-scopes.d.ts +2 -0
  21. package/dist/grants/verify-oauth-access.d.ts +13 -0
  22. package/dist/index.d.ts +7 -0
  23. package/dist/mcp-auth-error.d.ts +5 -0
  24. package/dist/open-mcp-auth-admin.d.ts +2 -0
  25. package/dist/open-mcp-auth.d.ts +2 -0
  26. package/dist/passkeys/answer-enroll-request.d.ts +3 -0
  27. package/dist/passkeys/create-enrollment-state.d.ts +6 -0
  28. package/dist/passkeys/create-passkey.d.ts +10 -0
  29. package/dist/passkeys/passkey-script.d.ts +4 -0
  30. package/dist/passkeys/read-enrollment-token.d.ts +2 -0
  31. package/dist/passkeys/read-passkey-rows.d.ts +13 -0
  32. package/dist/passkeys/render-enroll-page.d.ts +11 -0
  33. package/dist/passkeys/render-login-page.d.ts +11 -0
  34. package/dist/passkeys/update-passkey-use.d.ts +9 -0
  35. package/dist/passkeys/verify-passkey-assertion.d.ts +10 -0
  36. package/dist/passkeys/verify-passkey-registration.d.ts +15 -0
  37. package/dist/passkeys/verify-session-passkey.d.ts +8 -0
  38. package/dist/routes/build-routes.d.ts +3 -0
  39. package/dist/routes/with-form-origin.d.ts +4 -0
  40. package/dist/service-tokens/build-service-token-verifier.d.ts +13 -0
  41. package/dist/service-tokens/parse-service-token-file.d.ts +7 -0
  42. package/dist/sign-in/answer-authorize-request.d.ts +3 -0
  43. package/dist/sign-in/answer-consent-request.d.ts +3 -0
  44. package/dist/sign-in/answer-login-request.d.ts +3 -0
  45. package/dist/sign-in/build-consent-binding.d.ts +1 -0
  46. package/dist/sign-in/create-sign-in-state.d.ts +43 -0
  47. package/dist/sign-in/pick-consent-choice.d.ts +8 -0
  48. package/dist/sign-in/pick-consent-outcome.d.ts +4 -0
  49. package/dist/sign-in/read-session-id.d.ts +2 -0
  50. package/dist/sign-in/read-stored-client-name.d.ts +3 -0
  51. package/dist/sign-in/read-url-field.d.ts +1 -0
  52. package/dist/sign-in/render-consent-page.d.ts +11 -0
  53. package/dist/sign-in/route-context.d.ts +17 -0
  54. package/dist/sign-in/verify-oauth-query.d.ts +1 -0
  55. package/dist/store/check-cascade-keys.d.ts +2 -0
  56. package/dist/store/check-foreign-keys.d.ts +2 -0
  57. package/dist/store/check-table-names.d.ts +2 -0
  58. package/dist/store/check-user-columns.d.ts +2 -0
  59. package/dist/store/create-auth-server.d.ts +103 -0
  60. package/dist/store/create-grant-plugin.d.ts +28 -0
  61. package/dist/store/create-owned-tables.d.ts +3 -0
  62. package/dist/store/open-store.d.ts +15 -0
  63. package/dist/store/read-table-columns.d.ts +2 -0
  64. package/dist/store/remove-grant-rows.d.ts +3 -0
  65. package/dist/store/store-schema.d.ts +63 -0
  66. package/dist/test-utils/authorize-test-client.d.ts +12 -0
  67. package/dist/test-utils/build-form-request.d.ts +1 -0
  68. package/dist/test-utils/build-seeder.d.ts +13 -0
  69. package/dist/test-utils/build-stub-authenticator.d.ts +49 -0
  70. package/dist/test-utils/build-stub-clock.d.ts +5 -0
  71. package/dist/test-utils/build-test-requester.d.ts +2 -0
  72. package/dist/test-utils/create-test-database.d.ts +2 -0
  73. package/dist/test-utils/hook-sqlite-statements.d.ts +2 -0
  74. package/dist/test-utils/index.d.ts +12 -0
  75. package/dist/test-utils/open-test-auth.d.ts +21 -0
  76. package/dist/test-utils/parse-passkey-page.d.ts +21 -0
  77. package/dist/test-utils/read-json-record.d.ts +5 -0
  78. package/dist/test-utils/run-sign-in-to-consent.d.ts +13 -0
  79. package/dist/test-utils/seed-client.d.ts +7 -0
  80. package/dist/test-utils/seed-enrollment-token.d.ts +2 -0
  81. package/dist/test-utils/seed-passkey.d.ts +7 -0
  82. package/dist/tokens/answer-error-request.d.ts +2 -0
  83. package/dist/tokens/answer-metadata-request.d.ts +2 -0
  84. package/dist/tokens/answer-revoke-request.d.ts +2 -0
  85. package/dist/tokens/answer-token-request.d.ts +3 -0
  86. package/dist/tokens/build-better-auth-request.d.ts +6 -0
  87. package/dist/tokens/build-oauth-error.d.ts +1 -0
  88. package/dist/tokens/read-error-code.d.ts +1 -0
  89. package/dist/tokens/read-error-description.d.ts +1 -0
  90. package/dist/tokens/record-token-exchange.d.ts +10 -0
  91. package/dist/tokens/remove-token-sessions.d.ts +2 -0
  92. package/dist/types.d.ts +185 -0
  93. package/dist/utils/build-page-response.d.ts +5 -0
  94. package/dist/utils/derive-token-hash.d.ts +1 -0
  95. package/dist/utils/is-allowed-redirect-uri.d.ts +1 -0
  96. package/dist/utils/is-loopback-host.d.ts +1 -0
  97. package/dist/utils/normalize-client-name.d.ts +1 -0
  98. package/dist/utils/parse-approved-by.d.ts +2 -0
  99. package/dist/utils/parse-json-strings.d.ts +1 -0
  100. package/dist/utils/read-body-text.d.ts +1 -0
  101. package/dist/utils/read-form.d.ts +2 -0
  102. package/dist/utils/to-html-text.d.ts +1 -0
  103. package/dist/utils/to-script-json.d.ts +1 -0
  104. package/package.json +73 -4
  105. package/src/admin/build-admin.ts +22 -0
  106. package/src/admin/build-client-admin.ts +112 -0
  107. package/src/admin/build-grant-admin.ts +62 -0
  108. package/src/admin/build-passkey-admin.ts +53 -0
  109. package/src/admin/check-redirect-uris.ts +17 -0
  110. package/src/admin/create-enrollment-token.ts +18 -0
  111. package/src/admin/read-client-name.ts +13 -0
  112. package/src/admin/read-sign-in-grants.ts +22 -0
  113. package/src/admin/remove-expired.ts +47 -0
  114. package/src/admin/to-client-view.ts +12 -0
  115. package/src/default-paths.ts +21 -0
  116. package/src/elysia/create-mcp-http-app.ts +218 -0
  117. package/src/elysia/find-bearer-token.ts +6 -0
  118. package/src/elysia/index.ts +2 -0
  119. package/src/elysia/is-beside-prefix.ts +7 -0
  120. package/src/grants/collect-granted-scopes.ts +19 -0
  121. package/src/grants/read-access-payload.ts +37 -0
  122. package/src/grants/read-client-scopes.ts +36 -0
  123. package/src/grants/verify-oauth-access.ts +113 -0
  124. package/src/index.ts +7 -0
  125. package/src/mcp-auth-error.ts +17 -0
  126. package/src/open-mcp-auth-admin.ts +14 -0
  127. package/src/open-mcp-auth.ts +89 -0
  128. package/src/passkeys/answer-enroll-request.ts +179 -0
  129. package/src/passkeys/create-enrollment-state.ts +54 -0
  130. package/src/passkeys/create-passkey.ts +39 -0
  131. package/src/passkeys/passkey-script.ts +48 -0
  132. package/src/passkeys/read-enrollment-token.ts +21 -0
  133. package/src/passkeys/read-passkey-rows.ts +30 -0
  134. package/src/passkeys/render-enroll-page.ts +58 -0
  135. package/src/passkeys/render-login-page.ts +59 -0
  136. package/src/passkeys/update-passkey-use.ts +24 -0
  137. package/src/passkeys/verify-passkey-assertion.ts +120 -0
  138. package/src/passkeys/verify-passkey-registration.ts +116 -0
  139. package/src/passkeys/verify-session-passkey.ts +42 -0
  140. package/src/routes/build-routes.ts +31 -0
  141. package/src/routes/with-form-origin.ts +18 -0
  142. package/src/service-tokens/build-service-token-verifier.ts +56 -0
  143. package/src/service-tokens/parse-service-token-file.ts +104 -0
  144. package/src/sign-in/answer-authorize-request.ts +133 -0
  145. package/src/sign-in/answer-consent-request.ts +220 -0
  146. package/src/sign-in/answer-login-request.ts +243 -0
  147. package/src/sign-in/build-consent-binding.ts +11 -0
  148. package/src/sign-in/create-sign-in-state.ts +229 -0
  149. package/src/sign-in/pick-consent-choice.ts +27 -0
  150. package/src/sign-in/pick-consent-outcome.ts +14 -0
  151. package/src/sign-in/read-session-id.ts +11 -0
  152. package/src/sign-in/read-stored-client-name.ts +15 -0
  153. package/src/sign-in/read-url-field.ts +12 -0
  154. package/src/sign-in/render-consent-page.ts +57 -0
  155. package/src/sign-in/route-context.ts +25 -0
  156. package/src/sign-in/verify-oauth-query.ts +39 -0
  157. package/src/store/check-cascade-keys.ts +36 -0
  158. package/src/store/check-foreign-keys.ts +20 -0
  159. package/src/store/check-table-names.ts +13 -0
  160. package/src/store/check-user-columns.ts +22 -0
  161. package/src/store/create-auth-server.ts +97 -0
  162. package/src/store/create-grant-plugin.ts +68 -0
  163. package/src/store/create-owned-tables.ts +45 -0
  164. package/src/store/open-store.ts +72 -0
  165. package/src/store/read-table-columns.ts +12 -0
  166. package/src/store/remove-grant-rows.ts +27 -0
  167. package/src/store/store-schema.ts +61 -0
  168. package/src/test-utils/authorize-test-client.ts +93 -0
  169. package/src/test-utils/build-form-request.ts +12 -0
  170. package/src/test-utils/build-seeder.ts +19 -0
  171. package/src/test-utils/build-stub-authenticator.ts +244 -0
  172. package/src/test-utils/build-stub-clock.ts +21 -0
  173. package/src/test-utils/build-test-requester.ts +5 -0
  174. package/src/test-utils/create-test-database.ts +7 -0
  175. package/src/test-utils/hook-sqlite-statements.ts +17 -0
  176. package/src/test-utils/index.ts +12 -0
  177. package/src/test-utils/open-test-auth.ts +72 -0
  178. package/src/test-utils/parse-passkey-page.ts +25 -0
  179. package/src/test-utils/read-json-record.ts +15 -0
  180. package/src/test-utils/run-sign-in-to-consent.ts +100 -0
  181. package/src/test-utils/seed-client.ts +16 -0
  182. package/src/test-utils/seed-enrollment-token.ts +5 -0
  183. package/src/test-utils/seed-passkey.ts +51 -0
  184. package/src/tokens/answer-error-request.ts +26 -0
  185. package/src/tokens/answer-metadata-request.ts +51 -0
  186. package/src/tokens/answer-revoke-request.ts +47 -0
  187. package/src/tokens/answer-token-request.ts +133 -0
  188. package/src/tokens/build-better-auth-request.ts +23 -0
  189. package/src/tokens/build-oauth-error.ts +7 -0
  190. package/src/tokens/read-error-code.ts +12 -0
  191. package/src/tokens/read-error-description.ts +11 -0
  192. package/src/tokens/record-token-exchange.ts +73 -0
  193. package/src/tokens/remove-token-sessions.ts +32 -0
  194. package/src/types.ts +247 -0
  195. package/src/utils/build-page-response.ts +24 -0
  196. package/src/utils/derive-token-hash.ts +5 -0
  197. package/src/utils/is-allowed-redirect-uri.ts +17 -0
  198. package/src/utils/is-loopback-host.ts +8 -0
  199. package/src/utils/normalize-client-name.ts +20 -0
  200. package/src/utils/parse-approved-by.ts +9 -0
  201. package/src/utils/parse-json-strings.ts +13 -0
  202. package/src/utils/read-body-text.ts +23 -0
  203. package/src/utils/read-form.ts +16 -0
  204. package/src/utils/to-html-text.ts +8 -0
  205. package/src/utils/to-script-json.ts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zgeoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,77 @@
1
- # Temporary Holding Version
1
+ # @zgeoff/mcp-auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An OAuth server that lets a hosted MCP client, such as a Claude.ai connector, reach an app's `/mcp`
4
+ route. It is built on better-auth and `bun:sqlite`, and holds the OAuth routes and pages, passkey
5
+ login for the owner, pre-registered clients, service tokens and grant revoke. Each app passes in its
6
+ own scopes, paths, table names and grant limits.
7
+
8
+ The package exports the core from `@zgeoff/mcp-auth`, an Elysia 2 adapter from
9
+ `@zgeoff/mcp-auth/elysia` and the test helpers from `@zgeoff/mcp-auth/testing`. The package needs
10
+ Bun.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ bun add @zgeoff/mcp-auth kysely
16
+ ```
17
+
18
+ Kysely is a peer dependency. Elysia 2 is an optional peer dependency, needed only for the adapter.
19
+
20
+ ## Usage
21
+
22
+ The app opens the server once at start, on a `bun:sqlite` connection that it owns. Each route is a
23
+ function from `Request` to `Response`, and `verify` turns a bearer token into an `Access` or `null`.
24
+
25
+ ```ts
26
+ import { DEFAULT_PATHS, openMCPAuth } from '@zgeoff/mcp-auth';
27
+
28
+ const auth = await openMCPAuth({
29
+ database: sqlite,
30
+ origin: 'https://app.example.com',
31
+ productName: 'app',
32
+ scopes: ['read', 'write'],
33
+ paths: DEFAULT_PATHS,
34
+ tables: { passkey: 'app_passkey', enrollmentToken: 'app_enrollment_token' },
35
+ clock: { now: () => Date.now() },
36
+ security: { record: (event) => console.log(event) },
37
+ onGrantRevoked: (grantID) => closeStreamsOf(grantID),
38
+ });
39
+
40
+ const access = await auth.verify(bearerToken);
41
+ ```
42
+
43
+ `createMCPHTTPApp` from `@zgeoff/mcp-auth/elysia` serves the routes in an Elysia app. It refuses a
44
+ wrong Host or Origin header, and checks the bearer token before it hands a request to `mcp.fetch`.
45
+
46
+ ```ts
47
+ import { createMCPHTTPApp } from '@zgeoff/mcp-auth/elysia';
48
+
49
+ app.use(
50
+ createMCPHTTPApp({
51
+ auth,
52
+ hosts: new Set(['app.example.com']),
53
+ origins: new Set(['https://app.example.com']),
54
+ readRequester,
55
+ security: { record: (event) => console.log(event) },
56
+ mcp: { fetch: (request, access) => mcpHandler.fetch(request, access) },
57
+ besidePrefix: '/api',
58
+ }),
59
+ );
60
+ ```
61
+
62
+ A command that only manages clients, grants and passkeys calls `openMCPAuthAdmin`, with no origin.
63
+
64
+ ## Features
65
+
66
+ - OAuth authorization code flow with PKCE for clients the owner adds by name.
67
+ - Passkey login and consent pages, with the scopes the owner ticks.
68
+ - Refresh tokens that rotate, and a grant that ends when a client replays a replaced token.
69
+ - A revoke that ends every token of a grant with one delete, even in the middle of a refresh.
70
+ - Bearer tokens only: the token route drops DPoP, and `verify` refuses a token bound to a key.
71
+ - Service tokens for clients that cannot run the browser flow.
72
+ - An Elysia adapter that checks Host, Origin and the bearer token of each MCP request.
73
+ - Test helpers: `openTestAuth`, `authorizeTestClient`, and seeds for clients and passkeys.
74
+
75
+ ## Documentation
76
+
77
+ The [design](../../docs/design/mcp-auth/README.md) holds the contracts and constraints.
@@ -0,0 +1,4 @@
1
+ import type { SignInState } from '../sign-in/create-sign-in-state.ts';
2
+ import type { Store } from '../store/open-store.ts';
3
+ import type { MCPAuthAdmin } from '../types.ts';
4
+ export declare function buildAdmin(store: Store, signIns: Pick<SignInState, 'removeClient'> | null): MCPAuthAdmin;
@@ -0,0 +1,4 @@
1
+ import type { SignInState } from '../sign-in/create-sign-in-state.ts';
2
+ import type { Store } from '../store/open-store.ts';
3
+ import type { MCPAuthAdmin } from '../types.ts';
4
+ export declare function buildClientAdmin(store: Store, signIns: Pick<SignInState, 'removeClient'> | null): MCPAuthAdmin['clients'];
@@ -0,0 +1,3 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { MCPAuthAdmin } from '../types.ts';
3
+ export declare function buildGrantAdmin(store: Store): MCPAuthAdmin['grants'];
@@ -0,0 +1,3 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { MCPAuthAdmin } from '../types.ts';
3
+ export declare function buildPasskeyAdmin(store: Store): MCPAuthAdmin['passkeys'];
@@ -0,0 +1 @@
1
+ export declare function checkRedirectURIs(redirectURIs: readonly string[]): void;
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function createEnrollmentToken(store: Store): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare function readClientName(raw: string): string;
@@ -0,0 +1,3 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { GrantID } from '../types.ts';
3
+ export declare function readSignInGrants(store: Store): Promise<GrantID[]>;
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function removeExpired(store: Store): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { StoreSchema } from '../store/store-schema.ts';
2
+ import type { ClientView } from '../types.ts';
3
+ export declare function toClientView(row: StoreSchema['oauthClient']): ClientView;
@@ -0,0 +1,18 @@
1
+ export declare const DEFAULT_PATHS: {
2
+ readonly browser: {
3
+ readonly authorize: '/oauth2/authorize';
4
+ readonly login: '/login';
5
+ readonly enroll: '/enroll';
6
+ readonly consent: '/consent';
7
+ readonly error: '/error';
8
+ };
9
+ readonly machine: {
10
+ readonly mcp: '/mcp';
11
+ readonly root: '/';
12
+ readonly token: '/oauth2/token';
13
+ readonly revoke: '/oauth2/revoke';
14
+ readonly authorizationServerMetadata: '/.well-known/oauth-authorization-server';
15
+ readonly resourceMetadata: '/.well-known/oauth-protected-resource';
16
+ readonly mcpResourceMetadata: '/.well-known/oauth-protected-resource/mcp';
17
+ };
18
+ };
@@ -0,0 +1,17 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { Access, MCPAuth, Requester, SecuritySink } from '../types.ts';
3
+ export interface MCPHTTPAppOptions<Scope extends string, Limits> {
4
+ readonly auth: MCPAuth<Scope, Limits>;
5
+ readonly hosts: ReadonlySet<string>;
6
+ readonly origins: ReadonlySet<string>;
7
+ readonly readRequester: (request: Request) => Requester;
8
+ readonly security: SecuritySink;
9
+ readonly mcp: {
10
+ readonly fetch: (request: Request, access: Access<Scope, Limits>) => Promise<Response>;
11
+ };
12
+ readonly besidePrefix: string;
13
+ }
14
+ export declare function createMCPHTTPApp<Scope extends string, Limits>(options: MCPHTTPAppOptions<Scope, Limits>): Elysia<"", "local", import("elysia").DefaultSingleton, {
15
+ typebox: {};
16
+ error: [];
17
+ }, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral>;
@@ -0,0 +1 @@
1
+ export declare function findBearerToken(authorization: string | null): string | null;
@@ -0,0 +1,2 @@
1
+ export { createMCPHTTPApp } from './create-mcp-http-app.ts';
2
+ export type { MCPHTTPAppOptions } from './create-mcp-http-app.ts';
@@ -0,0 +1 @@
1
+ export declare function isBesidePrefix(path: string, prefix: string): boolean;
@@ -0,0 +1,7 @@
1
+ interface HeldScopes {
2
+ readonly grant: readonly string[];
3
+ readonly token: readonly string[];
4
+ readonly allowed: readonly string[] | null;
5
+ }
6
+ export declare function collectGrantedScopes<Scope extends string>(known: readonly Scope[], held: HeldScopes): Scope[];
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { GrantID, OAuthClientID } from '../types.ts';
2
+ interface AccessPayload {
3
+ readonly grantID: GrantID;
4
+ readonly clientID: OAuthClientID;
5
+ readonly audiences: readonly string[];
6
+ readonly scopes: readonly string[];
7
+ }
8
+ export declare function readAccessPayload(payload: unknown): AccessPayload | null;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function readClientScopes<Scope extends string>(store: Store, known: readonly Scope[], clientID: string): Promise<readonly Scope[] | null>;
@@ -0,0 +1,13 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { Access, GrantLimits } from '../types.ts';
3
+ interface OAuthVerification<Scope extends string, Limits> {
4
+ readonly store: Store;
5
+ readonly resource: string;
6
+ readonly scopes: readonly Scope[];
7
+ readonly grantLimits: GrantLimits<Limits> | null;
8
+ }
9
+ type OAuthAccess<Scope extends string, Limits> = Extract<Access<Scope, Limits>, {
10
+ kind: 'oauth';
11
+ }>;
12
+ export declare function verifyOAuthAccess<Scope extends string, Limits>(deps: OAuthVerification<Scope, Limits>, bearer: string): Promise<OAuthAccess<Scope, Limits> | null>;
13
+ export {};
@@ -0,0 +1,7 @@
1
+ export { DEFAULT_PATHS } from './default-paths.ts';
2
+ export { MCPAuthError } from './mcp-auth-error.ts';
3
+ export type { MCPAuthErrorCode } from './mcp-auth-error.ts';
4
+ export { openMCPAuth } from './open-mcp-auth.ts';
5
+ export { openMCPAuthAdmin } from './open-mcp-auth-admin.ts';
6
+ export { parseServiceTokenFile } from './service-tokens/parse-service-token-file.ts';
7
+ export type * from './types.ts';
@@ -0,0 +1,5 @@
1
+ export type MCPAuthErrorCode = 'conflict' | 'not-found' | 'invalid-client-name' | 'invalid-redirect-uri' | 'invalid-setup';
2
+ export declare class MCPAuthError extends Error {
3
+ readonly code: MCPAuthErrorCode;
4
+ constructor(code: MCPAuthErrorCode, message: string);
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { MCPAuthAdmin, MCPAuthAdminOptions } from './types.ts';
2
+ export declare function openMCPAuthAdmin<Scope extends string>(options: MCPAuthAdminOptions<Scope>): Promise<MCPAuthAdmin>;
@@ -0,0 +1,2 @@
1
+ import type { MCPAuth, MCPAuthOptions } from './types.ts';
2
+ export declare function openMCPAuth<Scope extends string, Limits = null>(options: MCPAuthOptions<Scope, Limits>): Promise<MCPAuth<Scope, Limits>>;
@@ -0,0 +1,3 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ import type { Requester } from '../types.ts';
3
+ export declare function answerEnrollRequest(ctx: RouteContext, request: Request, requester: Requester): Promise<Response>;
@@ -0,0 +1,6 @@
1
+ import type { TakenChallenge } from '../sign-in/create-sign-in-state.ts';
2
+ export interface EnrollmentState {
3
+ readonly mintChallenge: (tokenHash: string) => string;
4
+ readonly claimChallenge: (tokenHash: string) => TakenChallenge;
5
+ }
6
+ export declare function createEnrollmentState(now: () => number): EnrollmentState;
@@ -0,0 +1,10 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { PasskeyID } from '../types.ts';
3
+ export interface NewPasskey {
4
+ readonly tokenHash: string;
5
+ readonly id: PasskeyID;
6
+ readonly publicKey: string;
7
+ readonly counter: number;
8
+ readonly transports: readonly string[];
9
+ }
10
+ export declare function createPasskey(store: Store, passkey: NewPasskey): Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ export declare const PASSKEY_SCRIPT: {
2
+ readonly source: "(() => {\n const data = document.getElementById('mcp-auth-passkey');\n const form = document.getElementById('mcp-auth-passkey-form');\n const button = document.getElementById('mcp-auth-passkey-start');\n const status = document.getElementById('mcp-auth-passkey-status');\n if (data === null || form === null || button === null || status === null) return;\n const spec = JSON.parse(data.textContent);\n const toBytes = (value) => {\n const base64 = value.replace(/-/g, '+').replace(/_/g, '/');\n const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);\n return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));\n };\n const toText = (buffer) => {\n let text = '';\n for (const byte of new Uint8Array(buffer)) text += String.fromCharCode(byte);\n return btoa(text).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n };\n const toDescriptors = (list) => (list || []).map((item) => ({ ...item, id: toBytes(item.id) }));\n button.addEventListener('click', async () => {\n button.disabled = true;\n status.textContent = '';\n try {\n const options = spec.options;\n const credential = spec.mode === 'create'\n ? await navigator.credentials.create({ publicKey: { ...options, challenge: toBytes(options.challenge), user: { ...options.user, id: toBytes(options.user.id) }, excludeCredentials: toDescriptors(options.excludeCredentials) } })\n : await navigator.credentials.get({ publicKey: { ...options, challenge: toBytes(options.challenge), allowCredentials: toDescriptors(options.allowCredentials) } });\n const reply = credential.response;\n const response = spec.mode === 'create'\n ? { clientDataJSON: toText(reply.clientDataJSON), attestationObject: toText(reply.attestationObject), transports: typeof reply.getTransports === 'function' ? reply.getTransports() : [] }\n : { clientDataJSON: toText(reply.clientDataJSON), authenticatorData: toText(reply.authenticatorData), signature: toText(reply.signature), userHandle: reply.userHandle ? toText(reply.userHandle) : undefined };\n form.elements.namedItem('credential').value = JSON.stringify({ id: credential.id, rawId: toText(credential.rawId), type: credential.type, response, clientExtensionResults: credential.getClientExtensionResults(), authenticatorAttachment: credential.authenticatorAttachment || undefined });\n form.submit();\n } catch (error) {\n status.textContent = 'The passkey prompt ended without a passkey (' + (error && error.name ? error.name : 'Error') + '). Try again.';\n button.disabled = false;\n }\n });\n})();";
3
+ readonly policySource: `'sha256-${string}'`;
4
+ };
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function readEnrollmentToken(store: Store, token: string): Promise<string | null>;
@@ -0,0 +1,13 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { z } from 'zod';
3
+ import type { StoreSchema } from '../store/store-schema.ts';
4
+ declare const PasskeyRowsSchema: z.ZodArray<z.ZodObject<{
5
+ id: z.ZodString;
6
+ public_key: z.ZodString;
7
+ counter: z.ZodNumber;
8
+ transports: z.ZodString;
9
+ created_at: z.ZodString;
10
+ last_used_at: z.ZodNullable<z.ZodString>;
11
+ }, z.core.$strip>>;
12
+ export declare function readPasskeyRows(executor: Kysely<StoreSchema>, table: string, id: string | null): Promise<z.infer<typeof PasskeyRowsSchema>>;
13
+ export {};
@@ -0,0 +1,11 @@
1
+ interface EnrollPageView {
2
+ readonly productName: string;
3
+ readonly enrollPath: string;
4
+ readonly ceremony: {
5
+ readonly token: string;
6
+ readonly options: unknown;
7
+ } | null;
8
+ readonly error: string | null;
9
+ }
10
+ export declare function renderEnrollPage(view: EnrollPageView): string;
11
+ export {};
@@ -0,0 +1,11 @@
1
+ interface LoginPageView {
2
+ readonly productName: string;
3
+ readonly loginPath: string;
4
+ readonly oauthQuery: string;
5
+ readonly clientName: string;
6
+ readonly redirectURI: string;
7
+ readonly options: unknown;
8
+ readonly error: string | null;
9
+ }
10
+ export declare function renderLoginPage(view: LoginPageView): string;
11
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { PasskeyID } from '../types.ts';
3
+ interface PasskeyUse {
4
+ readonly id: PasskeyID;
5
+ readonly counter: number;
6
+ readonly newCounter: number;
7
+ }
8
+ export declare function updatePasskeyUse(store: Store, use: PasskeyUse): Promise<boolean>;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { PasskeyID } from '../types.ts';
3
+ interface AssertionCheck {
4
+ readonly credential: string;
5
+ readonly challenge: string;
6
+ readonly origin: string;
7
+ readonly rpID: string;
8
+ }
9
+ export declare function verifyPasskeyAssertion(store: Store, check: AssertionCheck): Promise<PasskeyID | null>;
10
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { PasskeyID } from '../types.ts';
2
+ interface RegistrationCheck {
3
+ readonly credential: string;
4
+ readonly challenge: string;
5
+ readonly origin: string;
6
+ readonly rpID: string;
7
+ }
8
+ export interface RegisteredPasskey {
9
+ readonly id: PasskeyID;
10
+ readonly publicKey: Uint8Array;
11
+ readonly counter: number;
12
+ readonly transports: readonly string[];
13
+ }
14
+ export declare function verifyPasskeyRegistration(check: RegistrationCheck): Promise<RegisteredPasskey | null>;
15
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { PasskeyID } from '../types.ts';
3
+ interface SessionPasskey {
4
+ readonly sessionID: string;
5
+ readonly passkeyID: PasskeyID;
6
+ }
7
+ export declare function verifySessionPasskey(store: Store, check: SessionPasskey): Promise<boolean>;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ import type { MCPAuthRoutes } from '../types.ts';
3
+ export declare function buildRoutes(ctx: RouteContext): MCPAuthRoutes;
@@ -0,0 +1,4 @@
1
+ import type { Requester } from '../types.ts';
2
+ type Route = (request: Request, requester: Requester) => Promise<Response>;
3
+ export declare function withFormOrigin(origin: string, route: Route): Route;
4
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { Access, ServiceTokenFile } from '../types.ts';
2
+ interface StoredToken<Scope extends string> {
3
+ readonly digest: Buffer;
4
+ readonly access: Extract<Access<Scope, never>, {
5
+ kind: 'service';
6
+ }>;
7
+ }
8
+ export interface ServiceTokenVerifier<Scope extends string> {
9
+ readonly verify: (token: string) => StoredToken<Scope>['access'] | null;
10
+ readonly findScopes: (clientID: string) => readonly Scope[] | null;
11
+ }
12
+ export declare function buildServiceTokenVerifier<Scope extends string>(file: ServiceTokenFile<Scope>): ServiceTokenVerifier<Scope>;
13
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ParsedServiceTokenFile } from '../types.ts';
2
+ interface ServiceTokenRules<Scope extends string> {
3
+ readonly prefix: string;
4
+ readonly scopes: readonly Scope[];
5
+ }
6
+ export declare function parseServiceTokenFile<Scope extends string>(text: string, rules: ServiceTokenRules<Scope>): ParsedServiceTokenFile<Scope>;
7
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Requester } from '../types.ts';
2
+ import type { RouteContext } from './route-context.ts';
3
+ export declare function answerAuthorizeRequest(ctx: RouteContext, request: Request, requester: Requester): Promise<Response>;
@@ -0,0 +1,3 @@
1
+ import type { Requester } from '../types.ts';
2
+ import type { RouteContext } from './route-context.ts';
3
+ export declare function answerConsentRequest(ctx: RouteContext, request: Request, requester: Requester): Promise<Response>;
@@ -0,0 +1,3 @@
1
+ import type { Requester } from '../types.ts';
2
+ import type { RouteContext } from './route-context.ts';
3
+ export declare function answerLoginRequest(ctx: RouteContext, request: Request, requester: Requester): Promise<Response>;
@@ -0,0 +1 @@
1
+ export declare function buildConsentBinding(oauthQuery: string): string;
@@ -0,0 +1,43 @@
1
+ import type { CorrelationID, OAuthClientID } from '../types.ts';
2
+ interface SignInRequest {
3
+ readonly key: string;
4
+ readonly clientID: OAuthClientID;
5
+ readonly clientName: string;
6
+ readonly redirectURI: string;
7
+ }
8
+ export interface PendingSignIn extends SignInRequest {
9
+ readonly correlationID: CorrelationID;
10
+ failures: number;
11
+ readonly expiresAt: number;
12
+ challenge: {
13
+ readonly value: string;
14
+ readonly expiresAt: number;
15
+ } | null;
16
+ }
17
+ export type TakenChallenge = {
18
+ readonly kind: 'taken';
19
+ readonly challenge: string;
20
+ } | {
21
+ readonly kind: 'expired';
22
+ } | {
23
+ readonly kind: 'missing';
24
+ };
25
+ interface ApprovedSignIn {
26
+ readonly binding: string;
27
+ readonly correlationID: CorrelationID;
28
+ readonly expiresAt: number;
29
+ }
30
+ export interface SignInState {
31
+ readonly createPending: (request: SignInRequest) => PendingSignIn | null;
32
+ readonly findPending: (key: string) => PendingSignIn | null;
33
+ readonly mintChallenge: (key: string) => string | null;
34
+ readonly claimChallenge: (key: string) => TakenChallenge;
35
+ readonly recordFailure: (key: string) => 'retry' | 'locked';
36
+ readonly removePending: (key: string) => void;
37
+ readonly removeClient: (clientID: OAuthClientID) => void;
38
+ readonly recordApproved: (sessionID: string, approved: Omit<ApprovedSignIn, 'expiresAt'>) => void;
39
+ readonly findApproved: (sessionID: string) => ApprovedSignIn | null;
40
+ readonly removeApproved: (sessionID: string) => void;
41
+ }
42
+ export declare function createSignInState(pendingMs: number, now: () => number): SignInState;
43
+ export {};
@@ -0,0 +1,8 @@
1
+ interface ConsentChoice {
2
+ readonly accept: boolean;
3
+ readonly scopes: readonly string[];
4
+ readonly scope: string | null;
5
+ readonly noneTicked: boolean;
6
+ }
7
+ export declare function pickConsentChoice(known: readonly string[], ticked: readonly string[], decision: string | null): ConsentChoice;
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { SecurityEvent } from '../types.ts';
2
+ type ConsentOutcome = Pick<SecurityEvent, 'kind' | 'outcome' | 'reason'>;
3
+ export declare function pickConsentOutcome(issuedCode: boolean, noneTicked: boolean): ConsentOutcome;
4
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function readSessionID(store: Store, cookie: string | null): Promise<string | null>;
@@ -0,0 +1,3 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ import type { OAuthClientID } from '../types.ts';
3
+ export declare function readStoredClientName(store: Store, clientID: OAuthClientID): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare function readURLField(body: unknown): string | null;
@@ -0,0 +1,11 @@
1
+ interface ConsentPageView {
2
+ readonly consentPath: string;
3
+ readonly oauthQuery: string;
4
+ readonly clientName: string;
5
+ readonly redirectURI: string;
6
+ readonly scopes: readonly string[];
7
+ readonly extraFields: string;
8
+ readonly error: string | null;
9
+ }
10
+ export declare function renderConsentPage(view: ConsentPageView): string;
11
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { EnrollmentState } from '../passkeys/create-enrollment-state.ts';
2
+ import type { Store } from '../store/open-store.ts';
3
+ import type { Clock, GrantLimits, MCPAuthPaths, SecuritySink } from '../types.ts';
4
+ import type { SignInState } from './create-sign-in-state.ts';
5
+ export interface RouteContext {
6
+ readonly store: Store;
7
+ readonly origin: string;
8
+ readonly resource: string;
9
+ readonly paths: MCPAuthPaths;
10
+ readonly productName: string;
11
+ readonly scopes: readonly string[];
12
+ readonly clock: Clock;
13
+ readonly security: SecuritySink;
14
+ readonly signIns: SignInState;
15
+ readonly enrollments: EnrollmentState;
16
+ readonly consentFields: Pick<GrantLimits<unknown>, 'renderConsentFields' | 'parseConsentFields'> | null;
17
+ }
@@ -0,0 +1 @@
1
+ export declare function verifyOAuthQuery(oauthQuery: string, secret: string, now: number): Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function checkCascadeKeys(sqlite: Database): void;
@@ -0,0 +1,2 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function checkForeignKeys(sqlite: Database): void;
@@ -0,0 +1,2 @@
1
+ import type { MCPAuthTables } from '../types.ts';
2
+ export declare function checkTableNames(tables: MCPAuthTables): void;
@@ -0,0 +1,2 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function checkUserColumns(sqlite: Database): void;