DEV Community

晓道
晓道

Posted on

Introduction to Solana Instruction Parsing MCP

Yesterday, I released the Solana instruction parsing MCP I built recently on the internet. I noticed that many people liked and followed me, but not many actually used it. I feel this is still worth trying, and combined with AI, it can be very useful.

The address is solmcp

Introduction to Solana Instruction Parsing MCP

The examples inside use MCP Inspector for calling. Why use this? AI can call MCP relying on AI's capabilities, the capabilities of MCP functions, looking at input and output.
MCP has the ability to parse instructions in formats like anchor, shank, codama. The parsing data comes from over 1k IDL datasets I collected.

The parsed tx inside comes from
4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a

Main functions: 4 functions:

  get_solana_transaction
  analyze_solana_instruction
  analyze_instruction_data
  get_transaction_with_inner_instructions
Enter fullscreen mode Exit fullscreen mode

Feature Showcase

analyze_solana_instruction (analyze based on instruction index in tx)

Defined as:

  server.tool(
    "analyze_solana_instruction",
    "Deep-dive analysis of a specific instruction within a Solana transaction. Parses the instruction data, identifies the program and function called, extracts parameters, and provides security risk assessment.",
    {
      signature: z.string().describe("Transaction signature (base58-encoded string, 88 characters)"),
      instruction_index: z.number().describe("Zero-based index of the instruction within the transaction (0 for first instruction)"),
      rpc_endpoint: z.string().optional().describe("Solana RPC endpoint URL (defaults to mainnet-beta if not specified)"),
    },
Enter fullscreen mode Exit fullscreen mode

Input:

signature: 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
instruction_index: 6
Enter fullscreen mode Exit fullscreen mode

We will get:


🔬 **Instruction Detailed Analysis**

**Instruction #6:**
- Program: Jupiter V6
- Program ID: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
- accountsInvolved: 38
- instructionName: route

**Instruction Parameters:**
- routePlan: [{"swap":{"__kind":"SolFiV2","isQuoteToBase":false},"percent":100,"inputIndex":0,"outputIndex":1},{"swap":{"__kind":"SolFiV2","isQuoteToBase":true},"percent":100,"inputIndex":1,"outputIndex":2}]
- inAmount: 249434750
- quotedOutAmount: 50066910
- slippageBps: 50
- platformFeeBps: 0
Enter fullscreen mode Exit fullscreen mode

analyze_instruction_data (analyze based on program id and instruction data)

Defined as:

  server.tool(
    "analyze_instruction_data",
    "Parse raw Solana instruction data to extract function names and parameters. Supports IDL-based parsing for known programs, with automatic fallback to generic instruction parsing for unknown programs.",
    {
      program_id: z.string().describe("The program ID (public key) that this instruction calls"),
      instruction_data: z.string().describe("Raw instruction data as hex string (without 0x prefix) or base64 string"),
      accounts: z.array(z.string()).optional().describe("Array of account public keys involved in this instruction (for context)"),
      data_format: z
        .enum(["hex"])
        .optional()
        .default("hex")
        .describe("Format of the instruction_data parameter ('hex' or 'base64')"),
      idl_file: z
        .string()
        .optional()
        .describe("Name of IDL file to use for parsing (searches in stored IDL collection)"),
    },
Enter fullscreen mode Exit fullscreen mode

Input:

program_id: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
instruction_data: e517cb977ae3ad2a020000005f006400015f016401027e12de0e00000000def5fb0200000000320000
Enter fullscreen mode Exit fullscreen mode

We will get:

🔍 **Instruction Data Analysis Report**

**Program Information:**
- Program ID: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
- Program Name: Jupiter V6

**Instruction Information:**
- Instruction Name: route
- Description: IDL parsing: route

**Instruction Parameters:**
- routePlan: [{"swap":{"__kind":"SolFiV2","isQuoteToBase":false},"percent":100,"inputIndex":0,"outputIndex":1},{"swap":{"__kind":"SolFiV2","isQuoteToBase":true},"percent":100,"inputIndex":1,"outputIndex":2}]
- inAmount: 249434750
- quotedOutAmount: 50066910
- slippageBps: 50
- platformFeeBps: 0

**Parsing Status:**
🔄 Using built-in parsing

Enter fullscreen mode Exit fullscreen mode

get_transaction_with_inner_instructions (Analyze internal instructions based on tx and program ID)

Defined as:

  server.tool(
    "get_transaction_with_inner_instructions",
    "Retrieve a Solana transaction and recursively parse all inner instructions (CPIs). Returns a hierarchical view of instruction execution with optional filtering by specific program IDs.",
    {
      signature: z.string().describe("Transaction signature (base58-encoded string, 88 characters)"),
      filter_program_ids: z
        .array(z.string())
        .optional()
        .describe("Array of program IDs to filter results - only instructions calling these programs will be included"),
      rpc_endpoint: z
        .string()
        .optional()
        .describe("Solana RPC endpoint URL (defaults to mainnet-beta if not specified)"),
    },
Enter fullscreen mode Exit fullscreen mode

Input:

signature: 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
filter_program_ids: [JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4]
Enter fullscreen mode Exit fullscreen mode

We will get:


🔍 **Transaction Instruction Parameter Analysis**
**Program filter:** JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4,

**Basic Information:**
- Signature: 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
- Status: ✅ Success
- Block: 369808306
- Fee: 0.00005693 SOL

**Instruction Parameter Details:**
**Instruction 1:**
- Program: Jupiter V6
- Program ID: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
- Instruction type: route
- Accounts involved: 38

**Parameters:**
- routePlan: [{"swap":{"__kind":"SolFiV2","isQuoteToBase":false},"percent":100,"inputIndex":0,"outputIndex":1},{"swap":{"__kind":"SolFiV2","isQuoteToBase":true},"percent":100,"inputIndex":1,"outputIndex":2}]
- inAmount: 249434750
- quotedOutAmount: 50066910
- slippageBps: 50
- platformFeeBps: 0

**Instruction 2:**
- Program: Jupiter V6
- Program ID: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
- Instruction type: swapEvent
- Accounts involved: 0

**Parameters:**
- amm: SV2EYYJyRz2YhfXwXnhNAevDEui5Q6yrfyo13WtupPF
- inputMint: So11111111111111111111111111111111111111112
- inputAmount: 249434750
- outputMint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
- outputAmount: 50079655

**Instruction 3:**
- Program: Jupiter V6
- Program ID: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
- Instruction type: swapEvent
- Accounts involved: 0

**Parameters:**
- amm: SV2EYYJyRz2YhfXwXnhNAevDEui5Q6yrfyo13WtupPF
- inputMint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
- inputAmount: 50079655
- outputMint: Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
- outputAmount: 50050803

Enter fullscreen mode Exit fullscreen mode

Top comments (0)