Add example showing how to setup an MCP server for a workspace - #28
Add example showing how to setup an MCP server for a workspace#28scuffi wants to merge 1 commit into
Conversation
commit: |
6b8cd20 to
be031a6
Compare
be031a6 to
c6048e3
Compare
c6048e3 to
f1cf132
Compare
c6048e3 to
509bf0d
Compare
|
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? |
509bf0d to
b2e6e91
Compare
b2e6e91 to
5cb656e
Compare
5cb656e to
652d3bd
Compare
aron-cf
left a comment
There was a problem hiding this comment.
Looking good, left some early comments.
| client = undefined; | ||
| }); | ||
|
|
||
| describe("Computer Codemode MCP", () => { |
There was a problem hiding this comment.
nit: We call it Code Mode, so camel case it'd be CodeMode, though lower case I still prefer codemode over codeMode...
| describe("Computer Codemode MCP", () => { | |
| describe("Computer Code Mode MCP", () => { |
| const TOOL_SETTLEMENT_TIMEOUT_MS = EXEC_TIMEOUT_MS + 1_000; | ||
|
|
||
| /** Build the native Computer tool server that Codemode wraps. */ | ||
| export function createComputerMcpServer(workspace: WorkspaceClient) { |
There was a problem hiding this comment.
nit: MCP over Mcp
| export function createComputerMcpServer(workspace: WorkspaceClient) { | |
| export function createComputerMCPServer(workspace: WorkspaceClient) { |
| exec(command, options) { | ||
| return workspace.runtime.exec(command, { | ||
| ...options, | ||
| timeoutMs: EXEC_TIMEOUT_MS, |
There was a problem hiding this comment.
We should probably make this an option on createAITools, also I don't think it should override the user provided one... or at least it should use the provided one as a cap...
| shell: { | ||
| backends: { | ||
| "worker-shell": { | ||
| description: "A fast, isolated shell over the durable Computer workspace.", | ||
| }, | ||
| }, | ||
| defaultBackend: "worker-shell", | ||
| }, |
There was a problem hiding this comment.
I don't like this interface much. As this is the tool description for exec, we probably need something a lot more detailed here to get good results. Check out the tool prompts in the think example.
|
|
||
| export { WorkspaceServiceProxy }; | ||
|
|
||
| const CodemodeExampleBase = withWorkspace(class extends DurableObject<Env> {}, (self) => { |
There was a problem hiding this comment.
This is weird, do you know why it needs to extend DurableObject here? Is it to do with the generics? We should fix this if so.
|
Hey @agent-think can you deploy a version of this MCP server example, then can you: (1) do some light smoke testing of file based workflows. |
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, andexectools. Codemode'scodeMcpServer()discovers those tools, generates their JavaScript types, and exposes them to MCP clients as onecodetool.The main composition is intentionally small:
Code running in the Codemode sandbox can then use the native Computer tools together:
To try it locally, run:
Then connect a Streamable HTTP MCP client to
http://127.0.0.1:8787/mcp. The local harness is stateless and acceptsPOSTonly; it does not open a session-bound event stream.The integration test connects with a real MCP client, checks that only
codeis 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.