Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/fork-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ jobs:
run: |
bun run e2e:self-host --test-name 'Self-host MCP (resumes all three|reports a crashed parked)|PAT MCP approvals bind|PAT MCP model-mode resume' --workers 1
- name: Person-only approval scenarios
run: bun run e2e:self-host --test-name 'a tool that requires a person refuses the agent|owner of an automatic-mode grant approves|A plain-URL API key in automatic mode' --workers 1
run: |
bun run e2e:self-host --test-name 'a tool that requires a person refuses the agent|owner of an automatic-mode grant approves|A plain-URL API key in automatic mode' --workers 1
bun run e2e:local --test-name '^Local person-only approval binds' --workers 1
- name: MCP Skills extension and client bounds
run: |
bun run e2e:self-host --test-name 'Skills extension|Self-host MCP (admits|never forgets) a' --workers 1
Expand Down
38 changes: 30 additions & 8 deletions apps/local/server/src/implementation/mcp-approvals.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { SqlClient } from "effect/sql";
import { GrantId, permitsBrowserApproval } from "@executor-js/mcp-auth";
import { GrantId, grantRefusal, permitsBrowserApproval } from "@executor-js/mcp-auth";
import { localMcpBackend } from "./mcp.ts";
import type { LocalMcpOAuth } from "./mcp-oauth.ts";
import { invocationAccounts, type Executor } from "@executor-js/sdk/core";
/** Browser approval access uses paired dashboard cookies, never the programmatic bearer key. */
import {
BrowserApprovalAddress,
BrowserApprovalAnswer,
BrowserApprovalMode,
BrowserSessionId,
type BrowserApprovals,
} from "@executor-js/mcp/browser";
Expand All @@ -15,6 +16,12 @@ import { HttpServerRequest, HttpServerResponse } from "effect/http";
import { localRequest, requestOrigin, sessionCookie, type LocalAuth } from "./auth.ts";
import type { ServerConfig } from "../contracts/config.ts";

const ApprovalQuery = Schema.Struct({
sessionId: BrowserSessionId,
grantId: GrantId,
mode: Schema.optionalKey(BrowserApprovalMode),
});

