mcp-intelligence-context

mcp-intelligence-context

Provides codebase indexing and retrieval tools that give AI agents token-efficient, query-relevant context packages (symbols, imports, and dependencies) instead of scanning entire repositories.

Category
访问服务器

README

MCP Intelligence Context

A Repository Intelligence MCP server that indexes a codebase's files, symbols, imports and dependency graph, and hands Copilot/agents a small, focused context package instead of making them scan the entire repository.

Why

When an agent gets an ambiguous question about a large repo, it often has to repeatedly list directories, open unrelated files, and re-derive structure before finding the relevant code — burning tokens and time. This project builds a persistent, incrementally-updated index of the repo (files, symbols, imports, reverse dependencies) and exposes MCP tools that return only the context relevant to a query, with an approximate token budget.

How it works

  1. index_repository walks the repo (honoring .gitignore), parses Python (via ast) and JS/TS (via lightweight regex heuristics) files for functions/classes/methods/imports/exports, and builds a reverse dependency graph. The index is cached at .mcp_intel_cache/index.json and refreshed incrementally (only changed files are re-parsed, based on mtime/size).
  2. search_code / get_relevant_context rank files by symbol-name, filename, docstring/summary, and import matches (lexical/symbol search — no embeddings in this MVP) and return a token-budgeted context package: symbol tables + small code excerpts, not whole files. get_relevant_context also reports a token_savings comparison against a naive full-repo-scan baseline, so the savings are visible in the tool's own response.
  3. get_file_summary / get_dependencies let an agent drill into a specific file's symbols or blast radius (importers/imports) without reading the whole file.
  4. Tools report a staleness warning if the cached index is older than 5 minutes and no live watcher is active. In practice, the first tool call for a repo starts a background file watcher (via watchdog) that applies create/modify/delete events to the in-memory index immediately, so the index stays continuously up to date as the code changes — no manual reindex needed during a session. The on-disk cache is flushed on a debounce (~2s) so rapid saves don't cause a write per keystroke.

Repository layout

src/mcp_intelligence_context/   Python MCP server package
  walker.py                     gitignore-aware file walker
  parsers/                      Python (ast) and JS/TS (regex) symbol extraction
  indexer.py                    builds/caches the RepoIndex, resolves imports
  watcher.py                    background file watcher that keeps the index live
  search.py                     lexical/symbol search + reverse-dep lookups
  context_builder.py            token-budgeted context package assembly
  server.py                     MCP tool definitions (stdio server)
vscode-extension/                VS Code extension wrapper (setup/reindex/status commands)
scripts/                         one-command bootstrap for new users

Quick Start (New Users)

If you are new to MCP and just want this working in VS Code quickly:

git clone https://github.com/LeoChimal09/MCP-INTELLIGENCE-CONTEXT.git
cd MCP-INTELLIGENCE-CONTEXT
bash scripts/setup_mcp_workspace.sh

What this script does:

  1. Installs (or updates) mcp-intelligence-context with pipx.
  2. Writes .vscode/mcp.json for this workspace.
  3. Restricts indexing to the current workspace folder by setting MCP_INTEL_ALLOWED_ROOTS=${workspaceFolder}.

Then in VS Code:

  1. Command Palette -> MCP: List Servers.
  2. Start/Restart mcp-intelligence-context.
  3. In Copilot Chat tool picker, enable mcp-intelligence-context.

If the script says pipx is missing, install it once:

brew install pipx
pipx ensurepath

Running the MCP server standalone

python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/mcp-intelligence-context        # or: python -m mcp_intelligence_context.server

