project-context-map-mcp

project-context-map-mcp

Generates structured project memory and exposes MCP tools for AI coding agents to query topology, read relevant files, and log changes in a repository.

Category
访问服务器

README

Project Context Map MCP

<div align="center">

Give your coding agent a map before it starts wandering

Turn a repository into structured project memory for MCP clients like Claude Code, so they can query context, inspect only relevant files, and understand topology before touching code.

Node 20+ MCP Server Project Memory Topology Aware

</div>


Why This Exists

AI coding tools often begin the same way in a medium or large repo:

  • they read too many files
  • they spend tokens on unrelated areas
  • they rebuild context from scratch every time
  • they miss the real dependency chain behind a feature or bug

project-context-map-mcp fixes that by generating a lightweight project memory and exposing it through MCP tools.

Instead of:

scan everything -> guess -> open random files

you get:

index first -> query topology -> read sparse files -> edit with context


What This Project Does

This package gives you:

  • an MCP server for project-aware queries
  • a CLI to generate and refresh repository memory
  • a readable .project.md with topology highlights and change log
  • a machine-readable .project-map.json
  • a human-readable .project-map.md
  • import/dependency relationships between files
  • sparse file access limited to indexed paths
  • MCP-assisted writes with automatic logging
  • Claude Code setup helpers and skill generation

At A Glance

Part Purpose
.project.md Main readable project memory for humans and agents
.project-map.json Structured index used by tools
.project-map.md Lightweight markdown summary
read_project_context Returns .project.md
query_topology Finds relevant files from natural-language queries
read_files_sparse Reads only indexed files
write_and_log Writes changes and appends to .project.md Change Log

Installation

Option 1: Global install

Best if you want to use it across many repositories.

npm install -g project-context-map-mcp

Option 2: Local install

Best if you want it only inside one project.

npm install project-context-map-mcp

Requirements

  • Node.js 20 or newer
  • an MCP-compatible client such as Claude Code

Quick Start

1. Generate the project memory

Run this from the root of the repo you want to index:

project-context-map-mcp refresh --project-root .

This creates:

  • .project.md
  • .project-map.json
  • .project-map.md

2. Configure Claude Code for that repo

project-context-map-mcp configure-claude --project-root .

This creates or updates:

  • .mcp.json
  • .claude/skills/project-context-map/SKILL.md

3. Start the MCP server

If your client starts the server from .mcp.json, you usually do not need to run it manually.

If you want to run it yourself:

project-context-map-mcp serve --project-root .

4. Use it from your MCP client

Typical flow:

  1. read the project context
  2. query topology with a natural-language task
  3. read only the matched files
  4. make changes
  5. refresh the map

Prompt examples:

  • See PROMPTS.md for tested starter prompts for Claude Code, Cursor, and VS Code Copilot Chat.
  • For best results, use prompts that name the feature area, module, or source files you want the agent to inspect.

MCP Config

If you want to wire the server manually, add this to your MCP config:

{
  "mcpServers": {
    "project-context-map": {
      "command": "project-context-map-mcp",
      "args": ["serve", "--project-root", "."],
      "env": {}
    }
  }
}

Generate it automatically

project-context-map-mcp print-mcp-config --project-root .

Write it into the repo

project-context-map-mcp configure-claude --project-root .

CLI Commands

project-context-map-mcp serve --project-root .
project-context-map-mcp refresh --project-root .
project-context-map-mcp install-hooks --project-root .
project-context-map-mcp configure-claude --project-root .
project-context-map-mcp print-mcp-config --project-root .
project-context-map-mcp help

<details> <summary><strong>Command details</strong></summary>

Command What it does
serve Starts the MCP server over stdio
refresh Regenerates .project.md, .project-map.json, and .project-map.md
install-hooks Installs git hooks to keep the map refreshed
configure-claude Creates repo-local Claude Code skill and .mcp.json
print-mcp-config Prints the MCP config JSON without writing files
help Shows command help

</details>


MCP Tools

These are the main tools exposed by the server.

Core workflow tools

Tool Purpose
read_project_context Returns .project.md content
query_topology Takes a natural-language query and returns matched file paths from the query index
read_files_sparse Reads file content only for indexed paths
write_and_log Writes file changes and appends an entry to .project.md Change Log

Additional tools

Tool Purpose
get_project_summary Returns summary, stack, modules, hotspots
refresh_project_map Regenerates the project memory artifacts
get_module_context Returns a focused view of one module
find_relevant_files Legacy ranking-oriented file query
get_recent_git_changes Summarizes recent git activity
explain_file_role Explains a file’s role and recent changes

