Skip to main content
Glama
kltng

LCSH MCP Server

by kltng

search_lcsh

Retrieve official Library of Congress Subject Headings (LCSH) and related terms by querying the public suggest2 API, enabling precise subject-based searches in AI workflows.

Instructions

Search Library of Congress Subject Headings (LCSH) using the public suggest2 API. Returns a dictionary with the top results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The main handler function for the 'search_lcsh' tool, decorated with @mcp.tool() for registration in FastMCP. It queries the Library of Congress LCSH suggest2 API, parses the response (handling both new 'hits' format and old list format), and returns results as a list of label/uri dicts or error info.
    @ mcp.tool()
    def search_lcsh(query: str) -> dict:
        """
        Search Library of Congress Subject Headings (LCSH) using the public suggest2 API.
        Returns a dictionary with the top results.
        """
        # Construct the API endpoint for LCSH subject headings
        url = "https://id.loc.gov/authorities/subjects/suggest2"
        params = {"q": query, "count": 25}
        headers = {"User-Agent": "cataloger mcp server/1.0 (contact: your-email@example.com)"}
        try:
            response = requests.get(url, params=params, headers=headers, timeout=10)
            response.raise_for_status()
            # Try to parse JSON, but handle unexpected formats robustly
            try:
                data = response.json()
            except Exception as json_err:
                return {
                    "error": f"Failed to parse JSON: {json_err}",
                    "raw_response": response.text,
                    "type": type(json_err).__name__,
                    "traceback": traceback.format_exc()
                }
            # Handle new API response format (dict with 'hits')
            if isinstance(data, dict) and 'hits' in data:
                results = []
                for hit in data['hits']:
                    label = hit.get('aLabel') or hit.get('label') or ''
                    uri = hit.get('uri') or ''
                    results.append({"label": label, "uri": uri})
                return {"results": results}
            # Old format (list with ids/labels)
            if isinstance(data, list) and len(data) >= 3:
                results = []
                for uri, label in zip(data[1], data[2]):
                    results.append({"label": label, "uri": uri})
                return {"results": results}
            else:
                return {
                    "error": "Unexpected API response format",
                    "data": data
                }
        except Exception as e:
            return {
                "error": str(e),
                "type": type(e).__name__,
                "traceback": traceback.format_exc()
            }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It discloses the API source ('public suggest2 API') and return type ('dictionary with the top results'), but lacks details on error handling, rate limits, authentication needs, or what 'top results' entails (e.g., ranking criteria, number of results). This leaves behavioral gaps for a search tool.

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 concise with two sentences, front-loading the main action and resource. It avoids unnecessary words, though it could be slightly more structured (e.g., separating API details from return values). Every sentence contributes meaning, making it efficient.

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's complexity (a search operation with no annotations, 0% schema coverage, and no output schema), the description is incomplete. It omits parameter details, behavioral traits like error handling, and specifics on the return value (e.g., dictionary structure). This is inadequate for effective tool use.

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 must compensate. It does not mention the 'query' parameter at all, failing to explain its purpose, format, or constraints. The description adds no semantic value beyond what the bare schema provides, leaving the parameter undocumented.

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 ('Search Library of Congress Subject Headings') and the resource (LCSH), with the specific verb 'search' and target 'LCSH'. It distinguishes itself by mentioning the 'public suggest2 API', though there are no sibling tools for comparison. The purpose is specific and unambiguous.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It mentions the 'public suggest2 API', but does not explain its context or limitations. With no sibling tools, this is less critical, but still lacks usage context.

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

Related 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/kltng/lcsh-mcp-server'

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