
Monad MCP 教程
概览
本项目演示了如何创建一个与Monad测试网交互的MCP服务器。MCP服务器提供了一个用于检查Monad测试网上MON令牌余额的工具。 模型上下文协议(MCP)是一个允许AI模型与外部工具和服务交互的标准。 在本教程中,我们将创建一个MCP服务器,允许MCP客户端(Claude Desktop)查询Monad测试网以检查账户的MON余额。 - Node.js(v16及更高版本)- npm 或纱线 - Claude 桌面版 Monad Testnet 相关的配置已经添加到 src 文件夹index.ts中。 下面是get-mon-balance工具的支架: 让我们把MON余额检查的实现加入到工具中: 4. 添加关于MCP服务器的详细信息并保存文件。
概述(AI 翻译)
本项目演示了如何创建一个与Monad测试网交互的MCP服务器。MCP服务器提供了一个用于检查Monad测试网上MON令牌余额的工具。
什么是MCP?
模型上下文协议(MCP)是一个允许AI模型与外部工具和服务交互的标准。
在本教程中,我们将创建一个MCP服务器,允许MCP客户端(Claude Desktop)查询Monad测试网以检查账户的MON余额。
先修条件
- Node.js(v16或更高版本)
npm或yarn- Claude桌面
开始
-
克隆此仓库
-
安装依赖:
构建MCP服务器
Monad Testnet 相关的配置已经添加到 index.ts 文件夹的 src 文件夹中。
定义服务器实例
定义MON平衡工具
下面是get-mon-balance工具的支架:
让我们把MON余额检查的实现加入到工具中:
从 main 函数初始化传输和服务器
建设项目
服务器现在已经准备好使用!
将MCP服务器添加到Claude桌面
-
打开“Claude 桌面”
-
打开设置
Claude > 设置 > 开发者
- 开放
claude_desktop_config.json
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Monad MCP Tutorial
This project demonstrates how to create a MCP server that interacts with the Monad testnet. The MCP server provides a tool for checking MON token balances on the Monad testnet.
What is MCP?
The Model Context Protocol (MCP) is a standard that allows AI models to interact with external tools and services.
In this tutorial, we’re creating an MCP server that allows MCP Client (Claude Desktop) to query Monad testnet to check MON balance of an account.
Prerequisites
- Node.js (v16 or later)
npmoryarn- Claude Desktop
Getting Started
- Clone this repository
git clone https://github.com/monad-developers/monad-mcp-tutorial.git
- Install dependencies:
npm install
Building the MCP server
Monad Testnet related configuration is already added to index.ts in the src folder.
Define the server instance
// Create a new MCP server instance
const server = new McpServer({
name: "monad-testnet",
version: "0.0.1",
// Array of supported tool names that clients can call
capabilities: ["get-mon-balance"]
});
Defining the MON balance tool
Below is the scaffold of the get-mon-balance tool:
server.tool(
// Tool ID
"get-mon-balance",
// Description of what the tool does
"Get MON balance for an address on Monad testnet",
// Input schema
{
address: z.string().describe("Monad testnet address to check balance for"),
},
// Tool implementation
async ({ address }) => {
// code to check MON balance
}
);
Let’s add the MON balance check implementation to the tool:
server.tool(
// Tool ID
"get-mon-balance",
// Description of what the tool does
"Get MON balance for an address on Monad testnet",
// Input schema
{
address: z.string().describe("Monad testnet address to check balance for"),
},
// Tool implementation
async ({ address }) => {
try {
// Check MON balance for the input address
const balance = await publicClient.getBalance({
address: address as `0x${string}`,
});
// Return a human friendly message indicating the balance.
return {
content: [
{
type: "text",
text: `Balance for ${address}: ${formatUnits(balance, 18)} MON`,
},
],
};
} catch (error) {
// If the balance check process fails, return a graceful message back to the MCP client indicating a failure.
return {
content: [
{
type: "text",
text: `Failed to retrieve balance for address: ${address}. Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
...
"monad-mcp": {
"command": "node",
"args": [
"/<path-to-project>/build/index.js"
]
}
}
}