@pithy-sh/auth 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/audit/actions.d.ts +39 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +40 -1
- package/dist/audit/emit.d.ts +34 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +47 -1
- package/dist/audit/evidence.d.ts +8 -2
- package/dist/audit/evidence.d.ts.map +1 -1
- package/dist/capability.d.ts +31 -11
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +38 -5
- package/dist/client/api.d.ts +55 -12
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +57 -18
- package/dist/client/bearer.d.ts +110 -0
- package/dist/client/bearer.d.ts.map +1 -0
- package/dist/client/bearer.js +265 -0
- package/dist/client/handoff.d.ts +77 -0
- package/dist/client/handoff.d.ts.map +1 -0
- package/dist/client/handoff.js +119 -0
- package/dist/client/mcp.d.ts +70 -0
- package/dist/client/mcp.d.ts.map +1 -0
- package/dist/client/mcp.js +65 -0
- package/dist/data/betterAuth.d.ts +3 -2
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +5 -3
- package/dist/data/kitFields.d.ts +5 -0
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +5 -0
- package/dist/data/tables.d.ts +25 -4
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +9 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +6 -2
- package/dist/data/verificationOutcome.d.ts +53 -0
- package/dist/data/verificationOutcome.d.ts.map +1 -0
- package/dist/data/verificationOutcome.js +50 -0
- package/dist/email/send.js +6 -2
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +56 -10
- package/dist/http/csrf.d.ts.map +1 -1
- package/dist/http/csrf.js +2 -1
- package/dist/http/guards.d.ts +15 -11
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +46 -11
- package/dist/http/handoff.d.ts +76 -0
- package/dist/http/handoff.d.ts.map +1 -0
- package/dist/http/handoff.js +316 -0
- package/dist/http/middleware.d.ts +12 -0
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +25 -4
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +9 -3
- package/dist/http/responses.d.ts +142 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +66 -10
- package/dist/http/routes.d.ts +2 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +35 -4
- package/dist/http/schemas.d.ts +57 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +44 -1
- package/dist/http/views.d.ts +22 -2
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +40 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/instance/auth.d.ts +148 -10
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +86 -41
- package/dist/instance/plugins.d.ts +6 -0
- package/dist/instance/plugins.d.ts.map +1 -1
- package/dist/instance/plugins.js +14 -1
- package/dist/ledger/read.d.ts +53 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +85 -0
- package/dist/ledger/record.d.ts +35 -0
- package/dist/ledger/record.d.ts.map +1 -0
- package/dist/ledger/record.js +98 -0
- package/dist/lifecycle/erasure.d.ts +9 -0
- package/dist/lifecycle/erasure.d.ts.map +1 -0
- package/dist/lifecycle/erasure.js +96 -0
- package/dist/lifecycle/inactivity.d.ts +19 -0
- package/dist/lifecycle/inactivity.d.ts.map +1 -0
- package/dist/lifecycle/inactivity.js +28 -0
- package/dist/lifecycle/transitions.d.ts +22 -1
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +51 -4
- package/dist/mcp/argumentClass.d.ts +51 -0
- package/dist/mcp/argumentClass.d.ts.map +1 -0
- package/dist/mcp/argumentClass.js +69 -0
- package/dist/mcp/capability.d.ts +50 -0
- package/dist/mcp/capability.d.ts.map +1 -0
- package/dist/mcp/capability.js +140 -0
- package/dist/mcp/clientMetadata.d.ts +40 -0
- package/dist/mcp/clientMetadata.d.ts.map +1 -0
- package/dist/mcp/clientMetadata.js +68 -0
- package/dist/mcp/consent.d.ts +49 -0
- package/dist/mcp/consent.d.ts.map +1 -0
- package/dist/mcp/consent.js +69 -0
- package/dist/mcp/dispatch.d.ts +35 -0
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +135 -0
- package/dist/mcp/floor.d.ts +37 -0
- package/dist/mcp/floor.d.ts.map +1 -0
- package/dist/mcp/floor.js +41 -0
- package/dist/mcp/host.d.ts +34 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +2 -0
- package/dist/mcp/http/redirectList.d.ts +9 -0
- package/dist/mcp/http/redirectList.d.ts.map +1 -0
- package/dist/mcp/http/redirectList.js +24 -0
- package/dist/mcp/http/responses.d.ts +143 -0
- package/dist/mcp/http/responses.d.ts.map +1 -0
- package/dist/mcp/http/responses.js +83 -0
- package/dist/mcp/http/routes.d.ts +28 -0
- package/dist/mcp/http/routes.d.ts.map +1 -0
- package/dist/mcp/http/routes.js +517 -0
- package/dist/mcp/http/schemas.d.ts +24 -0
- package/dist/mcp/http/schemas.d.ts.map +1 -0
- package/dist/mcp/http/schemas.js +18 -0
- package/dist/mcp/marker.d.ts +15 -0
- package/dist/mcp/marker.d.ts.map +1 -0
- package/dist/mcp/marker.js +15 -0
- package/dist/mcp/provider.d.ts +78 -0
- package/dist/mcp/provider.d.ts.map +1 -0
- package/dist/mcp/provider.js +108 -0
- package/dist/mcp/purge.d.ts +15 -0
- package/dist/mcp/purge.d.ts.map +1 -0
- package/dist/mcp/purge.js +31 -0
- package/dist/mcp/rpc.d.ts +79 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +103 -0
- package/dist/mcp/toolAudit.d.ts +76 -0
- package/dist/mcp/toolAudit.d.ts.map +1 -0
- package/dist/mcp/toolAudit.js +86 -0
- package/dist/migrations/0006_verification_outcomes.d.ts +15 -0
- package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
- package/dist/migrations/0006_verification_outcomes.js +35 -0
- package/dist/migrations/0007_erasure_record.d.ts +17 -0
- package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
- package/dist/migrations/0007_erasure_record.js +36 -0
- package/dist/migrations/0008_last_active.d.ts +15 -0
- package/dist/migrations/0008_last_active.d.ts.map +1 -0
- package/dist/migrations/0008_last_active.js +29 -0
- package/dist/migrations/set.d.ts +4 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +8 -2
- package/dist/peer.d.ts +3 -2
- package/dist/peer.d.ts.map +1 -1
- package/dist/processing/activities.d.ts +6 -0
- package/dist/processing/activities.d.ts.map +1 -0
- package/dist/processing/activities.js +12 -0
- package/dist/purge/contribution.d.ts +20 -5
- package/dist/purge/contribution.d.ts.map +1 -1
- package/dist/purge/contribution.js +20 -6
- package/dist/purge/run.d.ts +75 -5
- package/dist/purge/run.d.ts.map +1 -1
- package/dist/purge/run.js +117 -14
- package/dist/purge/workflow.d.ts +15 -2
- package/dist/purge/workflow.d.ts.map +1 -1
- package/dist/purge/workflow.js +51 -7
- package/dist/test-utils/accountFootprint.d.ts +5 -2
- package/dist/test-utils/accountFootprint.d.ts.map +1 -1
- package/dist/test-utils/accountFootprint.js +7 -2
- package/dist/test-utils/liveApp.d.ts +6 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +7 -2
- package/dist/token/handoff.d.ts +80 -0
- package/dist/token/handoff.d.ts.map +1 -0
- package/dist/token/handoff.js +136 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +59 -7
- package/docs/apple-signin.md +32 -4
- package/docs/facebook-oauth.md +2 -2
- package/docs/github-oauth.md +2 -2
- package/docs/google-oauth.md +9 -7
- package/docs/microsoft-oauth.md +2 -2
- package/package.json +11 -5
- package/pithy.manifest.json +2 -2
- package/pithy.mcp.manifest.json +36 -0
- package/src/audit/actions.ts +39 -0
- package/src/audit/emit.ts +63 -0
- package/src/audit/evidence.ts +8 -4
- package/src/capability.ts +80 -23
- package/src/client/api.ts +69 -19
- package/src/client/bearer.ts +388 -0
- package/src/client/handoff.ts +172 -0
- package/src/client/mcp.ts +140 -0
- package/src/data/betterAuth.ts +8 -4
- package/src/data/kitFields.ts +2 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +15 -3
- package/src/data/verificationOutcome.ts +86 -0
- package/src/email/send.ts +2 -2
- package/src/http/adminRoutes.ts +68 -3
- package/src/http/csrf.ts +4 -1
- package/src/http/guards.ts +48 -11
- package/src/http/handoff.ts +350 -0
- package/src/http/middleware.ts +29 -3
- package/src/http/resolve.ts +25 -25
- package/src/http/responses.ts +134 -8
- package/src/http/routes.ts +63 -4
- package/src/http/schemas.ts +85 -0
- package/src/http/views.ts +46 -2
- package/src/index.ts +2 -0
- package/src/instance/auth.ts +51 -1
- package/src/instance/plugins.ts +20 -2
- package/src/ledger/read.ts +133 -0
- package/src/ledger/record.ts +198 -0
- package/src/lifecycle/erasure.ts +118 -0
- package/src/lifecycle/inactivity.ts +56 -0
- package/src/lifecycle/transitions.ts +75 -5
- package/src/mcp/argumentClass.ts +112 -0
- package/src/mcp/capability.ts +194 -0
- package/src/mcp/clientMetadata.ts +81 -0
- package/src/mcp/consent.ts +95 -0
- package/src/mcp/dispatch.ts +154 -0
- package/src/mcp/floor.ts +62 -0
- package/src/mcp/host.ts +36 -0
- package/src/mcp/http/redirectList.ts +26 -0
- package/src/mcp/http/responses.ts +157 -0
- package/src/mcp/http/routes.ts +635 -0
- package/src/mcp/http/schemas.ts +37 -0
- package/src/mcp/marker.ts +18 -0
- package/src/mcp/provider.ts +151 -0
- package/src/mcp/purge.ts +39 -0
- package/src/mcp/rpc.ts +135 -0
- package/src/mcp/toolAudit.ts +132 -0
- package/src/migrations/0006_verification_outcomes.ts +51 -0
- package/src/migrations/0007_erasure_record.ts +43 -0
- package/src/migrations/0008_last_active.ts +30 -0
- package/src/migrations/set.ts +7 -1
- package/src/processing/activities.ts +14 -0
- package/src/purge/contribution.ts +37 -10
- package/src/purge/run.ts +179 -16
- package/src/purge/workflow.ts +65 -7
- package/src/seeds/example.ts +2 -2
- package/src/test-utils/accountFootprint.ts +10 -1
- package/src/test-utils/liveApp.ts +10 -1
- package/src/token/handoff.ts +180 -0
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/mcp/floor.ts
|
|
5
|
+
/**
|
|
6
|
+
* Who the MCP endpoint admits at all (`docs/AGENT-ACCESS.md` §4).
|
|
7
|
+
*
|
|
8
|
+
* **The default is closed.** Correct route gates are not the whole question: an endpoint that lets any signed-in
|
|
9
|
+
* user drive an agent against the application is remote automation of a surface built for a person at a keyboard,
|
|
10
|
+
* which changes rate, cost and abuse patterns even when every gate holds. So the capability is off unless composed,
|
|
11
|
+
* and composing it means choosing one of three floors — there is no default to fall into:
|
|
12
|
+
*
|
|
13
|
+
* - `{ power }` — a caller whose role in the acting organization holds this power.
|
|
14
|
+
* - `{ entitlement }` — a caller holding this entitlement, a tier floor.
|
|
15
|
+
* - `"signed-in"` — every signed-in user. A decision, stated in config, and `pithy doctor` says it out loud.
|
|
16
|
+
*
|
|
17
|
+
* The floor is the endpoint's, not a tool's. Above it, every tool is still gated by its own route.
|
|
18
|
+
*/
|
|
19
|
+
const McpFloor = z.union([
|
|
20
|
+
z.literal("signed-in").describe("Every signed-in user may connect an agent. `pithy doctor` reports it as open."),
|
|
21
|
+
z.object({ power: z.string().min(1).describe("The power a caller's role must hold, e.g. `agents:use`.") }).strict().describe("Only a caller whose role holds this power."),
|
|
22
|
+
z.object({ entitlement: z.string().min(1).describe("The entitlement a caller must hold, e.g. `pro`.") }).strict().describe("Only a caller holding this entitlement.")
|
|
23
|
+
]).describe("Who the MCP endpoint admits at all. Required: a power, an entitlement, or `signed-in` for every signed-in user. Every tool is still gated by its own route above it.");
|
|
24
|
+
/** Whether the floor admits this signed-in caller. */
|
|
25
|
+
async function floorAdmits(floor, caller) {
|
|
26
|
+
if (floor === "signed-in") return true;
|
|
27
|
+
if ("power" in floor) return caller.roleAllows?.(floor.power) ?? false;
|
|
28
|
+
return (await caller.entitlements()).has(floor.entitlement);
|
|
29
|
+
}
|
|
30
|
+
/** Whether the endpoint is open to every signed-in user. What `pithy doctor` reports. */
|
|
31
|
+
function isOpenToEverySignedInUser(floor) {
|
|
32
|
+
return floor === "signed-in";
|
|
33
|
+
}
|
|
34
|
+
/** The floor in one line, for `pithy doctor` and the manifest. */
|
|
35
|
+
function floorLine(floor) {
|
|
36
|
+
if (floor === "signed-in") return "open to every signed-in user";
|
|
37
|
+
if ("power" in floor) return `open only to callers whose role holds ${floor.power}`;
|
|
38
|
+
return `open only to callers holding the ${floor.entitlement} entitlement`;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { McpFloor, floorAdmits, floorLine, isOpenToEverySignedInUser };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { ClientDiscovery } from "@better-auth/oauth-provider";
|
|
4
|
+
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
5
|
+
import type { Context } from "hono";
|
|
6
|
+
import type { AuthInstance } from "../instance/auth";
|
|
7
|
+
/**
|
|
8
|
+
* What the auth capability lends the MCP capability composed beside it.
|
|
9
|
+
*
|
|
10
|
+
* The authorization server lives inside the auth instance — Better Auth composes a provider as a plugin, so the
|
|
11
|
+
* instance that signs a user in is the one that issues their agent's token. The MCP capability's routes need that
|
|
12
|
+
* instance, the address it resolves for this request, and the database it reads, and nothing else; this is that,
|
|
13
|
+
* and it is the only thing the MCP capability reads off auth.
|
|
14
|
+
*/
|
|
15
|
+
export interface McpHost {
|
|
16
|
+
/** This request's auth instance — the one the session middleware already built, memoized per request. */
|
|
17
|
+
instance(c: Context<PithyHonoEnv>): Promise<AuthInstance>;
|
|
18
|
+
/** The origin this request's instance runs under: the config's `baseURL`, or in `dev` the request's own host. */
|
|
19
|
+
baseURL(request: Request): string;
|
|
20
|
+
/** Where the auth handler mounts, e.g. `/auth`. The issuer is `baseURL` + this. */
|
|
21
|
+
readonly basePath: string;
|
|
22
|
+
/** The D1 binding auth's tables live in. */
|
|
23
|
+
readonly database: string;
|
|
24
|
+
}
|
|
25
|
+
/** What the MCP capability tells auth when composed, so the instance carries the provider. */
|
|
26
|
+
export interface McpWiring {
|
|
27
|
+
/** Where the MCP endpoint mounts, e.g. `/mcp`. The resource is `baseURL` + this. */
|
|
28
|
+
readonly path: string;
|
|
29
|
+
/** The scaffolded consent screen's path. */
|
|
30
|
+
readonly consentPage: string;
|
|
31
|
+
/** How a client whose id is its metadata document's URL is resolved. One per composed `mcp()`, so its cache lasts. */
|
|
32
|
+
readonly clientDiscovery: ClientDiscovery;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/mcp/host.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB,yGAAyG;IACzG,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,iHAAiH;IACjH,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,8FAA8F;AAC9F,MAAM,WAAW,SAAS;IACxB,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,sHAAsH;IACtH,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C"}
|
package/dist/mcp/host.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* A client's stored redirect URIs, as a list. The adapter stores them as a JSON array or comma-joined, and the
|
|
5
|
+
* connected-applications screen shows them as the one value that identifies the client, so a value that is JSON
|
|
6
|
+
* but not an array or a string names no URI rather than showing a fragment of itself as one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function redirectList(stored: string): string[];
|
|
9
|
+
//# sourceMappingURL=redirectList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectList.d.ts","sourceRoot":"","sources":["../../../src/mcp/http/redirectList.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/mcp/http/redirectList.ts
|
|
4
|
+
function entries(values) {
|
|
5
|
+
return values.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A client's stored redirect URIs, as a list. The adapter stores them as a JSON array or comma-joined, and the
|
|
9
|
+
* connected-applications screen shows them as the one value that identifies the client, so a value that is JSON
|
|
10
|
+
* but not an array or a string names no URI rather than showing a fragment of itself as one.
|
|
11
|
+
*/
|
|
12
|
+
function redirectList(stored) {
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = JSON.parse(stored);
|
|
16
|
+
} catch {
|
|
17
|
+
return entries(stored.split(","));
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(parsed)) return entries(parsed);
|
|
20
|
+
if (typeof parsed === "string") return entries([parsed]);
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { redirectList };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/** The MCP capability's response bodies. Every route names one in its `describeRoute`. */
|
|
5
|
+
/** RFC 9728 protected-resource metadata: where a client finds the authorization server for this endpoint. */
|
|
6
|
+
export declare const ProtectedResourceMetadata: z.ZodObject<{
|
|
7
|
+
resource: z.ZodString;
|
|
8
|
+
authorization_servers: z.ZodArray<z.ZodString>;
|
|
9
|
+
scopes_supported: z.ZodArray<z.ZodString>;
|
|
10
|
+
bearer_methods_supported: z.ZodArray<z.ZodString>;
|
|
11
|
+
resource_name: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type ProtectedResourceMetadata = z.infer<typeof ProtectedResourceMetadata>;
|
|
14
|
+
/** RFC 8414 authorization-server metadata, relayed from the provider unchanged. */
|
|
15
|
+
export declare const AuthorizationServerMetadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
16
|
+
export type AuthorizationServerMetadata = z.infer<typeof AuthorizationServerMetadata>;
|
|
17
|
+
/** One JSON-RPC answer. */
|
|
18
|
+
export declare const RpcResponse: z.ZodObject<{
|
|
19
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
20
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
21
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
22
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
code: z.ZodNumber;
|
|
24
|
+
message: z.ZodString;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type RpcResponse = z.infer<typeof RpcResponse>;
|
|
28
|
+
/** One operation a capability row lists. */
|
|
29
|
+
export declare const ConsentOperation: z.ZodObject<{
|
|
30
|
+
tool: z.ZodString;
|
|
31
|
+
summary: z.ZodString;
|
|
32
|
+
effect: z.ZodNullable<z.ZodEnum<{
|
|
33
|
+
charges: "charges";
|
|
34
|
+
deletes: "deletes";
|
|
35
|
+
sends: "sends";
|
|
36
|
+
writes: "writes";
|
|
37
|
+
}>>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type ConsentOperation = z.infer<typeof ConsentOperation>;
|
|
40
|
+
/** One capability, as the unit of consent. */
|
|
41
|
+
export declare const ConsentCapability: z.ZodObject<{
|
|
42
|
+
capability: z.ZodString;
|
|
43
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
44
|
+
tool: z.ZodString;
|
|
45
|
+
summary: z.ZodString;
|
|
46
|
+
effect: z.ZodNullable<z.ZodEnum<{
|
|
47
|
+
charges: "charges";
|
|
48
|
+
deletes: "deletes";
|
|
49
|
+
sends: "sends";
|
|
50
|
+
writes: "writes";
|
|
51
|
+
}>>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
reachable: z.ZodNumber;
|
|
54
|
+
total: z.ZodNumber;
|
|
55
|
+
effects: z.ZodObject<{
|
|
56
|
+
writes: z.ZodNumber;
|
|
57
|
+
sends: z.ZodNumber;
|
|
58
|
+
charges: z.ZodNumber;
|
|
59
|
+
deletes: z.ZodNumber;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
export type ConsentCapability = z.infer<typeof ConsentCapability>;
|
|
63
|
+
/** One scope the client asked for, and what became of it. */
|
|
64
|
+
export declare const ConsentScope: z.ZodObject<{
|
|
65
|
+
scope: z.ZodString;
|
|
66
|
+
granted: z.ZodBoolean;
|
|
67
|
+
reason: z.ZodNullable<z.ZodEnum<{
|
|
68
|
+
role: "role";
|
|
69
|
+
unknown: "unknown";
|
|
70
|
+
}>>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export type ConsentScope = z.infer<typeof ConsentScope>;
|
|
73
|
+
/** Everything the consent screen shows. */
|
|
74
|
+
export declare const ConsentView: z.ZodObject<{
|
|
75
|
+
client: z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
verifiedHost: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
|
+
reportedName: z.ZodNullable<z.ZodString>;
|
|
79
|
+
reportedUri: z.ZodNullable<z.ZodString>;
|
|
80
|
+
redirectUri: z.ZodString;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
capabilities: z.ZodArray<z.ZodObject<{
|
|
83
|
+
capability: z.ZodString;
|
|
84
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
85
|
+
tool: z.ZodString;
|
|
86
|
+
summary: z.ZodString;
|
|
87
|
+
effect: z.ZodNullable<z.ZodEnum<{
|
|
88
|
+
charges: "charges";
|
|
89
|
+
deletes: "deletes";
|
|
90
|
+
sends: "sends";
|
|
91
|
+
writes: "writes";
|
|
92
|
+
}>>;
|
|
93
|
+
}, z.core.$strip>>;
|
|
94
|
+
reachable: z.ZodNumber;
|
|
95
|
+
total: z.ZodNumber;
|
|
96
|
+
effects: z.ZodObject<{
|
|
97
|
+
writes: z.ZodNumber;
|
|
98
|
+
sends: z.ZodNumber;
|
|
99
|
+
charges: z.ZodNumber;
|
|
100
|
+
deletes: z.ZodNumber;
|
|
101
|
+
}, z.core.$strip>;
|
|
102
|
+
}, z.core.$strip>>;
|
|
103
|
+
requested: z.ZodArray<z.ZodObject<{
|
|
104
|
+
scope: z.ZodString;
|
|
105
|
+
granted: z.ZodBoolean;
|
|
106
|
+
reason: z.ZodNullable<z.ZodEnum<{
|
|
107
|
+
role: "role";
|
|
108
|
+
unknown: "unknown";
|
|
109
|
+
}>>;
|
|
110
|
+
}, z.core.$strip>>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
export type ConsentView = z.infer<typeof ConsentView>;
|
|
113
|
+
/** The answer to a consent decision. */
|
|
114
|
+
export declare const ConsentDecision: z.ZodObject<{
|
|
115
|
+
redirect: z.ZodString;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
export type ConsentDecision = z.infer<typeof ConsentDecision>;
|
|
118
|
+
/** One application the caller connected. */
|
|
119
|
+
export declare const ConnectedApplication: z.ZodObject<{
|
|
120
|
+
clientId: z.ZodString;
|
|
121
|
+
verifiedHost: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
122
|
+
reportedName: z.ZodNullable<z.ZodString>;
|
|
123
|
+
redirectUris: z.ZodArray<z.ZodString>;
|
|
124
|
+
approvedAt: z.ZodString;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
export type ConnectedApplication = z.infer<typeof ConnectedApplication>;
|
|
127
|
+
/** Every application the caller connected. */
|
|
128
|
+
export declare const ConnectedApplications: z.ZodObject<{
|
|
129
|
+
applications: z.ZodArray<z.ZodObject<{
|
|
130
|
+
clientId: z.ZodString;
|
|
131
|
+
verifiedHost: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
132
|
+
reportedName: z.ZodNullable<z.ZodString>;
|
|
133
|
+
redirectUris: z.ZodArray<z.ZodString>;
|
|
134
|
+
approvedAt: z.ZodString;
|
|
135
|
+
}, z.core.$strip>>;
|
|
136
|
+
}, z.core.$strip>;
|
|
137
|
+
export type ConnectedApplications = z.infer<typeof ConnectedApplications>;
|
|
138
|
+
/** The answer to a revocation. */
|
|
139
|
+
export declare const RevokedApplication: z.ZodObject<{
|
|
140
|
+
revoked: z.ZodLiteral<true>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
export type RevokedApplication = z.infer<typeof RevokedApplication>;
|
|
143
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../src/mcp/http/responses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,0FAA0F;AAE1F,6GAA6G;AAC7G,eAAO,MAAM,yBAAyB;;;;;;iBAQ2C,CAAC;AAClF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAElF,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,wCAEuD,CAAC;AAChG,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEtF,2BAA2B;AAC3B,eAAO,MAAM,WAAW;;;;;;;;iBAae,CAAC;AACxC,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB;;;;;;;;;iBASkC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,8CAA8C;AAC9C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;iBAiB4D,CAAC;AAC3F,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,6DAA6D;AAC7D,eAAO,MAAM,YAAY;;;;;;;iBAWqB,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,2CAA2C;AAC3C,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BwD,CAAC;AACjF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,wCAAwC;AACxC,eAAO,MAAM,eAAe;;iBAIgC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,4CAA4C;AAC5C,eAAO,MAAM,oBAAoB;;;;;;iBAYY,CAAC;AAC9C,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB;;;;;;;;iBAE4B,CAAC;AAC/D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,kCAAkC;AAClC,eAAO,MAAM,kBAAkB;;iBAEK,CAAC;AACrC,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/mcp/http/responses.ts
|
|
5
|
+
/** The MCP capability's response bodies. Every route names one in its `describeRoute`. */
|
|
6
|
+
/** RFC 9728 protected-resource metadata: where a client finds the authorization server for this endpoint. */
|
|
7
|
+
const ProtectedResourceMetadata = z.object({
|
|
8
|
+
resource: z.string().describe("The MCP endpoint's absolute URL. Every token's audience."),
|
|
9
|
+
authorization_servers: z.array(z.string()).describe("The issuer that mints tokens for this resource."),
|
|
10
|
+
scopes_supported: z.array(z.string()).describe("The one scope this server issues, and `offline_access`."),
|
|
11
|
+
bearer_methods_supported: z.array(z.string()).describe("How a token is presented: `header` only."),
|
|
12
|
+
resource_name: z.string().describe("What this resource is, for a client to show.")
|
|
13
|
+
}).describe("Protected-resource metadata (RFC 9728) for the app's MCP endpoint.");
|
|
14
|
+
/** RFC 8414 authorization-server metadata, relayed from the provider unchanged. */
|
|
15
|
+
const AuthorizationServerMetadata = z.record(z.string().describe("A metadata field."), z.unknown().describe("Its value.")).describe("Authorization-server metadata (RFC 8414), as the composed provider publishes it.");
|
|
16
|
+
/** One JSON-RPC answer. */
|
|
17
|
+
const RpcResponse = z.object({
|
|
18
|
+
jsonrpc: z.literal("2.0").describe("Always `2.0`."),
|
|
19
|
+
id: z.union([z.string(), z.number()]).describe("The id of the request this answers."),
|
|
20
|
+
result: z.unknown().optional().describe("The method's result, on success."),
|
|
21
|
+
error: z.object({
|
|
22
|
+
code: z.number().int().describe("The JSON-RPC error code."),
|
|
23
|
+
message: z.string().describe("What went wrong, in one sentence.")
|
|
24
|
+
}).optional().describe("What went wrong, on failure.")
|
|
25
|
+
}).describe("One JSON-RPC 2.0 answer.");
|
|
26
|
+
/** One operation a capability row lists. */
|
|
27
|
+
const ConsentOperation = z.object({
|
|
28
|
+
tool: z.string().describe("The tool's name, `<capability>_<operation>`."),
|
|
29
|
+
summary: z.string().describe("What it does, in the capability's own words."),
|
|
30
|
+
effect: z.enum([
|
|
31
|
+
"writes",
|
|
32
|
+
"sends",
|
|
33
|
+
"charges",
|
|
34
|
+
"deletes"
|
|
35
|
+
]).nullable().describe("What it does beyond reading, or null for a read.")
|
|
36
|
+
}).describe("One thing the client will be able to do, as you.");
|
|
37
|
+
/** One capability, as the unit of consent. */
|
|
38
|
+
const ConsentCapability = z.object({
|
|
39
|
+
capability: z.string().describe("The capability's name."),
|
|
40
|
+
operations: z.array(ConsentOperation).describe("What the client will be able to do in it — only what your role allows."),
|
|
41
|
+
reachable: z.number().int().describe("How many of its operations your role allows."),
|
|
42
|
+
total: z.number().int().describe("How many operations it offers agents in all."),
|
|
43
|
+
effects: z.object({
|
|
44
|
+
writes: z.number().int().describe("Operations that change data."),
|
|
45
|
+
sends: z.number().int().describe("Operations that send a message."),
|
|
46
|
+
charges: z.number().int().describe("Operations that charge money."),
|
|
47
|
+
deletes: z.number().int().describe("Operations that delete data.")
|
|
48
|
+
}).describe("The reachable operations that do more than read, counted by effect.")
|
|
49
|
+
}).describe("One capability the client will be able to act in, and what it can do there.");
|
|
50
|
+
/** One scope the client asked for, and what became of it. */
|
|
51
|
+
const ConsentScope = z.object({
|
|
52
|
+
scope: z.string().describe("The scope as the client asked for it."),
|
|
53
|
+
granted: z.boolean().describe("Whether approving grants it."),
|
|
54
|
+
reason: z.enum(["role", "unknown"]).nullable().describe("Why it is not granted: `role` when the caller's role does not reach it, `unknown` when no such permission exists. Null when it is granted.")
|
|
55
|
+
}).describe("One scope the client requested.");
|
|
56
|
+
/** Everything the consent screen shows. */
|
|
57
|
+
const ConsentView = z.object({
|
|
58
|
+
client: z.object({
|
|
59
|
+
id: z.string().describe("The client's id: assigned when it registered dynamically, or the URL of its metadata document."),
|
|
60
|
+
verifiedHost: z.string().nullable().optional().describe("The host that serves the client's metadata document, which is its id. Proven by fetching the document there, so it may be shown as verified. Null for a dynamically registered client, which nothing has verified."),
|
|
61
|
+
reportedName: z.string().nullable().describe("The name the client gave itself. Self-asserted and never verified — show it as reported."),
|
|
62
|
+
reportedUri: z.string().nullable().describe("The homepage the client gave itself. Also unverified."),
|
|
63
|
+
redirectUri: z.string().describe("Where the token goes. Enforced by the authorization server, so it is what identifies the client.")
|
|
64
|
+
}).describe("The application asking for access."),
|
|
65
|
+
capabilities: z.array(ConsentCapability).describe("One row per capability you can reach. Nothing is selectable."),
|
|
66
|
+
requested: z.array(ConsentScope).describe("What the client asked for, each with what approving grants.")
|
|
67
|
+
}).describe("What the consent screen shows: one decision, and its consequence.");
|
|
68
|
+
/** The answer to a consent decision. */
|
|
69
|
+
const ConsentDecision = z.object({ redirect: z.string().describe("Where the browser goes next: the client's redirect, carrying a code or a refusal.") }).describe("Where to send the browser after the decision.");
|
|
70
|
+
/** One application the caller connected. */
|
|
71
|
+
const ConnectedApplication = z.object({
|
|
72
|
+
clientId: z.string().describe("The client's id."),
|
|
73
|
+
verifiedHost: z.string().nullable().optional().describe("The host that serves the client's metadata document. Null for a dynamically registered client."),
|
|
74
|
+
reportedName: z.string().nullable().describe("The name the client gave itself. Unverified."),
|
|
75
|
+
redirectUris: z.array(z.string()).describe("Where its tokens go."),
|
|
76
|
+
approvedAt: z.string().describe("When you approved it, ISO-8601.")
|
|
77
|
+
}).describe("One application acting as you.");
|
|
78
|
+
/** Every application the caller connected. */
|
|
79
|
+
const ConnectedApplications = z.object({ applications: z.array(ConnectedApplication).describe("Newest first.") }).describe("The applications acting as you, each revocable.");
|
|
80
|
+
/** The answer to a revocation. */
|
|
81
|
+
const RevokedApplication = z.object({ revoked: z.literal(true).describe("Always true: the client can no longer act as you.") }).describe("A revoked connection.");
|
|
82
|
+
//#endregion
|
|
83
|
+
export { AuthorizationServerMetadata, ConnectedApplication, ConnectedApplications, ConsentCapability, ConsentDecision, ConsentOperation, ConsentScope, ConsentView, ProtectedResourceMetadata, RevokedApplication, RpcResponse };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
4
|
+
import { type AppTool } from "@pithy-sh/core/src/mcp/tools";
|
|
5
|
+
import type { Hono } from "hono";
|
|
6
|
+
import { type McpFloor } from "../floor";
|
|
7
|
+
import type { McpHost } from "../host";
|
|
8
|
+
/**
|
|
9
|
+
* The MCP capability's routes (`docs/AGENT-ACCESS.md` §4).
|
|
10
|
+
*
|
|
11
|
+
* - `POST <path>` — the MCP endpoint. A bearer token minted for this endpoint, and nothing else, gets in.
|
|
12
|
+
* - `GET|DELETE <path>` — 405. The endpoint is stateless: it opens no event stream and holds no session to end.
|
|
13
|
+
* - `GET /.well-known/oauth-protected-resource<path>` — where a client learns which authorization server to ask.
|
|
14
|
+
* - `GET /.well-known/oauth-authorization-server<basePath>` — that server's metadata, at the RFC 8414 address.
|
|
15
|
+
* - `GET|POST <path>/consent` — what the scaffolded consent screen reads, and the one decision it sends.
|
|
16
|
+
* - `GET <path>/connections`, `DELETE <path>/connections/:clientId` — what the user approved, and the revoke.
|
|
17
|
+
*/
|
|
18
|
+
/** What the routes are built over. Read lazily: the host and the router exist only once `createBackend` has run. */
|
|
19
|
+
export interface McpRouteDeps {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly floor: McpFloor;
|
|
22
|
+
readonly host: () => McpHost;
|
|
23
|
+
readonly app: () => Hono<PithyHonoEnv>;
|
|
24
|
+
readonly tools: () => readonly AppTool[];
|
|
25
|
+
}
|
|
26
|
+
/** Register every route. */
|
|
27
|
+
export declare function registerMcpRoutes(app: Hono<PithyHonoEnv>, deps: McpRouteDeps): void;
|
|
28
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/mcp/http/routes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAc7E,OAAO,EAAE,KAAK,OAAO,EAAgB,MAAM,8BAA8B,CAAC;AAE1E,OAAO,KAAK,EAAW,IAAI,EAAqB,MAAM,MAAM,CAAC;AAY7D,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAwBvC;;;;;;;;;GASG;AAEH,oHAAoH;AACpH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,SAAS,OAAO,EAAE,CAAC;CAC1C;AA+TD,4BAA4B;AAC5B,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CA6OnF"}
|