Claude MCP Scheduler
Use Claude API to prompt remote agents on a cron interval but use local MCPs to handle tool calls for context
Installation
npx claude-mcp-schedulerAsk AI about Claude MCP Scheduler
Powered by Claude Β· Grounded in docs
I know everything about Claude MCP Scheduler. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Cron + MCP Demo: Scheduling Claude AI Tasks
A demonstration project showing how to integrate cron scheduling with Model Context Protocol (MCP) servers. This example uses the filesystem MCP server to show how Claude AI can perform scheduled tasks with access to local MCP servers running on your machine.
What This Demo Shows
This project demonstrates how to:
- π Schedule AI Tasks - Use cron expressions to run Claude prompts at specific intervals
- π€ Integrate with MCP - Connect Claude to external tools via Model Context Protocol
- π Example: Filesystem Server - Shows one MCP integration (filesystem access) as a practical example
- π Extensible Architecture - Easily add other MCP servers for databases, APIs, or custom tools
- πΎ Manage Outputs - Save and organize results from scheduled AI tasks
- π Handle Errors Gracefully - Robust error handling and automatic reconnection
- π§ͺ Test Before Scheduling - Interactive prompt testing utility
What is MCP (Model Context Protocol)?
Model Context Protocol is an open standard that enables AI assistants like Claude to securely interact with external tools and data sources. Instead of being limited to text generation, MCP allows Claude to:
- Access local files and directories
- Query databases
- Call APIs
- Execute custom tools
- And much more
This demo uses the filesystem MCP server as an example, but the architecture supports any MCP-compatible server. This makes it a perfect starting point for building scheduled AI workflows that need to interact with your specific tools and data sources.
Why Use This Instead of Claude Desktop or Claude Code?
While Claude Desktop and Claude Code are excellent for interactive development, this scheduler demo offers unique advantages for different use cases:
When to Use This Scheduler:
- Automated Tasks - Run AI tasks unattended on schedules (hourly reports, daily analysis, etc.)
- Server Environments - Deploy on headless servers, VMs, or containers without a GUI
- Batch Processing - Process multiple scheduled tasks in parallel
- CI/CD Integration - Embed AI tasks into existing automation workflows
- Cost Optimization - Only pay for API usage when scheduled tasks actually run
- Custom MCP Servers - Full control over which MCP servers are available and how they're configured
When to Use Claude Desktop/Code:
- Interactive Development - Real-time coding assistance and exploration
- One-off Tasks - Quick questions or immediate help
- Visual Work - Tasks requiring UI interaction or visual feedback
- Learning/Experimentation - Exploring Claude's capabilities interactively
This demo bridges the gap between interactive AI assistants and production automation, showing how to leverage MCP servers in scheduled, unattended workflows.
Prerequisites
- Node.js v18.0.0 or higher
- Anthropic API key
- npm or yarn package manager
Installation
- Clone the repository:
git clone https://github.com/tonybentley/claude-mcp-scheduler.git
cd claude-mcp-scheduler
- Install dependencies:
npm install
- Create a
.envfile with your Anthropic API key:
ANTHROPIC_API_KEY=your-api-key-here
- Copy the example configuration:
cp config/config.example.json config/config.json
Configuration
Edit config/config.json to define your schedules. This example shows the filesystem MCP server, but you can easily add other MCP servers:
{
"schedules": [
{
"name": "file-check",
"cron": "* * * * *",
"enabled": true,
"prompt": "List all files in the current directory and report how many files exist.",
"outputPath": "outputs/file-check-{timestamp}.txt"
}
],
"mcp": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem"],
"allowedDirectories": ["./data", "./reports"]
}
// Add other MCP servers here:
// "database": {
// "command": "npx",
// "args": ["-y", "@your-org/mcp-database-server"],
// "config": { ... }
// },
// "api": {
// "command": "npx",
// "args": ["-y", "@your-org/mcp-api-server"],
// "config": { ... }
// }
},
"anthropic": {
"model": "claude-3-5-sonnet-20241022",
"maxTokens": 4096,
"temperature": 0.7
}
}
Schedule Configuration
name: Unique identifier for the schedulecron: Cron expression (e.g., "0 * * * *" for every hour)enabled: Whether the schedule is activeprompt: The prompt to send to ClaudeoutputPath: (Optional) Path to save output, supports placeholders:{name}- Schedule name{timestamp}- Full timestamp{date}- Date in YYYY-MM-DD format
Cron Expression Examples
* * * * *- Every minute0 * * * *- Every hour0 9 * * *- Daily at 9 AM0 0 * * 0- Weekly on Sunday0 0 1 * *- Monthly on the 1st
Usage
Running the Scheduler
npm start
The scheduler will:
- Load your configuration
- Connect to the MCP filesystem server
- Start scheduled tasks
- Run until stopped with Ctrl+C
Testing Prompts
Use the test utility to try prompts before scheduling:
# Test with a simple prompt
npm run test-prompt -- "List all files in the current directory"
# Test with a prompt file
npm run test-prompt -- --file prompts/analyze.txt
# Save test output
npm run test-prompt -- --save "Analyze the package.json file"
Output Files
Generated outputs are saved to:
- Scheduled outputs: As specified in
outputPath - Test outputs:
outputs/test-prompt-{timestamp}.txt - Logs:
logs/combined.logandlogs/error.log
Directory Structure
claude-mcp-scheduler/
βββ config/ # Configuration files
β βββ config.json # Your schedule configuration
βββ src/ # Source code
βββ dist/ # Compiled JavaScript
βββ logs/ # Application logs
βββ outputs/ # Generated outputs
βββ data/ # Your data directory
βββ reports/ # Your reports directory
Development
Building
npm run build
Running Tests
# Unit tests
npm test
# Integration tests
npm run test:e2e
# Watch mode
npm run test:watch
Linting
# Check for issues
npm run lint
# Fix issues
npm run lint:fix
Troubleshooting
MCP Server Connection Issues
If the MCP server fails to connect:
- Ensure
@modelcontextprotocol/server-filesystemis installed globally or available via npx - Check that allowed directories exist and have proper permissions
- Review logs for specific error messages
API Rate Limits
If you encounter rate limits:
- Reduce the frequency of scheduled tasks
- Implement longer delays between prompts
- Check your Anthropic API tier limits
Memory Usage
For large file operations:
- Monitor memory usage in logs
- Consider breaking large prompts into smaller tasks
- Adjust Node.js memory limits if needed
Security Considerations
- API keys are stored in environment variables, never in code
- Filesystem access is restricted to configured directories
- All file paths are validated to prevent directory traversal
- Sensitive data is never logged
License
MIT License - see LICENSE file for details
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
Support
For issues and questions:
- Check the logs in
logs/directory - Review the troubleshooting section
- Create an issue on GitHub
