The relationship between blockchain and artificial intelligence represents one of the most significant technological convergences of our generation. At Nexus, we're not just building another L1 blockchain; we're creating the infrastructure for an AI-native financial system. Today, I want to share a key component of this vision: our Nexus MCP Server, which enables AI agents to interact directly with blockchain infrastructure.
See the GitHub repo for this project.
The missing link: AI-to-blockchain communication
When we started building Nexus, we recognized a fundamental challenge: despite the rapid advancement of AI systems and their increasing ability to understand blockchain concepts, there was no standardized way for AI agents to directly interact with blockchain infrastructure. This limitation has restricted the potential of AI in the blockchain space to largely analytical roles rather than active participants.
The Model Context Protocol (MCP) has emerged as a powerful standard for AI agent tools, popularized by Anthropic's Claude and supported by leading AI systems. MCP provides a structured way for AI models to access external tools and data sources, making it the perfect foundation for our blockchain connectivity solution.
Introducing the Nexus MCP Server
The Nexus MCP Server is a bridge that translates between AI agent requests and blockchain RPC calls. It packages Nexus blockchain functionality into a format that any MCP-compatible AI agent can easily understand and utilize.
┌─────────┐
│ AI │
│ Agent │
└────┬────┘
│
│ MCP Protocol
▼
┌─────────────────────────────────┐
│ Nexus MCP Server │
├─────────────────────────────────┤
│ - getNetworkInfo │
│ - getBalance │
│ - getTransaction │
│ - getBlock │
│ - callContract │
│ - getLogs │
│ - sendRawTransaction │
└──────────────┬──────────────────┘
│ JSON-RPC
▼
┌─────────────────────────────────┐
│ Nexus Blockchain │
└─────────────────────────────────┘
Through the Nexus MCP Server, AI agents can:
- Query blockchain data (blocks, transactions, balances)
- Make read-only contract calls
- Submit signed transactions
- Monitor events and logs
This opens up a world where AI agents can not only analyze blockchain data but actively participate in the ecosystem by executing transactions, interacting with smart contracts, and much more - all while benefiting from the security, transparency, and composability of blockchain technology.
The technical architecture
Our implementation is built on a stack of modern technologies designed for reliability, scalability, and developer experience. Let's dive into the technical details of how we built the Nexus MCP Server.
Next.js and Vercel MCP Adapter
We chose Next.js as our framework for several technical reasons:
-
Route handlers: Next.js's route handlers provide a clean way to implement the MCP protocol endpoints. We leverage the dynamic
[transport]
route segment to support different transport protocols through a single codebase. -
Vercel MCP Adapter: We utilize the
@vercel/mcp-adapter
package, which provides a production-ready implementation of the MCP server specification. This adapter handles:- Protocol message formatting and validation
- Session management
- Transport protocol negotiation
- Type-safe tool definitions with Zod schema validation
// Example of our route handler implementation using Vercel MCP Adapter
import { createMcpHandler } from "@vercel/mcp-adapter";
import { z } from "zod";
import * as Nexus from "../lib/nexus";
const handler = createMcpHandler(
(server) => {
// Define blockchain tools with type-safe schemas
server.tool(
"getNetworkInfo",
"Get Nexus blockchain network information",
{}, // Empty schema means no parameters required
async () => {
const info = await Nexus.getNetworkInfo();
return {
content: [{ type: "text", text: JSON.stringify(info, null, 2) }],
};
}
);
// Additional tools defined here...
},
// Server capabilities configuration
{ capabilities: { /* ... */ } },
// Transport configuration
{
redisUrl: process.env.REDIS_URL,
basePath: "",
verboseLogs: true,
maxDuration: 60,
}
);
export { handler as GET, handler as POST, handler as DELETE };
Redis for streaming with SSE transport
One of the most powerful aspects of our implementation is the Server-Sent Events (SSE) transport, which provides real-time, bidirectional communication between AI agents and the blockchain. This is critical for scenarios where the AI needs to receive ongoing updates or handle long-running operations.
Redis serves as the backbone of our SSE implementation, providing:
-
Pub/sub messaging: Redis pub/sub channels enable message broadcasting across multiple server instances, essential for scalable deployments.
-
Session management: We store session state in Redis, allowing for stateful connections that can persist across server restarts or in a distributed environment.
-
Message queue: Redis acts as a reliable message queue for handling asynchronous blockchain operations, ensuring that no responses are lost even during high-load situations.
Our implementation conditionally activates Redis based on environment configuration:
// Conditional Redis configuration
{
// Only use Redis if the URL is provided
...(process.env.REDIS_URL ? { redisUrl: process.env.REDIS_URL } : {}),
basePath: "",
verboseLogs: true,
maxDuration: 60
}
This approach allows developers to run the server without Redis for simple local development (falling back to HTTP transport) while enabling the full streaming capabilities in production environments.
Blockchain RPC layer
Our RPC layer is designed with careful abstraction to ensure security, performance, and error handling:
// Basic JSON-RPC request function with robust error handling
export async function rpcRequest(method: string, params: any[] = []) {
const response = await fetch(NEXUS_CONFIG.rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: Date.now(),
method,
params,
}),
});
if (!response.ok) {
throw new Error(`RPC request failed: ${response.statusText}`);
}
const data = await response.json();
if (data.error) {
throw new Error(`RPC error: ${data.error.message}`);
}
return data.result;
}
This layer handles all communication with the Nexus blockchain, translating between MCP tool calls and Ethereum-compatible JSON-RPC methods.
Streaming implementation details
The streaming capabilities of our MCP server are particularly important for blockchain interactions, where real-time data and long-running operations are common. Here's how it works:
-
Connection establishment:
- Client connects to the
/sse
endpoint - Server generates a unique session ID and starts an SSE stream
- Redis subscription is created for this session channel
- Client connects to the
-
Bidirectional communication:
- Client makes requests to the
/message
endpoint with the session ID - Server processes requests and publishes responses to the Redis channel
- SSE transport delivers responses in real-time to the client
- Client makes requests to the
-
Real-time blockchain updates:
- For operations like monitoring new blocks or transaction confirmations
- Server can push updates to the client as soon as they occur on-chain
- No need for polling, reducing latency and bandwidth consumption
This architecture is particularly valuable for AI agents that need to make decisions based on real-time blockchain data or monitor multiple on-chain events simultaneously.
How to use the Nexus MCP Server
Getting started with the Nexus MCP Server is straightforward, whether you're a blockchain developer interested in AI integration or an AI developer looking to tap into blockchain functionality.
Basic setup
# 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
Connecting an AI agent
Once your server is running, any MCP-compatible AI agent can connect to it. Here's a simple example using the test client:
# Using the included test client
node scripts/test-nexus-client.mjs http://localhost:3000
For AI developers integrating with Claude or other LLMs, you can use the tool definitions provided by the MCP server to enable your AI to interact with the blockchain:
// Example of calling Nexus blockchain tools from an AI system
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
}
});
Performance and scale considerations
For production deployment, we've designed the system with several performance optimizations:
-
Connection pooling: We implement RPC connection pooling to minimize overhead when making multiple blockchain calls.
-
Response caching: Frequently accessed data like network information can be cached to reduce redundant blockchain queries.
-
Scalable Redis architecture: For high-traffic deployments, we recommend a clustered Redis setup to handle increased connection loads.
-
Deployment on Vercel edge network: The server can be deployed to Vercel's edge network for global low-latency access, with all requests automatically routed to the nearest region.
// Example of maxDuration configuration for Vercel Fluid Compute
const handler = createMcpHandler(
// Server definition...
// Capabilities configuration...
{
redisUrl: process.env.REDIS_URL,
basePath: "",
verboseLogs: true,
maxDuration: process.env.NODE_ENV === 'production' ? 800 : 60, // 800 seconds for Pro/Enterprise accounts
}
);
Real-world applications
The integration of AI with blockchain through MCP opens up exciting possibilities:
- AI-powered DeFi agents that can monitor market conditions and execute trades based on specific parameters
- Smart contract auditors that can analyze code, find vulnerabilities, and simulate various transaction scenarios
- Onchain data analysts that can process blockchain data and generate insights in natural language
- Wallet assistants that help users manage their crypto assets with natural language instructions
- DAO governance agents that can monitor proposals, summarize discussions, and execute onchain votes
The future: Building the AI-native financial system
At Nexus, we believe that the future of finance will be driven by the convergence of AI and blockchain. The Nexus MCP Server is just the beginning of our journey to create truly AI-native financial infrastructure.
By lowering the barriers between AI systems and blockchain networks, we're enabling a new generation of AI-powered applications that can autonomously interact with decentralized finance protocols, execute complex financial strategies, and provide unprecedented levels of financial accessibility.
In the coming months, we'll be expanding the capabilities of our MCP server, adding support for more advanced blockchain operations, and creating specialized tools for AI agents focused on financial use cases. We're also working on AI-native smart contract frameworks that are specifically designed to be easily understood and interacted with by AI systems.
Join us in building the future
The intersection of AI and blockchain represents one of the most promising frontiers in technology today. If you're excited about this vision, we invite you to:
- Try out the Nexus MCP Server and provide feedback
- Contribute to the open-source codebase
- Build AI agents that interact with the Nexus blockchain
- Share your ideas for AI-native blockchain applications
Together, we can build the foundation for a more intelligent, accessible, and efficient financial system.
If you'd like to learn more or get involved, visit us at nexus.xyz or join our Discord community.