A server designed to monitor and manage file changes within a specified zone of the local file system. For each file, the MCP server initiates a new assistant conversation, facilitating intelligent responses to queries about file modifications.
- File change monitoring in specified directories
- File content caching with intelligent diff calculation
- Assistant conversation management for each file
- Structured responses to client queries
- Context-aware information about file changes
- Robust error handling and resilience
- Automatic cleanup of inactive conversations
- Comprehensive logging
- Multiple AI provider support (Anthropic Claude, OpenAI GPT)
- API key authentication
- Background tasks for cleanup
- Extensive unit and integration tests
- Metrics collection and reporting
- Docker support for easy deployment
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
- Configure your environment variables (copy
.env.example
to.env
and fill in your API keys)
- Start the server:
python mcp_server.py
- Use the client interface to query information about file changes:
python mcp_client.py query test_files/sample.py "What changes were made to this file recently?"
- Configure your environment variables in a
.env
file - Use Docker Compose to start the server:
docker-compose up -d
When API key authentication is enabled, use the --api-key
parameter:
python mcp_client.py --api-key YOUR_API_KEY query test_files/sample.py "Analyze changes"
# Check server status
python mcp_client.py status
# List all monitored files
python mcp_client.py files
# Get information about a specific file
python mcp_client.py file test_files/sample.py
# Query about file changes
python mcp_client.py query test_files/sample.py "Summarize the recent changes"
# Manually notify about a change
python mcp_client.py notify test_files/sample.py modified
# Get server metrics
python mcp_client.py config
Run unit tests for components:
python test_components.py
Run integration tests for the full system:
python test_mcp.py
These tests verify various aspects of the system, from individual component functionality to the entire flow of file creation, modification, querying, and deletion.
The server collects metrics about:
- API requests and response times
- File change events
- Query performance
- System health
Access metrics via the /metrics
endpoint (requires API key if enabled).
Configure the monitored directories and other settings in your .env
file and config.py
.
WATCH_DIRECTORIES
: Directories to monitor for file changesFILE_PATTERNS
: File patterns to monitor (e.g., *.py, *.js, *.txt)AI_PROVIDER
: AI provider to use (anthropic or openai)API_KEY_ENABLED
: Whether to enable API key authenticationMAX_HISTORY_ENTRIES
: Maximum number of file change entries to keepMAX_CACHE_SIZE
: Maximum number of files to keep in the content cacheANTHROPIC_API_KEY
: API key for Claude assistantOPENAI_API_KEY
: API key for OpenAI (optional)
mcp_server.py
: Main server module with API endpointsfile_monitor.py
: Tracks file changes with content cachingconversation_manager.py
: Manages assistant conversations with contextresponse_handler.py
: Handles structured responsesconfig.py
: Configuration settingsmetrics.py
: Collects and reports metricsmcp_client.py
: Client interface for testingtest_mcp.py
: Integration testing scripttest_components.py
: Unit tests for components
The server provides the following endpoints:
GET /health
: Health check endpointGET /metrics
: Get server metricsGET /files
: List all monitored filesGET /files/{file_path}
: Get information about a specific fileGET /conversations
: List all conversationsGET /conversations/{file_path}
: Get conversation for a specific filePOST /query
: Query about a specific filePOST /notify
: Notify about a file changeDELETE /conversations/{file_path}
: Clear conversation for a specific filePOST /conversations/cleanup
: Clean up inactive conversationsGET /config
: Get server configuration
All endpoints (except for root and health) require API key authentication when API_KEY_ENABLED=true
.
- API key authentication for endpoints (configurable)
- Input validation on all endpoints
- Error handling and logging of security issues
- Configurable access controls
MIT