Overview
Contextual MCP server acts as a bridge between AI interfaces 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 and include citations and attributions.
Remote MCP server
The Remote MCP server enables direct access to hosted MCP services without requiring any local installation. You only need- Server URL:
https://mcp.app.contextual.ai/mcp
- Contextual API key for authentication. You can obtain your API key here.
- Contextual Agent ID. You can create your agent by following the Beginner’s Guide.
OpenAI GUI
- Start on OpenAI and create a new chat.

- Under Tools, click Add → MCP Server → Add new. Enter the server URL
https://mcp.app.contextual.ai/mcp
. SelectNone
for Authentication. Click Connect.

- Add the MCP server by clicking Add.

- Enter a system message like this:

- In Hosted Tools settings, make sure MCP tool usage is enabled for your project.
Cursor
- Create the MCP configuration file. For Cursor, you can use 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
- Cursor IDE chat
- Test script to check for connectivity
- Install FastMCP:
pip install fastmcp
- Replace placeholders with your actual values
- Run:
python test_script.py
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:API_KEY
: Your Contextual AI API keyAGENT_ID
: Your Contextual AI agent ID
.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:
- 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 usesuv
for dependency management, which provides faster and more reliable Python package installation.
Usage
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:
- Determine if this should be routed to the MCP Server
- Route the query to the Contextual AI agent
- Retrieve relevant documentation
- Generate a response with specific citations
- Return the formatted answer to Cursor