Skip to main content
Glama

Get GOV.UK Page Section

govuk_get_section
Read-onlyIdempotent

Retrieve the HTML content of a specific section from a GOV.UK page by providing the base path and section anchor ID. Use after obtaining the list of available sections.

Instructions

Get the HTML content of one named section of a GOV.UK page.

Use govuk_get_content first to get the list of available section anchors, then call this with the anchor of the section you want to read.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_pathYesGOV.UK base_path, e.g. '/universal-credit'
anchorYesSection anchor ID from govuk_get_content sections list

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The tool 'govuk_get_section' is registered via the @mcp.tool decorator with name='govuk_get_section' and annotations for title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint.
    @mcp.tool(
        name="govuk_get_section",
        annotations={
            "title": "Get GOV.UK Page Section",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
  • The async function govuk_get_section handles the tool logic: fetches content from GOV.UK Content API using the base_path, then calls parsers.extract_section(payload, anchor) to extract the HTML for the named section. Raises ValueError if the anchor is not found.
    async def govuk_get_section(
        base_path: Annotated[str, Field(description="GOV.UK base_path, e.g. '/universal-credit'", min_length=1, max_length=500)],
        anchor: Annotated[str, Field(description="Section anchor ID from govuk_get_content sections list", min_length=1, max_length=200)],
        ctx: Context,
    ) -> dict:
        """Get the HTML content of one named section of a GOV.UK page.
    
        Use govuk_get_content first to get the list of available section anchors,
        then call this with the anchor of the section you want to read.
        """
        path = base_path.lstrip("/")
        client = _client(ctx)
        resp = await client.get(f"{CONTENT_BASE}/{path}")
        resp.raise_for_status()
        payload = resp.json()
        try:
            html = parsers.extract_section(payload, anchor)
        except KeyError:
            raise ValueError(
                f"Section '{anchor}' not found in '{base_path}'. "
                "Use govuk_get_content to list available anchors."
            )
        return {"base_path": base_path, "anchor": anchor, "content": html}
  • The extract_section function is the core parsing helper. It handles both guide-format pages (using details.parts by slug) and standard pages (slicing HTML between <h2 id='anchor'> tags). Raises KeyError if anchor not found.
    def extract_section(payload: dict, anchor: str) -> str:
        """Return the content for a named section.
    
        For guide-format pages: returns the body of the part whose slug matches
        anchor. For standard pages: returns the HTML slice from `<h2 id="anchor">`
        to the next `<h2 id="...">`. Raise KeyError if no such anchor exists.
        """
        details = payload.get("details", {})
    
        # Guide format: look in parts by slug
        parts = details.get("parts") or []
        if parts:
            for part in parts:
                if part.get("slug") == anchor:
                    return part.get("body", "")
            raise KeyError(f"No part with slug {anchor!r}")
    
        # Standard format: h2 slice in body
        body = details.get("body", "")
        pattern = re.compile(
            rf'<h2\b[^>]*\bid="{re.escape(anchor)}"[^>]*>',
            re.IGNORECASE,
        )
        m = pattern.search(body)
        if not m:
            raise KeyError(f"No <h2 id={anchor!r}> in body")
        rest = body[m.end():]
        next_m = _HEADING_WITH_ID.search(rest)
        end = m.end() + next_m.start() if next_m else len(body)
        return body[m.start():end]
  • Input parameters defined via Pydantic Field annotations: base_path (str, 1-500 chars) and anchor (str, 1-200 chars). Return type is dict (informal, not a Pydantic model).
        base_path: Annotated[str, Field(description="GOV.UK base_path, e.g. '/universal-credit'", min_length=1, max_length=500)],
        anchor: Annotated[str, Field(description="Section anchor ID from govuk_get_content sections list", min_length=1, max_length=200)],
        ctx: Context,
    ) -> dict:
Behavior4/5

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

Annotations already convey read-only, idempotent, non-destructive behavior. The description adds the dependency on govuk_get_content for anchors, which is valuable behavioral context beyond the annotations.

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

Conciseness5/5

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

Two sentences with clear structure: first states purpose, second gives usage guidance. No extraneous content, highly efficient.

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

Completeness4/5

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

Given the presence of an output schema and annotations, the description covers purpose, usage sequence, and output type. It could mention error handling but is sufficient for a simple tool.

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

Parameters3/5

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

The input schema already provides full descriptions for both parameters (100% coverage). The description does not add new semantic information beyond what is in the schema, so baseline score of 3 is appropriate.

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 it gets 'the HTML content of one named section of a GOV.UK page'. The verb 'get' and resource 'HTML content of one named section' are specific, and it distinguishes itself from sibling tools like govuk_get_content by focusing on a single section.

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

Usage Guidelines5/5

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

Explicitly instructs the agent to use govuk_get_content first to obtain section anchors, then call this tool. This provides a clear sequence and prerequisite, effectively guiding when and how to use the tool.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/paulieb89/govuk-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server