dynamic-context-mcp
A Model Context Protocol (MCP) server that injects 'Just-in-Time' context into AI conversations based on file paths and glob patterns.
README
Dynamic Context MCP Server
A Model Context Protocol (MCP) server that injects "Just-in-Time" context into AI conversations based on file paths and glob patterns.
🚀 What is this?
When coding with AI, you often have specific guidelines, architectural patterns, or database schemas that apply only to certain parts of your codebase.
Dynamic Context MCP allows you to define these rules in Markdown files with glob pattern headers. When the AI agent (like Claude or Gemini) looks at a specific file path, this tool automatically injects the relevant context for that file.
Example Flow:
- You are working on
src/backend/api.ts. - The AI calls this tool with that path.
- This server finds
backend-guidelines.md(which matchessrc/backend/**/*.ts). - The server also finds
general-ts-guidelines.md(which matches*.ts) - It combines all matching context files and delivers the result to your AI agent before it generates code
📦 usage
Quick Start (instead of manual setup)
Run the init command to automatically detect your framework (Laravel, Next.js, Python), create starter rules in .agent/rules, and append (NOT OVERWRITE) your primary context files (like GEMINI.md, CLAUDE.md, or .cursorrules) with the necessary instructions.
npx dynamic-context-mcp init
1. Prepare your Context Directory
Create a folder (default is .agent/rules) in your project root. Add markdown files with YAML frontmatter containing globs (either a single string or a list).
Example 1: Single Glob
File: .agent/rules/styles.md
---
trigger: glob
globs: "**/*.css"
---
# CSS Rules
- Use flexbox layout.
Example 2: Multiple Globs & Brace Expansion
File: .agent/rules/frontend.md
---
trigger: glob
globs:
- "src/helpers/**/*.ts"
- "resources/js/**/*.{vue,ts}" # Matches both .vue and .ts files
---
# Frontend Rules
- Ensure strict type checking.
- Prefer Composition API for Vue files.
Example 3: Always Trigger
Use this for high-level rules that should apply to every file, such as general coding standards or project philosophy.
File: .agent/rules/general.md
---
trigger: always
---
# General Guidelines
- Write clean, commented code.
- Follow SOLID principles.
2. Configure your AI Client
Add this to your MCP configuration file (e.g., claude_desktop_config.json):
{
"mcpServers": {
"dynamic-context": {
"command": "npx",
"args": [
"-y",
"dynamic-context-mcp",
"/optional/absolute/path/to/your/project/.agent/rules"
]
}
}
}
Note: The last argument is optional. If omitted, it looks for .agent/rules in the directory where the MCP server runs.
3. IMPORTANT: Agent Configuration
To ensure your AI agent uses this tool effectively, add the following instruction to your agent's system prompt or custom instructions (e.g., in GEMINI.md, CLAUDE.md, or your agent's settings):
<!-- DYNAMIC CONTEXT MCP GUIDELINES START -->
<CRITICAL_INSTRUCTION>
## DYNAMIC CONTEXT INSTRUCTIONS
This project uses dynamic context mcp to deliver "just in time" context for files that you are about to read, create, or edit.
**CRITICAL GUIDANCE**
- Before you read, create, or edit a file, check for dynamic context by requesting the `dynamic-context.get_context_for_file` tool with the file path as input.
- If dynamic context is available, read it carefully to understand important details about how to work with that file.
- dynamic context mcp takes a file path as input and goes through all context files that match that path (by glob patterns) to compile relevant context for that file
- file paths must be relative to the project root i.e. `resources/js/components/MyComponent.vue` and NOT `/absolute/path/to/project/resources/js/components/MyComponent.vue`
- dynamic context mcp does NOT take a folder path as input. If no file exists at that path, then you can create a fake file name and extension like `path/to/fakefile.txt` to check for context for that folder.
- Group context for files that have the same path and extension. If you are working with multiple files that have the same path and extension then assume that the compiled context is the same every time and use the same context for all of them.
</CRITICAL_INSTRUCTION>
<!-- DYNAMIC CONTEXT MCP GUIDELINES END -->
🛠 Local Development
If you want to modify or contribute to this project:
-
Clone the repo:
git clone [https://github.com/yourusername/dynamic-context-mcp.git](https://github.com/yourusername/dynamic-context-mcp.git) cd dynamic-context-mcp -
Install dependencies:
npm install -
Build the project:
npm run build -
Test locally: You can run the compiled script directly:
node dist/index.js ./path/to/test/context-folder
🤝 Contributing
Contributions are welcome!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
Distributed under the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。