History

Revert the outbound MCP SDK v2 migration (#1697)

* Revert the outbound MCP SDK v2 migration * Drop the v2 MCP packages from the lockfile

Rhys Sullivan committed 2 months ago

Commit a5800a11 parent 54cde5e91 files · +5838 −10032Browse files

Showing the changes to apps/host-selfhost/src (6 of 91 files). Show all

Unified · Split

6 files
  1. apps/host-selfhost/src/app.ts +2 −12
  2. apps/host-selfhost/src/config.ts +0 −3
  3. apps/host-selfhost/src/mcp/index.ts +2 −11
  4. apps/host-selfhost/src/mcp/mcp.test.ts +0 −35
  5. apps/host-selfhost/src/mcp/session-store.ts +3 −21
  6. apps/host-selfhost/src/testing/test-app.ts +0 −2
apps/host-selfhost/src/app.ts+2−12
@@ -78,12 +78,7 @@ export const makeSelfHostApp = async (options: MakeSelfHostAppOptions = {}) => { · 77 unmodified lines
78 // ---- the in-process MCP serving seams (+ shutdown hook) ----------------78 // ---- the in-process MCP serving seams (+ shutdown hook) ----------------
79 // Pass the pinned public origin so browser-approval URLs are reachable behind79 // Pass the pinned public origin so browser-approval URLs are reachable behind
80 // a reverse proxy (not the internal 127.0.0.1 bind from the request URL).80 // a reverse proxy (not the internal 127.0.0.1 bind from the request URL).
81 const mcp = makeSelfHostMcpSeams(81 const mcp = makeSelfHostMcpSeams(dbHandle, betterAuth, config.webBaseUrl);
82 dbHandle,
83 betterAuth,
84 config.webBaseUrl,
85 config.mcp20260728Enabled,
86 );
87 82
88 // CLI device-login discovery (`executor login`). Points the CLI at Better83 // CLI device-login discovery (`executor login`). Points the CLI at Better
89 // Auth's device endpoints; `requestFormat: "json"` because those endpoints84 // Auth's device endpoints; `requestFormat: "json"` because those endpoints
@@ -115,12 +110,7 @@ export const makeSelfHostApp = async (options: MakeSelfHostAppOptions = {}) => { · 25 unmodified lines
115 // plane's decorator is wired in mcp/session-store.ts's stack layer).110 // plane's decorator is wired in mcp/session-store.ts's stack layer).
116 decorator: SelfHostAnalyticsEngineDecorator,111 decorator: SelfHostAnalyticsEngineDecorator,
117 },112 },
118 mcp: {113 mcp: { auth: mcp.auth, sessions: mcp.sessions, reporter: mcp.reporter },
119 auth: mcp.auth,
120 sessions: mcp.sessions,
121 modern: mcp.modern,
122 reporter: mcp.reporter,
123 },
124 plugins: { provider: SelfHostPluginsProvider, config: SelfHostHostConfig },114 plugins: { provider: SelfHostPluginsProvider, config: SelfHostHostConfig },
125 errorCapture: ErrorCaptureLive,115 errorCapture: ErrorCaptureLive,
126 },116 },
apps/host-selfhost/src/config.ts+0−3
@@ -32,8 +32,6 @@ export interface SelfHostConfig { · 31 unmodified lines
32 * internal network unless an operator opts in.32 * internal network unless an operator opts in.
33 */33 */
34 readonly allowLocalNetwork: boolean;34 readonly allowLocalNetwork: boolean;
35 /** Emergency rollback for inbound MCP 2026-07-28 traffic only. */
36 readonly mcp20260728Enabled: boolean;
37 // Better Auth session secret. Always resolved (env, else generated + persisted35 // Better Auth session secret. Always resolved (env, else generated + persisted
38 // under the data dir) so a single-container deploy boots with no env; the auth36 // under the data dir) so a single-container deploy boots with no env; the auth
39 // layer still validates an explicitly-set env secret is long enough.37 // layer still validates an explicitly-set env secret is long enough.
@@ -152,7 +150,6 @@ export const loadConfig = (): SelfHostConfig => { · 112 unmodified lines
152 dbPath: process.env.EXECUTOR_DB_PATH ?? join(dataDir, "data.db"),150 dbPath: process.env.EXECUTOR_DB_PATH ?? join(dataDir, "data.db"),
153 webBaseUrl: resolveWebBaseUrl(port),151 webBaseUrl: resolveWebBaseUrl(port),
154 allowLocalNetwork: process.env.EXECUTOR_ALLOW_LOCAL_NETWORK === "true",152 allowLocalNetwork: process.env.EXECUTOR_ALLOW_LOCAL_NETWORK === "true",
155 mcp20260728Enabled: process.env.MCP_2026_07_28_ENABLED !== "false",
156 authSecret: resolveAuthSecret(),153 authSecret: resolveAuthSecret(),
157 bootstrapAdminEmail: process.env.EXECUTOR_BOOTSTRAP_ADMIN_EMAIL,154 bootstrapAdminEmail: process.env.EXECUTOR_BOOTSTRAP_ADMIN_EMAIL,
158 bootstrapAdminPassword: process.env.EXECUTOR_BOOTSTRAP_ADMIN_PASSWORD,155 bootstrapAdminPassword: process.env.EXECUTOR_BOOTSTRAP_ADMIN_PASSWORD,
apps/host-selfhost/src/mcp/index.ts+2−11
@@ -4,7 +4,6 @@ import { IdentityProvider } from "@executor-js/api/server"; · 3 unmodified lines
4import type {4import type {
5 McpAuthProvider,5 McpAuthProvider,
6 McpErrorReporter,6 McpErrorReporter,
7 McpModernServerBuilder,
8 McpSessionStore,7 McpSessionStore,
9 Principal,8 Principal,
10} from "@executor-js/host-mcp";9} from "@executor-js/host-mcp";
@@ -14,7 +13,6 @@ import type { SelfHostDbHandle } from "../db/self-host-db"; · 3 unmodified lines
14import { selfHostMcpAuth } from "./auth";13import { selfHostMcpAuth } from "./auth";
15import {14import {
16 makeSelfHostMcpSessionStore,15 makeSelfHostMcpSessionStore,
17 makeSelfHostMcpModernServerBuilder,
18 selfHostMcpReporter,16 selfHostMcpReporter,
19 selfHostMcpSessions,17 selfHostMcpSessions,
20} from "./session-store";18} from "./session-store";
@@ -22,7 +20,6 @@ import { · 1 unmodified line
22export { selfHostMcpAuth } from "./auth";20export { selfHostMcpAuth } from "./auth";
23export {21export {
24 makeSelfHostMcpSessionStore,22 makeSelfHostMcpSessionStore,
25 makeSelfHostMcpModernServerBuilder,
26 selfHostMcpReporter,23 selfHostMcpReporter,
27 selfHostMcpSessions,24 selfHostMcpSessions,
28 McpEngineBuildError,25 McpEngineBuildError,
@@ -37,15 +34,13 @@ export { · 8 unmodified lines
37// own auth + session handling and is mounted OUTSIDE the API's execution34// own auth + session handling and is mounted OUTSIDE the API's execution
38// middleware, like /api/auth.35// middleware, like /api/auth.
39//36//
40// Self-host provides both era seams plus auth and an error-reporter override:37// Self-host provides the TWO envelope seams plus an error-reporter override:
41// - McpAuthProvider -> `selfHostMcpAuth` (Better Auth mcp() OAuth). It still38// - McpAuthProvider -> `selfHostMcpAuth` (Better Auth mcp() OAuth). It still
42// requires `IdentityProvider`, which `make` provides from39// requires `IdentityProvider`, which `make` provides from
43// the resolved identity seam.40// the resolved identity seam.
44// - McpSessionStore -> `selfHostMcpSessions`: in-process Map. The store owns41// - McpSessionStore -> `selfHostMcpSessions`: in-process Map. The store owns
45// dispatch (create + forward + ownership) and builds its42// dispatch (create + forward + ownership) and builds its
46// engine internally over the shared SelfHostDb.43// engine internally over the shared SelfHostDb.
47// - McpModernServerBuilder -> one stateless MCP server per request over
48// the same scoped execution stack and tool config.
49// - McpErrorReporter -> `selfHostMcpReporter`: route 500 defects through the44// - McpErrorReporter -> `selfHostMcpReporter`: route 500 defects through the
50// host's console capture.45// host's console capture.
51//46//
@@ -58,8 +53,6 @@ export interface SelfHostMcpSeams { · 6 unmodified lines
58 readonly auth: Layer.Layer<McpAuthProvider, never, IdentityProvider>;53 readonly auth: Layer.Layer<McpAuthProvider, never, IdentityProvider>;
59 /** The in-process session store seam (dispatch + lifetime). */54 /** The in-process session store seam (dispatch + lifetime). */
60 readonly sessions: Layer.Layer<McpSessionStore>;55 readonly sessions: Layer.Layer<McpSessionStore>;
61 /** Stateless MCP server construction for modern requests. */
62 readonly modern: Layer.Layer<McpModernServerBuilder>;
63 /** Route 500 defects through the host's console `ErrorCapture`. */56 /** Route 500 defects through the host's console `ErrorCapture`. */
64 readonly reporter: Layer.Layer<McpErrorReporter>;57 readonly reporter: Layer.Layer<McpErrorReporter>;
65 /**58 /**
@@ -133,14 +126,13 @@ const makeApprovalHandler = · 67 unmodified lines
133 * Build the self-host MCP serving seams over the long-lived DB handle. The auth126 * Build the self-host MCP serving seams over the long-lived DB handle. The auth
134 * seam is `selfHostMcpAuth` (Better Auth mcp() OAuth), with the Better Auth127 * seam is `selfHostMcpAuth` (Better Auth mcp() OAuth), with the Better Auth
135 * instance provided; it still requires `IdentityProvider` from the resolved128 * instance provided; it still requires `IdentityProvider` from the resolved
136 * identity seam. Returns the four seam Layers plus the `close()` lifetime hook129 * identity seam. Returns the three seam Layers plus the `close()` lifetime hook
137 * the app wires into shutdown.130 * the app wires into shutdown.
138 */131 */
139export const makeSelfHostMcpSeams = (132export const makeSelfHostMcpSeams = (
140 dbHandle: SelfHostDbHandle,133 dbHandle: SelfHostDbHandle,
141 betterAuth: BetterAuthHandle,134 betterAuth: BetterAuthHandle,
142 webBaseUrl?: string,135 webBaseUrl?: string,
143 modernEnabled = true,
144): SelfHostMcpSeams => {136): SelfHostMcpSeams => {
145 const sessionStore = makeSelfHostMcpSessionStore(dbHandle, webBaseUrl);137 const sessionStore = makeSelfHostMcpSessionStore(dbHandle, webBaseUrl);
146 const auth: Layer.Layer<McpAuthProvider, never, IdentityProvider> = selfHostMcpAuth.pipe(138 const auth: Layer.Layer<McpAuthProvider, never, IdentityProvider> = selfHostMcpAuth.pipe(
@@ -149,7 +141,6 @@ export const makeSelfHostMcpSeams = ( · 2 unmodified lines
149 return {141 return {
150 auth,142 auth,
151 sessions: selfHostMcpSessions(sessionStore),143 sessions: selfHostMcpSessions(sessionStore),
152 modern: makeSelfHostMcpModernServerBuilder(dbHandle, modernEnabled),
153 reporter: selfHostMcpReporter,144 reporter: selfHostMcpReporter,
154 approvalHandler: makeApprovalHandler(sessionStore, betterAuth),145 approvalHandler: makeApprovalHandler(sessionStore, betterAuth),
155 close: sessionStore.close,146 close: sessionStore.close,
apps/host-selfhost/src/mcp/mcp.test.ts+0−35
@@ -3,7 +3,6 @@ import { tmpdir } from "node:os"; · 2 unmodified lines
3import { join } from "node:path";3import { join } from "node:path";
4 4
5import { afterAll, expect, test } from "@effect/vitest";5import { afterAll, expect, test } from "@effect/vitest";
6import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
7 6
8import { mintInviteCode } from "../testing/mint-invite";7import { mintInviteCode } from "../testing/mint-invite";
9 8
@@ -88,40 +87,6 @@ test("an authenticated MCP client initializes, lists tools, and executes code", · 78 unmodified lines
88 expect(JSON.stringify(await call.json())).toContain("42");87 expect(JSON.stringify(await call.json())).toContain("42");
89});88});
90 89
91test("an authenticated modern MCP client discovers, lists tools, and executes code", async () => {
92 const token = await signUp("modern@mcp.test");
93 const seenMethods: string[] = [];
94 const transport = new StreamableHTTPClientTransport(new URL(`${BASE}/mcp`), {
95 fetch: async (input, init) => {
96 const request =
97 input instanceof Request ? new Request(input, init) : new Request(input.toString(), init);
98 const body = (await request.clone().json()) as { readonly method?: string };
99 if (body.method) seenMethods.push(body.method);
100 const headers = new Headers(request.headers);
101 headers.set("authorization", `Bearer ${token}`);
102 return handler(new Request(request, { headers }));
103 },
104 });
105 const client = new Client(
106 { name: "selfhost-modern-test", version: "1.0.0" },
107 { capabilities: {}, versionNegotiation: { mode: { pin: "2026-07-28" } } },
108 );
109
110 await client.connect(transport);
111 // oxlint-disable-next-line executor/no-try-catch-or-throw -- test boundary: always close the authenticated modern client
112 try {
113 expect(seenMethods).toContain("server/discover");
114 expect((await client.listTools()).tools.map(({ name }) => name)).toContain("execute");
115 const result = await client.callTool({
116 name: "execute",
117 arguments: { code: "export default 6 * 7" },
118 });
119 expect(JSON.stringify(result)).toContain("42");
120 } finally {
121 await client.close();
122 }
123});
124
125test("an MCP session cannot be reused by another user, and unauth is rejected", async () => {90test("an MCP session cannot be reused by another user, and unauth is rejected", async () => {
126 const alice = await signUp("alice2@mcp.test");91 const alice = await signUp("alice2@mcp.test");
127 const bob = await signUp("bob2@mcp.test");92 const bob = await signUp("bob2@mcp.test");
apps/host-selfhost/src/mcp/session-store.ts+3−21
@@ -1,7 +1,7 @@
1import { Layer } from "effect";1import { Layer } from "effect";
2 2
3import { makeConsoleMcpErrorReporter, makeMcpBuildServer } from "@executor-js/api/server";3import { makeConsoleMcpErrorReporter, makeMcpBuildServer } from "@executor-js/api/server";
4import { McpModernServerBuilder, type McpErrorReporter } from "@executor-js/host-mcp";4import type { McpErrorReporter } from "@executor-js/host-mcp";
5import {5import {
6 inMemoryMcpSessionsLayer,6 inMemoryMcpSessionsLayer,
7 makeInMemoryMcpSessionStore,7 makeInMemoryMcpSessionStore,
@@ -19,8 +19,8 @@ import { SelfHostExecutionStackLayer } from "../execution"; · 11 unmodified lines
19// ALL shared (`@executor-js/host-mcp/in-memory-session-store` + `makeMcpBuildServer`19// ALL shared (`@executor-js/host-mcp/in-memory-session-store` + `makeMcpBuildServer`
20// / `makeConsoleMcpErrorReporter` in `@executor-js/api/server`). Self-host20// / `makeConsoleMcpErrorReporter` in `@executor-js/api/server`). Self-host
21// supplies only its fully-provided execution-stack layer (QuickJS over the21// supplies only its fully-provided execution-stack layer (QuickJS over the
22// long-lived `SelfHostDb`) and its `ErrorCapture`; the builder creates the22// long-lived `SelfHostDb`) and its `ErrorCapture`. The Cloudflare host wires the
23// connection-lifetime assembly used by the shared store.23// identical seam with its own stack layer.
24// ---------------------------------------------------------------------------24// ---------------------------------------------------------------------------
25 25
26import { loadMcpAppsShellHtml } from "@executor-js/mcp-apps-shell";26import { loadMcpAppsShellHtml } from "@executor-js/mcp-apps-shell";
@@ -51,24 +51,6 @@ export const makeSelfHostMcpSessionStore = ( · 24 unmodified lines
51 { webBaseUrl },51 { webBaseUrl },
52 );52 );
53 53
54/** Build the stateless MCP server seam over the same self-host stack/config. */
55export const makeSelfHostMcpModernServerBuilder = (
56 db: SelfHostDbHandle,
57 enabled = true,
58): Layer.Layer<McpModernServerBuilder> =>
59 Layer.succeed(McpModernServerBuilder)({
60 enabled,
61 build: makeMcpBuildServer(
62 SelfHostExecutionStackLayer.pipe(Layer.provide(Layer.succeed(SelfHostDb)(db))),
63 {
64 loadAppShellHtml: loadMcpAppsShellHtml,
65 smokeRenderArtifact,
66 onArtifactUsage: (action) =>
67 selfHostAnalytics.record(`artifact_${action}`, { via: "agent" }),
68 },
69 ),
70 });
71
72/** The `McpSessionStore` envelope seam over a freshly built in-process store. */54/** The `McpSessionStore` envelope seam over a freshly built in-process store. */
73export const selfHostMcpSessions = inMemoryMcpSessionsLayer;55export const selfHostMcpSessions = inMemoryMcpSessionsLayer;
74 56
apps/host-selfhost/src/testing/test-app.ts+0−2
@@ -28,7 +28,6 @@ import { · 27 unmodified lines
28import executorConfig from "../../executor.config";28import executorConfig from "../../executor.config";
29import { loadConfig, SELF_HOST_NAMESPACE, SELF_HOST_SCHEMA_VERSION } from "../config";29import { loadConfig, SELF_HOST_NAMESPACE, SELF_HOST_SCHEMA_VERSION } from "../config";
30import {30import {
31 makeSelfHostMcpModernServerBuilder,
32 makeSelfHostMcpSessionStore,31 makeSelfHostMcpSessionStore,
33 selfHostMcpReporter,32 selfHostMcpReporter,
34 selfHostMcpSessions,33 selfHostMcpSessions,
@@ -237,7 +236,6 @@ export const makeSelfHostTestApp = async ( · 202 unmodified lines
237 mcp: {236 mcp: {
238 auth: stubMcpAuth,237 auth: stubMcpAuth,
239 sessions: selfHostMcpSessions(sessionStore),238 sessions: selfHostMcpSessions(sessionStore),
240 modern: makeSelfHostMcpModernServerBuilder(dbHandle),
241 reporter: selfHostMcpReporter,239 reporter: selfHostMcpReporter,
242 },240 },
243 plugins: { provider: pluginsProvider, config: SelfHostHostConfig },241 plugins: { provider: pluginsProvider, config: SelfHostHostConfig },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t