fetch_entry_flatfile
Retrieve UniProt entry flatfiles in txt or fasta format using accession numbers and version identifiers for protein data analysis.
Instructions
Return the UniProt flatfile (txt or fasta) for a specific entry version.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accession | Yes | ||
| version | Yes | ||
| format | No | txt |
Implementation Reference
- src/uniprot_mcp/server.py:173-195 (handler)MCP tool handler for fetch_entry_flatfile. This is the primary implementation decorated with @mcp.tool(), handling input validation and delegating to the raw client helper.@mcp.tool() # type: ignore[misc] async def fetch_entry_flatfile( accession: str, version: str, format: str = "txt", ) -> str: """Return the UniProt flatfile (txt or fasta) for a specific entry version.""" normalized = _validate_accession(accession) normalized_format = format.lower() async with new_client() as client: text = cast( str, await fetch_entry_flatfile_raw( client, normalized, version, format=normalized_format, ), ) if not text: return RESOURCE_NOT_FOUND_MESSAGE.format(accession=normalized) return text
- Supporting utility function (imported as fetch_entry_flatfile_raw) that performs the actual HTTP request to the UniProt API with retry logic and error handling.@retry( # type: ignore[misc] reraise=True, stop=stop_after_attempt(4), wait=_wait_retry_after_or_exponential, retry=retry_if_exception(_should_retry), before_sleep=_before_sleep, ) async def fetch_entry_flatfile( client: httpx.AsyncClient, accession: str, version: str, *, format: str = "txt", ) -> str: """Return a flatfile representation (txt or fasta) for a specific entry version.""" normalized_format = format.lower() if normalized_format not in FLATFILE_ACCEPT: raise ValueError("format must be 'txt' or 'fasta'") headers = {"Accept": FLATFILE_ACCEPT[normalized_format]} params = {"version": version, "format": normalized_format} async with _SEMAPHORE: response = await client.get( f"/uniprotkb/{accession}", params=params, headers=headers, ) if response.status_code == 404: return "" if response.status_code >= 400: if response.status_code in RETRYABLE_STATUS: response.raise_for_status() else: try: response.raise_for_status() except httpx.HTTPStatusError as exc: raise UniProtClientError(str(exc)) from exc return cast(str, response.text)
- src/uniprot_mcp/server.py:173-173 (registration)The @mcp.tool() decorator registers this function as an MCP tool.@mcp.tool() # type: ignore[misc]