- Tracing plugin: Automatically trace OpenCode sessions and access Braintrust data through built-in tools.
- MCP server: Manually configure OpenCode to access Braintrust data through the MCP server.
Tracing plugin
The@braintrust/trace-opencode plugin provides automatic tracing and data access tools for OpenCode.
Setup
Install OpenCode
If you haven’t already, install OpenCode.
Install the plugin
Add the Braintrust plugin to your OpenCode configuration file:
Set your API key
The plugin reads your API key from the Then restart your terminal.
BRAINTRUST_API_KEY environment variable. Set this along with TRACE_TO_BRAINTRUST to enable tracing:Usage
Once the plugin is installed and configured, automatic tracing and data access tools are enabled when OpenCode starts.Automatic tracing
OpenCode sessions are automatically traced to your Braintrust project (default:opencode). Each session includes:
- Session spans: Capture workspace and hostname metadata
- Turn spans: Record each user-assistant exchange
- Tool spans: Log individual tool executions
https://www.braintrust.dev/app/projects/opencode/logs
Data access tools
The plugin provides OpenCode with built-in tools to access your Braintrust data:braintrust_query_logs: Execute SQL queries against Braintrust logsbraintrust_list_projects: View organization projectsbraintrust_log_data: Manually log evaluation databraintrust_get_experiments: Access recent experiments
- “Can you show me the last 10 logs from Braintrust?”
- “List my Braintrust projects”
- “Query logs where
scores.Factuality < 0.5” - “Show me my recent experiments”
Configuration
You can customize the plugin behavior by creating abraintrust.json file at .opencode/braintrust.json (project-level) or ~/.config/opencode/braintrust.json (global):
| Setting | Environment variable | Type | Default | Description |
|---|---|---|---|---|
trace_to_braintrust | TRACE_TO_BRAINTRUST | boolean | false | Enable or disable tracing |
project | BRAINTRUST_PROJECT | string | "opencode" | Project name for traces |
debug | BRAINTRUST_DEBUG | boolean | false | Enable debug logging |
api_key | BRAINTRUST_API_KEY | string | — | API key for authentication (required) |
api_url | BRAINTRUST_API_URL | string | "https://api.braintrust.dev" | API endpoint (for self-hosted instances) |
app_url | BRAINTRUST_APP_URL | string | "https://www.braintrust.dev" | App URL for dashboard access |
org_name | BRAINTRUST_ORG_NAME | string | — | Organization name (optional) |
MCP server
You can also manually configure OpenCode to connect to the Braintrust MCP server for data access.Setup
Install OpenCode
If you haven’t already, install OpenCode.
Add the Braintrust MCP server
Edit your OpenCode configuration file and add the Braintrust MCP server:Replace
YOUR_BRAINTRUST_API_KEY with your actual API key.Usage
Once configured, OpenCode can access your Braintrust data through the MCP server. See MCP documentation for the full list of available tools.Troubleshooting
BRAINTRUST_API_KEY is not set
BRAINTRUST_API_KEY is not set
- Verify the variable is set:
echo $BRAINTRUST_API_KEY(macOS/Linux) orecho %BRAINTRUST_API_KEY%(Windows). - OpenCode must be restarted after setting environment variables.
Traces not appearing
Traces not appearing
- Verify
TRACE_TO_BRAINTRUSTis set totrue. - Ensure your API key is correct.
- Enable debug mode:
export BRAINTRUST_DEBUG=trueand check the logs.
Plugin doesn't seem to work
Plugin doesn't seem to work
- Verify the plugin is listed in your OpenCode configuration file.
- Check the OpenCode config documentation for config file locations.
- Ensure you’re running a recent version of OpenCode that supports plugins.
MCP server not appearing
MCP server not appearing
- Verify the JSON syntax in your OpenCode configuration file.
- Ensure the URL is exactly
https://api.braintrust.dev/mcp(no trailing slash). - Restart OpenCode after configuration changes.
MCP authentication failures
MCP authentication failures
- Verify your API key is correct and has access to Braintrust.
- Check the authorization header format:
"Authorization": "Bearer YOUR_BRAINTRUST_API_KEY".
Next steps
- Run evaluations: Check out the evaluation guide to learn evaluation patterns.
- Browse the source: The braintrust-opencode-plugin repository contains the plugin source code.