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

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:

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