区块链数据分析服务

该项目实现了一个模型上下文协议(MCP)服务器,通过Dune API提供区块链数据分析功能,允许LLM代理和其他MCP客户端分析区块链信息。

  • by crazyrabbitLTC
  • JavaScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 crazyrabbitltc/mcp-web3-stats

使用说明

沙丘API MCP服务器

该项目实现了一个模型上下文协议(MCP)服务器,该服务器公开了Dune API的功能,允许LLM代理和其他MCP客户端分析区块链信息。

特性

服务器基于Dune API提供以下MCP工具和资源:

EVM工具:

  • get_evm_balances:获取钱包的EVM代币余额。
  • get_evm_activity:获取EVM帐户活动。
  • get_evm_collectibles:获取EVM NFT收藏品。
  • get_evm_transactions:检索细粒度EVM事务详细信息。
  • get_evm_token_info:获取EVM代币的元数据和价格。
  • get_evm_token_holders:发现EVM代币持有者分布。

SVM工具:

  • get_svm_balances:获取SVM令牌余额。
  • get_svm_transactions:获取SVM事务(仅限Solana)。

资源:

  • dune://evm/supported-chains:提供Dune API支持的EVM链的列表。

提示:

  • /evm_wallet_overview {walletAddress}:快速了解EVM钱包。
  • /analyze_erc20_token {chainId} {tokenAddress}:分析特定的ERC20代币。
  • /svm_address_check {walletAddress}:检查SVM地址的基本信息。

快速开始

# Clone the repository
git clone https://github.com/crazyrabbitLTC/mcp-web3-stats.git
cd mcp-web3-stats

# Install dependencies
bun install

# Create .env file with your Dune API key
echo "DUNE_API_KEY=your_actual_dune_api_key_here" > .env

# Start the server
bun start

# In a separate terminal, run the MCP Inspector to test the tools
npx @modelcontextprotocol/inspector bun run index.ts

从npm安装

您可以通过npm全局安装Web3 Stats服务器:

# Install globally
npm install -g mcp-web3-stats

# Set your Dune API key as an environment variable
export DUNE_API_KEY=your_actual_dune_api_key_here

# Run the server
mcp-web3-stats

# In a separate terminal, test with the MCP Inspector
npx @modelcontextprotocol/inspector mcp-web3-stats

或者,您可以直接使用npx运行它:

# Set your Dune API key as an environment variable
export DUNE_API_KEY=your_actual_dune_api_key_here

# Run the server with npx
npx mcp-web3-stats

# In a separate terminal, test with the MCP Inspector
npx @modelcontextprotocol/inspector npx mcp-web3-stats

你能用这个做什么

此MCP服务器允许您和您的AI助手直接分析区块链数据和钱包信息。以下是一些示例用例:

1.检查钱包余额

您可以快速查看任何钱包地址持有的所有代币(包括ERC20和NFT):

Assistant: Let me check the balances in this wallet for you.

[Uses get_evm_balances with walletAddress=0xYourWalletAddress]

This wallet contains:
- 1.25 ETH (~$3,800)
- 500 USDC ($500)
- Several NFTs including a CryptoPunk and two Bored Apes

2.分析代币信息和持有者

您可以研究特定的代币及其分布:

Assistant: Let me analyze this token for you.

[Uses get_evm_token_info with chainId=1 and tokenAddress=0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984]

UNI Token Information:
- Current price: $5.32
- Market cap: $2.7B 
- 24h trading volume: $89M

[Uses get_evm_token_holders with chainId=1 and tokenAddress=0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984]

Top UNI Token Holders:
1. 0x47173B170C64d16393a52e6C480b3Ad8c302ba1e: 5.2% of supply
2. 0x1a9C8182C09F50C8318d769245beA52c32BE35BC: 3.8% of supply
...

3.审查最近的交易

您可以分析任何地址的交易历史:

Assistant: Here's a summary of recent transactions.

[Uses get_evm_transactions with walletAddress=0xYourWalletAddress]

Recent activity:
- Yesterday: Swapped 2 ETH for 3,500 UNI on Uniswap
- 3 days ago: Withdrew 5 ETH from Binance
- Last week: Minted an NFT for 0.08 ETH

4.检查Solana余额

您还可以分析Solana钱包:

Assistant: Let me check your Solana wallet balances.

[Uses get_svm_balances with walletAddress=YourSolanaAddress]

This wallet contains:
- 12.5 SOL (~$875)
- 2,500 USDC ($2,500)
- Several SPL tokens including 150 BONK

使用Claude Desktop或其他MCP客户端配置此服务器,使您的AI助手能够实时检索和分析链上数据。

