Code Intelligence MCP Server
A Model Context Protocol (MCP) server that indexes Python codebases and exposes intelligent tools for code exploration and search.
Overview
This server analyzes a Python project at startup, building an in-memory index that includes:
- AST parsing: Extracts classes, functions, methods with signatures and docstrings
- Import tracking: Maps what each file imports
- Usage tracking: Finds where symbols are referenced throughout the codebase
- BM25 search: Full-text keyword search across all code
The indexed data powers 8 MCP tools that let an AI assistant navigate and query codebases semantically.
Quick Start (uvx)
Run directly without installing:
uvx code-intelligence-mcp --root D:\path\to\your\project
Note: On Windows, use double backslashes or forward slashes for paths.
Directory Structure
code_intelligence_mcp/
├── main.py # Entry point - run this to start the server
├── mcp_client.py # Test client that connects to the server
├── pyproject.toml # Package configuration
├── README.md # This file
├── src/
│ ├── __init__.py # Package exports
│ ├── __main__.py # Package entry point (for python -m src)
│ ├── types.py # SymbolInfo, CodeIndex data classes
│ ├── indexer.py # AST parsing and codebase indexing
│ ├── search.py # BM25 search setup and search logic
│ └── tools.py # MCP tool definitions (create_tools, handle_tool)
└── code_intelligence.py # Original monolithic file (kept for reference)
Requirements
- Python 3.12+
uvpackage manager- Dependencies (installed in project virtual environment):
langchain-mcp-adapters>=0.3.0mcp>=1.27.2rank-bm25>=0.2.2
Install Dependencies
From the repo root:
uv add mcp rank-bm25
If you already have them installed, skip this step.
Run the MCP Server
Option 1: uvx (recommended for quick testing)
uvx code-intelligence-mcp --root D:\path\to\your\project
Option 2: Local development
cd code_intelligence_mcp
uv run python main.py --root D:\path\to\your\project
Option 3: python -m src
cd code_intelligence_mcp
uv run python -m src --root D:\path\to\your\project
Note: On Windows, pass the root path with normal backslashes and use
uv run pythoninstead of callinguvdirectly as the subprocess command.
The server will print indexing progress and then wait for MCP requests:
[code-intel] Indexing: D:\path\to\project
[code-intel] Setting up BM25 search index...
[code-intel] Done — 42 files, 156 symbols, 320 BM25 chunks
MCP Tools
1. get_overview
High-level overview of the entire codebase. Call this first to orient yourself.
- Returns: project root, total files/classes/functions, file tree, all symbol names
2. get_file
Get the full source of a specific file by relative path.
- Arguments:
path(string) - relative path to the file - Returns: Full file contents with path header
3. find_symbol
Look up a class or function by exact name.
- Arguments:
name(string) - class or function name - Returns: File, line, docstring, signature, and (for classes) method signatures
4. search_code
Full-text search using BM25 algorithm - good for finding code by keyword or phrase.
- Arguments:
query(string, required) - search keyword/phrasetop_k(integer, default=5) - number of results
- Returns: Top matching code snippets with scores, file, and line context
5. get_imports
Get all imports for a specific file - what modules/names it depends on.
- Arguments:
path(string) - relative path to the file - Returns: List of imported module names
6. find_usages
Find every location in the codebase where a given name is referenced (calls, attribute access, variable use).
- Arguments:
name(string, required) - symbol name to findlimit(integer, default=20) - max results
- Returns: Total usage count and list of {file, line} locations
7. list_classes
List ALL classes in the codebase with their file, line, and method signatures.
- Returns: Array of {name, file, line, docstring, methods} sorted by file/line
8. list_functions
List ALL top-level functions with their file, line, signature, and docstring.
- Returns: Array of {name, signature, file, line, docstring} sorted by file/line
Example Usage
Test with mcp_client.py
import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient
async def main():
client = MultiServerMCPClient(
{
"project-intel": {
"transport": "stdio",
"command": "uv",
"args": [
"run",
"python",
"main.py",
"--root",
"D:\\path\\to\\your\\project",
],
}
}
)
tools = await client.get_tools()
print(f"Loaded {len(tools)} tools:")
for tool in tools:
print(f" - {tool.name}")
if __name__ == "__main__":
asyncio.run(main())
Run with:
uv run python mcp_client.py
Install from PyPI
After publishing, users can install and run:
# Install globally
uv pip install code-intelligence-mcp
# Or run directly with uvx (recommended)
uvx code-intelligence-mcp --root D:\path\to\your\project
Troubleshooting
mcp.shared.exceptions.McpError: Connection closedusually means the server subprocess failed to start correctly.- Verify the
uv run pythoncommand works manually before using it insidemcp_client.py. - Ensure the path passed to
--rootis valid and accessible. - If you get import errors, make sure you're running from the project directory with the correct virtual environment activated.
Metadata
Release files for code-intelligence-mcp 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| code_intelligence_mcp-0.1.9.tar.gz | 50.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| code_intelligence_mcp-0.1.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.5 kB
Release files / code_intelligence_mcp-0.1.9.tar.gz
| Download URL | code_intelligence_mcp-0.1.9.tar.gz |
|---|---|
| Size | 50.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb1aafcc111539fbfc8efab28a52d678b07082ccad6860a849f6b8fa652280a9
|
|
BLAKE2b-256 checksum How to use checksums |
8894482238cef230c1356104b8b80f07be4f4e64c43ddef742ead478ee0f05ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Release files / code_intelligence_mcp-0.1.9-py3-none-any.whl
| Download URL | code_intelligence_mcp-0.1.9-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02eb1447e88188d8221cc305fd7472c6fa86652fe60df0df608d4ca36c9e78a6
|
|
BLAKE2b-256 checksum How to use checksums |
fd8a95e8587e5753aeccefc6d2008fe865845267a51de54bdbf4a9a4dc9ad24b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Security for code-intelligence-mcp 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.