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 and external systems through standardized protocol interfaces.
MCPs core advantages
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 flows.
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 operations: sending transactions, deploying contracts, calling smart contracts
DeFi integration: interact with DeFi applications such as DEX, lending protocols, liquidity mining, etc.
Cross-chain operations: support multi-chain asset management and cross-chain transfers
NFT Management: Query, transfer, and trade NFT assets
This article will build a simple Web3 MCP service through nodejs+typescript, and analyze the working principles and best practices of MCP.
1. Create a project
Create a project folder and initialize the project
Install required packages
Add typescript configuration and modify it according to personal needs
Modify the package.json configuration
2. Write the 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, get the rpcUrl , and then instantiate a provider
Writing tool logic
Start the service and add error handling
At this point, a minimal mcp service has been written
3. Debugging Service
At this point, we need to package the js product, and then execute modelcontextprotocol/inspector to debug it.
4. Improve the logic and reference it in Cursor
Improve more logic and methods, such as supporting multiple evm networks, querying gas, sending transactions, querying token information, and token transactions, and other common methods, packaged and referenced in Cursor. Cursor is a new intelligent IDE that seamlessly integrates AI technology. Cursor is built on VSCode, easy to use, and can greatly improve your work efficiency. It is also an application that supports MCP integration.
5. Use
Then you can use it happily in chat~ (chat is Cursors 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, Transfer 0.1 ETH to this address 0x2c1d9ef7ccede70d77e6038701cd63138dd920a0:
6. Final Thoughts
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 has opened 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.
If you are interested, come and try it!