DEV Community

晓道
晓道

Posted on

An Instruction Analysis MCP Usage Case

An Instruction Analysis MCP Usage Case

When developing MCP, we often use @modelcontextprotocol/inspector for direct calls. I just tried it directly with qwen, and it feels pretty good.

Transaction tx: 4kVvQfb4faVsGjwUoDa7Ez1RYSy6t4TdZ5uwVDt9Rdx8zsfbDqYHyx3YdRdah9YVCGd4GwgDiV7xPBeezRQwy1EU

The process is as follows:

Installing MCP in Qwen

qwen mcp add sol-mcp -t http https://solmcp.daog1.workers.dev/mcp?apiKey={your_api_key}
Enter fullscreen mode Exit fullscreen mode

Checking if MCP is effective

Execute in qwen

/mcp list
🟢 sol-mcp - Ready (4 tools)
   Tools:
   - analyze_instruction_data
   - analyze_solana_instruction
   - get_solana_transaction
   - get_transaction_with_inner_instructions
Enter fullscreen mode Exit fullscreen mode

If it includes the above, it's ready.

Triggering MCP call with prompt

I wrote it like this.

Help me get what happened to JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 in this Solana tx 4kVvQfb4faVsGjwUoDa7Ez1RYSy6t4TdZ5uwVDt9Rdx8zsfbDqYHyx3YdRdah9YVCGd4GwgDiV7xPBeezRQwy1EU
Enter fullscreen mode Exit fullscreen mode

Effect

I used qwen to summarize the process directly and posted it below, followed by what qwen generated.

Detailed Explanation of Solana MCP (Multi-Chain Processing) Call Process

What is Solana MCP

Solana MCP (Multi-Chain Processing) is a tool system for analyzing and processing complex transactions on the Solana blockchain, particularly suitable for analyzing multi-hop transactions, arbitrage transactions, and cross-protocol interactions. Through MCP tools, users can gain deep insights into the detailed operations within transactions, including embedded instructions, cross-protocol interactions, and token exchange paths.

MCP Call Process

1. Initial Transaction Identification

When a user needs to analyze a Solana transaction, they first need to obtain the transaction signature (Transaction Signature). The transaction signature is a unique identifier used to locate a specific transaction on the blockchain.

For example: 4kVvQfb4faVsGjwUoDa7Ez1RYSy6t4TdZ5uwVDt9Rdx8zsfbDqYHyx3YdRdah9YVCGd4GwgDiV7xPBeezRQwy1EU

2. Obtaining Basic Transaction Information

Call the get_solana_transaction function to obtain basic transaction information, including:

  • Transaction status (success/failure)
  • Block height
  • Fee
  • Transaction timestamp
  • Participating accounts

3. Deep Instruction Analysis

Use the get_transaction_with_inner_instructions function to deeply analyze each instruction in the transaction, including:

  • Top-level instructions
  • Inner instructions (also known as CPI - Cross-Program Invocations)
  • Parameters and data for each instruction
  • List of executing accounts

4. Protocol Identification and Classification

The MCP tool will automatically identify the protocols and programs involved in the transaction, such as:

  • Jupiter DEX (JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4)
  • Serum DEX (CMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK)
  • Orca Whirlpool (whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc)
  • Raydium pools
  • Token Program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)

5. Token Exchange Path Analysis

Track the path for transactions involving token exchanges, including:

  • Input token type and quantity
  • Output token type and quantity
  • Exchange route (route plan)
  • Slippage settings
  • Price impact

6. Value Flow Analysis

The MCP tool tracks the flow of tokens between different protocols, identifying:

  • Arbitrage opportunities
  • Price difference utilization
  • Cross-protocol fund flows
  • Fund aggregation and dispersion

7. Risk Assessment

  • Check for security risks
  • Identify potential malicious operations
  • Analyze the economic rationality of the transaction

Actual Case Analysis

Case: Complex Jupiter Arbitrage Transaction

Taking the transaction 4kVvQfb4faVsGjwUoDa7Ez1RYSy6t4TdZ5uwVDt9Rdx8zsfbDqYHyx3YdRdah9YVCGd4GwgDiV7xPBeezRQwy1EU as an example:

