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兼容区块链,请在中编辑连接URL src/index.ts:
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: 获取最近的交易
What is the last transaction made by on SOON testnet?检索令牌持有量
What tokens does hold on SOON mainnet?致谢
- 人物克劳德 对于AI能力
- 模型上下文协议 用于实现工具集成
- Solana Web3.js 用于区块链交互
- SOON网络 对于本示例中使用的SVM实现
