Skip to main content
Glama

query

Execute blockchain data queries through the NIX MCP Server to retrieve blocks, transactions, account information, and network status across multiple blockchain networks.

Instructions

Execute a NIX query with JSON parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesQuery action name
paramsNoJSON parameters for the query
contractNoContract namenix.q
environmentNoEnvironment (dev, uat, cdev, perf, simnext, prod, local)dev

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool registration, input schema, and handler for the 'query' tool. Validates parameters and executes via handle_query.
    @mcp.tool()
    async def query(
        action: str = Field(..., description="Query action name"),
        params: Optional[Dict[str, Any]] = Field(default=None, description="JSON parameters for the query"),
        contract: str = Field(default="nix.q", description="Contract name"),
        environment: str = Field(default="dev", description="Environment (dev, uat, cdev, perf, simnext, prod, local)")
    ) -> str:
        """Execute a NIX query with JSON parameters"""
        # Create client with specified environment
        client = SimpleNixClient(environment=environment)
        result = await handle_query(client, action, params, contract, environment)
        return result[0].text
  • Core helper function implementing the query execution logic using SimpleNixClient.query(), handling JSON/text responses and errors.
    async def handle_query(
        client: SimpleNixClient,
        action: str,
        params: Optional[Dict[str, Any]] = None,
        contract: str = "nix.q",
        environment: str = "dev"
    ) -> List[TextContent]:
        """
        Execute a NIX query with JSON parameters
        
        Args:
            client: SimpleNixClient instance
            action: Query action name
            params: JSON parameters for the query
            contract: Contract name (default: nix.q)
            environment: Environment name
        
        Returns:
            List containing TextContent with query result
        """
        try:
            # Execute the query
            result = await client.query(
                contract=contract,
                action=action,
                params=params or {}
            )
            
            # Handle both JSON and raw text responses
            if isinstance(result, dict):
                # Add environment info to result if it's a dict
                result["environment"] = environment
                return [TextContent(
                    type="text",
                    text=json.dumps(result, indent=2)
                )]
            else:
                # Return raw text response
                return [TextContent(
                    type="text",
                    text=str(result)
                )]
        except Exception as e:
            logger.error(f"Error executing query: {e}")
            return [TextContent(
                type="text",
                text=f"Error: {str(e)}"
            )]

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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/haiqiubullish/nix-mcp'

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