Skip to main content
Glama
josefdc

UniProt MCP Server

by josefdc

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
NameRequiredDescriptionDefault
accessionYes
versionYes
formatNotxt

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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)
  • The @mcp.tool() decorator registers this function as an MCP tool.
    @mcp.tool()  # type: ignore[misc]

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.0.0
    • addedInput schema / title
      Added value: +"fetch_entry_flatfileArguments"
  2. First observed

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description must fully disclose behavior. It only states it returns a flatfile, but omits potential rate limits, authentication, size limits, error handling, or whether the response is file content or a URL. This leaves significant uncertainty for the agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that conveys the core purpose. However, it could be considered slightly under-specified; still, it is well-structured and avoids unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters, no annotations, and an output schema (which reduces need to describe return values), the description still lacks crucial context about parameter usage, default behaviors, and edge cases. It is insufficient for an agent to use it confidently without further inference.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description should explain parameters. It clarifies 'format' can be 'txt or fasta', but fails to define 'accession' and 'version' beyond being entry identifiers. No constraints or allowed values are given for these parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns a UniProt flatfile for a specific entry version, explicitly mentioning the available formats (txt or fasta). This distinguishes it from siblings like fetch_entry (likely returns structured data) and get_sequence (returns sequence only).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives such as fetch_entry, get_sequence, or search_uniprot. The agent is left to infer from the name and description alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.