Skip to content

Add example showing how to setup an MCP server for a workspace - #28

Open
scuffi wants to merge 1 commit into
mainfrom
workspace-codemode-adapter
Open

Add example showing how to setup an MCP server for a workspace#28
scuffi wants to merge 1 commit into
mainfrom
workspace-codemode-adapter

Conversation

@scuffi

@scuffi scuffi commented Jul 31, 2026

Copy link
Copy Markdown

Codemode already runs model-written JavaScript in an isolated Dynamic Worker, and Computer already provides bounded tools for working with a durable workspace. This example shows how to compose those pieces without adding another Computer backend or executor. All implementation code stays in examples/codemode.

The example creates an internal MCP server from Computer's read, ls, write, edit, and exec tools. Codemode's codeMcpServer() discovers those tools, generates their JavaScript types, and exposes them to MCP clients as one code tool.

MCP client
  → code
  → Codemode DynamicWorkerExecutor
  → Computer read / ls / write / edit / exec
  → durable Workspace

The main composition is intentionally small:

const computer = createComputerMcpServer(workspace);
const server = await codeMcpServer({
  server: computer,
  executor: new DynamicWorkerExecutor({
    loader: env.LOADER,
    globalOutbound: null,
  }),
});

Code running in the Codemode sandbox can then use the native Computer tools together:

async () => {
  await codemode.write({
    path: "/workspace/message.txt",
    content: "hello from codemode"
  });
  const file = await codemode.read({ path: "/workspace/message.txt" });
  const shell = await codemode.exec({ command: "pwd" });
  return { content: file.content, cwd: shell.stdout.trim() };
}

To try it locally, run:

npm install
npm run dev --workspace @example/computer-codemode

Then connect a Streamable HTTP MCP client to http://127.0.0.1:8787/mcp. The local harness is stateless and accepts POST only; it does not open a session-bound event stream.

The integration test connects with a real MCP client, checks that only code is public, exercises all five Computer tools through Codemode's Dynamic Worker, and confirms that files persist across calls. The example README documents the architecture, local setup, and trust boundary. A public deployment would still need tenant-derived Workspace identity, authentication, authorization, limits, and storage quotas.

@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@28

commit: 652d3bd

@aron-cf
aron-cf changed the base branch from workspace-runtime-execution to workspace-javascript-backend July 31, 2026 12:11
@scuffi
scuffi force-pushed the workspace-codemode-adapter branch 3 times, most recently from 6b8cd20 to be031a6 Compare July 31, 2026 12:35
Base automatically changed from workspace-javascript-backend to workspace-runtime-execution July 31, 2026 14:14
Base automatically changed from workspace-runtime-execution to main July 31, 2026 14:19
@scuffi
scuffi force-pushed the workspace-codemode-adapter branch from be031a6 to c6048e3 Compare July 31, 2026 14:38
@aron-cf aron-cf closed this Jul 31, 2026
@aron-cf
aron-cf force-pushed the workspace-codemode-adapter branch from c6048e3 to f1cf132 Compare July 31, 2026 14:38
@scuffi scuffi reopened this Jul 31, 2026
@scuffi
scuffi force-pushed the workspace-codemode-adapter branch from c6048e3 to 509bf0d Compare July 31, 2026 15:10
@aron-cf

aron-cf commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Trying to figure out if we need this on top of the existing backend. I'm not sure what it would be used for. What are your thoughts?

@scuffi
scuffi force-pushed the workspace-codemode-adapter branch from 509bf0d to b2e6e91 Compare August 3, 2026 10:35
@scuffi scuffi changed the title Add external Codemode runtime adapter example Add Computer tools as a Codemode MCP example Aug 3, 2026
@aron-cf aron-cf changed the title Add Computer tools as a Codemode MCP example Add example showing how to setup an MCP server for a workspace Aug 3, 2026
@scuffi
scuffi force-pushed the workspace-codemode-adapter branch from b2e6e91 to 5cb656e Compare August 3, 2026 15:20
@scuffi
scuffi force-pushed the workspace-codemode-adapter branch from 5cb656e to 652d3bd Compare August 3, 2026 15:53
@scuffi
scuffi marked this pull request as ready for review August 3, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants