Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_query_open_targets_graphql

Execute GraphQL queries to retrieve biomedical data on targets, diseases, drugs, and variants from the Open Targets API for research and analysis.

Instructions

Execute GraphQL queries against the Open Targets API. Use get_open_targets_query_examples() or get_open_targets_graphql_schema() first.

Returns: dict: GraphQL response with data field containing targets, diseases, drugs, variants, studies or error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_stringYesGraphQL query string starting with 'query' keyword
variablesNoOptional variables for the GraphQL query

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that implements the bc_query_open_targets_graphql tool. It takes a GraphQL query string and optional variables, executes it against the Open Targets GraphQL API, and returns the response or error.
    @core_mcp.tool()
    def query_open_targets_graphql(
        query_string: Annotated[str, Field(description="GraphQL query string starting with 'query' keyword")],
        variables: Annotated[Optional[dict], Field(description="Optional variables for the GraphQL query")] = None,
    ) -> dict:
        """Execute GraphQL queries against the Open Targets API. Use get_open_targets_query_examples() or get_open_targets_graphql_schema() first.
    
        Returns:
            dict: GraphQL response with data field containing targets, diseases, drugs, variants, studies or error message.
        """
        base_url = "https://api.platform.opentargets.org/api/v4/graphql"
        try:
            response = execute_graphql_query(base_url, query_string, variables)
            return response
        except Exception as e:
            return {"error": f"Failed to execute GraphQL query: {e!s}"}
  • Registers the core_mcp server (containing the tool) into the main BioContextAI MCP app under the 'bc' prefix (slugify('BC')), making the tool available as 'bc_query_open_targets_graphql'.
    for mcp in [core_mcp, *(await get_openapi_mcps())]:
        await mcp_app.import_server(
            mcp,
            slugify(mcp.name),
        )
  • Creates the core_mcp FastMCP server instance named 'BC', onto which tools like query_open_targets_graphql are registered via the @core_mcp.tool() decorator.
    core_mcp = FastMCP(  # type: ignore
        "BC",
        instructions="Provides access to biomedical knowledge bases.",
    )
  • Utility function used by the handler to execute the GraphQL query against the specified endpoint.
    def execute_graphql_query(endpoint_url, query_string, variables=None, headers=None) -> dict:
        """Make a generic GraphQL API call.
    
        Args:
            endpoint_url (str): The GraphQL endpoint URL
            query_string (str): The GraphQL query or mutation as a string
            variables (dict, optional): Variables for the GraphQL query
            headers (dict, optional): HTTP headers to include
    
        Returns:
            dict: The response data from the GraphQL API
        """
        # Set default headers if none provided
        if headers is None:
            headers = {
                "Content-Type": "application/json",
            }
    
        # Prepare the transport
        transport = RequestsHTTPTransport(
            url=endpoint_url,
            headers=headers,
            use_json=True,
        )
    
        # Create a client
        client = Client(transport=transport)
    
        # Parse the query string
        try:
            query = gql(query_string)
        except Exception as e:
            return {"status": "error", "message": f"Failed to parse query: {e!s}"}
    
        try:
            result = client.execute(query, variable_values=variables)
            return {"status": "success", "data": result}
        except Exception as e:
            return {"status": "error", "message": str(e)}
  • Pydantic-based input schema definition for the tool parameters using Annotated and Field for descriptions.
    def query_open_targets_graphql(
        query_string: Annotated[str, Field(description="GraphQL query string starting with 'query' keyword")],
        variables: Annotated[Optional[dict], Field(description="Optional variables for the GraphQL query")] = None,
    ) -> dict:
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions that the tool returns a dict with a data field containing targets, diseases, etc., or an error message, which adds some context about output structure and error handling. However, it lacks details on rate limits, authentication needs, or potential side effects (e.g., whether it's read-only or mutative), leaving gaps in behavioral understanding for an AI agent.

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 highly concise and well-structured, consisting of two sentences that efficiently convey purpose, usage guidelines, and return value. Every sentence earns its place: the first states what the tool does and when to use it, and the second clarifies the output format. There is no wasted verbiage, making it easy for an agent to parse quickly.

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

Completeness4/5

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

Given the tool's complexity (executing arbitrary GraphQL queries), the description is reasonably complete. It includes usage prerequisites and output details, and since an output schema exists, it doesn't need to explain return values further. However, without annotations, it could benefit from more behavioral context (e.g., rate limits or error conditions), but the presence of an output schema and clear guidelines mitigates this gap.

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

Parameters3/5

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

Schema description coverage is 100%, meaning the input schema already fully documents the two parameters (query_string and variables). The description does not add any additional semantic information about these parameters beyond what the schema provides (e.g., it doesn't explain query syntax or variable usage further). According to the rules, with high schema coverage, the baseline is 3 even without param info in the description.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Execute GraphQL queries against the Open Targets API.' It specifies the verb ('execute') and resource ('GraphQL queries against the Open Targets API'), which is specific and unambiguous. However, it doesn't explicitly differentiate from its sibling tools like bc_get_open_targets_graphql_schema or bc_get_open_targets_query_examples, which are related but serve different purposes.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: 'Use get_open_targets_query_examples() or get_open_targets_graphql_schema() first.' This clearly indicates prerequisites and alternatives, helping the agent understand the proper workflow and when to choose this tool over others. It effectively distinguishes it from sibling tools by establishing a sequence of operations.

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/biocontext-ai/knowledgebase-mcp'

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