SVM-MCP:SOON 模型上下文协议服务器
一个模型上下文协议 (MCP) 服务器,将 Claude AI 与 SOON 及其他基于 SVM 的区块链集成。该服务器提供用于查询余额、获取近期交易以及查看 SOON 测试网和主网上的代币持有情况的工具,包括账户余额、交易记录和代币持有量。
概述
该 MCP 服务器旨在将 Claude 与 SOON 生态系统连接起来,使其能够:
- 查询测试网和主网上的钱包余额
- 获取某个地址的最新交易
- 检查任何账户的代币持有量
当前实现使用 SOON 的 RPC 端点,但可以轻松修改以与任何与 Solana 兼容的区块链或自定义 SVM 实现一起使用。
特征
- 获取余额:获取 SOON 测试网或主网上任何地址的原生代币余额
- 获取最后一笔交易:检索某个地址的最近一笔交易
- 获取代币账户:列出某个地址拥有的所有代币账户
先决条件
- Node.js(v16+)
- NPM 或 Bun 包管理器
- Claude Desktop(用于本地测试)
安装
- 克隆存储库:
git clone https://github.com/rkmonarch/svm-mcp
cd svm-mcp
- 安装依赖项:
npm install
# or
bun install
- 构建项目:
npm run build
# or
bun run build
项目结构
主服务器实现位于src/index.ts
中:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { Connection, PublicKey } from "@solana/web3.js";
import { z } from "zod";
const connectionTestnet = new Connection("https://rpc.testnet.soo.network/rpc");
const connectionMainnet = new Connection("https://rpc.mainnet.soo.network/rpc");
const server = new McpServer({
name: "svm-mcp",
version: "0.0.1",
capabilities: [
"get-soon-testnet-balance",
"get-soon-testnet-last-transaction",
"get-soon-testnet-account-tokens",
"get-soon-mainnet-balance",
"get-soon-mainnet-last-transaction",
"get-soon-mainnet-account-tokens",
],
});
工具实现
获取余额
server.tool(
"get-soon-testnet-balance",
"Get the balance of a address on the Soon testnet",
{
address: z.string().describe("The Solana address to get the balance of"),
},
async ({ address }) => {
try {
const balance = await connectionTestnet.getBalance(new PublicKey(address));
return {
content: [
{
type: "text",
text: `Balance: ${balance}`,
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error getting balance: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
}
);
获取最后交易
server.tool(
"get-soon-testnet-last-transaction",
"Get the last transaction of an address on the Soon testnet",
{
address: z
.string()
.describe("The Solana address to get the last transaction for"),
},
async ({ address }) => {
try {
// Fetch the most recent transaction signatures for the address
const signatures = await connectionTestnet.getSignaturesForAddress(
new PublicKey(address),
{ limit: 1 } // Limit to just the most recent transaction
);
if (signatures.length === 0) {
return {
content: [
{
type: "text",
text: "No transactions found for this address",
},
],
};
}
// Get the most recent transaction using its signature
const latestSignature = signatures[0].signature;
const transaction = await connectionTestnet.getConfirmedTransaction(
latestSignature
);
return {
content: [
{
type: "text",
text: JSON.stringify(transaction),
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error getting transaction: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
}
);
获取代币账户
server.tool(
"get-soon-testnet-account-tokens",
"Get the tokens of a address on the Soon testnet",
{
address: z.string().describe("The Solana address to get the tokens of"),
},
async ({ address }) => {
try {
const tokens = await connectionTestnet.getTokenAccountsByOwner(
new PublicKey(address),
{
programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
}
);
return {
content: [
{
type: "text",
text: JSON.stringify(tokens),
},
],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error getting tokens: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
}
);
服务器初始化
async function main() {
try {
console.error("Starting MCP server...");
const transport = new StdioServerTransport();
console.error("Transport initialized, connecting to server...");
await server.connect(transport);
console.error("Server connection established successfully");
// The server will keep running in this state
} catch (error) {
console.error("There was an error connecting to the server:", error);
process.exit(1);
}
}
main().catch((err) => {
console.error("There was an error starting the server:", err);
process.exit(1);
});
配置
Claude桌面配置
要将此 MCP 服务器与 Claude Desktop 一起使用,请将以下内容添加到您的claude_desktop_config.json
文件中:
{
"mcpServers": {
"svm-mcp": {
"command": "bun",
"args": ["/path/to/svm-mcp/build/index.js"]
}
}
}
自定义 RPC 端点
要使用不同的 RPC 端点或连接到不同的 Solana 兼容区块链,请编辑src/index.ts
中的连接 URL:
const connectionTestnet = new Connection("YOUR_TESTNET_RPC_URL");
const connectionMainnet = new Connection("YOUR_MAINNET_RPC_URL");
与 Claude 一起使用
一旦 MCP 服务器运行并连接到 Claude,您就可以使用以下命令:
检查地址余额
Can you check the balance of this SOON testnet address: <address>
获取近期交易
What is the last transaction made by <address> on SOON testnet?
检索代币持有量
What tokens does <address> hold on SOON mainnet?
致谢