s

svm-mcp服务器

@rkmonarch/svm-mcp
0 Stars 20 次浏览 rkmonarch 更新于 2026-08-23

一个模型上下文协议服务器,它将Claude AI与SOON和其他基于SVM的区块链连接起来,允许用户在SOON的测试网和主网上查看账户余额、获取最近的交易记录以及查看代币持有情况。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

SVM-MCP: SOON 模型上下文协议服务器

一个集成了 Claude AI 与 SOON 及其他基于 SVM 的区块链的模型上下文协议 (MCP) 服务器。该服务器提供了检查余额、获取最近交易和查看 SOON 测试网和主网上的代币持有情况的工具,适用于账户余额、交易和代币持有。

概述

这个 MCP 服务器旨在将 Claude 与 SOON 生态系统连接起来,使其能够:

  • 查询测试网和主网上的钱包余额
  • 获取地址的最新交易
  • 检查任何账户的代币持有情况

当前实现使用了 SOON 的 RPC 端点,但可以轻松修改以适应任何兼容 Solana 的区块链或自定义 SVM 实现。

功能

  • 获取余额:获取 SOON 测试网或主网上任何地址的原生代币余额
  • 获取最后交易:检索地址的最新交易
  • 获取代币账户:列出地址拥有的所有代币账户

前提条件

  • Node.js (v16+)
  • NPM 或 Bun 包管理器
  • Claude Desktop(用于本地测试)

安装

  1. 克隆仓库:
git clone https://github.com/rkmonarch/svm-mcp
cd svm-mcp
  1. 安装依赖项:
npm install
# or
bun install
  1. 构建项目:
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 Desktop 配置

要将此 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?

致谢