Nexus MCP服务器
Enabling AI Agents to Interact with the Nexus Blockchain
概述
Nexus MCP服务器是一个桥梁,使AI代理能够使用模型上下文协议(MCP)直接与Nexus区块链交互。它将区块链功能作为MCP工具公开,任何兼容MCP的AI系统都可以访问,包括Claude和其他领先的LLM。
👉 阅读完整的博客文章 了解Nexus如何为人工智能时代构建区块链,从MCP集成开始。
特性
- 查询区块链数据:获取区块、交易、账户余额等
- 智能合约交互:进行只读合约调用以查询链数据
- 事务管理:将已签名的交易提交到网络
- 事件监控:通过日志跟踪和过滤区块链事件
- 易于AI集成:与任何启用MCP的AI系统兼容
可用工具
| 工具名称 | 描述 | 参数 |
|---|---|---|
getNetworkInfo | 获取Nexus区块链网络信息 | 无 |
getBalance | 获取地址余额 | address:string |
getTransaction | 通过哈希获取交易详细信息 | txHash:string |
getBlock | 按编号获取区块详细信息 | blockNumber:字符串, fullTransactions:boolean(可选) |
callContract | 调用智能合约方法(只读) | to:字符串, data:string |
getLogs | 从区块链获取事件日志 | filterObject:对象 |
sendRawTransaction | 向网络提交已签名的交易 | signedTx:string |
快速开始
安装
# Clone the repository
git clone https://github.com/nexus/mcp-for-nexus
cd mcp-for-nexus
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Start the server
npm run dev与客户进行测试
服务器运行后,您可以使用附带的测试客户端连接到它:
# Using the test client (requires Redis for SSE transport)
node scripts/test-nexus-client.mjs http://localhost:3000对于本地开发,请确保Redis已安装并正在运行:
# Install Redis (macOS)
brew install redis
# Start Redis
brew services start redis
# Verify Redis is running
redis-cli ping # Should respond with "PONG"客户端使用示例
// Example of calling blockchain tools from your application
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const transport = new SSEClientTransport(new URL(`http://localhost:3000/sse`));
const client = new Client(
{ name: "my-app", version: "1.0.0" },
{ capabilities: { prompts: {}, resources: {}, tools: {} } }
);
await client.connect(transport);
// Get blockchain info
const networkInfo = await client.callTool({
name: "getNetworkInfo",
arguments: {}
});
// Query an account balance
const balance = await client.callTool({
name: "getBalance",
arguments: { address: "0x1234567890abcdef1234567890abcdef12345678" }
});
// Get block information
const blockData = await client.callTool({
name: "getBlock",
arguments: {
blockNumber: "latest",
fullTransactions: true
}
});与AI系统集成
Claude集成示例
// Example of integrating with Claude
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
import Anthropic from "@anthropic-ai/sdk";
// Setup MCP client
const mcpClient = new Client(...);
await mcpClient.connect(transport);
// Get available tools
const tools = await mcpClient.listTools();
const toolDefinitions = tools.map(tool => ({
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema
}));
// Setup Claude client
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
// Create message with tools
const message = await anthropic.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1000,
messages: [{ role: "user", content: "What's the latest block on Nexus?" }],
tools: toolDefinitions
});
// Handle tool calls from Claude
for (const content of message.content) {
if (content.type === 'tool_use') {
const result = await mcpClient.callTool({
name: content.name,
arguments: content.input
});
// Send tool result back to Claude
// ...
}
}部署选项
地方发展
服务器可以在本地运行用于开发目的,这对于测试与Nexus区块链集成的AI开发人员来说是理想的。
Vercel上的生产部署
对于生产使用,服务器可以部署在Vercel上:
- 配置Redis(SSE传输所需):
- 从Vercel仪表板添加Redis集成,或 - 集 REDIS_URL 托管Redis实例的环境变量
- 启用流体计算以实现更长时间的运行操作
贡献
我们欢迎为改进Nexus MCP服务器做出贡献!请查看我们的 贡献指南 了解更多信息。
许可证
该项目根据 MIT许可证.
连接Nexus
- 网站: nexus.xyz
- 推特: @nexus_xyz
- Discord 的中文翻译是“不和谐”或“纷争”。: 加入我们的社区
- GitHub: 纽带
