Solana 指令解析 mcp 介绍
昨天在网上放出我前段打造的Solana指令解析mcp,我发现给我点赞关注的不少,实际去使用的却不多。感觉我这个还是值得一试,并且结合ai能有大用。
地址在solmcp
里面的例子使用,MCP Inspector进行调用,为什么用这个呢,ai能调用 mcp是靠ai的能力,mcp的函数的能力,看输入输出。 mcp 具备解析anchor,shank,codama 几种格式指令,解析数据来源于我收集的1k多idl数据集。
里面的解析tx来自 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
get_solana_transaction
analyze_solana_instruction
analyze_instruction_data
get_transaction_with_inner_instructions
定义如下:
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)"),
},
输入:
signature: 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
instruction_index: 6
我们将得到:
🔬 **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
定义如下:
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)"),
},
输入:
program_id: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
instruction_data: e517cb977ae3ad2a020000005f006400015f016401027e12de0e00000000def5fb0200000000320000
我们将得到:
🔍 **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
定义如下:
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)"),
},
输入:
signature: 4mSCpNds15mvygBex3aCfyMyZ8JYyzTuNikeYT2LgADH5DZgz6jnMZkLuwhAmqUHRVu2LXgmcVxXzeRvXPesPb5a
filter_program_ids: [JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4]
我们将得到:
🔍 **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
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!