Skip to main content
Glama
josefdc

UniProt MCP Server

by josefdc

fetch_entry

Retrieve structured protein data from UniProtKB by accession number to analyze sequences, annotations, and cross-references.

Instructions

Return a structured UniProt entry.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accessionYes
fieldsNo
versionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
goNoGene Ontology annotations extracted from the entry.
idNoUniProt entry name/ID.
xrefsNoCross-references to external databases.
featuresNoAnnotated sequence features.
organismNoScientific name of the source organism.
reviewedYesTrue for Swiss-Prot, False for TrEMBL.
sequenceNoProtein sequence metadata when available.
accessionYesPrimary accession identifier.
raw_payloadNoOriginal UniProt payload for debugging or future enrichment.
taxonomy_idNoNCBI taxonomy identifier for the organism.
gene_symbolsNoCanonical gene symbols associated with the entry.
protein_nameNoRecommended protein name where available.

Implementation Reference

  • The handler function for the 'fetch_entry' tool, registered via @mcp.tool(). Fetches UniProt entry JSON, handles missing entries with a stub, and parses to Entry model.
    @mcp.tool()  # type: ignore[misc]
    async def fetch_entry(
        accession: str,
        fields: list[str] | None = None,
        version: str | None = None,
    ) -> Entry:
        """Return a structured UniProt entry."""
    
        if version is not None:
            raise ValueError(
                "Versioned entries are only available as flatfiles. "
                "Use fetch_entry_flatfile(accession, version) for historical versions."
            )
        normalized, payload = await _load_entry(accession, fields=fields)
        if not payload:
            return Entry(
                accession=normalized,
                reviewed=False,
                gene_symbols=[],
                features=[],
                go=[],
                xrefs=[],
            )
        return parse_entry(payload)
  • Pydantic BaseModel defining the output schema Entry returned by the fetch_entry tool.
    class Entry(BaseModel):
        """Normalized UniProtKB entry."""
    
        model_config = ConfigDict(protected_namespaces=())
    
        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, False for TrEMBL.")
        protein_name: str | None = Field(
            default=None, description="Recommended protein name where available."
        )
        gene_symbols: list[str] = Field(
            default_factory=list, description="Canonical gene symbols associated with the entry."
        )
        organism: str | None = Field(
            default=None, description="Scientific name of the source organism."
        )
        taxonomy_id: int | None = Field(
            default=None, description="NCBI taxonomy identifier for the organism."
        )
        sequence: Sequence | None = Field(
            default=None, description="Protein sequence metadata when available."
        )
        features: list[Feature] = Field(
            default_factory=list, description="Annotated sequence features."
        )
        go: list[GOAnnotation] = Field(
            default_factory=list, description="Gene Ontology annotations extracted from the entry."
        )
        xrefs: list[XRef] = Field(
            default_factory=list, description="Cross-references to external databases."
        )
        raw_payload: dict[str, object] | None = Field(
            default=None,
            description="Original UniProt payload for debugging or future enrichment.",
        )
  • Helper function parse_entry that transforms raw UniProt JSON into the structured Entry model, invoked by the fetch_entry handler.
    def parse_entry(js: dict[str, Any]) -> Entry:
        """Convert a UniProt entry payload into the Entry model."""
    
        accession = js.get("primaryAccession") or js.get("accession")
        if not accession:
            raise ValueError("UniProt entry payload missing primary accession.")
    
        entry_type = js.get("entryType") or ""
        xrefs, go_terms = _extract_xrefs(js)
    
        entry = Entry(
            accession=str(accession),
            id=js.get("uniProtkbId") or js.get("id"),
            reviewed=entry_type.startswith("UniProtKB reviewed"),
            protein_name=_extract_protein_name(js),
            gene_symbols=_extract_gene_symbols(js),
            organism=(js.get("organism") or {}).get("scientificName")
            if isinstance(js.get("organism"), dict)
            else None,
            taxonomy_id=_to_int_or_none((js.get("organism") or {}).get("taxonId"))
            if isinstance(js.get("organism"), dict)
            else None,
            sequence=_extract_sequence(js),
            features=_extract_features(js),
            go=_extract_go(js) or go_terms,
            xrefs=xrefs,
            raw_payload=js,
        )
        return entry
  • Internal helper _load_entry used by fetch_entry to fetch and normalize the raw JSON payload from UniProt API.
    async def _load_entry(
        accession: str,
        *,
        fields: Iterable[str] | None = None,
    ) -> tuple[str, dict[str, Any]]:
        normalized = _validate_accession(accession)
        async with new_client() as client:
            payload = await fetch_entry_json(client, normalized, fields=fields)
        return normalized, cast(dict[str, Any], payload)

Schema Changelog

Changes observed during successful MCP inspections.

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

TDQS

C2.4/5.0
Behavior2/5

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

With no annotations, the description is the sole source of behavioral info. It only says 'structured' without explaining behavior like auth, errors, or idempotency. Output schema exists but is not described.

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

Conciseness3/5

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

The description is one sentence, concise, but so minimal that it sacrifices informativeness. It could be expanded while staying concise.

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

Completeness1/5

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

Given 3 parameters, no annotations, and existing output schema, the description fails to provide sufficient context for correct usage. It omits parameter roles, output format, and use cases.

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

Parameters1/5

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

Schema description coverage is 0%, so the description must compensate. It adds no explanation for parameters (accession, fields, version) beyond their names, leaving the agent uninformed.

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

Purpose4/5

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

The description clearly states the action (return) and resource (structured UniProt entry). However, it does not differentiate from sibling tools like fetch_entry_flatfile, so it could be more specific.

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 on when to use this tool versus alternatives. Sibling tools exist but are not mentioned, and no usage context is provided.

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