search_gmail
Search Gmail inbox using Gmail search syntax to find emails by sender, subject, read status, or other criteria for revenue tracking and business management.
Instructions
Search Gmail inbox. Use Gmail search syntax like 'from:email@example.com' or 'is:unread' or 'subject:proposal'
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Max results (default: 25, max: 100) | |
| query | No | Gmail search query (default: 'is:unread') |
Implementation Reference
- index.js:334-350 (registration)Tool registration and schema definition for 'search_gmail' in the MCP tools list returned by ListToolsRequestSchema handler.{ name: "search_gmail", description: "Search Gmail inbox. Use Gmail search syntax like 'from:email@example.com' or 'is:unread' or 'subject:proposal'", inputSchema: { type: "object", properties: { query: { type: "string", description: "Gmail search query (default: 'is:unread')" }, maxResults: { type: "number", description: "Max results (default: 25, max: 100)" } } } },
- index.js:678-680 (handler)Handler dispatch for 'search_gmail' tool in the CallToolRequestSchema switch statement. Calls callAPI helper with action 'searchGmail'.case "search_gmail": result = await callAPI("searchGmail", args); break;
- index.js:74-131 (helper)callAPI helper function that performs HTTP POST to Google Apps Script web app URL with action='searchGmail' and input arguments, executing the core Gmail search logic remotely.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; } }