MCP Integration
Model Context Protocol (MCP) turns agents into metaprogrammable systems. TestBase embraces both hosted HTTP/SSE servers and local stdio servers, so you can give agents access to filesystems, search, SaaS APIs, or proprietary tools.
Configure MCP servers at agent creation
Add MCP definitions to the agent config. Hosted servers run outside the container; local servers are npm packages launched with npx.
import { Agent } from 'computer-agents';
const worker = new Agent({
name: 'Worker with MCP',
agentType: 'worker',
workspace: './repo',
codexMcpServers: [
{
type: 'hosted',
name: 'notion',
url: process.env.NOTION_MCP_URL!,
bearerToken: process.env.NOTION_TOKEN
},
{
type: 'local',
name: 'filesystem',
command: 'npx',
args: ['@modelcontextprotocol/server-filesystem', './repo'],
env: {
TZ: 'UTC'
}
}
]
});- Hosted servers only require a URL and optional auth headers or bearer tokens. They speak MCP over HTTP/SSE.
- Local servers run inside the agent process (or container) using stdio. When deployed to TestBase Cloud, the runtime installs the npm package specified in
argsbefore launching the server.
Managing MCP servers in TestBase Cloud
The Cloud SDK mirrors Cloud API endpoints for adding, removing, or listing servers at runtime.
import { TestbaseCloud } from '@testbase/cloud';
const cloud = new TestbaseCloud({ apiKey: process.env.TESTBASE_API_KEY });
const cloudAgent = await cloud.createCloudAgent({
name: 'Cloud Worker',
agentType: 'worker',
workspace: './repo'
});
// Add hosted Notion server
await cloud.addMcpServer(cloudAgent.containerId, {
type: 'hosted',
name: 'notion',
url: process.env.NOTION_MCP_URL!,
bearerToken: process.env.NOTION_TOKEN
});
// Add local Brave Search server (installs npm package)
await cloud.addMcpServer(cloudAgent.containerId, {
type: 'local',
name: 'brave-search',
package: '@modelcontextprotocol/server-brave-search',
command: 'npx',
args: ['@modelcontextprotocol/server-brave-search'],
env: { BRAVE_API_KEY: process.env.BRAVE_API_KEY }
});
// Review server list
const servers = await cloud.listMcpServers(cloudAgent.containerId);
console.log(servers.map((server) => server.name));
// Remove when no longer needed
await cloud.removeMcpServer(cloudAgent.containerId, 'brave-search');Behind the scenes the API encodes configurations in a container manifest and restarts the affected MCP server if required.
Runtime behaviour
- MCP tool availability is reflected in agent prompts so the model knows which tools it can call.
- If a hosted server becomes unreachable, the agent surfaces a tool error—catch it in your code and decide whether to retry or fail the task.
- Local servers inherit the container’s environment; ensure required env vars are provided in the
envmap. - You can mix multiple hosted and local servers. Order does not matter, but descriptive names help with tool invocation clarity.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Server fails to start in cloud | npm package missing or incompatible | Verify package, command, and Node version. Check container logs via cloud.getLogs. |
| Tool times out | startupTimeoutSec or toolTimeoutSec defaults too low | Increase timeouts in the MCP config. |
| Hosted server 401s | Token missing | Provide bearerToken or headers in the config and rotate keys. |
| Local filesystem path mismatch | Using local path instead of container path | Point to /workspace inside containers; use repo-relative paths locally. |
With MCP, a single agent can assemble data from SaaS APIs, search indexes, and private repositories before touching code—no redeployments required.
Last updated on