Skip to main content
Glama

querySubgraph

Execute GraphQL queries against blockchain subgraphs to retrieve indexed data in JSON format for analysis and integration.

Instructions

Execute a GraphQL query against a specified subgraph.

Args: subgraphId (str): The ID of the subgraph to query. query (str): The GraphQL query string to execute.

Returns: str: Query result in JSON format, or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subgraphIdYes
queryYes

Implementation Reference

  • main.py:90-110 (handler)
    The handler function for the 'querySubgraph' tool. It is decorated with @mcp.tool() for registration. It sends a POST request with the provided GraphQL query to the subgraph endpoint on TheGraph API and returns the JSON response or error.
    async def querySubgraph(subgraphId: str, query: str) -> str:
        """Execute a GraphQL query against a specified subgraph.
    
        Args:
            subgraphId (str): The ID of the subgraph to query.
            query (str): The GraphQL query string to execute.
    
        Returns:
            str: Query result in JSON format, or an error message.
        """
        if not API_KEY:
            return "API key is required. Set THEGRAPH_API_KEY in your .env file."
        
        async with httpx.AsyncClient() as client:
            url = f"{THEGRAPH_API_BASE_URL}{API_KEY}/subgraphs/id/{subgraphId}"
            try:
                response = await client.post(url, json={"query": query}, timeout=10)
                response.raise_for_status()
                return json.dumps(response.json())
            except httpx.HTTPError as e:
                return f"Error executing query: {str(e)}"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool executes queries and returns results or errors, which covers basic functionality. However, it doesn't mention authentication requirements, rate limits, timeout behavior, or whether queries are read-only or can mutate data. The description adds some value but lacks comprehensive behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly structured with a clear purpose statement followed by well-organized sections for Args and Returns. Every sentence earns its place, with no redundant information. The formatting with clear headings makes it easy to parse while remaining extremely concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of GraphQL query execution and the lack of both annotations and output schema, the description provides adequate but minimal information. It covers the basic purpose and parameters but doesn't explain the format of query results beyond 'JSON format', nor does it address error handling, authentication, or other operational considerations that would be helpful for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate for the lack of parameter documentation in the schema. It clearly explains that 'subgraphId' identifies which subgraph to query and 'query' is the GraphQL query string to execute, providing essential semantic meaning beyond the bare schema. However, it doesn't specify format requirements or constraints for these parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a GraphQL query') and resource ('against a specified subgraph'), distinguishing it from the sibling tool 'getSubgraphSchema' which presumably retrieves schema information rather than executing queries. The verb+resource combination is precise and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying it's for executing GraphQL queries against subgraphs, but doesn't explicitly state when to use this tool versus alternatives like 'getSubgraphSchema' or other query methods. It provides clear context but lacks explicit comparison or exclusion guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/kukapay/thegraph-mcp'

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