add_revenue
Record closed deals and revenue data in Google Sheets for tracking sales performance and financial metrics.
Instructions
Add a closed deal
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clientName | Yes | ||
| leadId | No | ||
| serviceType | No | ||
| projectDescription | No | ||
| contractValue | Yes | ||
| status | No | ||
| paymentReceived | No | ||
| notes | No |
Implementation Reference
- index.js:650-652 (handler)Handler for the 'add_revenue' MCP tool. Dispatches the tool call to the backend Google Apps Script API via callAPI with action 'addRevenue' and the provided arguments.case "add_revenue": result = await callAPI("addRevenue", args); break;
- index.js:240-263 (registration)Registration of the 'add_revenue' tool in the MCP server's tool list, including name, description, and input schema definition.{ name: "add_revenue", description: "Add a closed deal", inputSchema: { type: "object", properties: { clientName: { type: "string" }, leadId: { type: "number" }, serviceType: { type: "string", enum: ["Website", "Automation", "SaaS Consulting", "Combined", "Other"] }, projectDescription: { type: "string" }, contractValue: { type: "number" }, status: { type: "string", enum: ["Proposed", "Accepted", "In Progress", "Delivered", "Paid"] }, paymentReceived: { type: "number" }, notes: { type: "string" }, }, required: ["clientName", "contractValue"], }, },
- index.js:243-262 (schema)Input schema validation definition for the 'add_revenue' tool.inputSchema: { type: "object", properties: { clientName: { type: "string" }, leadId: { type: "number" }, serviceType: { type: "string", enum: ["Website", "Automation", "SaaS Consulting", "Combined", "Other"] }, projectDescription: { type: "string" }, contractValue: { type: "number" }, status: { type: "string", enum: ["Proposed", "Accepted", "In Progress", "Delivered", "Paid"] }, paymentReceived: { type: "number" }, notes: { type: "string" }, }, required: ["clientName", "contractValue"], },
- index.js:74-131 (helper)Helper function callAPI that handles all backend API calls for MCP tools, including 'addRevenue'. Makes POST requests to the Google Apps Script web app URL with action and form-encoded data.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; } }