MD

monad-developers/monad-mcp-tutorial

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

22 stars 12 forks Качество 53 Тренд 0

Учебник MCP Monad

Обзор

Этот проект демонстрирует, как создать MCP-сервер, который взаимодействует с тестовой сетью Monad. Сервер MCP предоставляет инструмент для проверки остатков токенов MON в тестовой сети Monad. Model Context Protocol (MCP) — это стандарт, позволяющий моделям ИИ взаимодействовать с внешними инструментами и сервисами. В этом руководстве мы создаем MCP-сервер, который позволяет MCP-клиенту (Claude Desktop) запрашивать Monad testnet для проверки баланса MON учетной записи. Node.js (v16 или более поздний) - npm или yarn - Claude Desktop Конфигурация Monad Testnet уже добавлена в index.ts в папке src. Ниже приведен каркас инструмента Get-mon-balance: Добавим реализацию проверки баланса MON в инструмент: 4. Добавить информацию о MCP-сервере и сохранить файл.

Обзор (машинный перевод)

Этот проект демонстрирует, как создать MCP-сервер, который взаимодействует с тестовой сетью Monad. Сервер MCP предоставляет инструмент для проверки остатков токенов MON в тестовой сети Monad.

Что такое MCP?

Model Context Protocol (MCP) — это стандарт, позволяющий моделям ИИ взаимодействовать с внешними инструментами и сервисами.

В этом руководстве мы создаем MCP-сервер, который позволяет MCP-клиенту (Claude Desktop) запрашивать Monad testnet для проверки баланса MON учетной записи.

Предпосылки

Node.js (v16 или более поздняя версия)

  • [[Т0]] или [[Т1]] Клод Десктоп

Начало работы

  1. Клонировать это хранилище

  2. Установить зависимости:

Создание MCP-сервера

Конфигурация Monad Testnet уже добавлена в index.ts в папке src.

Определение сервера

###Определение инструмента баланса

Ниже приведена таблица [[Т4]]:

Добавим реализацию проверки баланса MON в инструмент:

Инициализируйте транспорт и сервер из функции main

Постройте проект

Сервер уже готов к использованию!

Добавление MCP-сервера в Claude Desktop

  1. Открыть “Claude Desktop”

  2. Открытые настройки

Клод Настройки > разработчик

  1. Открыть [6]

Эта страница переведена автоматически. Технические детали смотрите в оригинале.

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)
  • npm or yarn
  • Claude Desktop

Getting Started

  1. Clone this repository
git clone https://github.com/monad-developers/monad-mcp-tutorial.git
  1. 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)
                        }`,
                    },
                ],
            };
Открыть полный README на GitHub

Установка

This server does not publish a one-line install command.

Open the repository installation guide Новичок в MCP? Начните с руководства на mcpskill.org →

Конфигурация

{ "mcpServers": { ... "monad-mcp": { "command": "node", "args": [ "/<path-to-project>/build/index.js" ] } } }