Skip to main content
Glama
marksverdhei

DHLAB MCP Server

by marksverdhei

find_collocations

Identify words that frequently appear near a target word in Norwegian digital documents to analyze linguistic patterns and context.

Instructions

Find collocations (words that appear near the target word) in a document.

Args: urn: URN identifier for the document word: Target word to find collocations for window: Size of context window (default: 5) limit: Maximum number of collocations to return (default: 100)

Returns: JSON string containing collocation statistics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urnYes
wordYes
windowNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the find_collocations tool using dhlab.Corpus to compute collocations for a given word in a document identified by URN, returning JSON results.
    @mcp.tool()
    def find_collocations(
        urn: str,
        word: str,
        window: int = 5,
        limit: int = 100,
    ) -> str:
        """Find collocations (words that appear near the target word) in a document.
    
        Args:
            urn: URN identifier for the document
            word: Target word to find collocations for
            window: Size of context window (default: 5)
            limit: Maximum number of collocations to return (default: 100)
    
        Returns:
            JSON string containing collocation statistics
        """
        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 collocations using corpus method
            colls = corpus.coll(words=word, before=window, after=window)
    
            if colls.coll is not None and len(colls.coll) > 0:
                return colls.coll.to_json(orient='records', force_ascii=False)
            return "No collocations found"
        except Exception as e:
            return f"Error finding collocations: {str(e)}"
  • The @mcp.tool() decorator registers the find_collocations function as an MCP tool.
    @mcp.tool()
  • Function signature defines the input schema (parameters with types and defaults) and output type for the tool.
    def find_collocations(
        urn: str,
        word: str,
        window: int = 5,
        limit: int = 100,
    ) -> str:
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool returns 'JSON string containing collocation statistics,' which hints at a read-only operation, but doesn't clarify if it's safe, has rate limits, requires authentication, or what the statistics include. This is inadequate for a tool with computational analysis.

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. It starts with a clear purpose sentence, followed by an 'Args' section listing parameters with defaults, and ends with return information. Every sentence adds value, though the 'Returns' line could be more specific about the JSON structure.

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's moderate complexity (4 parameters, no annotations, but has an output schema), the description is partially complete. It covers parameters well but lacks behavioral context and usage guidelines. The output schema existence reduces the need to detail return values, but more operational guidance would improve completeness.

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

Parameters4/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 meaningful semantics: 'URN identifier for the document,' 'Target word to find collocations for,' 'Size of context window (default: 5),' and 'Maximum number of collocations to return (default: 100).' This clarifies all 4 parameters beyond their schema types, though it could detail units or constraints like window size limits.

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 collocations (words that appear near the target word) in a document.' It specifies the verb ('Find'), resource ('collocations'), and scope ('in a document'). However, it doesn't explicitly differentiate from sibling tools like 'find_concordances' or 'word_concordance', which might have overlapping functionality with text analysis.

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. It doesn't mention sibling tools or contexts where this tool is preferred, such as for statistical analysis of word associations rather than simple concordance searches. This leaves the agent without clear usage boundaries.

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