先决条件

设置

  1. 克隆存储库(如果适用)或确保您拥有项目文件。

  2. 安装依赖项:

    bun install
    
  3. 配置环境变量: 创建一个 .env 文件,并添加您的Dune API密钥:

    DUNE_API_KEY=your_actual_dune_api_key_here
    

    替换 your_actual_dune_api_key_here 使用您的有效密钥。

运行服务器

  • 要使用Bun直接运行服务器(用于开发/测试):

    bun start
    

    服务器将启动并通过stdio监听MCP消息。

  • 要将服务器构建为JavaScript(对于需要JS的环境): 使用配置的构建脚本,该脚本利用TypeScript编译器(tsc):

    bun run build
    

    此命令执行 bunx tsc 如所定义 package.json. tsc 使用 tsconfig.json 文件以确定入口点(如 index.ts)以及编译选项,将JavaScript文件输出到 ./dist 目录。

    然后,您可以使用Node.js或Bun运行构建的服务器:

    node dist/index.js 
    # or
    bun dist/index.js
    

    或者,如果您希望直接使用Bun的内置bundler(其行为或配置需求可能与Bun不同) tsc),您通常会明确指定入口点: bun build ./index.ts --outdir ./dist 然而,该项目旨在使用 tsc 通过构建 bun run build 脚本。

MCP检验员测试

一旦服务器运行(例如,通过 bun start 在一个终端)中,您可以使用另一个终端中的MCP检查器连接到它:

# If running the TypeScript source directly
npx @modelcontextprotocol/inspector bun run index.ts

或者,如果您已经构建了服务器并正在运行JavaScript版本:

# If running the built JavaScript version from ./dist
npx @modelcontextprotocol/inspector node dist/index.js

这将启动检查器UI,允许您发现和测试此服务器提供的工具、资源和提示。

与MCP客户端集成(例如,Claude Desktop)

要将此服务器与Claude Desktop等MCP客户端一起使用,您需要配置客户端以启动此服务器。对于Claude Desktop,您可以修改其 claude_desktop_config.json 文件(通常位于 ~/Library/Application Support/Claude/claude_desktop_config.json 在macOS或 %APPDATA%\Claude\claude_desktop_config.json 在Windows上)。

以下是示例配置。您可以选择服务器名称(例如。, dune_api_server 或 web3_stats_server)这对你来说是有道理的。

示例1:使用Node.js运行构建的JavaScript版本(推荐用于稳定性)

这假设您已经运行过 bun run build 创建 ./dist 目录。

{
  "mcpServers": {
    "dune_api_server": { // You can name this server entry whatever you like
      "command": "node",
      "args": [
        "/ABSOLUTE/PATH/TO/YOUR/mcp-web3-stats/dist/index.js"
      ],
      "env": {
        "DUNE_API_KEY": "your_actual_dune_api_key_here" // Replace with your key
      }
    }
  }
}

示例2:直接使用Bun运行TypeScript源代码

这便于开发,但可能需要指定Bun可执行文件的完整路径。

{
  "mcpServers": {
    "dune_api_server_dev": { // You can name this server entry whatever you like
      "command": "/full/path/to/your/bun/executable", // e.g., /Users/username/.bun/bin/bun or C:\Users\username\.bun\bin\bun.exe
      "args": [
        "run",
        "/ABSOLUTE/PATH/TO/YOUR/mcp-web3-stats/index.ts"
      ],
      "env": {
        "DUNE_API_KEY": "your_actual_dune_api_key_here" // Replace with your key
      }
    }
  }
}

重要配置说明:

  • API密钥: 你 必须 替换 "your_actual_dune_api_key_here" 在 env 使用您的实际Dune API密钥阻止。虽然服务器脚本包括 dotenv 加载本地 .env 文件,依赖于客户端(如Claude Desktop)通过其配置传递环境变量,对于外部主机启动的服务器来说更可靠。
  • 绝对路径: 你 必须 替换 /ABSOLUTE/PATH/TO/YOUR/... 通过正确和完整的绝对路径 dist/index.js 文件(用于节点)或 index.ts 文件(用于Bun直接执行)和Bun可执行文件(如果直接运行TypeScript)。
  • Bun可执行路径: 如果直接使用Bun(实施例2) command 可能需要是Bun可执行文件的完整、绝对路径(例如。, ~/.bun/bin/bun 在macOS/Linux上,或Windows上的等效路径),如果它不在Claude Desktop等应用程序的path中普遍存在。
  • 重新启动客户端: 保存更改后 claude_desktop_config.json,您必须重新启动Claude Desktop才能使更改生效。