Skip to main content
Glama

모나드 MCP 튜토리얼

이 프로젝트는 Monad 테스트넷과 연동되는 MCP 서버를 만드는 방법을 보여줍니다. MCP 서버는 Monad 테스트넷에서 MON 토큰 잔액을 확인하는 도구를 제공합니다.

MCP란 무엇인가요?

MCP(Model Context Protocol)는 AI 모델이 외부 도구 및 서비스와 상호 작용할 수 있도록 하는 표준입니다.

이 튜토리얼에서는 MCP 클라이언트(Claude Desktop)가 Monad 테스트넷에 쿼리를 보내 계정의 MON 잔액을 확인할 수 있는 MCP 서버를 만들어 보겠습니다.

Related MCP server: GOAT MCP Server

필수 조건

  • Node.js(v16 이상)

  • npm 또는 yarn

  • 클로드 데스크탑

시작하기

  1. 이 저장소를 복제하세요

지엑스피1

  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. 설정 열기

Claude > 설정 > 개발자

클로드 세팅

  1. claude_desktop_config.json 엽니다.

클로드 구성

  1. MCP 서버에 대한 세부 정보를 추가하고 파일을 저장합니다.

{ "mcpServers": { ... "monad-mcp": { "command": "node", "args": [ "/<path-to-project>/build/index.js" ] } } }
  1. "Claude Desktop"을 다시 시작하세요

MCP 서버 사용

최종 결과는 다음과 같습니다.

최종 결과

추가 자료

One-click Deploy
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