Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_get_kegg_id_by_gene_symbol

Convert gene symbols to KEGG IDs for pathway analysis. Use this tool to map gene symbols from organisms like human, mouse, or yeast to their corresponding KEGG gene identifiers.

Instructions

Convert gene symbol to KEGG ID for use in subsequent API calls. Returns KEGG gene ID required for query_kegg().

Returns: str or dict: KEGG gene ID string (e.g., 'hsa:7157') or error dict.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gene_symbolYesGene symbol (e.g., 'TP53' for human, 'Trp53' for mouse)
organism_codeYesTaxonomy ID: 9606 (human), 10090 (mouse), 10116 (rat), 562 (E. coli), 4932 (yeast)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function `get_kegg_id_by_gene_symbol` decorated with `@core_mcp.tool()`, implements the logic to retrieve KEGG gene ID from gene symbol and organism code. Uses Ensembl REST API to get Entrez ID, then KEGG conversion API. Tool name prefixed to 'bc_get_kegg_id_by_gene_symbol' due to 'BC' MCP server name.
    @core_mcp.tool()
    def get_kegg_id_by_gene_symbol(
        gene_symbol: Annotated[str, Field(description="Gene symbol (e.g., 'TP53' for human, 'Trp53' for mouse)")],
        organism_code: Annotated[
            str, Field(description="Taxonomy ID: 9606 (human), 10090 (mouse), 10116 (rat), 562 (E. coli), 4932 (yeast)")
        ],
    ) -> str | dict:
        """Convert gene symbol to KEGG ID for use in subsequent API calls. Returns KEGG gene ID required for query_kegg().
    
        Returns:
            str or dict: KEGG gene ID string (e.g., 'hsa:7157') or error dict.
        """
        if not gene_symbol or not organism_code:
            return "Gene symbol and organism code are required."
    
        organism_name = "human" if organism_code == "9606" else "mouse" if organism_code == "10090" else None
        if organism_name is None:
            return {"error": "Unsupported organism code. Please use 9606 for human or 10090 for mouse."}
    
        # Get the Entrez ID
        entrez_url = f"https://rest.ensembl.org/xrefs/name/{organism_name}/{gene_symbol}?content-type=application/json&species={organism_code}"
        try:
            response = requests.get(entrez_url)
            response.raise_for_status()
            data = response.json()
    
            # Filter the data for the first entry where the dbname is "EntrezGene"
            entrez_id = next((item["primary_id"] for item in data if item["dbname"] == "EntrezGene"), None)
        except requests.exceptions.RequestException as e:
            return {"error": f"Failed to fetch Entrez ID: {e!s}"}
        if not entrez_id:
            return {"error": f"No Entrez ID found for gene symbol: {gene_symbol}"}
    
        if not gene_symbol or not organism_code:
            return "Gene symbol and organism code are required."
    
        # Construct the query
        query = f"ncbi-geneid:{entrez_id}"
        path = f"conv/genes/{query}"
    
        # Execute the query
        try:
            return execute_kegg_query(path)
        except Exception as e:
            return {"error": f"Failed to fetch KEGG ID: {e!s}"}
  • Defines `core_mcp = FastMCP('BC', ...)`, the FastMCP instance for core biocontext tools. The 'BC' name leads to 'bc_' prefix when imported into main app.
    from fastmcp import FastMCP
    
    core_mcp = FastMCP(  # type: ignore
        "BC",
        instructions="Provides access to biomedical knowledge bases.",
    )
  • Main app setup imports `core_mcp` (and others) into root `mcp_app` using `slugify(mcp.name)` ('bc') as prefix, registering tools like 'bc_get_kegg_id_by_gene_symbol'.
    for mcp in [core_mcp, *(await get_openapi_mcps())]:
        await mcp_app.import_server(
            mcp,
            slugify(mcp.name),
        )
  • Key helper `execute_kegg_query(path)` performs HTTP GET to KEGG REST API endpoint and returns raw response text. Called by the handler to query KEGG gene conversion.
    def execute_kegg_query(path: str) -> str:
        """Internal helper - executes the HTTP GET and returns raw text."""
        base = "https://rest.kegg.jp"
        url = f"{base}/{path.lstrip('/')}"
        r = requests.get(url, timeout=30.0)
        r.raise_for_status()
        return r.text
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 describes the return behavior (KEGG ID string or error dict) and mentions the tool's purpose in a workflow context, which adds useful context beyond basic functionality. However, it doesn't address potential limitations like rate limits, authentication requirements, or what happens with invalid inputs beyond the error dict mention.

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 concise and well-structured with just two sentences. The first sentence states the core purpose and context, while the second clearly documents the return format. Every word earns its place with no redundancy or unnecessary information, 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 straightforward purpose (ID conversion), 100% schema coverage, and the presence of an output schema (implied by 'Has output schema: true'), the description provides adequate context. It explains the tool's role in a workflow and documents the return format. The main gap is the lack of behavioral details that would be helpful without annotations, but the output schema likely covers return values.

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?

With 100% schema description coverage, the input schema already fully documents both parameters with clear descriptions and examples. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline expectation but doesn't provide extra value. The description focuses on the tool's purpose and output rather than parameter details.

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 tool's purpose with a specific verb ('Convert') and resource ('gene symbol to KEGG ID'), distinguishing it from sibling tools like 'bc_get_ensembl_id_from_gene_symbol' or 'bc_get_uniprot_id_by_protein_symbol' which perform different ID conversions. It explicitly mentions the downstream use case ('for use in subsequent API calls') and references a specific sibling tool ('query_kegg()'), providing clear differentiation.

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 usage guidance by stating when to use this tool ('for use in subsequent API calls') and naming a specific alternative scenario ('Returns KEGG gene ID required for query_kegg()'). It clearly establishes the tool's role in a workflow context, helping the agent understand this is a preparatory step for another specific tool rather than a standalone query.

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