Skip to main content
Glama
cuongpo

Rootstock MCP Server

by cuongpo

call_contract

Execute read-only smart contract methods on the Rootstock blockchain by specifying the contract address, method name, and parameters using the standardized Model Context Protocol APIs.

Instructions

Call a smart contract method (read-only)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiNoOptional contract ABI
contractAddressYesSmart contract address
methodNameYesMethod name to call
parametersNoMethod parameters

Implementation Reference

  • MCP server handler for 'call_contract' tool: calls rootstockClient.callContract and returns formatted result or error.
    private async handleCallContract(params: CallContractParams) {
      try {
        const result = await this.rootstockClient.callContract(
          params.contractAddress,
          params.methodName,
          params.parameters || [],
          params.abi
        );
        return {
          content: [
            {
              type: 'text',
              text: `Contract Call Result:\n\nContract: ${params.contractAddress}\nMethod: ${params.methodName}\nResult: ${JSON.stringify(result.result, null, 2)}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to call contract: ${error}`);
      }
    }
  • TypeScript interface defining input parameters for call_contract: contract address, method, params, optional ABI.
    export interface CallContractParams {
      contractAddress: string;
      methodName: string;
      parameters?: any[];
      abi?: any[];
    }
  • src/index.ts:316-343 (registration)
    Tool registration in MCP server's getAvailableTools(): defines name, description, and inputSchema for 'call_contract'.
    {
      name: 'call_contract',
      description: 'Call a smart contract method (read-only)',
      inputSchema: {
        type: 'object',
        properties: {
          contractAddress: {
            type: 'string',
            description: 'Smart contract address',
          },
          methodName: {
            type: 'string',
            description: 'Method name to call',
          },
          parameters: {
            type: 'array',
            description: 'Method parameters',
            items: {},
          },
          abi: {
            type: 'array',
            description: 'Optional contract ABI',
            items: {},
          },
        },
        required: ['contractAddress', 'methodName'],
      },
    },
  • Low-level implementation in RootstockClient: creates ethers.Contract and performs read-only method call using provided or generated ABI.
    async callContract(
      contractAddress: string,
      methodName: string,
      parameters: any[] = [],
      abi?: any[]
    ): Promise<ContractCallResponse> {
      try {
        // Use a basic ABI if none provided
        const contractAbi = abi || [
          `function ${methodName}(${parameters.map((_, i) => `uint256 param${i}`).join(', ')}) view returns (uint256)`,
        ];
    
        const contract = new ethers.Contract(contractAddress, contractAbi, this.getProvider());
        const result = await contract[methodName](...parameters);
    
        return {
          result: result.toString(),
        };
      } catch (error) {
        throw new Error(`Failed to call contract: ${error}`);
      }
    }

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/cuongpo/rootstock-mcp'

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