Skip to main content
Glama
pokt-network

Grove Public Endpoints MCP Server

Official
by pokt-network

call_rpc_method

Execute JSON-RPC methods on blockchain networks using Grove's public endpoints. Specify blockchain, method, and parameters to interact with Ethereum, Solana, Cosmos, and Layer 2 solutions without authentication.

Instructions

Call a JSON-RPC method on a specific blockchain service

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockchainYesBlockchain name (e.g., "ethereum", "polygon")
methodYesRPC method name (e.g., "eth_blockNumber", "eth_getBalance")
paramsNoArray of parameters for the RPC method
networkNoNetwork type (defaults to mainnet)

Implementation Reference

  • Main handler execution logic for the 'call_rpc_method' tool. Performs safety validation, retrieves the appropriate blockchain service, and calls the underlying callRPCMethod.
    case 'call_rpc_method': {
      const blockchain = args?.blockchain as string;
      const method = args?.method as string;
      const params = (args?.params as any[]) || [];
      const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet';
    
      // SAFETY CHECK: Validate RPC call before execution
      const safetyCheck = validateRPCCall(blockchain, method, params);
      if (!safetyCheck.safe) {
        return {
          content: [
            {
              type: 'text',
              text: `⛔ UNSAFE RPC CALL BLOCKED\n\n` +
                    `Reason: ${safetyCheck.reason}\n\n` +
                    `Suggestion: ${safetyCheck.suggestion}\n\n` +
                    `This protection prevents session crashes from large responses.`,
            },
          ],
          isError: true,
        };
      }
    
      const service = blockchainService.getServiceByBlockchain(blockchain, network);
    
      if (!service) {
        return {
          content: [
            {
              type: 'text',
              text: `Blockchain service not found: ${blockchain} (${network})`,
            },
          ],
          isError: true,
        };
      }
    
      const result = await blockchainService.callRPCMethod(service.id, method, params);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
        isError: !result.success,
      };
    }
  • Tool schema definition for 'call_rpc_method', specifying input parameters and validation rules.
      name: 'call_rpc_method',
      description: 'Call a JSON-RPC method on a specific blockchain service',
      inputSchema: {
        type: 'object',
        properties: {
          blockchain: {
            type: 'string',
            description: 'Blockchain name (e.g., "ethereum", "polygon")',
          },
          method: {
            type: 'string',
            description: 'RPC method name (e.g., "eth_blockNumber", "eth_getBalance")',
          },
          params: {
            type: 'array',
            description: 'Array of parameters for the RPC method',
          },
          network: {
            type: 'string',
            enum: ['mainnet', 'testnet'],
            description: 'Network type (defaults to mainnet)',
          },
        },
        required: ['blockchain', 'method'],
      },
    },
  • src/index.ts:88-101 (registration)
    Registration of tools on the MCP server, including 'call_rpc_method' via registerBlockchainHandlers call. The tools list is used for listTools and dispatch to handlers.
    const tools: Tool[] = [
      ...registerBlockchainHandlers(server, blockchainService),
      ...registerDomainHandlers(server, domainResolver),
      ...registerTransactionHandlers(server, advancedBlockchain),
      ...registerTokenHandlers(server, advancedBlockchain),
      ...registerMultichainHandlers(server, advancedBlockchain),
      ...registerContractHandlers(server, advancedBlockchain),
      ...registerUtilityHandlers(server, advancedBlockchain),
      ...registerEndpointHandlers(server, endpointManager),
      ...registerSolanaHandlers(server, solanaService),
      ...registerCosmosHandlers(server, cosmosService),
      ...registerSuiHandlers(server, suiService),
      ...registerDocsHandlers(server, docsManager),
    ];
  • Core helper function callRPCMethod that executes the actual JSON-RPC HTTP request to the blockchain service endpoint, handles HTTP/JSON-RPC errors, and returns structured response.
    async callRPCMethod(
      serviceId: string,
      method: string,
      params: any[] = []
    ): Promise<EndpointResponse> {
      const service = this.getServiceById(serviceId);
      if (!service) {
        return {
          success: false,
          error: `Service not found: ${serviceId}`,
        };
      }
    
      const rpcUrl = service.rpcUrl;
    
      try {
        const response = await fetch(rpcUrl, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            jsonrpc: '2.0',
            method,
            params,
            id: 1,
          }),
        });
    
        // Handle HTTP errors (rate limiting, server errors, etc.)
        if (!response.ok) {
          const errorText = await response.text().catch(() => 'Unable to read error response');
          let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
    
          // Common HTTP error interpretations
          if (response.status === 429) {
            errorMessage = `Rate limit exceeded (HTTP 429). The endpoint may be experiencing high traffic.`;
          } else if (response.status === 503) {
            errorMessage = `Service temporarily unavailable (HTTP 503). The endpoint may be overloaded.`;
          } else if (response.status >= 500) {
            errorMessage = `Server error (HTTP ${response.status}). The RPC endpoint encountered an internal error.`;
          }
    
          return {
            success: false,
            error: errorMessage,
            data: {
              httpStatus: response.status,
              httpStatusText: response.statusText,
              responseBody: errorText.substring(0, 500), // Limit error body size
            },
            metadata: {
              timestamp: new Date().toISOString(),
              endpoint: rpcUrl,
            },
          };
        }
    
        const data = await response.json();
    
        // Handle JSON-RPC errors
        if (data.error) {
          return {
            success: false,
            error: data.error.message || 'RPC error',
            data: data.error,
            metadata: {
              timestamp: new Date().toISOString(),
              endpoint: rpcUrl,
            },
          };
        }
    
        return {
          success: true,
          data: data.result,
          metadata: {
            timestamp: new Date().toISOString(),
            endpoint: rpcUrl,
          },
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
          data: {
            errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
            errorStack: error instanceof Error ? error.stack : undefined,
          },
          metadata: {
            timestamp: new Date().toISOString(),
            endpoint: rpcUrl,
          },
        };
      }
    }

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/pokt-network/mcp'

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