bc_get_open_targets_graphql_schema
Retrieve the Open Targets GraphQL schema to access structured biomedical data through BioContextAI Knowledgebase MCP, facilitating integration with AI systems and biomedical knowledge bases.
Instructions
Fetch the Open Targets GraphQL schema.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The core handler function for the tool, decorated with @core_mcp.tool(). Fetches the Open Targets GraphQL schema from the API endpoint and returns it as a printable string or an error message.@core_mcp.tool() def get_open_targets_graphql_schema() -> dict: """Retrieve the Open Targets GraphQL schema for query construction. Returns: dict: Schema string in format {'schema': '...'} containing GraphQL type definitions or error message. """ base_url = "https://api.platform.opentargets.org/api/v4/graphql" try: schema = fetch_graphql_schema(base_url) return {"schema": print_schema(schema)} except Exception as e: return {"error": f"Failed to fetch Open Targets GraphQL schema: {e!s}"}
- Helper function used by the tool handler to fetch the GraphQL schema from the Open Targets endpoint using gql library.def fetch_graphql_schema(endpoint_url: str) -> GraphQLSchema: """Fetch the GraphQL schema from the given endpoint URL. Args: endpoint_url (str): The GraphQL endpoint URL. Returns: GraphQLSchema: The fetched GraphQL schema. """ # Create a transport with your GraphQL endpoint transport = RequestsHTTPTransport( url=endpoint_url, ) # Create a client client = Client(transport=transport, fetch_schema_from_transport=True) with client as _session: # The schema is automatically fetched and stored in the client if not client.schema: raise ValueError("Failed to fetch schema from the GraphQL endpoint.") return client.schema
- src/biocontext_kb/core/_server.py:1-6 (registration)Creation of the core_mcp FastMCP instance with prefix 'BC', which is used to register all tools including this one via the @core_mcp.tool() decorator. This likely results in the tool name 'bc_get_open_targets_graphql_schema'.from fastmcp import FastMCP core_mcp = FastMCP( # type: ignore "BC", instructions="Provides access to biomedical knowledge bases.", )