search_by_gene_symbol
Search for genes using their symbols, with an optional organism filter, to retrieve detailed information from the NCBI Gene database.
Instructions
Search for genes by symbol with optional organism filter
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organism | No | Optional organism filter (e.g., 'human', 'Homo sapiens') | |
| symbol | Yes | Gene symbol (e.g., 'BRCA1', 'TP53') |
Implementation Reference
- MCP tool handler for 'search_by_gene_symbol': extracts symbol and optional organism from arguments, calls bridge method, formats a textual list of results or 'not found' message, sends as text content response.elif name == "search_by_gene_symbol": symbol = arguments.get("symbol") organism = arguments.get("organism") if not symbol: raise ValueError("symbol is required") results = self.bridge.search_by_gene_symbol(symbol, organism) if not results: response_text = f"No genes found for symbol '{symbol}'" if organism: response_text += f" in organism '{organism}'" else: response_text = f"Found {len(results)} gene(s) for symbol '{symbol}'" if organism: response_text += f" in organism '{organism}'" response_text += ":\n\n" for i, gene in enumerate(results, 1): response_text += f"{i}. {gene.name} (ID: {gene.gene_id})\n" response_text += f" Description: {gene.description}\n" response_text += f" Organism: {gene.organism}\n" if gene.chromosome: response_text += f" Chromosome: {gene.chromosome}\n" response_text += "\n" self.send_response({ "content": [{ "type": "text", "text": response_text }] })
- ncbi_gene_mcp_client/mcp_server.py:117-134 (registration)Registration of the 'search_by_gene_symbol' tool in the tools/list response, including name, description, and input schema.{ "name": "search_by_gene_symbol", "description": "Search for genes by symbol with optional organism filter", "inputSchema": { "type": "object", "properties": { "symbol": { "type": "string", "description": "Gene symbol (e.g., 'BRCA1', 'TP53')" }, "organism": { "type": "string", "description": "Optional organism filter (e.g., 'human', 'Homo sapiens')" } }, "required": ["symbol"] } }
- Input schema for the search_by_gene_symbol tool: object with required 'symbol' string and optional 'organism' string."inputSchema": { "type": "object", "properties": { "symbol": { "type": "string", "description": "Gene symbol (e.g., 'BRCA1', 'TP53')" }, "organism": { "type": "string", "description": "Optional organism filter (e.g., 'human', 'Homo sapiens')" } }, "required": ["symbol"] }
- Core helper function in NCBIBridge that implements the search: constructs Entrez query like 'SYMBOL[gene] AND ORGANISM[organism]', performs esearch for up to 10 IDs, fetches full GeneInfo for each valid one.def search_by_gene_symbol(self, symbol: str, organism: Optional[str] = None) -> List[GeneInfo]: """ Search for genes by symbol and optionally filter by organism. Args: symbol: Gene symbol (e.g., "BRCA1") organism: Optional organism filter (e.g., "human", "Homo sapiens") Returns: List of GeneInfo objects """ query = f"{symbol}[gene]" if organism: query += f" AND {organism}[organism]" search_result = self.search_genes(query, max_results=10) genes = [] for gene_id in search_result.ids: try: gene_info = self.fetch_gene_info(gene_id) genes.append(gene_info) except Exception as e: # Skip genes that can't be fetched continue return genes