get_metrics
Retrieve recent daily metrics for revenue tracking and business management from integrated Google services.
Instructions
Get recent daily metrics (last 7 days)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:674-676 (handler)Handler for the get_metrics tool. Executes by calling the callAPI helper function with action 'getMetrics', which proxies the request to the Google Apps Script API at the configured URL.case "get_metrics": result = await callAPI("getMetrics"); break;
- index.js:326-333 (registration)Registration of the get_metrics tool in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema (empty object, no parameters required).{ name: "get_metrics", description: "Get recent daily metrics (last 7 days)", inputSchema: { type: "object", properties: {}, }, },
- index.js:329-332 (schema)Input schema for get_metrics tool: an empty object, indicating no input parameters are required.inputSchema: { type: "object", properties: {}, },
- index.js:74-131 (helper)Shared helper function callAPI used by get_metrics (and other tools) to make form-encoded POST requests to the external Google Apps Script API endpoint.async function callAPI(action, data = {}) { debugLog('=== API CALL START ==='); debugLog(`Action: ${action}`); debugLog(`Data: ${JSON.stringify(data)}`); try { // Build form-encoded body for POST const formData = new URLSearchParams(); formData.append('action', action); // Add all data fields to form for (const [key, value] of Object.entries(data)) { if (value !== undefined && value !== null) { formData.append(key, value.toString()); } } const formString = formData.toString(); debugLog(`FormData: ${formString}`); debugLog(`API_URL: ${API_URL}`); // Use POST with proper content type const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: formString }); debugLog(`Response status: ${response.status}`); debugLog(`Response ok: ${response.ok}`); if (!response.ok) { debugLog(`Response not OK: ${response.status} ${response.statusText}`); throw new Error(`API request failed: ${response.status} ${response.statusText}`); } const text = await response.text(); debugLog(`Response text length: ${text.length}`); debugLog(`Response text: ${text}`); if (!text) { debugLog('ERROR: Empty response from API'); throw new Error('Empty response from API'); } const parsed = JSON.parse(text); debugLog(`Parsed successfully: ${JSON.stringify(parsed)}`); debugLog('=== API CALL END ==='); return parsed; } catch (error) { debugLog(`ERROR in callAPI: ${error.message}`); debugLog(`ERROR stack: ${error.stack}`); throw error; } }