/** Local endpoints share the execution manager with /mcp while retaining separate cookie/Origin checks. */
export const localMcpApproval = (
approvals: BrowserApprovals,
Expand All @@ -35,13 +42,14 @@ export const localMcpApproval = (
return HttpServerResponse.empty({ status: 403 });
if (!(yield* auth.valid(request.cookies[sessionCookie(config)])))
return HttpServerResponse.empty({ status: 401 });
const query = yield* HttpServerRequest.schemaSearchParams(
Schema.Struct({ sessionId: BrowserSessionId, grantId: GrantId }),
);
const url = new URL(request.url, "http://localhost");
const query = yield* Schema.decodeUnknownEffect(ApprovalQuery)(
HttpServerRequest.searchParamsFromURL(url),
);
const address = yield* Schema.decodeUnknownEffect(BrowserApprovalAddress)({
...query,
requestId: url.pathname.split("/").at(-1),
sessionId: query.sessionId,
...(query.mode === undefined ? {} : { mode: query.mode }),
});
const headers = new Headers(request.headers);
headers.set("origin", oauth.origin);
Expand All @@ -50,12 +58,25 @@ export const localMcpApproval = (
? {
id: query.grantId,
policy: { kind: "all" as const },
target: { kind: "mcp" as const, mode: "browser" as const },
target: { kind: "mcp" as const, mode: address.mode ?? ("browser" as const) },
}
: (yield* oauth.browserGrant(headers, query.grantId)).grant;
if (!permitsBrowserApproval(grant)) return HttpServerResponse.empty({ status: 403 });
// Browser-mode links name an MCP session; person-only caller-mode links name a grant and mode.
const permitted =
address.mode === undefined
? permitsBrowserApproval(grant)
: grant.target.kind === "mcp" &&
grant.target.mode === address.mode &&
address.sessionId === address.mode &&
grantRefusal(grant) === undefined;
if (!permitted) return HttpServerResponse.empty({ status: 403 });
const view = yield* approvals.get(grant.id, address);
if (view.status === "pending") {
if (
address.mode !== undefined &&
(view.request.status !== "approval-required" || view.request.human !== true)
)
return HttpServerResponse.empty({ status: 403 });
const tool =
view.request.status === "approval-required"
? {
Expand Down Expand Up @@ -89,7 +110,8 @@ export const localMcpApproval = (
);
}).pipe(
Effect.catchTags({
LocalMcpUnauthorized: () => Effect.succeed(HttpServerResponse.empty({ status: 401 })),
// Pairing was checked above; an unresolvable grant is forbidden.
LocalMcpUnauthorized: () => Effect.succeed(HttpServerResponse.empty({ status: 403 })),
LocalMcpAuthUnavailable: () => Effect.succeed(HttpServerResponse.empty({ status: 503 })),
AppNotFound: () => Effect.succeed(HttpServerResponse.jsonUnsafe({ status: "unavailable" })),
StorageError: () => Effect.succeed(HttpServerResponse.empty({ status: 503 })),
Expand Down
1 change: 1 addition & 0 deletions apps/local/server/src/implementation/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const localMcp = (
const url = new URL(`/mcp/approve/${address.requestId}`, oauth.origin);
url.searchParams.set("sessionId", address.sessionId);
url.searchParams.set("grantId", caller);
if (address.mode !== undefined) url.searchParams.set("mode", address.mode);
return url.toString();
}),
},
Expand Down
26 changes: 18 additions & 8 deletions apps/local/web/src/implementation/pages/mcp-approve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ const approvals = browserApprovalAtoms(BrowserAtoms);
function Review() {
const location = useLocation();
const page = usePageUrl();
const address = Schema.decodeUnknownOption(
Schema.Struct({ ...BrowserApprovalAddress.fields, grantId: GrantId }),
)({
requestId: location.pathname.split("/").at(-1),
grantId: new URLSearchParams(page.search).get("grantId"),
sessionId: new URLSearchParams(page.search).get("sessionId"),
});
const query = new URLSearchParams(page.search);
const mode = query.get("mode");
const address = ["grantId", "sessionId", "mode"].some((key) => query.getAll(key).length > 1)
? Option.none()
: Schema.decodeUnknownOption(
Schema.Struct({ ...BrowserApprovalAddress.fields, grantId: GrantId }),
)({
requestId: location.pathname.split("/").at(-1),
grantId: query.get("grantId"),
sessionId: query.get("sessionId"),
...(mode === null ? {} : { mode }),
});
if (Option.isNone(address))
return (
<main className="p-8">
Expand All @@ -26,10 +31,15 @@ function Review() {
</h1>
</main>
);
const params = new URLSearchParams({
sessionId: address.value.sessionId,
grantId: address.value.grantId,
...(address.value.mode === undefined ? {} : { mode: address.value.mode }),
});
return (
<BrowserApprovalPage
atoms={approvals(
`/dashboard/api/mcp/approvals/${encodeURIComponent(address.value.requestId)}?${new URLSearchParams({ sessionId: address.value.sessionId, grantId: address.value.grantId })}`,
`/dashboard/api/mcp/approvals/${encodeURIComponent(address.value.requestId)}?${params}`,
)}
/>
);
Expand Down
18 changes: 18 additions & 0 deletions e2e/test-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10912,6 +10912,24 @@ export const scenarios = plan({
local: na("This scenario uses hosted memberships and personal API keys."),
},
},
localPersonApprovalOAuth: {
file: "caller-identity.spec.ts",
title: "Local person-only approval binds model and automatic OAuth grants to their own links",
targets: {
local: scheduled,
"self-host": na("This scenario exercises Local pairing and grant routing."),
cloud: na("This scenario exercises Local pairing and grant routing."),
},
},
localPersonApprovalAdministrator: {
file: "caller-identity.spec.ts",
title: "Local person-only approval binds the administrator key to its MCP mode",
targets: {
local: scheduled,
"self-host": na("The Local administrator key has no hosted equivalent."),
cloud: na("The Local administrator key has no hosted equivalent."),
},
},
sharedRuntime: {
fixtures: "actors",
file: "shared-runtime.spec.ts",
Expand Down
Loading
Loading