Skip to main content
Glama

create_filter

Create Gmail filters by specifying criteria (sender, subject, size, etc.) and actions (label, forward). Automate email organization.

Instructions

Creates a filter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
criteriaYesFilter criteria
actionYesActions to perform on messages matching the criteria

Implementation Reference

  • The 'create_filter' tool handler. It takes 'criteria' and 'action' parameters, and calls gmail.users.settings.filters.create to create a filter in Gmail.
    server.tool("create_filter",
      "Creates a filter",
      {
        criteria: z.object({
          from: z.string().optional().describe("The sender's display name or email address"),
          to: z.string().optional().describe("The recipient's display name or email address"),
          subject: z.string().optional().describe("Case-insensitive phrase in the message's subject"),
          query: z.string().optional().describe("A Gmail search query that specifies the filter's criteria"),
          negatedQuery: z.string().optional().describe("A Gmail search query that specifies criteria the message must not match"),
          hasAttachment: z.boolean().optional().describe("Whether the message has any attachment"),
          excludeChats: z.boolean().optional().describe("Whether the response should exclude chats"),
          size: z.number().optional().describe("The size of the entire RFC822 message in bytes"),
          sizeComparison: z.enum(['smaller', 'larger']).optional().describe("How the message size in bytes should be in relation to the size field")
        }).describe("Filter criteria"),
        action: z.object({
          addLabelIds: z.array(z.string()).optional().describe("List of labels to add to messages"),
          removeLabelIds: z.array(z.string()).optional().describe("List of labels to remove from messages"),
          forward: z.string().optional().describe("Email address that the message should be forwarded to")
        }).describe("Actions to perform on messages matching the criteria")
      },
      async (params) => {
        return handleTool(config, async (gmail: gmail_v1.Gmail) => {
          const { data } = await gmail.users.settings.filters.create({ userId: 'me', requestBody: params })
          return formatResponse(data)
        })
      }
    )
  • The Zod schema for 'create_filter' input validation, defining 'criteria' (from, to, subject, query, negatedQuery, hasAttachment, excludeChats, size, sizeComparison) and 'action' (addLabelIds, removeLabelIds, forward) objects.
    {
      criteria: z.object({
        from: z.string().optional().describe("The sender's display name or email address"),
        to: z.string().optional().describe("The recipient's display name or email address"),
        subject: z.string().optional().describe("Case-insensitive phrase in the message's subject"),
        query: z.string().optional().describe("A Gmail search query that specifies the filter's criteria"),
        negatedQuery: z.string().optional().describe("A Gmail search query that specifies criteria the message must not match"),
        hasAttachment: z.boolean().optional().describe("Whether the message has any attachment"),
        excludeChats: z.boolean().optional().describe("Whether the response should exclude chats"),
        size: z.number().optional().describe("The size of the entire RFC822 message in bytes"),
        sizeComparison: z.enum(['smaller', 'larger']).optional().describe("How the message size in bytes should be in relation to the size field")
      }).describe("Filter criteria"),
      action: z.object({
        addLabelIds: z.array(z.string()).optional().describe("List of labels to add to messages"),
        removeLabelIds: z.array(z.string()).optional().describe("List of labels to remove from messages"),
        forward: z.string().optional().describe("Email address that the message should be forwarded to")
      }).describe("Actions to perform on messages matching the criteria")
    },
  • src/index.ts:1012-1038 (registration)
    The tool is registered via server.tool("create_filter", ...) inside createServer() function.
    server.tool("create_filter",
      "Creates a filter",
      {
        criteria: z.object({
          from: z.string().optional().describe("The sender's display name or email address"),
          to: z.string().optional().describe("The recipient's display name or email address"),
          subject: z.string().optional().describe("Case-insensitive phrase in the message's subject"),
          query: z.string().optional().describe("A Gmail search query that specifies the filter's criteria"),
          negatedQuery: z.string().optional().describe("A Gmail search query that specifies criteria the message must not match"),
          hasAttachment: z.boolean().optional().describe("Whether the message has any attachment"),
          excludeChats: z.boolean().optional().describe("Whether the response should exclude chats"),
          size: z.number().optional().describe("The size of the entire RFC822 message in bytes"),
          sizeComparison: z.enum(['smaller', 'larger']).optional().describe("How the message size in bytes should be in relation to the size field")
        }).describe("Filter criteria"),
        action: z.object({
          addLabelIds: z.array(z.string()).optional().describe("List of labels to add to messages"),
          removeLabelIds: z.array(z.string()).optional().describe("List of labels to remove from messages"),
          forward: z.string().optional().describe("Email address that the message should be forwarded to")
        }).describe("Actions to perform on messages matching the criteria")
      },
      async (params) => {
        return handleTool(config, async (gmail: gmail_v1.Gmail) => {
          const { data } = await gmail.users.settings.filters.create({ userId: 'me', requestBody: params })
          return formatResponse(data)
        })
      }
    )
  • The handleTool wrapper function used by create_filter to authenticate and execute the Gmail API call.
    const findHeader = (headers: MessagePartHeader[] | undefined, name: string) => {
      if (!headers || !Array.isArray(headers) || !name) return undefined
      return headers.find(h => h?.name?.toLowerCase() === name.toLowerCase())?.value ?? undefined
    }
  • The formatResponse helper used by create_filter to format the API response.
    const formatResponse = (response: any) => ({ content: [{ type: "text", text: JSON.stringify(response) }] })
Behavior1/5

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

With no annotations, the description bears full responsibility for disclosing behavioral traits. It fails to mention any side effects, authentication requirements, idempotency, or return value, leaving the agent blind to important behavior.

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

Conciseness2/5

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

The description is extremely short but lacks essential detail, making it under-specified rather than concise. It does not front-load key information or structure usefully.

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

Completeness1/5

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

Given the tool's complexity (nested objects, many fields, no output schema) and the lack of annotations, the description is completely incomplete. It fails to provide context about return values, error conditions, or how filters interact with the system.

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 coverage is 100%, so the input schema already describes all parameters thoroughly. The description adds no additional meaning, meeting the baseline for high schema coverage.

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

Purpose1/5

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

The description 'Creates a filter' is a tautology, restating the tool name without specifying what kind of filter or context. It does not indicate the system (e.g., Gmail) or distinguish from other create tools like create_draft or create_label.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The sibling list includes many creation tools, but the description gives no context for selecting create_filter over others.

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/shinzo-labs/gmail-mcp'

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