Point the repo to index by setting MCP_INTEL_REPO_ROOT, or pass repo_root explicitly to any tool call (defaults to the server's current working directory).

Installing without cloning this repo

Other users don't need a local checkout — install directly from the git repository (or from PyPI, once published there):

python3 -m venv .venv
.venv/bin/pip install "git+https://github.com/LeoChimal09/MCP-INTELLIGENCE-CONTEXT.git"
# once published: .venv/bin/pip install mcp-intelligence-context

The mcp-intelligence-context console script and MCP_INTEL_REPO_ROOT env var work exactly the same either way — only the pip install source differs.

Register with an MCP client (e.g. VS Code)

Add to .vscode/mcp.json in the target workspace:

{
  "servers": {
    "mcp-intelligence-context": {
      "type": "stdio",
      "command": "/absolute/path/to/.venv/bin/python",
      "args": ["-m", "mcp_intelligence_context.server"],
      "env": { "MCP_INTEL_REPO_ROOT": "${workspaceFolder}" }
    }
  }
}

VS Code extension

vscode-extension/ bundles a thin wrapper with three commands:

  • MCP Intelligence: Setup Server — creates a venv and installs the Python package, then writes the .vscode/mcp.json entry above.
  • MCP Intelligence: Reindex Repository — forces a re-index of the open workspace.
  • MCP Intelligence: Show Status — prints the cached index's file count, git commit, and age.

By default, "Setup Server" installs the package from this project's git repository into a venv under the extension's private storage — no local clone required. Two settings control this:

  • mcpIntelligenceContext.serverPath — point at a local editable checkout (used for development on this monorepo); leave empty otherwise.
  • mcpIntelligenceContext.pythonPackageSource — override the pip install target (e.g. a PyPI package name) when serverPath is empty.

To build it:

cd vscode-extension
npm install
npm run compile

Then press F5 in VS Code (with vscode-extension/ open) to launch an Extension Development Host.

Available MCP tools

Tool Purpose
index_repository Build/refresh the index for a repo root
get_repo_overview Top-level directories, language breakdown, core modules
search_code Ranked file/symbol hits for a query
get_file_summary Symbol table, imports, exports for one file
get_dependencies What a file imports and who imports it
get_relevant_context Token-budgeted context package for a query, plus a token_savings estimate vs. a naive full-repo scan

Evaluating whether this actually helps

eval/ contains a small, honest benchmark against this repo's own code (no LLM calls, no fabricated numbers): 10 hand-written queries with known ground-truth files, comparing our indexed tool against a naive baseline (list the tree, grep, read whole matching files).

.venv/bin/python eval/run_eval.py

It reports hit@1/hit@3 (does the top result point at the right file), average token reduction, and latency. This only measures retrieval/token mechanics — it does not measure whether a real Copilot answer is actually better, since that requires live model calls.

Current limitations (MVP)

  • JS/TS parsing is regex-based (not a full AST), so unusual syntax may be missed. Python parsing uses the standard ast module and is exact.
  • Search is lexical/symbol-based only (with stopword filtering and accumulated multi-signal scoring); no embeddings/semantic search yet.
  • The file watcher applies per-file changes but does not re-walk .gitignore changes themselves at runtime — if .gitignore is edited, run index_repository with refresh=true once to pick up the new rules.

Security considerations before broader/production use

Already fixed:

  • Shell injection — the VS Code extension previously interpolated workspace settings into shell command strings; it now uses execFile with argument arrays (no shell), and refuses to run "Setup Server" in untrusted workspaces.
  • Symlink escape — the walker skips symlinks that resolve outside the repo root (blocks a planted symlink from exposing files like /etc/passwd).
  • Secret leakage — filenames matching common credential patterns (.env, *.pem, id_rsa, credentials.json, etc., see SENSITIVE_FILENAME_PATTERNS in config.py) are skipped even if not gitignored, so their contents can't end up in tool output.
  • Corrupted-cache crash — a malformed/tampered .mcp_intel_cache/index.json now triggers a clean rebuild instead of crashing the server on launch.
  • ReDoS — the JS/TS regex parser skips pathologically long single lines (minified files) to avoid catastrophic-backtracking DoS.
  • Unrestricted repo_root — set MCP_INTEL_ALLOWED_ROOTS (a :-separated list of absolute paths) to restrict which directories the server will index; unset by default to preserve today's flexible single-user behavior.

Still architectural, not fully solved — read before deploying beyond a single local user:

  • Not safe as a shared/multi-tenant network service. This is designed as a local, one-process-per-user stdio server. The in-memory index/watcher caches have no per-user isolation or authentication. Do not expose this as a shared HTTP/SSE endpoint without adding per-caller sandboxing and auth.
  • Dependencies are unpinned (>= only) — pin exact versions or use a lock file for reproducible, vetted production installs (this already bit us once with an mcp 1.x → 2.0 breaking API change).
  • No automated regression tests for this codebase itself yet — changes are currently verified via the manual eval/ harness and ad hoc runs, not a CI-gated test suite.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选