Skip to main content
Glama
RockYuan

MCP Smart Contract Analyst

by RockYuan

analyze-verified-contract

Analyze verified smart contracts on the Monad testnet to evaluate functionality and security by inputting a contract address.

Instructions

Analyze a verified contract from an address on the Monad testnet.

Input Schema

NameRequiredDescriptionDefault
addressYesMonad testnet address to analyze verified contract for

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "address": { "description": "Monad testnet address to analyze verified contract for", "type": "string" } }, "required": [ "address" ], "type": "object" }

Implementation Reference

  • The handler function fetches verified contract source code from an API using the provided address, concatenates source files if multiple, and returns formatted text for analysis. Handles errors gracefully.
    async ({ address }) => { try { const apiUrl = process.env.API_URL const apiKey = process.env.API_KEY; if (!apiUrl) { throw new Error("API_URL not set."); } if (!apiKey) { throw new Error("API_KEY not set."); } const url = `${apiUrl}${address}`; const response = await fetch(url, { method: 'GET', headers: { "accept": "application/json", "x-api-key": apiKey } }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); if (data.code !== 0) { throw new Error(`API request failed with error: ${data.message}`); } const sourceCodeList = data.result.sourceCode; if (sourceCodeList && sourceCodeList.length > 0) { const allSourceCode = sourceCodeList .map((item: { content: string }) => item.content) .join('\n\n'); return { content: [ { type: "text", text: `Analyze the source code of smart contract, including its core functionalities, main logic flow, and security aspects:\n\`\`\`\n${allSourceCode}\n\`\`\``, }, ], }; } else { throw new Error(`Failed to retrieve source code`); } } catch (error) { console.error("Error getting contract sourceCode:", error); return { content: [ { type: "text", text: `Failed to retrieve contract sourceCode for address: ${address}. Error: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • src/index.ts:31-101 (registration)
    Registers the 'analyze-verified-contract' tool with MCP server, including name, description, input schema, and handler function.
    server.tool( "analyze-verified-contract", "Analyze a verified contract from an address on the Monad testnet.", { address: z.string().describe("Monad testnet address to analyze verified contract for"), }, async ({ address }) => { try { const apiUrl = process.env.API_URL const apiKey = process.env.API_KEY; if (!apiUrl) { throw new Error("API_URL not set."); } if (!apiKey) { throw new Error("API_KEY not set."); } const url = `${apiUrl}${address}`; const response = await fetch(url, { method: 'GET', headers: { "accept": "application/json", "x-api-key": apiKey } }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); if (data.code !== 0) { throw new Error(`API request failed with error: ${data.message}`); } const sourceCodeList = data.result.sourceCode; if (sourceCodeList && sourceCodeList.length > 0) { const allSourceCode = sourceCodeList .map((item: { content: string }) => item.content) .join('\n\n'); return { content: [ { type: "text", text: `Analyze the source code of smart contract, including its core functionalities, main logic flow, and security aspects:\n\`\`\`\n${allSourceCode}\n\`\`\``, }, ], }; } else { throw new Error(`Failed to retrieve source code`); } } catch (error) { console.error("Error getting contract sourceCode:", error); return { content: [ { type: "text", text: `Failed to retrieve contract sourceCode for address: ${address}. Error: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
  • Zod schema for input parameter 'address' as a string.
    { address: z.string().describe("Monad testnet address to analyze verified contract for"), },

Other Tools

Related Tools

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/RockYuan/mcp-contract-analyst'

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