library / AI and blockchain / SI0020
Transaction debugging MCP tools
You get a stdio MCP server with three read-only tools that let a model debug a Solana transaction on Carbium RPC: list an address's recent failures, read why one signature failed, and check where a signature stands.
Three questions a model asks
Debugging a transaction comes down to three questions. Where does this signature stand? If it failed, which instruction failed and with what error? And for an address that keeps failing, which signatures are worth opening first? Each question maps to one tool, and each tool makes one RPC call.
- recent_failures takes an address, reads its newest 100 signatures with getSignaturesForAddress and returns how many it checked, how many failed and up to five failed ones with slot and error. It also returns the newest signature, so a model has something to explain even when none of the 100 failed.
- explain_failure takes a signature, reads the transaction with getTransaction and returns the error, the fee, the compute units consumed, the failing instruction with its program, the program on the last failed: log line, the top-level programs the transaction called and the last eight log lines.
- signature_status takes a signature and returns what getSignatureStatuses knows: slot, commitment level reached and error, or the word unknown.
With an address in hand the model works in that order. With a signature a user pasted from a wallet error, it starts at the second tool.
The server file
One file for Node 24, with @solana/kit 8.6.0 as its only dependency. Set CARBIUM_KEY before starting; the file exits with a message when it is missing. The key goes in the x-api-key header, and CARBIUM_RPC_URL overrides the default endpoint, https://services.carbium.sh.
// SI0020 · Transaction debugging MCP tools// https://carbium.sh/library/si/transaction-debugging-mcp-tools// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Transaction debugging MCP server over stdio. Run: CARBIUM_KEY=... node main.ts Check: node main.ts --demo [address]import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, signature as toSignature } from "@solana/kit";import { createInterface } from "node:readline";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));type Tool = { description: string; arg: "address" | "signature"; run: (v: string) => Promise<unknown> };// Three read calls. The model picks a name; it never supplies a method.const TOOLS: Record<string, Tool> = { recent_failures: { description: "Failed transactions among the newest 100 signatures of an address (30 days at most).", arg: "address", run: async (v) => { const rows = await rpc.getSignaturesForAddress(address(v), { limit: 100 }).send(); const failed = rows.filter((r) => r.err !== null); return { checked: rows.length, failed: failed.length, newest: rows[0]?.signature, failures: failed.slice(0, 5).map(({ signature, slot, err }) => ({ signature, slot, err })) }; }, }, explain_failure: { description: "Why one transaction failed: error, failing instruction and program, program on the last failed log line, fee, compute units, last log lines.", arg: "signature", run: async (v) => { const tx: any = await rpc.getTransaction(toSignature(v), { encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send(); if (!tx) return "no transaction found: the signature is unknown or older than the ledger the node keeps"; const { meta, transaction } = tx; const ixs: any[] = transaction.message.instructions; const at = meta.err?.InstructionError?.[0]; // The Custom code belongs to the program on the last "Program <id> failed:" line, which may be an inner program. const failLine: string | undefined = (meta.logMessages ?? []).findLast((l: string) => /^Program \w+ failed:/.test(l)); return { slot: tx.slot, err: meta.err, fee: meta.fee, computeUnits: meta.computeUnitsConsumed, failingInstruction: at === undefined ? null : { index: at, program: ixs[at]?.programId }, failedProgram: failLine?.split(" ")[1] ?? null, programs: [...new Set(ixs.map((i) => i.programId))], logs: (meta.logMessages ?? []).slice(-8).map((l: string) => l.slice(0, 200)), }; }, }, signature_status: { description: "Slot, commitment level reached and error of one signature, or unknown.", arg: "signature", run: async (v) => (await rpc.getSignatureStatuses([toSignature(v)], { searchTransactionHistory: true }).send()).value[0] ?? "unknown", },};const text = (v: unknown) => JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));async function handle(msg: any): Promise<object | undefined> { if (msg.id === undefined) return undefined; // a notification gets no reply const ok = (result: object) => ({ jsonrpc: "2.0", id: msg.id, result }); const bad = (code: number, message: string) => ({ jsonrpc: "2.0", id: msg.id, error: { code, message } }); const { method, params } = msg; if (method === "initialize") return ok({ protocolVersion: params?.protocolVersion ?? "2025-06-18", capabilities: { tools: {} }, serverInfo: { name: "solana-tx-debug", version: "1.0.0" } }); if (method === "ping") return ok({}); if (method === "tools/list") return ok({ tools: Object.entries(TOOLS).map(([name, t]) => ({ name, description: t.description, inputSchema: { type: "object", properties: { [t.arg]: { type: "string" } }, required: [t.arg] } })) }); if (method !== "tools/call") return bad(-32601, `method not found: ${method}`); if (typeof params?.name !== "string" || !Object.hasOwn(TOOLS, params.name)) return bad(-32602, `unknown tool: ${params?.name}`); const tool = TOOLS[params.name] as Tool; try { return ok({ content: [{ type: "text", text: text(await tool.run(String(params.arguments?.[tool.arg] ?? ""))) }] }); } catch (e) { return ok({ content: [{ type: "text", text: (e as Error).message }], isError: true }); }}if (process.argv[2] === "--demo") { const target = process.argv[3] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"; const ask = async (id: number, name: string, arg: string) => { const r: any = await handle({ jsonrpc: "2.0", id, method: "tools/call", params: { name, arguments: { [TOOLS[name]?.arg ?? "address"]: arg } } }); const body: string = r.result ? r.result.content[0].text : r.error.message; console.log(`${name}: ${r.result?.isError ? "error " : ""}${body.slice(0, 700)}`); return body; }; let pick: string | undefined; try { const s = JSON.parse(await ask(1, "recent_failures", target)); pick = s.failures?.[0]?.signature ?? s.newest; } catch {} // the failure was already printed if (pick) { await ask(2, "explain_failure", pick); await ask(3, "signature_status", pick); } await ask(4, "send_transaction", pick ?? "");} else { for await (const line of createInterface({ input: process.stdin })) { if (!line.trim()) continue; try { const out = await handle(JSON.parse(line)); if (out) process.stdout.write(text(out) + "\n"); } catch {} // a malformed line is skipped }}
run: node main.ts --demo
node main.ts --demo runs the tools in the order above against a busy program, or against an address you pass second. It prints the failure summary, the explanation of the first failed signature (the newest signature when none of the 100 failed), that signature's status, and a call to a tool that is not in the table, which is refused with no request sent. Without the flag the file reads one JSON-RPC message per stdin line and writes one reply per line to stdout, the way an MCP client expects.
Reading the error
A failed transaction carries err. For a program failure it looks like { InstructionError: [2, { Custom: 6001 }] }. The first number is the index of the failing instruction among the transaction's top-level instructions. Custom is the code that whichever program failed returned, and that can be a program the instruction invoked, as with a Jupiter route that calls into a pool program. The index therefore gives the top-level program in failingInstruction, and failedProgram gives the program from the last Program <id> failed: log line, which is the one whose error list to read. Anchor programs number their own errors from 6000, so 6001 is the second error in that program's list, and the IDL of the failedProgram gives its name.
The last eight log lines name the program that failed and any message it wrote. The runtime writes a line such as Program <id> failed: custom program error: 0x1771, and programs add their own messages before it. 0x1771 is 6001 in hex. The tool takes failedProgram from the whole log before it keeps eight lines, and eight lines usually hold the message and the failing frame. The runtime stops recording once a transaction's log passes its byte limit and writes Log truncated, so a transaction that logs heavily loses its end, often including the failed: line. failedProgram is then null, and the model reads err instead of the tail. The file also cuts each line at 200 characters.
A failed transaction still pays its fee, so fee and computeUnits appear for failures too. The compute figure settles one common case: an instruction that fails with a compute budget error reads at or near the limit the transaction asked for.
Version and null answers
getTransaction takes maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and with the value absent or 0 the call answers -32015, uncharged, for one of them. A debugging tool opens odd transactions more often than most code, so it must not fail on a v1 transaction. Kit 8.6.0 types the value as 'legacy' | 0 | 1, so the 1 needs no cast. The version error entry walks through the error itself.
A null answer is the other case. getSignaturesForAddress on Carbium reads from its own address index, which keeps up to 30 days, and its pages reach below the validator's ledger floor. A signature in the list can therefore make getTransaction answer null. The tool then returns a sentence naming the likely causes, because a model that receives a bare null tends to tell the user the transaction does not exist.
Cost and limits
| Tool | RPC method | Cells per call | Req/s on Free, Dev, Business, Pro |
|---|---|---|---|
| recent_failures | getSignaturesForAddress | 50 | 0.24, 1.2, 100, 500 |
| explain_failure | getTransaction | 50 | 0.24, 1.2, 5, 25 |
A debugging session is a chain: one list, then one explanation per failed signature. The list call costs 50 cells whether it reads 5 rows or 100, so asking for 100 is the better use of it. A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. On Free and Dev that is about twenty calls of 50 cells at once, while Business and Pro getSignaturesForAddress get a larger bucket. After the bucket empties the rate sets the pace, and on Free getTransaction runs at 0.24 req/s, one call about every four seconds.
Limits are per account and an account's keys share one budget, so a job on another key can spend what the model needs. The server does not count calls. Put a cap per task in the client's loop.
Wiring it to a client
Register the file in your MCP client as a stdio server: command node, arguments the absolute path to main.ts, and CARBIUM_KEY in the server's env block. Config syntax differs between clients, and those three values stay the same. Check in order: run --demo and read the output, start the server from the client and look for the three tool names, then give the model an address that fails and ask why.
The protocol side of this file is the same hand-written subset as the Read-only MCP server, which explains the message flow in detail. Here tools/call looks the name up in TOOLS and refuses any other name before a request is sent.
Where it ends
- The tools read what landed. They do not simulate, replay or resend, so the model can say why a transaction failed and cannot say what would happen on a second try.
- Program logs are text written by whoever deployed the program. A model that reads them receives that text as tool output, so treat it as data: the file cuts lines at 200 characters and keeps eight, and your client prompt should say that log text carries no instructions.
- The error comes back as a code. Turning Custom: 6001 into a name needs the IDL of the program on the last failed: log line, the failedProgram field, which you can place in the model's context for the programs you care about.
- getSignaturesForAddress reaches back 30 days at most. An empty page past that marks the index's limit, and the address may hold older transactions. The tool reads one page of 100 and does not page.
- A tool that waits for a signature to land would use signatureSubscribe, which sends one confirmation and then ends. This file reads status once, with no WebSocket.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| explain_failure fails with -32015 on some signatures. | The call lacks maxSupportedTransactionVersion: 1. With it absent or 0, a v1 transaction answers -32015. Keep the 1 in the options object. |
| explain_failure returns the no-transaction sentence for a signature that recent_failures listed. | The address index reaches below the validator's ledger floor, so an older listed signature can read as null. Explain the newest signatures, or keep your own record of older ones. |
| recent_failures reports zero failures for an address you know fails. | It checks the newest 100 rows only, and a busy program fills 100 rows quickly. Pass a narrower address, such as one wallet or one account the failing transactions touch. |
| The model gets 429 after chaining several explanations. | Each getTransaction costs 50 cells and the account's keys share one budget. Cap explanations per task in the client's loop and check what other keys on the account spend. |
| The model quotes an error code as if it were a name. | The tool returns the number. Add the error list from the IDL of the failedProgram, the program on the last failed: log line, to the model's context, or have the model say the code and that program id and stop there. |
Questions
Does `explain_failure` work on a successful transaction?
Yes. err, failingInstruction and failedProgram come back null, and the fee, compute units, programs and log tail still arrive. It shows which top-level programs a transaction called.
Why does the file ask for the jsonParsed encoding?
Every instruction then carries programId as a plain string, which the file needs to name the failing program. The encoding also decodes instructions of well-known programs, and the file passes none of that on.
Which commitment do the tools read at?
Confirmed. Kit 8.6.0 fills it in when a call leaves commitment out, while the JSON-RPC server's own default is finalized. signature_status reports the level a signature has reached.
Can the model resend a failed transaction through this server?
No. The file has no keypair, no signing code and no send method, and its table holds three read calls. A tool that spends belongs in a separate process with a human approval step.
Can it find failures older than a month?
No. The address index keeps up to 30 days and the node's ledger keeps less, so older activity has to come from your own records.