Skip to main content
Glama

search_gmail

Find emails in Gmail using search queries like 'from:email@example.com' or 'subject:proposal' to manage communications within revenue workflows.

Instructions

Search Gmail inbox. Use Gmail search syntax like 'from:email@example.com' or 'is:unread' or 'subject:proposal'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoGmail search query (default: 'is:unread')
maxResultsNoMax results (default: 25, max: 100)

Implementation Reference

  • Handler for the search_gmail tool. Dispatches tool execution to the callAPI helper function with action 'searchGmail' and tool arguments.
    case "search_gmail":
      result = await callAPI("searchGmail", args);
      break;
  • Input schema for search_gmail tool defining parameters: query (string, Gmail search syntax) and maxResults (number).
    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:334-350 (registration)
    Registration of the search_gmail tool in the MCP server's tool list, including name, description, and input schema.
    {
      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)"
          }
        }
      }
    },
  • Shared helper function callAPI used by search_gmail (and other tools) to proxy requests to the Google Apps Script backend at the configured API_URL with the specified action and parameters.
    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;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions search syntax but doesn't cover critical aspects like authentication requirements, rate limits, pagination behavior, error conditions, or what the return format looks like (e.g., list of message IDs vs full metadata). The description is insufficient for a tool that performs read operations on a sensitive resource like email.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place: the first states the core purpose, the second provides essential usage examples. There's no wasted text, and information is front-loaded appropriately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of email search (with authentication, privacy considerations, and result formatting) and the absence of both annotations and an output schema, the description is incomplete. It doesn't address what the tool returns, error handling, or security implications, leaving significant gaps for an AI agent to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description adds minimal value beyond the schema by mentioning Gmail search syntax examples, but doesn't provide additional semantic context like how queries are interpreted or performance implications. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Search') and resource ('Gmail inbox'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_email_content' or 'send_email', which would require mentioning it returns message metadata rather than content or that it's for finding emails rather than reading/sending them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance through the search syntax examples, suggesting it's for finding emails based on criteria. However, it lacks explicit when-to-use guidance versus alternatives like 'get_email_content' for reading specific emails or 'send_email' for composing messages, and doesn't mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PromptishOperations/mcpSpec'

If you have feedback or need assistance with the MCP directory API, please join our Discord server