MCP Server
Integrate Contextual AI with MCP-compatible clients like Cursor IDE and Claude Desktop
A Model Context Protocol (MCP) server that provides RAG (Retrieval-Augmented Generation) capabilities using Contextual AI. This server integrates with a variety of MCP clients. In this documentation, we will show integration with the both Cursor IDE and Claude Desktop.
Overview
This MCP server acts as a bridge between AI interfaces (Cursor IDE or Claude Desktop) and a specialized Contextual AI agent. It enables:
- Query Processing: Direct your domain specific questions to a dedicated Contextual AI agent
- Intelligent Retrieval: Searches through comprehensive information in your knowledge base
- Context-Aware Responses: Generates answers that are:
- Grounded in source documentation
- Include citations and attributions
- Maintain conversation context
Local MCP server
Prerequisites
- Python 3.10 or higher
- Cursor IDE and/or Claude Desktop
- Contextual AI API key
- MCP-compatible environment
Installation
- Clone the repository:
- Create and activate a virtual environment:
- Install dependencies:
Configuration
Configure MCP Server
The server requires modifications of settings or use. For example, the single use server should be customized with an appropriate docstring for your RAG Agent.
The docstring for your query tool is critical as it helps the MCP client understand when to route questions to your RAG agent. Make it specific to your knowledge domain. Here is an example:
or
The server also requires the following settings from your RAG Agent:
API_KEY
: Your Contextual AI API keyAGENT_ID
: Your Contextual AI agent ID
If you’d like to store these files in .env
file you can specify them like so:
AI Interface Integration
This MCP server can be integrated with a variety of clients. To use with either Cursor IDE or Claude Desktop create or modify the MCP configuration file in the appropriate location:
- First, find the path to your
uv
installation:
- Create the configuration file using the full path from step 1:
- Move to the correct folder location, see below for options:
Configuration locations:
- For Cursor:
- Project-specific:
.cursor/mcp.json
in your project directory - Global:
~/.cursor/mcp.json
for system-wide access
- Project-specific:
- For Claude Desktop:
- Use the same configuration file format in the appropriate Claude Desktop configuration directory
Environment Setup
This project uses uv
for dependency management, which provides faster and more reliable Python package installation.
Usage
The server provides Contextual AI RAG capabilities using the python SDK, which can available a variety of commands accessible from MCP clients, such as Cursor IDE and Claude Desktop.
The current server focuses on using the query command from the Contextual AI python SDK, however you could extend this to support other features such as listing all the agents, updating retrieval settings, updating prompts, extracting retrievals, or downloading metrics.
For example, in Cursor, you might ask:
The MCP client will
- Determine if this should be routed to the MCP Server
Then the MCP server will
- Route the query to the Contextual AI agent
- Retrieve relevant documentation
- Generate a response with specific citations
- Return the formatted answer to Cursor
Remote MCP server
Cursor supports remote MCP servers via Server-Sent Events (SSE). This allows you to connect directly to hosted MCP services without local installation.
Configuration
- Create the MCP configuration file in one of these locations:
- Project-specific:
.cursor/mcp.json
in your project directory - Global:
~/.cursor/mcp.json
for system-wide access
- Add the configuration:
- Restart Cursor IDE
Usage
Cursor IDE chat
In Cursor’s chat interface, you might ask:
The MCP client will route the query to the Contextual AI agent and generate a response to Cursor.
Test script to check for connectivity
You may also run a short test script to verify the connection in Cursor (requires your Contextual AI API key and Agent ID):
To run the test:
- Install FastMCP:
pip install fastmcp
- Replace placeholders with your actual values
- Run:
python test_script.py