Overview
MCP (Model-Context Protocol) is an open protocol launched by Anthropic, which provides a standardized way for large language models to securely access external tools, data sources, and services. Unlike traditional plug-in systems, MCP adopts a client-server architecture and achieves seamless integration of models with external systems through standardized protocol interfaces.
Core advantages of MCP
Standardized interface: MCP defines a unified protocol specification, avoiding the problem that each application needs to develop its own integration solution.
Security: Ensure secure access to external tools through strict permission control and sandbox mechanism.
Extensibility: Supports a wide range of tool types, from simple API calls to complex data processing processes.
Interoperability: Any client that supports MCP can use compatible services, achieving true cross-platform compatibility.
Application scenarios of Web3 + MCP
In the Web3 field, MCP can provide rich blockchain interaction capabilities for large language models:
Asset query: query various token balances and transaction history
On-chain operation: send transactions, deploy contracts, call smart contracts
DeFi integration: interact with DeFi applications such as DEX, lending agreements, and liquidity mining
Cross-chain operation: support multi-chain asset management and cross-chain transfer
NFT management: query, transfer, and trade NFT assets
This article will Nodejs+typescript builds a simple Web3 MCP service, and analyzes the working principle and best practices of MCP.
1. Create a project




2. Writing server
Use server.tool to quickly create a tool. Here, we take the getBalance of the sepolia test network as an example to write a tool
First, we need to register a zan account, activate the node service, obtain the rpcUrl, and then instantiate a provider



So far, a minimum mcp service has been written
3. Debugging services
At this step, we need to package the js product, and then execute modelcontextprotocol/inspector, and then we can debug


Fourth, improve the logic and reference it in Cursor


5. Use
Then you can use it happily in chat~ (chat is Cursor's AI assistant, which is located in the sidebar and can interact with the code base through natural language.)
For example, "Query the balance of this address 0xE21E97Ad8B527acb90F0b148EfaFbA46625382cE on sepolia":

For example, "Give this address 0x2c1d9ef7ccede70d77e6038701cd63138dd920a0 to 0.1ETH":

Sixth, write at the end
There is still a lot of room for our imagination. This article has explained the overall process. What else can we do later? For example, support multiple chains (Bitcoin, Solana, Tron), or connect to cross-chain. In the chat, we can exchange the USDT of my chain for another chain? The combination of Web3 and MCP opens up a new world of possibilities for us. Whether it is DeFi protocol integration, NFT market operations, or complex cross-chain asset management, these can be achieved through simple conversations.
Interested friends, come and try it!