get_cost_by_service
Analyze cloud spending by service across AWS, Azure, and GCP for specific date ranges to identify cost drivers and optimize expenses.
Instructions
Get cost breakdown by service
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| provider | Yes | Cloud provider | |
| startDate | Yes | Start date (YYYY-MM-DD) | |
| endDate | Yes | End date (YYYY-MM-DD) |
Implementation Reference
- src/tools/cost-analysis.ts:99-107 (handler)Handler logic for 'get_cost_by_service' tool within handleCostAnalysisTool function, dispatching to AWS-specific implementation or returning unimplemented message for other providers.case 'get_cost_by_service': { const startDate = params.startDate as string; const endDate = params.endDate as string; if (provider === 'aws') { return await getAWSCostByService(startDate, endDate); } return { message: `Cost by service not yet implemented for ${provider}` }; }
- src/tools/cost-analysis.ts:37-59 (schema)Input schema and metadata definition for the 'get_cost_by_service' tool.{ name: 'get_cost_by_service', description: 'Get cost breakdown by service', inputSchema: { type: 'object', properties: { provider: { type: 'string', enum: ['aws', 'azure', 'gcp'], description: 'Cloud provider', }, startDate: { type: 'string', description: 'Start date (YYYY-MM-DD)', }, endDate: { type: 'string', description: 'End date (YYYY-MM-DD)', }, }, required: ['provider', 'startDate', 'endDate'], }, },
- src/server.ts:72-73 (registration)Top-level registration and dispatch for cost analysis tools, including 'get_cost_by_service', in the MCP server tool call handler.} else if (costAnalysisTools.some((t) => t.name === name)) { result = await handleCostAnalysisTool(name, args || {});
- src/server.ts:19-27 (registration)Aggregation of all tools including costAnalysisTools (containing 'get_cost_by_service') into allTools list provided to MCP clients.const allTools = [ ...awsTools, ...azureTools, ...gcpTools, ...resourceManagementTools, ...costAnalysisTools, ...monitoringTools, ...securityTools, ];
- src/tools/cost-analysis.ts:204-215 (helper)AWS-specific helper function that retrieves cost breakdown by service using analyzeAWSCosts and returns parsed data.async function getAWSCostByService(startDate: string, endDate: string): Promise<unknown> { try { const analysis = await analyzeAWSCosts(startDate, endDate, 'monthly'); // Parse the formatted analysis to extract service breakdown return { breakdown: JSON.parse(analysis), message: 'Cost breakdown by service retrieved', }; } catch (error) { throw new Error(`Failed to get cost by service: ${error instanceof Error ? error.message : String(error)}`); } }