lamplighter-mcp
Version:
An intelligent context engine for AI-assisted software development
288 lines (246 loc) • 9.93 kB
JavaScript
#!/usr/bin/env node
/**
* Lamplighter-MCP - An intelligent context engine for AI-assisted software development
* This script serves as the entry point for the CLI
*/
const path = require('path');
const fs = require('fs');
const { spawn } = require('child_process');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
// Default port
const PORT = process.env.PORT || 3001;
// Print banner
console.log(`
\x1b[36m┌─────────────────────────────────────────────────┐
│ │
│ 🔦 Lamplighter-MCP │
│ │
│ An intelligent context engine for software │
│ development with AI assistants │
│ │
└─────────────────────────────────────────────────┘\x1b[0m
`);
// Handle CLI arguments
const args = process.argv.slice(2);
const command = args[0];
// Check for required environment variables
const requiredVars = [
{ name: 'CONFLUENCE_URL', example: 'https://your-domain.atlassian.net' },
{ name: 'CONFLUENCE_API_TOKEN', example: 'your-api-token' },
{ name: 'CONFLUENCE_USERNAME', example: 'your-username' },
{ name: 'AI_PROVIDER', example: 'openai' },
];
// Check for help command
if (command === 'help' || command === '--help' || command === '-h') {
console.log(`
\x1b[33mUsage: npx lamplighter-mcp [command]\x1b[0m
\x1b[32mCommands:\x1b[0m
start Start the Lamplighter-MCP server
init Initialize a new project with Lamplighter-MCP configuration
help Show this help message
\x1b[32mExamples:\x1b[0m
npx lamplighter-mcp start Start the MCP server
npx lamplighter-mcp init Initialize a new project
`);
process.exit(0);
}
// Initialize a new project
if (command === 'init') {
console.log('🚀 Initializing a new Lamplighter-MCP project...');
// Create directory structure
const directories = [
'./lamplighter_context',
'./lamplighter_context/feature_tasks',
'./.cursor',
'./.cursor/rules',
];
directories.forEach(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
console.log(`📁 Created directory: ${dir}`);
}
});
// Create .env file if it doesn't exist
if (!fs.existsSync('./.env')) {
const envContent = `# Server Configuration
PORT=3001
LAMPLIGHTER_CONTEXT_DIR=./lamplighter_context
# Confluence Configuration (for specification processing)
CONFLUENCE_URL=https://your-domain.atlassian.net
CONFLUENCE_API_TOKEN=your-api-token
CONFLUENCE_USERNAME=your-username
# AI Service Configuration
AI_PROVIDER=openai # openai or google
OPENAI_API_KEY=your-openai-key
GOOGLE_API_KEY=your-google-key
AI_MODEL=gpt-4 # or google's model name`;
fs.writeFileSync('./.env', envContent);
console.log('📄 Created .env file with template values');
}
// Create mcp.json if it doesn't exist
if (!fs.existsSync('./.cursor/mcp.json')) {
const mcpContent = `{
"server": {
"url": "http://localhost:3001/sse"
},
"tools": [
{
"name": "analyze_codebase",
"description": "Analyzes the current codebase structure and generates a summary"
},
{
"name": "process_confluence_spec",
"description": "Processes a Confluence specification into actionable tasks",
"parameters": {
"confluence_url": {
"type": "string",
"description": "URL of the Confluence page containing the specification"
}
}
},
{
"name": "update_task_status",
"description": "Updates the status of a specific task within a feature",
"parameters": {
"feature_identifier": {
"type": "string",
"description": "Identifier of the feature containing the task"
},
"task_identifier": {
"type": "string",
"description": "Text of the task to update or a unique identifier"
},
"new_status": {
"type": "string",
"enum": ["ToDo", "InProgress", "Done"],
"description": "The new status to set for the task"
}
}
},
{
"name": "suggest_next_task",
"description": "Identifies and returns the next actionable task from a feature",
"parameters": {
"feature_identifier": {
"type": "string",
"description": "Identifier of the feature to suggest a task from"
}
}
},
{
"name": "get_codebase_summary",
"description": "Retrieves the codebase summary"
},
{
"name": "get_history_log",
"description": "Retrieves the history log"
},
{
"name": "get_feature_tasks",
"description": "Retrieves tasks for a specific feature",
"parameters": {
"feature_identifier": {
"type": "string",
"description": "Identifier of the feature to retrieve tasks for"
}
}
}
]
}`;
fs.writeFileSync('./.cursor/mcp.json', mcpContent);
console.log('📄 Created .cursor/mcp.json configuration file');
}
// Create system_overview.mdc if it doesn't exist
if (!fs.existsSync('./.cursor/rules/system_overview.mdc')) {
const rulesContent = `---
description: System Overview for Lamplighter-MCP
globs: **
alwaysApply: false
---
# Lamplighter-MCP System Overview
Lamplighter-MCP is an intelligent context engine for software development teams. It serves as a bridge between AI coding assistants (like you) and the complex context of software projects.
## System Architecture
Lamplighter-MCP follows a modular architecture with these key components:
1. **CodebaseAnalyzer**: Scans project files and directories to create a structured representation of the codebase.
2. **HistoryLogger**: Maintains a chronological record of actions taken during development.
3. **FeatureSpecProcessor**: Processes feature specifications from Confluence into actionable tasks.
4. **TaskManager**: Tracks the status of tasks and suggests prioritization.
5. **AIService**: Provides specialized AI functionality for tasks like summarization and contextual understanding.
6. **ConfluenceReader**: Interfaces with Confluence to retrieve and parse documentation.
## Context Files (Source of Truth)
Lamplighter-MCP maintains these essential context files:
- **codebase_summary.md**: Contains a structured overview of the project architecture.
- **feature_tasks/feature_[ID]_tasks.md**: Contains the task breakdown for each feature specification.
- **history_log.md**: Contains a chronological log of all system events and actions.
## API Tools for AI Assistants
Use these tools to interact with Lamplighter-MCP:
- \`analyze_codebase()\`: Analyzes project structure and creates/updates the codebase summary
- \`process_confluence_spec(url)\`: Processes a Confluence specification and creates tasks
- \`update_task_status(task_id, status)\`: Updates the status of a specific task
- \`suggest_next_task(feature_id)\`: Identifies the next task to work on
- \`get_codebase_summary()\`: Retrieves the latest codebase summary
- \`get_history_log()\`: Retrieves recent history entries
- \`get_feature_tasks(feature_id)\`: Retrieves tasks for a specific feature`;
fs.writeFileSync('./.cursor/rules/system_overview.mdc', rulesContent);
console.log('📄 Created .cursor/rules/system_overview.mdc file');
}
console.log('\n✅ Lamplighter-MCP initialized successfully!');
console.log('\n🔶 Next steps:');
console.log('1. Edit the .env file with your credentials');
console.log('2. Start the server with: npx lamplighter-mcp start');
console.log('3. Configure Cursor to use the MCP by enabling MCP in preferences');
console.log('\n📚 Documentation can be found at: https://github.com/yourusername/lamplighter-mcp');
process.exit(0);
}
// Default command (start)
if (!command || command === 'start') {
console.log('🚀 Starting Lamplighter-MCP server...');
// Check for required environment variables
let missingVars = false;
requiredVars.forEach(variable => {
if (!process.env[variable.name]) {
console.warn(`⚠️ Missing environment variable: ${variable.name} (Example: ${variable.example})`);
missingVars = true;
}
});
if (missingVars) {
console.log('\n🔶 Some environment variables are missing. You can:');
console.log('1. Set them in your .env file');
console.log('2. Provide them as environment variables when starting the server');
console.log('\nContinuing with default values...\n');
}
// Find the server.js file path
const serverPath = path.resolve(__dirname, '../dist/server.js');
// Check if server.js exists
if (!fs.existsSync(serverPath)) {
console.error('❌ Server file not found. Make sure to build the project first with: npm run build');
process.exit(1);
}
// Start the server
console.log(`📡 Starting server on port ${PORT}...`);
const server = spawn('node', [serverPath], {
stdio: 'inherit',
env: process.env
});
server.on('error', (error) => {
console.error(`❌ Failed to start server: ${error.message}`);
process.exit(1);
});
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\n🛑 Stopping Lamplighter-MCP server...');
server.kill('SIGINT');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n🛑 Stopping Lamplighter-MCP server...');
server.kill('SIGTERM');
process.exit(0);
});
} else {
console.error(`❌ Unknown command: ${command}`);
console.log('Run "npx lamplighter-mcp help" for usage information');
process.exit(1);
}