Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

monad-mcp-tutorial

MCP.Pizza Chef: monad-developers

Monad MCP Tutorial is an MCP server that enables querying MON token balances on the Monad testnet. It demonstrates how to build an MCP server that integrates with the Monad blockchain testnet, allowing clients like Claude Desktop to fetch real-time account balance data. This server is built with Node.js and provides a practical example of connecting blockchain data to AI models via MCP.

Use This MCP server To

Query MON token balances on the Monad testnet Integrate Monad blockchain data with AI models Enable Claude Desktop to fetch blockchain account info Demonstrate building MCP servers for blockchain interaction Provide real-time token balance data to MCP clients

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

Initialize the transport and server from the main function

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

Build the project

npm run build

The server is now ready to use!

Adding the MCP server to Claude Desktop

  1. Open "Claude Desktop"

claude desktop

  1. Open Settings

Claude > Settings > Developer

claude settings

  1. Open claude_desktop_config.json

claude config

  1. Add details about the MCP server and save the file.
{
  "mcpServers": {
    ...
    "monad-mcp": {
      "command": "node",
      "args": [
        "/<path-to-project>/build/index.js"
      ]
    }
  }
}
  1. Restart "Claude Desktop"

Using the MCP server

Here's the final result

final result

Further Resources

monad-mcp-tutorial FAQ

How do I set up the monad-mcp-tutorial server?
Clone the repo, install dependencies with npm or yarn, then run the server using Node.js v16 or later.
Which MCP clients can interact with this server?
This server is designed to work with MCP clients like Claude Desktop.
What blockchain network does this MCP server connect to?
It connects to the Monad testnet to query MON token balances.
What programming language is used to build this MCP server?
The server is built using TypeScript/JavaScript running on Node.js.
Can this MCP server be extended to support other blockchain queries?
Yes, the server architecture allows adding more blockchain-related tools and queries.
Is this MCP server compatible with multiple LLM providers?
Yes, it supports interaction with models from OpenAI, Anthropic Claude, and Google Gemini via MCP.
What prerequisites are needed before running this MCP server?
Node.js v16+, npm or yarn, and an MCP client like Claude Desktop are required.
How does this MCP server enhance AI model capabilities?
It provides real-time blockchain context, enabling models to access live token balances during interactions.