Skip to main content
Glama
ContextualAI

Contextual MCP Server

Official
by ContextualAI

query

Answer questions about enterprise knowledge bases using retrieval-augmented generation with context-aware responses and source citations.

Instructions

An enterprise search tool that can answer questions about any sort of knowledge base

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes

Implementation Reference

  • Handler for the 'query' MCP tool. Reranks available agents by relevance to the user prompt and queries the most relevant agent using the ContextualAI client.
    @mcp.tool()
    def query(prompt: str) -> str:
        """An enterprise search tool that can answer questions about any sort of knowledge base"""
    
        client = ContextualAI(
            api_key=API_KEY,  # This is the default and can be omitted
        )
    
        instruction = "Rank documents based on their ability to answer the question/query"
    
        agents = {}
        for agent in client.agents.list():
            agents.update({agent.id: f"{agent.name} - {agent.description}"})
        documents = list(agents.values())
    
        results = client.rerank.create(
            model="ctxl-rerank-en-v1-instruct",
            instruction=instruction,
            query=prompt,
            documents=documents,
            metadata=metadata,
            top_n=1
        )
    
        agent_index = results.results[0].index
        agent_id = list(agents.keys())[agent_index]
    
        query_result = client.agents.query.create(
            agent_id=agent_id,
            messages=[{
                "content": prompt,
                "role": "user"
            }]
        )
        return query_result.message.content
  • Handler for the 'query' MCP tool. Directly queries a predefined specific agent using the ContextualAI client.
    @mcp.tool()
    def query(prompt: str) -> str:
        """An enterprise search tool that can answer questions about a specific knowledge base"""
        client = ContextualAI(
            api_key=API_KEY,  # This is the default and can be omitted
        )
        query_result = client.agents.query.create(
            agent_id=AGENT,
            messages=[{
                "content": prompt,
                "role": "user"
            }]
        )
        return query_result.message.content
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 can 'answer questions' but doesn't describe how it behaves—such as whether it returns summaries, citations, or raw data; latency; authentication needs; or rate limits. This leaves significant 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 a single, efficient sentence that front-loads the core purpose without unnecessary details. It's appropriately sized for a basic tool, though it could be more structured with additional context.

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 as a search/query function with no annotations, no output schema, and low parameter coverage, the description is incomplete. It lacks details on behavior, output format, and parameter usage, making it inadequate for effective tool selection and invocation.

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?

The input schema has 1 parameter with 0% description coverage, and the tool description adds no information about the 'prompt' parameter—such as what format it expects, examples, or constraints. This fails to compensate for the low schema coverage, leaving the parameter's meaning unclear.

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

Purpose3/5

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

The description states the tool performs 'enterprise search' to 'answer questions about any sort of knowledge base', which gives a general purpose but lacks specificity about what resources it searches or how it differs from other search tools. It's vague about the exact verb and resource scope, though it distinguishes itself as a search/query tool.

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 limitations. It mentions 'any sort of knowledge base' but doesn't specify contexts or exclusions, leaving usage entirely implicit with no sibling tools to differentiate from.

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/ContextualAI/contextual-mcp-server'

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