This transaction executed a complex arbitrage operation through Jupiter DEX.

Jupiter DEX Operation Details

This transaction executed two main exchange operations through Jupiter V6:

First Jupiter Route (Instruction 1)

  • Program: Jupiter V6
  • Type: route
  • Route Plan:
    • Use RaydiumClmmV2 pool, 100% conversion (inputIndex 0 → outputIndex 1)
    • Use SolFiV2 pool, 100% conversion (inputIndex 1 → outputIndex 2)
    • Use RaydiumClmm pool, 100% conversion (inputIndex 2 → outputIndex 3)
  • Input Amount: 71,500,000 lamports (0.0715 SOL)
  • Expected Output: 2,683,896 (corresponding to outputIndex 3 token)
  • Slippage: 0.05% (5 basis points)

Second Jupiter Route (Instruction 2)

  • Program: Jupiter V6
  • Type: route
  • Route Plan:
    • Use Whirlpool pool, 100% conversion (inputIndex 0 → outputIndex 1)
    • Use GoonFi pool, 100% conversion (inputIndex 1 → outputIndex 2)
  • Input Amount: 2,683,896
  • Expected Output: 71,515,882
  • Slippage: 0.01% (1 basis point)

Jupiter Swap Events Record (swapEvents)

  1. Instruction 7:

    • Through CMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK (Serum DEX) AMM
    • Input SOL: 71,500,000 lamports
    • Output pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn: 2,746,079,690
  2. Instruction 11:

    • Through SV2EYYJyRz2YhfXwXnhNAevDEui5Q6yrfyo13WtupPF AMM
    • Input pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn: 2,746,079,690
    • Output USDC (EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v): 15,077,885
  3. Instruction 15:

    • Through HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq AMM
    • Input USDC: 15,077,885
    • Output PYTH (27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4): 2,683,936
  4. Instruction 19:

    • Through whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc (Orca Whirlpool) AMM
    • Input PYTH: 2,683,896
    • Output USDC: 15,077,787
  5. Instruction 23:

    • Through goonERTdGsjnkZqWuVjs73BZ3Pb9qoCUdBUL17BnS5j AMM
    • Input USDC: 15,077,787
    • Output SOL: 71,510,809 lamports

Complete exchange path as follows:

SOL (0.0715) →
RaydiumClmmV2 → SolFiV2 → RaydiumClmm →
Pump.fun token (2,746,079,690) →
USDC (15.08) →
PYTH token (2.68) →
USDC (15.08) →
Orca Whirlpool →
USDC (15.08) →
GoonFi →
SOL (0.071510809)
Enter fullscreen mode Exit fullscreen mode

Through this path, approximately 0.000010809 SOL in arbitrage profit was achieved.

Advantages of MCP Tools

  1. Comprehensiveness: Able to analyze every detail of the transaction, including inner instructions
  2. Ease of Use: Provides structured output, making it easy to understand complex multi-protocol interactions
  3. Real-time: Directly obtains data from the blockchain, ensuring accuracy and timeliness
  4. Protocol Support: Supports mainstream Solana protocols, including DEXes, lending protocols, yield aggregators, etc.
  5. Analysis Depth: Not only shows what happened in the transaction, but also explains why it happened

Application Scenarios

  1. Transaction Auditing: Helps developers and users understand the execution process of complex transactions
  2. Arbitrage Analysis: Identifies and analyzes arbitrage opportunities
  3. Security Analysis: Detects potential malicious transactions
  4. Research Analysis: Studies market behavior and protocol interaction patterns
  5. Educational Purposes: Helps users understand the internal mechanisms of DeFi transactions

Conclusion

Solana MCP is a powerful tool capable of deeply parsing complex multi-protocol transactions on the Solana chain. Through a systematic analysis process, users can clearly understand every aspect of the transaction, which is valuable for DeFi participants, protocol developers, and security researchers.

The design of MCP tools makes analyzing complex cross-protocol interactions simpler and more understandable, contributing to the transparency and security of the Solana ecosystem.

Top comments (0)