Skip to main content
Glama

get_contract_info

Retrieve detailed information about a specific smart contract on the Neo N3 blockchain by providing the contract name and network (mainnet or testnet).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractNameYesContract name
networkNoNetwork to use: "mainnet" or "testnet"

Implementation Reference

  • Primary handler implementation for the 'get_contract_info' MCP tool. Retrieves contract details (name, description, scriptHash, operations) from ContractService based on contractName and network, formats as JSON response.
    this.server.tool(
      'get_contract_info',
      {
        contractName: z.string().describe('Contract name'),
        network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'),
      },
      async ({ contractName, network }) => {
        const contractService = await this.getContractService(network);
    
        try {
          const contract = contractService.getContract(contractName);
          const operations = contractService.getContractOperations(contractName);
          const scriptHash = contractService.getContractScriptHash(contractName);
    
          const result = {
            name: contract.name,
            description: contract.description,
            scriptHash,
            operations,
            network: contractService.getNetwork()
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          throw new Error(`Contract ${contractName} not found or not available on this network`);
        }
      }
    );
  • Input schema validation for get_contract_info tool using Zod schema: contractName (required string), network (optional string).
    {
      contractName: z.string().describe('Contract name'),
      network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'),
    },
  • src/index.ts:299-333 (registration)
    Registers the 'get_contract_info' tool with the MCP McpServer instance.
    this.server.tool(
      'get_contract_info',
      {
        contractName: z.string().describe('Contract name'),
        network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'),
      },
      async ({ contractName, network }) => {
        const contractService = await this.getContractService(network);
    
        try {
          const contract = contractService.getContract(contractName);
          const operations = contractService.getContractOperations(contractName);
          const scriptHash = contractService.getContractScriptHash(contractName);
    
          const result = {
            name: contract.name,
            description: contract.description,
            scriptHash,
            operations,
            network: contractService.getNetwork()
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          throw new Error(`Contract ${contractName} not found or not available on this network`);
        }
      }
    );
  • Helper method in ContractService that returns detailed operations information for a specific contract, used by the tool handler.
    getContractOperations(contractName: string): any {
      try {
        // Get the contract definition
        const contract = this.getContract(contractName);
    
        // Return the operations with additional metadata
        return {
          operations: contract.operations,
          count: Object.keys(contract.operations).length,
          contractName: contract.name,
          network: this.network,
          available: this.isContractAvailable(contractName)
        };
      } catch (error) {
        // If it's already a ContractError, rethrow it
        if (error instanceof ContractError) {
          throw error;
        }
    
        // Otherwise, wrap it in a ContractError
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new ContractError(`Failed to get contract operations: ${errorMessage}`);
      }
    }
Install Server

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/r3e-network/neo-n3-mcp'

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