Skip to main content
Glama
marksverdhei

DHLAB MCP Server

by marksverdhei

find_concordances

Locate word contexts within documents from the National Library of Norway's digital collections to analyze usage patterns and textual occurrences.

Instructions

Find concordances (contexts) for a word in a specific document.

Args: urn: URN identifier for the document word: Word to find concordances for window: Number of words before and after the match (default: 25) limit: Maximum number of concordances to return (default: 100)

Returns: JSON string containing concordance results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urnYes
wordYes
windowNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler function decorated with @mcp.tool(), implementing the logic to find concordances for a word in a document using dhlab.Corpus.conc method. Handles input parameters, performs the query, and returns JSON results or error messages.
    def find_concordances(
        urn: str,
        word: str,
        window: int = 25,
        limit: int = 100,
    ) -> str:
        """Find concordances (contexts) for a word in a specific document.
    
        Args:
            urn: URN identifier for the document
            word: Word to find concordances for
            window: Number of words before and after the match (default: 25)
            limit: Maximum number of concordances to return (default: 100)
    
        Returns:
            JSON string containing concordance results
        """
        try:
            # Create corpus from URN
            corpus = dhlab.Corpus.from_identifiers([urn])
    
            if len(corpus.corpus) == 0:
                return f"No document found for URN: {urn}"
    
            # Get concordances using corpus method
            concs = corpus.conc(words=word, window=window, limit=limit)
    
            if concs.concordance is not None and len(concs.concordance) > 0:
                return concs.concordance.to_json(orient='records', force_ascii=False)
            return "No concordances found"
        except Exception as e:
            return f"Error finding concordances: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool returns 'JSON string containing concordance results,' which adds some context about output format. However, it lacks details on permissions, rate limits, error handling, or whether it's read-only (implied but not stated). For a tool with no annotations, this is a significant gap in transparency.

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 well-structured and appropriately sized, with a clear purpose statement followed by parameter details and return information. Each sentence adds value, and there's no redundant or verbose content. It could be slightly more front-loaded by emphasizing key usage, but overall it's efficient.

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

Completeness3/5

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

Given the tool has an output schema (implied by 'Returns' statement) and no annotations, the description covers the basics: purpose, parameters, and return format. However, for a tool with 4 parameters and sibling tools that might cause confusion, it lacks context on differentiation, error cases, or behavioral nuances. It's minimally adequate but has clear gaps in completeness.

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 description includes an 'Args' section that lists and briefly explains all four parameters, adding meaning beyond the input schema (which has 0% description coverage). It clarifies the purpose of 'urn' and 'word' as required, and provides default values and intent for 'window' and 'limit'. However, it doesn't elaborate on URN format, word case-sensitivity, or constraints, leaving some semantic gaps.

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 tool's purpose: 'Find concordances (contexts) for a word in a specific document.' It specifies the verb ('find'), resource ('concordances'), and scope ('for a word in a specific document'), making the intent unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'word_concordance' or 'search_texts', which appear related, preventing a perfect score.

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. With sibling tools such as 'word_concordance' and 'search_texts' that might overlap in functionality, there's no mention of specific contexts, exclusions, or comparisons. Usage is implied only by the purpose statement, lacking explicit direction.

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/marksverdhei/dhlab-mcp'

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