MCP Code Mode
Discover app actions, inspect their current inputs, and compose calls in JavaScript through a compact MCP surface.
Code Mode lets an agent discover actions as it needs them, then call the workspace's configured apps from JavaScript. Start here when an agent needs several apps. Use Tool Mode when you want a small, explicit list of tools instead.
For a person connecting Claude, ChatGPT, Codex or another MCP client, use the Weavz connector. It handles sign-in and workspace selection without a custom server setup.
The execution tools
| Tool | Purpose |
|---|---|
weavz_search | Find configured app aliases and actions. |
weavz_read_api | Inspect current typed declarations and required inputs. |
weavz_execute | Run JavaScript that calls weavz.<alias>.<action>(). |
A client that supports MCP app UI can also open the app-management surface. Client capabilities determine whether the visual UI appears; the execution tools remain available without it.
Configure your MCP Workspace endpoint
Keep API keys on your backend. This example explicitly creates shared workspace files. Use end-user persistence when each customer's files should remain separate.
const workspaceId = '550e8400-e29b-41d4-a716-446655440000'
await client.workspaces.addIntegration(workspaceId, {
integrationName: 'storage',
alias: 'files',
settings: { persistence: { scope: 'workspace' } },
})
const { server, mcpEndpoint } = await client.mcpWorkspaces.configureMcp(workspaceId, {
name: 'Support assistant',
mode: 'CODE',
endUserAccess: 'restricted',
})Connect an OAuth-capable MCP client to the returned mcpEndpoint. For a known end user’s programmatic agent, issue private access through your backend:
const access = await client.mcpWorkspaces.createAccessToken(workspaceId, {
endUserId: 'customer_123',
scopes: ['mcp:tools', 'mcp:code'],
expiresIn: 3600,
})
// Deliver access.accessToken privately to that user's intended client.Do not print bearer tokens, put them in public configuration or use them for customer REST requests. Customer REST APIs use wvz_ API keys.
Discover, inspect, execute
Ask the agent to find the configured files alias and inspect write_file. The code it runs can combine ordinary JavaScript with app actions:
const summary = { status: 'ready', items: ['Review draft', 'Check sources'] }
return await weavz.files.write_file({
path: 'reports/summary.json',
content: JSON.stringify(summary),
})You do not need separate integrations for JSON reshaping, dates or simple calculations. Use JavaScript between app calls. Add Sandbox when you need Python, shell, packages or a longer computation.
Aliases are executable names. An app configured as support_slack is called as weavz.support_slack, even if its display name changes. Inspect declarations again after changing enabled actions or saved inputs.
Review and resume
Without a matching approval rule, enabled actions run under the caller's existing permissions. A matching rule may return an approval request instead of executing an action. The agent should show that request and wait for the authorized reviewer.
For a backend-owned execution, use the returned approval ID to continue the stored run:
const resumed = await client.mcpServers.executeCode(server.id, {
approvalId,
waitForApprovalSeconds: 30,
})A pending response is not completion. Poll within your application's timeout and show the reviewer a link or inbox entry. A rejected or expired request must not be retried as a fresh action to bypass the decision. See Approval rules.
Recover from a failed call
- Missing or unknown input: inspect the current action declaration and correct the input. Do not guess field names from a different integration.
- App not connected: complete the returned connection flow for the intended end user.
- Alias not found: add the app to this workspace and confirm the configured alias.
- Quota or rate limit: read the error and retry timing; do not repeatedly start a mutating call.
- Human takeover: pause the agent's computer or browser work until the person explicitly returns control.
Batch related browser observations and actions when appropriate, but inspect the result before continuing with a different task. Responses include execution timings for diagnosing slow work.