MCP 区块链服务器和 DApp
一个安全的系统,使人工智能助手能够与区块链智能合约交互,同时确保用户完全控制他们的私钥和交易签名。
概述
该项目解决了人工智能区块链集成中的一个关键挑战:允许人工智能助手读取区块链数据并准备交易,同时确保用户对交易签名和私钥保持独占控制。
该系统包括:
MCP 服务器:模型上下文协议服务器,将区块链操作公开为可供 AI 助手使用的工具
Web DApp :一个 React 应用程序,提供用于钱包连接和交易签名的用户界面
数据库:PostgreSQL 数据库,用于存储用户、API 密钥和交易记录
缓存:Redis 用于缓存经常访问的数据
特征
MCP 服务器功能
区块链数据访问:读取余额、合约状态和其他链上数据
交易准备:创建未签名的交易以供用户批准
多链支持:可与以太坊、Polygon 和其他 EVM 兼容链配合使用
智能合约交互:从支持网络上已验证的智能合约中读取
安全第一的设计:私钥永远不会离开用户的钱包
Web DApp 功能
钱包集成:连接 MetaMask 和其他 Web3 钱包
交易审查:清晰的用户界面,用于在签名前审查交易详情
交易签名:使用连接的钱包签署交易
交易跟踪:监控已提交交易的状态
移动兼容性:响应式设计适用于所有设备
安全原则
私钥隔离:密钥永远不会离开用户的钱包
交易验证:清晰的用户界面,用于审查交易详情
API 身份验证:安全 API 密钥管理
速率限制:防止滥用
输入验证:清理所有输入
审计日志:跟踪所有操作
仅 HTTPS :安全通信
内容安全策略:防止XSS
交易流程
AI助手通过MCP服务器请求交易
MCP 服务器使用 UUID 准备未签名交易
MCP 服务器返回交易 URL 给 AI 助手
AI助手向用户提供URL
用户在浏览器中打开 URL
用户连接钱包并查看交易详情
用户使用钱包批准并签署交易
Web DApp 将签名的交易提交至区块链
交易状态已更新并跟踪
入门
先决条件
Node.js(v18 或更高版本)
npm 或 yarn
PostgreSQL
Redis(可选,用于缓存)
Infura API 密钥(用于区块链访问)
Etherscan API 密钥(用于合约 ABI)
安装
克隆存储库:
安装依赖项:
设置环境变量:在根目录中创建一个
.env
文件(或从.env.example
复制):
设置数据库:
有关安装和配置 PostgreSQL 的详细说明,请参阅数据库设置指南。
启动服务器:
使用 Docker Compose
快速开始使用 Docker:
这将开始:
PostgreSQL 数据库
Redis 缓存
MCP 服务器
Web DApp
发展
服务器结构
src/mcp
:MCP 服务器实现src/services
:核心业务逻辑服务src/utils
:实用程序函数src/index.ts
:主入口点
Web DApp 结构
web/src/components
:React 组件web/src/hooks
:自定义 React hooksweb/src/services
:API 服务web/src/pages
:页面组件
使用 MCP 服务器
MCP 服务器提供了几种可供 AI 助手使用的工具:
get-chains
:获取支持的区块链网络列表get-balance
:获取地址的账户余额read-contract
:从智能合约读取数据prepare-transaction
:准备未签名的交易以供用户批准get-transaction-status
:获取交易的当前状态
工具使用示例
故障排除
如果您遇到依赖关系问题:
有关数据库连接问题,请参阅数据库设置指南。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
一个安全的系统,使人工智能助手能够与区块链数据交互并准备交易,同时确保用户对其私钥和交易签名保持独占控制。
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityProvides tools for AI assistants to interact with the Ethereum blockchain through standard JSON-RPC methods, enabling queries for account balances, gas prices, and smart contract code.Last updated -310MIT License
- -securityAlicense-qualityA comprehensive toolkit for building AI agents with blockchain capabilities, enabling interactions with multiple blockchain networks for tasks like wallet management, fund transfers, smart contract interactions, and cross-chain asset bridging.Last updated -3GPL 3.0
- -securityFlicense-qualityA Model Context Protocol server that enables AI assistants to access Flow blockchain data and perform operations such as checking balances, resolving domains, executing scripts, and submitting transactions.Last updated -1
- AsecurityAlicenseAqualityIntegrates Aptos blockchain access into AI applications, enabling interaction with tools for native APT operations, custom coin management, and transaction handling.Last updated -12MIT License