UNPKG

prompt-scheduler-mcp

Version:

MCP server for managing Augment Prompt Scheduler tasks with local workspace storage and real-time countdown features

337 lines 15.4 kB
#!/usr/bin/env node import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import { PromptSchedulerManager } from './scheduler-manager.js'; // Define the task schema const TaskSchema = z.object({ title: z.string().describe('Title of the task'), prompt: z.string().describe('The prompt to send to Augment'), priority: z.enum(['low', 'medium', 'high']).default('medium').describe('Task priority'), tags: z.array(z.string()).default([]).describe('Tags for categorization'), executionMode: z.enum(['once', 'limited', 'infinite']).default('infinite').describe('How many times to execute'), maxExecutions: z.number().default(-1).describe('Maximum executions (for limited mode)'), idleThresholdMinutes: z.number().min(1).max(60).default(5).describe('Minutes to wait when idle before execution'), isActive: z.boolean().default(true).describe('Whether the task is active'), }); const UpdateTaskSchema = TaskSchema.partial().extend({ id: z.string().describe('Task ID to update'), }); class PromptSchedulerMCPServer { server; schedulerManager; constructor() { this.server = new Server({ name: 'prompt-scheduler-mcp', version: '1.0.0', }, { capabilities: { tools: {}, }, }); this.schedulerManager = new PromptSchedulerManager(); this.setupToolHandlers(); } setupToolHandlers() { // List available tools this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'create_task', description: 'Create a new scheduled task for the Augment Prompt Scheduler', inputSchema: { type: 'object', properties: { title: { type: 'string', description: 'Title of the task' }, prompt: { type: 'string', description: 'The prompt to send to Augment' }, priority: { type: 'string', enum: ['low', 'medium', 'high'], default: 'medium', description: 'Task priority' }, tags: { type: 'array', items: { type: 'string' }, default: [], description: 'Tags for categorization' }, executionMode: { type: 'string', enum: ['once', 'limited', 'infinite'], default: 'infinite', description: 'How many times to execute the task' }, maxExecutions: { type: 'number', default: -1, description: 'Maximum executions (for limited mode, -1 for infinite)' }, idleThresholdMinutes: { type: 'number', minimum: 1, maximum: 60, default: 5, description: 'Minutes to wait when idle before execution' }, isActive: { type: 'boolean', default: true, description: 'Whether the task is active' }, }, required: ['title', 'prompt'], }, }, { name: 'list_tasks', description: 'List all scheduled tasks', inputSchema: { type: 'object', properties: { activeOnly: { type: 'boolean', default: false, description: 'Only return active tasks' }, priority: { type: 'string', enum: ['low', 'medium', 'high'], description: 'Filter by priority' }, }, }, }, { name: 'get_task', description: 'Get details of a specific task', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Task ID' }, }, required: ['id'], }, }, { name: 'update_task', description: 'Update an existing scheduled task', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Task ID to update' }, title: { type: 'string', description: 'New title' }, prompt: { type: 'string', description: 'New prompt' }, priority: { type: 'string', enum: ['low', 'medium', 'high'] }, tags: { type: 'array', items: { type: 'string' } }, executionMode: { type: 'string', enum: ['once', 'limited', 'infinite'] }, maxExecutions: { type: 'number' }, idleThresholdMinutes: { type: 'number', minimum: 1, maximum: 60 }, isActive: { type: 'boolean' }, }, required: ['id'], }, }, { name: 'delete_task', description: 'Delete a scheduled task', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Task ID to delete' }, }, required: ['id'], }, }, { name: 'execute_task', description: 'Manually execute a specific task immediately', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Task ID to execute' }, }, required: ['id'], }, }, { name: 'get_scheduler_status', description: 'Get the current status of the prompt scheduler', inputSchema: { type: 'object', properties: {}, }, }, { name: 'set_workspace', description: 'Set the workspace for task isolation (matches VS Code workspace)', inputSchema: { type: 'object', properties: { workspaceId: { type: 'string', description: 'Workspace identifier (usually the workspace folder path)' }, }, required: ['workspaceId'], }, }, { name: 'get_workspace_info', description: 'Get current workspace information and storage paths', inputSchema: { type: 'object', properties: {}, }, }, ], }; }); // Handle tool calls this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'create_task': { const taskData = TaskSchema.parse(args); const result = await this.schedulerManager.createTask(taskData); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'list_tasks': { const { activeOnly = false, priority } = args; const result = await this.schedulerManager.listTasks({ activeOnly, priority }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'get_task': { const { id } = args; const result = await this.schedulerManager.getTask(id); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'update_task': { const updateData = UpdateTaskSchema.parse(args); const result = await this.schedulerManager.updateTask(updateData); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'delete_task': { const { id } = args; const result = await this.schedulerManager.deleteTask(id); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'execute_task': { const { id } = args; const result = await this.schedulerManager.executeTask(id); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'get_scheduler_status': { const result = await this.schedulerManager.getSchedulerStatus(); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'set_workspace': { const { workspaceId } = args; this.schedulerManager.setWorkspace(workspaceId); const info = this.schedulerManager.getWorkspaceInfo(); return { content: [ { type: 'text', text: JSON.stringify({ success: true, message: `Workspace set to: ${workspaceId}`, workspaceInfo: info }, null, 2), }, ], }; } case 'get_workspace_info': { const info = this.schedulerManager.getWorkspaceInfo(); return { content: [ { type: 'text', text: JSON.stringify({ success: true, workspaceInfo: info }, null, 2), }, ], }; } default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { return { content: [ { type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }); } async run() { const transport = new StdioServerTransport(); await this.server.connect(transport); console.error('Prompt Scheduler MCP Server running on stdio'); } } // Start the server const server = new PromptSchedulerMCPServer(); server.run().catch(console.error); //# sourceMappingURL=index.js.map