UNPKG

@brandcast_app/zoomshift-mcp-server

Version:

Model Context Protocol server for ZoomShift employee scheduling. Use ZoomShift with Claude Desktop.

133 lines 4.7 kB
#!/usr/bin/env node /** * ZoomShift MCP Server (Standalone - stdio transport) * * A Model Context Protocol server for ZoomShift employee scheduling. * Allows Claude Desktop to interact with ZoomShift schedules via natural language. * * Authentication: Environment variables (ZOOMSHIFT_EMAIL, ZOOMSHIFT_PASSWORD, ZOOMSHIFT_SCHEDULE_ID) * Transport: stdio (standard input/output) */ 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 { ZoomShiftClient } from './zoomshift-client.js'; import { ZOOMSHIFT_TOOLS, executeTool } from './tools.js'; // Environment variable validation const REQUIRED_ENV_VARS = [ 'ZOOMSHIFT_EMAIL', 'ZOOMSHIFT_PASSWORD', 'ZOOMSHIFT_SCHEDULE_ID', ]; function validateEnvironment() { const missing = REQUIRED_ENV_VARS.filter(varName => !process.env[varName]); if (missing.length > 0) { console.error('❌ Missing required environment variables:'); missing.forEach(varName => { console.error(` - ${varName}`); }); console.error('\nPlease set these environment variables in your Claude Desktop config:'); console.error(JSON.stringify({ mcpServers: { zoomshift: { command: 'npx', args: ['-y', '@brandcast_app/zoomshift-mcp-server'], env: { ZOOMSHIFT_EMAIL: 'your@email.com', ZOOMSHIFT_PASSWORD: 'your-password', ZOOMSHIFT_SCHEDULE_ID: 'your-schedule-id', }, }, }, }, null, 2)); process.exit(1); } } // Validate environment on startup validateEnvironment(); // Initialize ZoomShift client const client = new ZoomShiftClient({ debug: false }); const email = process.env.ZOOMSHIFT_EMAIL; const password = process.env.ZOOMSHIFT_PASSWORD; const scheduleId = process.env.ZOOMSHIFT_SCHEDULE_ID; let isAuthenticated = false; /** * Ensure client is authenticated with ZoomShift */ async function ensureAuthenticated() { if (isAuthenticated) return; try { await client.authenticate(email, password, scheduleId); isAuthenticated = true; console.error('✅ Authenticated with ZoomShift'); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; console.error(`❌ Failed to authenticate with ZoomShift: ${errorMessage}`); throw new Error(`Authentication failed: ${errorMessage}`); } } // Create MCP server const server = new Server({ name: '@brandcast_app/zoomshift-mcp-server', version: '1.0.0', }, { capabilities: { tools: {}, }, }); // Handle tools/list server.setRequestHandler(ListToolsRequestSchema, async () => { console.error('📋 Listing available tools'); return { tools: ZOOMSHIFT_TOOLS }; }); // Handle tools/call server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; console.error(`🔧 Calling tool: ${name}`); // Ensure we're authenticated before executing tools await ensureAuthenticated(); try { const result = await executeTool(name, args || {}, client); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; console.error(`❌ Tool execution failed: ${errorMessage}`); return { content: [ { type: 'text', text: JSON.stringify({ error: errorMessage, tool: name, }, null, 2), }, ], isError: true, }; } }); // Start server async function main() { console.error('🚀 Starting ZoomShift MCP Server...'); console.error(`📧 Email: ${email}`); console.error(`🔢 Schedule ID: ${scheduleId}`); const transport = new StdioServerTransport(); await server.connect(transport); console.error('✅ ZoomShift MCP Server running on stdio'); console.error('💡 Ready to receive requests from Claude Desktop'); } main().catch((error) => { console.error('❌ Fatal error:', error); process.exit(1); }); //# sourceMappingURL=index.js.map