UNPKG

syia-mcp-vessel-accounts

Version:

MCP server for vessel account management including EyeShare API integration, vessel expenses, and purchase orders

190 lines (164 loc) 7.67 kB
import { logger } from "../utils/logger.js"; export class PromptHandler { constructor(server) { this.server = server; } // List of available prompts getPromptList() { return [ { name: "vessel_committed_cost_analyzer", description: "Generate vessel committed cost analysis report using the complete analyzer script", arguments: [ { name: "vessel_code", description: "Vessel code (e.g., ACET, BWET)", required: true }, { name: "end_date", description: "End date for analysis in YYYY-MM-DD format (default: current date)", required: false } ] } ]; } async handleGetPrompt(name, arguments_) { try { switch (name) { case "vessel_committed_cost_analyzer": return this.getVesselCommittedCostAnalyzerPrompt(arguments_); default: throw new Error(`Unknown prompt: ${name}`); } } catch (error) { logger.error(`Error calling prompt ${name}:`, error); throw error; } } getVesselCommittedCostAnalyzerPrompt(arguments_) { const vesselCode = arguments_?.vessel_code; const endDate = arguments_?.end_date || new Date().toISOString().split('T')[0]; // Validate vessel code is provided if (!vesselCode) { throw new Error("vessel_code is required. Please provide a valid 4-letter vessel code (e.g., BASC, BWET, GEVI, ACET) or comma-separated codes (e.g., ACET,BASC,BWET)"); } // Parse vessel codes (single or comma-separated) const vesselCodes = vesselCode.includes(',') ? vesselCode.split(',').map(code => code.trim()) : [vesselCode]; // Validate each vessel code format for (const code of vesselCodes) { if (!/^[A-Z]{4}$/.test(code)) { throw new Error(`Invalid vessel code format: ${code}. Must be exactly 4 uppercase letters (e.g., BASC, BWET, GEVI)`); } } const isMultipleVessels = vesselCodes.length > 1; const analyzerGuide = `# Vessel Committed Cost Analysis Report Generation ## Task: Generate Committed Cost Report for ${isMultipleVessels ? `Vessels ${vesselCodes.join(', ')}` : `Vessel ${vesselCode}`} until ${endDate} ### Recommended Approach: Use the MCP Tool The easiest way to generate the committed cost report is to use the dedicated MCP tool: \`\`\` mcp(operation='callTool', toolName='generate_committed_cost_report', toolArgs={ 'vesselCode': '${vesselCode}',${isMultipleVessels ? ' // Multiple vessels: comma-separated' : ''} 'endDate': '${endDate}', 'outputPath': '.' // Use current directory - will save in chat workspace }, serverId='mcp-vessel-accounts') \`\`\` ${isMultipleVessels ? ` ### Multi-Vessel Processing This request will process ${vesselCodes.length} vessels sequentially: ${vesselCodes.map(code => `- ${code}`).join('\n')} Each vessel will generate its own set of 5 Excel reports. Total expected reports: ${vesselCodes.length * 5} ` : ''} ### Examples for Different Vessels: \`\`\` // Step 1: Get current workspace path Bash(command='pwd', description='Get current workspace path') // Step 2: Use the returned path in MCP call // For vessel BASC till July 2025 - saves files in current chat folder mcp(operation='callTool', toolName='generate_committed_cost_report', toolArgs={'vesselCode': 'BASC', 'endDate': '2025-07-20', 'outputPath': '[USE_PWD_RESULT]'}, serverId='mcp-vessel-accounts') // For vessel BWET till current date - saves files in current chat folder mcp(operation='callTool', toolName='generate_committed_cost_report', toolArgs={'vesselCode': 'BWET', 'outputPath': '[USE_PWD_RESULT]'}, serverId='mcp-vessel-accounts') // For vessel GEVI with specific date - saves files in current chat folder mcp(operation='callTool', toolName='generate_committed_cost_report', toolArgs={'vesselCode': 'GEVI', 'endDate': '2025-12-31', 'outputPath': '[USE_PWD_RESULT]'}, serverId='mcp-vessel-accounts') \`\`\` Replace \`[USE_PWD_RESULT]\` with the actual path returned by the \`pwd\` command. This tool will: - Automatically use the MCP server's configuration (MongoDB URI, EyeShare credentials) - Execute the vessel_committed_cost_analyzer.py script with proper environment variables - **IMPORTANT: Save all Excel reports in the current chat workspace folder (use 'outputPath': '.')** - Generate 5 comprehensive Excel reports with vessel-specific naming - Return a summary of the analysis results ### 📁 File Output Location: **CRITICAL:** To ensure all generated files are saved in the current chat workspace folder: 1. **Recommended:** Use the current working directory by running \`Bash\` tool first: \`\`\` Bash(command='pwd', description='Get current workspace path') \`\`\` Then use the returned path as 'outputPath' in the MCP call. 2. **Alternative:** Use \`'outputPath': '.'\` but this may save files in the MCP server directory instead of your chat workspace. **Example with explicit workspace path:** \`\`\` // First get the current workspace path Bash(command='pwd') // Then use the returned path (e.g., /Users/user/.siya/workspaces/your-chat-folder) mcp(operation='callTool', toolName='generate_committed_cost_report', toolArgs={ 'vesselCode': '${vesselCode}', 'endDate': '${endDate}', 'outputPath': '/Users/user/.siya/workspaces/your-chat-folder' }, serverId='mcp-vessel-accounts') \`\`\` This ensures all Excel reports are saved directly in your current chat workspace for easy access. ### Alternative: Manual Script Execution If you prefer to run the script manually: 1. Access the script resource: \`mcp(operation='readResource', resourceUri='committed-cost://vessel-analyzer', serverId='mcp-vessel-accounts')\` 2. Save it as \`vessel_committed_cost_analyzer.py\` 3. Create a .env file with required credentials: \`\`\` MONGODB_URI=<from MCP config> EYESHARE_CLIENT_ID=<from MCP config> EYESHARE_CLIENT_SECRET=<from MCP config> \`\`\` 4. Run: \`python vessel_committed_cost_analyzer.py ${vesselCode} --end-date ${endDate}\` ### Expected Output The analysis will generate 5 Excel reports: 1. **Purchase Orders Report**: All purchase orders for the vessel 2. **Vessel Expenses Report**: Combined current and previous year expenses 3. **PO Lines Report**: Detailed PO lines fetched from EyeShare API 4. **Committed Cost Report**: Calculated committed costs with summary 5. **Complete Analysis Report**: Comprehensive report with all data and summaries ### Success Indicators: - ✅ All EyeShare IDs from expenses are processed - ✅ PO lines count matches expense EyeShare ID count - ✅ Total committed cost amount is calculated - ✅ All 5 Excel reports are generated successfully`; const messages = [ { role: "assistant", content: { type: "text", text: analyzerGuide } } ]; return { description: `Generate vessel committed cost analysis for ${isMultipleVessels ? `${vesselCodes.length} vessels (${vesselCodes.join(', ')})` : vesselCode} until ${endDate}`, messages }; } } //# sourceMappingURL=index.js.map