query
Execute blockchain data queries on the NIX system to retrieve blocks, transactions, account information, and network status across multiple blockchain networks using JSON parameters.
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)Primary MCP tool handler for the 'query' tool. Includes input schema via Pydantic Field validators, registration via @mcp.tool() decorator, and execution logic delegating to internal handle_query function.@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/server_fastmcp.py:91-94 (schema)Input schema definition for the 'query' tool using Pydantic Fields, specifying required action name, optional params dict, contract, and environment.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)")
- src/nix_mcp/tools.py:116-163 (helper)Internal helper function containing the core query execution logic: invokes SimpleNixClient.query() with provided parameters and formats the response as TextContent for MCP.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)}" )]