get_batch_protein_info
Retrieve detailed protein information for multiple UniProt accession numbers, including names, functions, sequences, and organism data, directly from UniProt, via a single query.
Instructions
Get protein information for multiple accession No.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessions | Yes | List of UniProt accession No. |
Implementation Reference
- src/uniprot_mcp_server/server.py:185-205 (handler)Handler logic within the call_tool function that processes the get_batch_protein_info tool request. It loops through the list of accessions, calls the fetch_protein_info helper for each, handles errors, and returns a JSON dump of the results.elif name == "get_batch_protein_info": accessions = arguments.get("accessions", []) if not accessions: raise ValueError("At least one accession No. is required") results = [] for accession in accessions: try: protein_info = await fetch_protein_info(accession) results.append(protein_info) except httpx.HTTPError as e: results.append( { "accession": accession, "error": f"Failed to fetch data: {str(e)}", } ) return [ TextContent(type="text", text=json.dumps(results, indent=2)) ]
- src/uniprot_mcp_server/server.py:95-109 (registration)Registration of the get_batch_protein_info tool in the list_tools handler, defining its name, description, and input schema.Tool( name="get_batch_protein_info", description="Get protein information for multiple accession No.", inputSchema={ "type": "object", "properties": { "accessions": { "type": "array", "items": {"type": "string"}, "description": "List of UniProt accession No.", } }, "required": ["accessions"], }, ),
- TypedDict defining the structure of protein information returned by the tool.class ProteinInfo(TypedDict): """Type definition for protein information.""" accession: str protein_name: str function: list[str] sequence: str length: int organism: str
- Helper function used by both get_protein_info and get_batch_protein_info to fetch individual protein data from UniProt API, parse it, and apply caching.async def fetch_protein_info(accession: str) -> ProteinInfo: """Fetch protein information from UniProt API with caching.""" # Check cache first cached_data = self.cache.get(accession) if cached_data: logger.info(f"Cache hit for {accession}") return cached_data logger.info(f"Fetching data for {accession}") async with httpx.AsyncClient() as client: response = await client.get( f"{API_BASE_URL}/{accession}", headers={"Accept": "application/json"}, ) response.raise_for_status() data = response.json() # Extract relevant information protein_info: ProteinInfo = { "accession": accession, "protein_name": data.get("proteinDescription", {}) .get("recommendedName", {}) .get("fullName", {}) .get("value", "Unknown"), "function": [], "sequence": "", "length": 0, "organism": "Unknown", } # Extract function information safely for comment in data.get("comments", []): if comment.get("commentType") == "FUNCTION": texts = comment.get("texts", []) if texts: protein_info["function"].extend( [text.get("value", "") for text in texts] ) # Add sequence information seq_info = data.get("sequence", {}) org_info = data.get("organism", {}) protein_info.update( { "sequence": seq_info.get("value", ""), "length": seq_info.get("length", 0), "organism": org_info.get("scientificName", "Unknown"), } ) # Cache the result self.cache.set(accession, protein_info) return protein_info