<details> <summary><strong>What each core tool returns</strong></summary>

read_project_context

Returns:

  • .project.md path
  • full markdown content

query_topology

Returns:

  • matched file paths
  • confidence score
  • match reasons
  • per-file dependencies
  • per-file usedBy relationships

read_files_sparse

Returns:

  • file content for indexed files
  • safe errors for files outside the repo or outside the known topology

write_and_log

Returns:

  • path written
  • bytes written
  • appended change log entry

</details>


Recommended Workflow

flowchart LR
  A[Refresh project map] --> B[Read .project.md]
  B --> C[Query topology]
  C --> D[Read sparse files]
  D --> E[Implement change]
  E --> F[Write and log]
  F --> G[Refresh project map]

Example task flow

User asks:

Fix the login bug where session expires after refresh

Recommended agent behavior:

  1. call read_project_context
  2. call query_topology with the task
  3. call read_files_sparse with the matched file paths
  4. inspect only those files first
  5. edit code
  6. call write_and_log if using MCP-managed writes
  7. call refresh_project_map

Topology & Visual Graph

The project map is not only a file list. It also extracts internal relationships such as:

  • JavaScript and TypeScript imports
  • CommonJS require(...) usage
  • basic Python import detection
  • reverse usage information with used_by

That data is written into:

  • .project-map.json
  • .project.md

.project.md includes a Mermaid graph so markdown viewers that support Mermaid can render a visual dependency map.


What It Generates

.project.md

The main working document. It includes:

  • project summary
  • key modules
  • query index preview
  • topology highlights
  • Mermaid dependency graph
  • running change log

.project-map.json

The structured source of truth. It includes fields such as:

  • project_summary
  • tech_stack
  • modules
  • files
  • topology
  • entrypoints
  • dependencies
  • recent_changes
  • hotspots

.project-map.md

A shorter human-readable summary.


Claude Code Setup

After running:

project-context-map-mcp configure-claude --project-root .

your repo will contain:

.mcp.json
.claude/skills/project-context-map/SKILL.md

The generated skill tells Claude Code to:

  • consult project memory first
  • avoid broad repo scans
  • query relevant files before opening source
  • refresh the project map after edits

Git Hooks

If you want the map to stay fresh automatically:

project-context-map-mcp install-hooks --project-root .

This installs:

  • post-commit
  • post-merge
  • post-push

Each hook refreshes the project memory after repository activity.


Interactive Setup Guide

<details open> <summary><strong>I just installed it. What should I do next?</strong></summary>

  1. Go to your repo root.
  2. Run project-context-map-mcp refresh --project-root .
  3. Run project-context-map-mcp configure-claude --project-root .
  4. Open the repo in Claude Code.
  5. Approve the MCP server from .mcp.json.
  6. Ask the agent to use read_project_context and query_topology first.

</details>

<details> <summary><strong>I want to use my own MCP config instead of the generated one</strong></summary>

Use:

project-context-map-mcp print-mcp-config --project-root .

Then copy the JSON into your own MCP config file and adjust:

  • server name
  • command path
  • working project root

</details>

<details> <summary><strong>I only want the package inside one repo</strong></summary>

Install locally:

npm install project-context-map-mcp

Then run through npx:

npx project-context-map-mcp refresh --project-root .
npx project-context-map-mcp configure-claude --project-root .

</details>

<details> <summary><strong>How do I know it is working?</strong></summary>

You should see:

  • .project.md
  • .project-map.json
  • .project-map.md
  • .mcp.json after Claude setup

You can also run:

project-context-map-mcp help
project-context-map-mcp refresh --project-root .

</details>


Example Prompts For Your MCP Client

Tested prompt templates now live in PROMPTS.md.

Quick examples:

  • Use the project context map first, then find the files involved in session refresh logic.
  • Use query_topology to locate the files related to npm publishing, package configuration, and release safety checks.
  • Use get_module_context for src and explain how the CLI and MCP server fit together.
  • Find the files that control authentication and prefer source files over docs.

Best Fit Repositories

  • Node.js applications
  • React apps
  • Next.js projects
  • mixed frontend/backend repos
  • Python services
  • large internal tools where AI agents are used often

Local Development

npm install
npm run check
node src/cli.js refresh --project-root .
node src/cli.js serve --project-root .

Current Limitations

  • topology detection is strongest for JS, TS, and simple Python import patterns
  • visual graph output is Mermaid markdown, not a full interactive web app
  • natural-language ranking quality depends on file names, summaries, tags, and recent changes

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选