Skip to main content
Glama

モナドMCPチュートリアル

このプロジェクトは、Monadテストネットと連携するMCPサーバーの作成方法を示します。MCPサーバーは、Monadテストネット上のMONトークン残高を確認するためのツールを提供します。

MCPとは何ですか?

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

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

Related MCP server: Mattermost MCP Server

前提条件

  • Node.js (v16以降)

  • npmまたはyarn

  • クロードデスクトップ

はじめる

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

git clone https://github.com/bble/monad-mcp.git
  1. 依存関係をインストールします:

npm install

MCPサーバーの構築

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

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

// 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"]
});

MONバランスツールの定義

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)
                        }`,
                    },
                ],
            };
        }
    }
);

NFT数を照会する機能を追加

### Add functionality to query NFT count
server.tool(
    // Function identifier
    "get-nft-count",
    // Function description
    "Query the number of NFTs held by an address on the Monad testnet",
    // Parameter definition
    {
        address: z.string().describe("The Monad testnet address to query"),
        nftContract: z.string().describe("NFT contract address")
    },
    // Function implementation
    async ({ address, nftContract }) => {
        try {
            // Call the contract's balanceOf method to get the NFT count
            const balance = await publicClient.readContract({
                address: nftContract as `0x${string}`,
                abi: [
                    {
                        inputs: [{ name: "owner", type: "address" }],
                        name: "balanceOf",
                        outputs: [{ name: "", type: "uint256" }],
                        stateMutability: "view",
                        type: "function"
                    }
                ],
                functionName: "balanceOf",
                args: [address as `0x${string}`]
            });

            // Return the formatted query result
            return {
                content: [
                    {
                        type: "text",
                        text: `The address ${address} holds ${balance.toString()} NFTs in contract ${nftContract}.`,
                    },
                ],
            };
        } catch (error) {
            // Error handling
            return {
                content: [
                    {
                        type: "text",
                        text: `Failed to query NFT count for address ${address}: ${
                        error instanceof Error ? error.message : String(error)
                        }`,
                    },
                ],
            };
        }
    }
);

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

async function main() {
    // Create a transport layer using standard input/output
    const transport = new StdioServerTransport();
    
    // Connect the server to the transport
    await server.connect(transport);
    
    console.error("Monad testnet MCP Server running on stdio");
}

プロジェクトを構築する

npm run build

サーバーの使用準備が完了しました。

Claude DesktopにMCPサーバーを追加する

  1. 「Claude Desktop」を開く

クロードデスクトップ

  1. 設定を開く

クロード > 設定 > 開発者

クロード設定

  1. claude_desktop_config.jsonを開く

クロード・コンフィグ

  1. MCP サーバーの詳細を追加し、ファイルを保存します。

{
  "mcpServers": {
    ...
    "monad-mcp": {
      "command": "node",
      "args": [
        "/<path-to-project>/build/index.js"
      ]
    }
  }
}
  1. 「Claude Desktop」を再起動します

MCPサーバーの使用

これが最終結果です

最終結果

その他のリソース

Install Server
A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bble/monad-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server