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
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Query action name | |
| params | No | JSON parameters for the query | |
| contract | No | Contract name | nix.q |
| environment | No | Environment (dev, uat, cdev, perf, simnext, prod, local) | dev |
Implementation Reference
- src/nix_mcp/server_fastmcp.py:89-100 (handler)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
- src/nix_mcp/tools.py:116-163 (helper)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)}" )]