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)

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

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