search_genes
Search for specific genes in the NCBI database by entering a gene name, symbol, or query. Retrieve relevant gene information quickly with customizable result limits.
Instructions
Search for genes in NCBI database using a query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_results | No | Maximum number of results to return (default: 20) | |
| query | Yes | Search query (gene name, symbol, etc.) |
Implementation Reference
- ncbi_gene_mcp_client/bridge.py:98-124 (handler)Core handler implementation for the search_genes tool. Performs an ESearch query on the NCBI Gene database via Entrez API, returning a SearchResult with hit count, ID list, and query translation.def search_genes(self, query: str, max_results: int = 20) -> SearchResult: """ Search for genes using NCBI Entrez. Args: query: Search query (gene name, symbol, etc.) max_results: Maximum number of results to return Returns: SearchResult object containing IDs and metadata """ params = { "db": "gene", "term": query, "retmax": max_results } response = self._make_request("esearch", params) esearch_result = response.get("esearchresult", {}) return SearchResult( count=int(esearch_result.get("count", 0)), ids=esearch_result.get("idlist", []), query_translation=esearch_result.get("querytranslation") )
- MCP server dispatch handler for 'search_genes' tool calls. Extracts parameters, invokes the bridge implementation, and formats the SearchResult into MCP-standard text content response.if name == "search_genes": query = arguments.get("query") max_results = arguments.get("max_results", 20) if not query: raise ValueError("query is required") result = self.bridge.search_genes(query, max_results) self.send_response({ "content": [{ "type": "text", "text": f"Found {result.count} genes matching '{query}':\n\nGene IDs: {', '.join(result.ids[:10])}\n\nQuery translation: {result.query_translation or 'N/A'}" }] })
- ncbi_gene_mcp_client/mcp_server.py:70-88 (registration)Registration of the 'search_genes' tool in the MCP server's tools/list response, including tool name, description, and input schema definition.{ "name": "search_genes", "description": "Search for genes in NCBI database using a query", "inputSchema": { "type": "object", "properties": { "query": { "type": "string", "description": "Search query (gene name, symbol, etc.)" }, "max_results": { "type": "integer", "description": "Maximum number of results to return (default: 20)", "default": 20 } }, "required": ["query"] } },
- ncbi_gene_mcp_client/models.py:33-39 (schema)Pydantic model defining the structure of search results returned by the search_genes handler, used for type validation and serialization.class SearchResult(BaseModel): """Model for search results from NCBI Entrez.""" count: int = Field(description="Total number of results") ids: List[str] = Field(description="List of IDs found") query_translation: Optional[str] = Field(default=None, description="Translated query")