Skip to main content
Glama
ContextualAI

Contextual MCP Server

Official
by ContextualAI

query

Enhance enterprise search by querying domain-specific knowledge bases with context-aware responses and source citations using the Contextual MCP Server.

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: queries a fixed ContextualAI agent with the user prompt and returns the response content.
    @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
  • Handler for the 'query' MCP tool in multi-agent: reranks available ContextualAI agents for the prompt, selects the best, queries it, and returns the response.
    @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

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

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