Web3 Beginner Series: MCP completes the transaction in one sentence

avatar
ZAN Team
5 hours ago
This article is approximately 551 words,and reading the entire article takes about 1 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.

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

Web3 Beginner Series: MCP completes the transaction in one sentence

  • Install required packages

Web3 Beginner Series: MCP completes the transaction in one sentence

  • Add typescript configuration and modify it according to personal needs

Web3 Beginner Series: MCP completes the transaction in one sentence

  • Modify the package.json configuration

Web3 Beginner Series: MCP completes the transaction in one sentence

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

Web3 Beginner Series: MCP completes the transaction in one sentence

  • Writing tool logic

Web3 Beginner Series: MCP completes the transaction in one sentence

  • Start the service and add error handling

Web3 Beginner Series: MCP completes the transaction in one sentence

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.

Web3 Beginner Series: MCP completes the transaction in one sentence

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.

Web3 Beginner Series: MCP completes the transaction in one sentence

Web3 Beginner Series: MCP completes the transaction in one sentence

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:

Web3 Beginner Series: MCP completes the transaction in one sentence

For example, Transfer 0.1 ETH to this address 0x2c1d9ef7ccede70d77e6038701cd63138dd920a0:

Web3 Beginner Series: MCP completes the transaction in one sentence

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!

Original article, author:ZAN Team。Reprint/Content Collaboration/For Reporting, Please Contact report@odaily.email;Illegal reprinting must be punished by law.

ODAILY reminds readers to establish correct monetary and investment concepts, rationally view blockchain, and effectively improve risk awareness; We can actively report and report any illegal or criminal clues discovered to relevant departments.

Recommended Reading
Editor’s Picks