anchor-debug
Provides structured access to Solana Anchor error data, enabling AI coding agents to parse logs, debug transactions, and look up error codes.
README
anchor-debug
CLI tool that makes Anchor program failures understandable.
When your Anchor test fails with custom program error: 0x1770, anchor-debug tells you exactly what broke, where, and why.
Before vs After
Without anchor-debug:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x7d2
With anchor-debug:
✗ Transaction failed
Error: ConstraintHasOne
Code: 0x7d2 (2002)
Msg: A has_one constraint was violated — account field does not match expected value
Program: my_program (9uvbWC...)
CPI call stack:
└─ ✗ my_program (9uvbWC...) ← failed here
Error: A has_one constraint was violated — account field does not match expected value
└─ ✓ TokenkegQfeZy... (Token Program)
└─ ✗ my_program::validate_authority ← failed here
Installation
npm install -g anchor-debug
# or use directly with npx
npx anchor-debug --help
Usage
Pipe anchor test output
anchor test 2>&1 | npx anchor-debug
anchor-debug reads stdin, finds the failure, and prints a human-readable error. If the test succeeds, output is passed through unchanged.
Debug a transaction by signature
npx anchor-debug tx <SIGNATURE> --cluster devnet
npx anchor-debug tx <SIGNATURE> --cluster mainnet-beta
npx anchor-debug tx <SIGNATURE> --cluster http://localhost:8899
Fetches the transaction from the RPC, extracts its logs, and formats the error.
Run tests with automatic error formatting
npx anchor-debug test
npx anchor-debug test --skip-build
Runs anchor test for you and prints the parsed error on failure.
Options
| Flag | Description |
|---|---|
--raw |
Also show raw log lines |
-v, --verbose |
Show all program log messages |
-c, --cluster <cluster> |
Cluster or RPC URL (tx command) |
--skip-build |
Pass --skip-build to anchor test |
How it works
- Log parser — reads Solana program logs line-by-line using a regex state machine
- Error database — 60+ Anchor framework errors mapped by hex code (both new 0x7d0+ and legacy 0x1770+ ranges)
- CPI tracer — rebuilds the full
Program invoke [N]call tree and marks the innermost failing invocation - IDL resolver — reads
Anchor.tomlandtarget/idl/*.jsonto show program names instead of pubkeys
Supported error ranges
| Range | Source |
|---|---|
0x64–0x67 (100–103) |
Instruction errors |
0x3e8–0x3ea (1000–1002) |
IDL errors |
0x7d1–0x7f8 (2001–2040) |
Constraint errors (Anchor ≥ 0.24) |
0xbb8–0xbc1 (3000–3017) |
Account errors |
0xfa0–0xfa2 (4000–4002) |
State errors |
0x1770–0x1783 (6000–6019) |
Legacy constraint errors (Anchor < 0.24) |
MCP Server (for AI agents)
anchor-debug works as an MCP server, giving AI coding agents (Claude Code, Cursor, etc.) structured access to Solana error data.
Add to .mcp.json in your project:
{
"mcpServers": {
"anchor-debug": {
"command": "npx",
"args": ["anchor-debug", "mcp"]
}
}
}
Or globally in ~/.claude/mcp.json.
Available tools:
| Tool | What it does |
|---|---|
parse_logs |
Takes raw log lines → structured error + CPI stack |
debug_transaction |
Takes signature + cluster → fetches and parses |
lookup_error |
Takes hex code → error name + message |
Example agent response after calling parse_logs:
{
"failed": true,
"error": {
"name": "ConstraintHasOne",
"code": 2002,
"hex": "0x7d2",
"message": "A has_one constraint was violated — account field does not match expected value",
"category": "constraint"
},
"failedProgram": "my_program",
"failedNode": {
"program": "my_program",
"depth": 2,
"errorMessage": "A has_one constraint was violated"
},
"cpiStack": [...]
}
Instead of reasoning about 0x1770, the agent immediately knows what failed and can fix it in one shot.
Programmatic API
import { parseLogsFromString, formatResult } from "anchor-debug";
const logs = [
"Program MyProg invoke [1]",
"Program MyProg failed: custom program error: 0x7d2",
];
const parsed = parseLogsFromString(logs.join("\n"));
console.log(formatResult(parsed));
Milestones
- [x] M1 — npm package, log parser, Anchor error database
- [x] M2 — CPI call stack visualizer, IDL integration
- [ ] M3 — VS Code extension (inline hints)
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。