MD

monad-developers/monad-mcp-tutorial

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

22 stars 12 forks 品質 53 トレンド 0

Monad MCPチュートリアル

概要

このプロジェクトでは、Monad testnet と相互作用する MCP サーバーを作成する方法を示します。 MCP サーバーは、Monad testnet でMONトークン残高を確認するためのツールを提供しています。 モデルコンテキストプロトコル(MCP)は、AIモデルが外部ツールやサービスとやり取りできる標準です。 このチュートリアルでは、MCP Client (Claude Desktop) が Monad testnet をクエリして、Monad testnet のアカウントのMON残高を確認できるように、MCP サーバーを作成しています。 - Node.js (v16以降) - npm または yarn - Claude デスクトップ Monad Testnet 関連の設定は、src フォルダーの index.ts に追加されます。 以下は、 get-mon-balance ツールの足場です。 ツールにMONバランスチェックの実装を追加してみましょう: 4. MCP サーバーの詳細を追加し、ファイルを保存します.

概要(AI 翻訳)

このプロジェクトでは、Monad testnet と相互作用する MCP サーバーを作成する方法を示します。 MCP サーバーは、Monad testnet でMONトークン残高を確認するためのツールを提供しています。

MCPとは?

モデルコンテキストプロトコル(MCP)は、AIモデルが外部ツールやサービスとやり取りできる標準です。

このチュートリアルでは、MCP Client (Claude Desktop) が Monad testnet をクエリして、Monad testnet のアカウントのMON残高を確認できるように、MCP サーバーを作成しています。

前提条件

  • Node.js(v16以降)
  • [npmまたは[yarn]
  • クロードデスクトップ

はじめる

  1. このリポジトリをクローンする

  2. 依存関係を取付けて下さい:

MCP サーバーの構築

Monad Testnet 関連の設定は、[src] フォルダに [index.ts]] に追加されます。

サーバーインスタンスを定義する

##MONバランスツールの定義

以下は[get-mon-balanceの足場です。

ツールにMONバランスチェックの実装を追加してみましょう:

##[main関数からトランスポートとサーバーを初期化

プロジェクトのビルド

サーバが使えるようになりました!

##ClaudeデスクトップにMCPサーバーを追加する

  1. 「デスクトップをロード」開く

  2. 設定を開く

クロード > 設定 > デベロッパー

  1. 開いた[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)
  • 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)
                        }`,
                    },
                ],
            };
GitHub で README 全文を見る

インストール

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" ] } } }