Risk Warning: Beware of illegal fundraising in the name of 'virtual currency' and 'blockchain'. — Five departments including the Banking and Insurance Regulatory Commission
Information
Discover
Search
Login
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt
BTC
ETH
HTX
SOL
BNB
View Market
Web3 Beginner Series: MCP completes the transaction in one sentence
ZAN Team
特邀专栏作者
2025-06-09 02:42
This article is about 987 words, reading the full article takes about 2 minutes
This is a practical tutorial combining MCP (Model-Context Protocol) and Web3 technology, showing how to add blockchain interaction capabilities to large language models.

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.

MCP's 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

  • 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 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, "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!

MCP
Welcome to Join Odaily Official Community