search_uniprot
Search the UniProtKB protein database to find curated protein entries, sequences, and annotations using flexible query parameters.
Instructions
Search UniProtKB and return curated hits.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| size | No | ||
| reviewed_only | No | ||
| fields | No | ||
| sort | No | ||
| include_isoform | No |
Implementation Reference
- src/uniprot_mcp/server.py:145-170 (handler)Primary handler function for the 'search_uniprot' tool. Registers the tool via @mcp.tool() decorator, handles input parameters including size capping at 500, optional light fields from env var, calls UniProtClient.search_json, and returns parsed results.@mcp.tool() # type: ignore[misc] async def search_uniprot( query: str, size: int = 10, reviewed_only: bool = False, fields: list[str] | None = None, sort: str | None = None, include_isoform: bool = False, ) -> list[SearchHit]: """Search UniProtKB and return curated hits.""" size = max(1, min(size, 500)) effective_fields = fields if fields is None and os.getenv("UNIPROT_ENABLE_FIELDS"): effective_fields = [FIELDS_SEARCH_LIGHT] async with new_client() as client: payload = await search_json( client, query=query, size=size, reviewed_only=reviewed_only, fields=effective_fields, sort=sort, include_isoform=include_isoform, ) return parse_search_hits(payload)
- Pydantic model defining the output schema for each hit returned by search_uniprot.class SearchHit(BaseModel): """Result entry returned by UniProt search endpoints.""" accession: str = Field(description="Primary accession identifier.") id: str | None = Field(default=None, description="UniProt entry name/ID.") reviewed: bool = Field(description="True for Swiss-Prot hits.") protein_name: str | None = Field( default=None, description="Recommended protein name when available." ) organism: str | None = Field( default=None, description="Scientific name of the source organism." )
- Utility function that transforms raw UniProt search JSON into list of structured SearchHit objects, used by the tool handler.def parse_search_hits(js: dict[str, Any]) -> list[SearchHit]: """Convert a UniProt search response into SearchHit models.""" hits: list[SearchHit] = [] for result in js.get("results") or []: if not isinstance(result, dict): continue accession = result.get("primaryAccession") or result.get("accession") if not accession: continue organism_block = result.get("organism", {}) organism_name = ( organism_block.get("scientificName") if isinstance(organism_block, dict) else None ) entry_type = result.get("entryType") or "" hits.append( SearchHit( accession=str(accession), id=result.get("uniProtkbId") or result.get("id"), reviewed=str(entry_type).startswith("UniProtKB reviewed"), protein_name=_extract_protein_name(result), organism=organism_name, ) ) return hits