OpenCode is a terminal-based AI coding agent that integrates with multiple LLM providers and supports MCP servers via a TOML configuration file. It offers a clean TUI (text user interface) optimized for keyboard-driven workflows, making it a strong choice for developers who live in the terminal and want Sentry error investigation without leaving the command line.
This topic covers the full setup of Sentry MCP in OpenCode, practical query patterns, a complete real-world investigation example, and the known limitations of the integration.
Installing and Connecting Sentry MCP to OpenCode
Prerequisites
- OpenCode installed — check the latest install method from the official repo, typically:
curl -fsSL https://opencode.ai/install | bash
npm install -g opencode-ai
- A Sentry auth token (see Module 3, Topic 1 for how to generate one)
OpenCode MCP configuration
OpenCode reads its configuration from ~/.config/opencode/config.toml. Add Sentry MCP using HTTP transport to connect to the official Sentry MCP server:
[mcp.sentry]
type = "http"
url = "https://mcp.sentry.dev/mcp"
[mcp.sentry.headers]
Authorization = "Bearer YOUR_SENTRY_AUTH_TOKEN"
Replace YOUR_SENTRY_AUTH_TOKEN with your actual Sentry auth token. To avoid committing secrets, use an environment variable reference:
[mcp.sentry]
type = "http"
url = "https://mcp.sentry.dev/mcp"
[mcp.sentry.headers]
Authorization = "Bearer ${SENTRY_AUTH_TOKEN}"
Then set SENTRY_AUTH_TOKEN in your shell profile (~/.zshrc or ~/.bashrc):
export SENTRY_AUTH_TOKEN="sntrys_eyJ..."
Project-level config
OpenCode also supports a project-level .opencode/config.toml in your project root. This is useful for team setups where different projects use different Sentry organizations:
[mcp.sentry]
type = "http"
url = "https://mcp.sentry.dev/mcp"
[mcp.sentry.headers]
Authorization = "Bearer ${SENTRY_AUTH_TOKEN}"
Commit this file to version control — the auth token is injected via environment variable, so no secrets are stored in the file.
Verify the connection
Start OpenCode and run a quick test:
List the top 5 unresolved Sentry issues in my organization
Tips
- Restart OpenCode after editingconfig.toml— changes are not hot-reloaded.
- If you work across multiple Sentry orgs, use project-level configs to avoid confusion between org slugs.
Querying Sentry Issues and Stack Traces from OpenCode
Once Sentry MCP is connected, OpenCode can query Sentry data using natural language prompts. The MCP server translates your intent into Sentry API calls automatically.
Listing unresolved issues:
Use Sentry to list the 10 most frequent unresolved issues in the "backend-api" project. Show issue ID, title, event count, and last seen date.
Getting a specific issue with full event detail:
Get Sentry issue BACKEND-1822. Show me the full exception message, stack trace (in-app frames only), and all breadcrumbs in order.
Searching by query string:
Search Sentry for unresolved issues in project "web-frontend" matching query: is:unresolved level:error !has:assignee. Return the top 5 by event count.
Fetching a specific event by ID:
Get Sentry event with ID "b3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8". Show me the request headers, user context, and all exception frames.
Release-based regression queries:
List all Sentry issues in project "api-gateway" where firstSeen is after 2026-04-28. This was when we deployed v4.2.0. I want to know what broke.
Working with trace data:
Get the Sentry trace "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6". Show me the span tree and identify which span contains an error.
OpenCode renders long outputs in a scrollable pane within the TUI, which is particularly useful for stack traces with many frames. Use arrow keys and Page Up/Down to navigate the output.
Tips
- In OpenCode's TUI, use/to enter command mode and type prompts directly. For long investigation sessions, pressCtrl+Lto clear the screen without losing context.
- When dealing with long stack traces, ask OpenCode to "show only in-app stack frames, excluding library and framework frames." This dramatically reduces noise.
- OpenCode supports piping context from shell commands. Runopencode "$(cat sentry-event.json) — analyze this event and suggest a fix"to pass a pre-fetched event payload directly.
- Chain queries in a single session: list issues first, then say "investigate the #2 issue from the previous list." OpenCode retains the session context.
Practical Example: Investigating a Production Error in OpenCode
This walkthrough shows a complete error investigation session from alert to fix proposal, using only OpenCode and Sentry MCP.
Scenario: Your alerting system fires for issue API-3091 — a NullPointerException in the user authentication service that's affecting 3% of login requests.
Step 1: Get context on the issue.
Get Sentry issue API-3091. Summarize: what type of error is it, what function threw it, how many users are affected, and when did it first appear?
Expected output from the AI:
- Error type: NullPointerException in UserAuthService.validateToken()
- First seen: 2026-05-07 at 14:23 UTC
- Last seen: 2026-05-08 at 09:01 UTC
- Affected users: 847 unique users
Step 2: Deep-dive into the stack trace and breadcrumbs.
Now get the latest event for issue API-3091. Show me:
1. The full in-app stack trace with file names and line numbers
2. The breadcrumbs in chronological order
3. The request URL, method, and any relevant headers
Step 3: Cross-reference with the codebase.
The stack trace points to UserAuthService.java line 142. I have the source file here at src/main/java/com/acme/auth/UserAuthService.java. Read the file and identify what could cause a NullPointerException at line 142.
OpenCode reads the local file alongside the Sentry data:
// UserAuthService.java:140-145
public boolean validateToken(String token) {
DecodedJWT jwt = jwtVerifier.verify(token); // line 142: NPE here
String userId = jwt.getClaim("user_id").asString();
return userRepository.exists(userId);
}
Step 4: Request root cause and fix.
Based on the Sentry stack trace and the source code, what is the root cause of this NullPointerException? Propose a minimal fix and explain why it prevents the error.
AI response identifies: jwtVerifier.verify() returns null when the token is malformed rather than throwing. The fix adds a null check:
public boolean validateToken(String token) {
DecodedJWT jwt = jwtVerifier.verify(token);
if (jwt == null) {
throw new InvalidTokenException("Token verification returned null for token: " + token);
}
String userId = jwt.getClaim("user_id").asString();
return userRepository.exists(userId);
}
Step 5: Verify fix scope and write a regression test.
Write a JUnit 5 test that reproduces the NullPointerException scenario. Use a mock jwtVerifier that returns null to simulate the condition from the Sentry event.
Step 6: Check release history.
Check Sentry releases for project "auth-service". When was API-3091 first seen, and does it align with a specific release version?
Tips
- Save your investigation session as a Markdown file using OpenCode's export feature — it becomes your incident postmortem draft with the full AI reasoning chain preserved.
- If OpenCode loses MCP tool context mid-session, type "reconnect MCP servers" or restart withopencode --mcp-restartto reload server connections without losing session history.
- Ask the AI to write a Sentry search query you can paste into the Sentry dashboard for ongoing monitoring: "Write a Sentry search query to track all future occurrences of this specific error pattern."
- After fixing, ask: "What Sentry alert rule should I create to get paged if this error recurs?" The AI can suggest the exact alert configuration including threshold and notification channel.
Known Limitations for Sentry MCP in OpenCode
Understanding the current limitations helps you avoid wasted time and plan around gaps in capability.
No native Sentry event attachment support. Sentry can store file attachments on events (screenshots, log files, core dumps). The current @sentry/mcp-server does not expose an attachment-fetching tool. You must download attachments manually from the Sentry dashboard.
No write operations on issues. The MCP server is currently read-only. You cannot assign issues, change status to "resolved", or add comments via MCP. These actions require the Sentry web UI or direct API calls.
curl -X PUT \
-H "Authorization: Bearer $SENTRY_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"status": "resolved"}' \
"https://sentry.io/api/0/issues/4521/"
Rate limiting. Sentry's API enforces rate limits (typically 100 requests/minute for free/team plans). Intensive investigation sessions that fire many MCP tool calls in rapid succession may hit limits. If you see 429 Too Many Requests errors, add explicit pauses between queries or upgrade your Sentry plan.
Large event payloads and context window limits. Events with large breadcrumb arrays, many stack frames, or extra data attached can return very large JSON payloads. OpenCode's context window has a fixed size. If you ask for many events simultaneously, earlier context may be truncated. Work one issue at a time.
No streaming updates. Sentry MCP is a pull-based integration — it fetches a snapshot at query time. It does not provide real-time updates or streaming. If you want live monitoring, use Sentry's native alerting to trigger investigations rather than polling via MCP.
OpenCode version compatibility. Sentry MCP requires MCP protocol version 0.1 or later. Older versions of OpenCode (pre-0.3.x) may not support all MCP tool schemas. Run opencode --version and update if you encounter tool schema errors.
npm update -g opencode-ai
Tips
- For write operations (resolve, assign, comment), pair OpenCode with a shell alias that calls the Sentry API directly:alias sentry-resolve='curl -X PUT -H "Authorization: Bearer $SENTRY_AUTH_TOKEN" ...'
- To work around context window limits with large events, ask the AI to fetch and summarize one section at a time: first the stack trace, then the breadcrumbs, then the request context.
- Monitor your Sentry API rate limit usage from the response headers:X-Sentry-Rate-Limit-Remaining. Ask the AI to report this value after each query during intensive sessions.
- If OpenCode's TUI becomes unresponsive due to a large MCP response, pressCtrl+Cto cancel the current request and then narrow your query to a smaller time range or fewer fields.