DEV Community

Cover image for Bypassing Gmail MCP Limits to Stop Token Drain
Altrouter
Altrouter

Posted on Originally published at altrouter.ai

Bypassing Gmail MCP Limits to Stop Token Drain

An AI agent's log shows hundreds of identical access errors. The agent tried to send an approved email through Google's new protocol, got rejected, tried again, and burned a week's token budget in an hour.

Below is the mechanics of this trap and the setup of a direct send call to break the loop before the new rules take effect.

The official Gmail MCP server blocks direct email sending

Google officially released the Model Context Protocol servers and the Workspace CLI on November 24, 2026. The basic Gmail MCP server on the main /mcp/v1 endpoint exposes 30 different tools. A developer gets ready-made methods for deep integration with a mailbox. An agent gains the ability to search for specific emails by complex criteria, read long thread trends, manage color labels, archive old messages, and draft replies. Each operation returns a strictly typed response.

But the agent cannot directly send emails or reply to incoming messages. Forwarding is also blocked without special partner access. A developer connects the server and sees a set of reading tools. The process then hits an error when trying to perform the final action.

Discussions on specialized resources highlight the transformation of the technology. Users write that the initially open MCP standard has turned into a proprietary managed gateway. Google Workspace remote MCP servers operate based on the Streamable HTTP protocol and are hosted at addresses like gmailmcp.googleapis.com. The ban on the basic sending function inside this gateway breaks familiar automation scenarios.

The model sees the draft creation tool and successfully uses it. Then it tries to find a logical next step to complete the task. The sending tool is missing, or an attempt to access an undocumented endpoint returns a hard access denied error.

The protocol architecture assumes strict control over every action. Reading tools return data as structured text. Writing tools are restricted to safe operations. Creating a draft does not send data outward, so the server allows this operation. Sending an email transmits data to an external recipient, so the server requires additional permissions.

The error loop burns the token budget

The logic of modern language models is built on correcting their own mistakes. When an agent calls a tool and receives an execution error, it does not stop working. It analyzes the error text, changes the request parameters, and calls the tool again.

A coin acceptor connected by a transparent tube to its own change dispenser window

When working with blocked email sending, this mechanism turns into a loss generator. The model generates the email text, successfully saves the draft via an available MCP tool, and tries to send it. The server returns a 403 Forbidden error or reports missing permissions. The agent decides it passed an invalid draft ID or made a syntax error. It rereads all the accumulated context, generates a new call with modified parameters, and gets rejected again. An endless loop begins.

Each new iteration takes the entire previous conversation context. Let us calculate the token costs in our looping model. Assume the system prompt and the agent's action history take 4,000 tokens at the start. The first error adds the tool call and the server's system response to the context, which is about 500 tokens. On the second iteration, the model reads 4,500 tokens. On the third, the context grows to 5,000 tokens.

By the fiftieth attempt, the input context size reaches 28,500 tokens. To find the total cost, we sum the arithmetic progression from 4,000 to 28,500 tokens for 50 steps. We multiply the average value of 16,250 by 50 iterations. The result is 812,500 input tokens just for attempts to break through a blocked endpoint.

Besides input tokens, the model generates output tokens. Every tool call requires formatting a JSON object with parameters. The agent writes the function name and passes the arguments. It also escapes special characters in the email body. Over 50 attempts, a solid volume of generated text accumulates. Output tokens always cost more than input tokens, so financial losses grow faster.

If the gpt-4o model is connected, this failure quickly drains funds from the balance, and the task remains unfulfilled. Such a model looping error is expensive due to the cumulative effect of the context window. The agent operates at API speed. Fifty iterations pass faster than a developer has time to notice an anomaly in the logs and forcibly stop the process.

Workspace AI Tools Addendum enables technical enforcement

The published Workspace AI Tools Addendum document makes the use of Google MCP mandatory for all AI agents starting February 1, 2027. Technical enforcement begins on this date. Agents will lose the ability to directly access old REST APIs without restrictions.

The free Standard Tier for Workspace developers sets a quota of up to 5,000 requests per day per project and product. This is a hard limit. If we take a typical set of agent actions to process one email, it will take about five requests to the MCP. The agent searches for new messages, reads the thread, requests calendar details, creates a draft reply, and assigns a label. We divide the 5,000 available requests by 5 operations. The free quota is exactly enough for 1,000 processed emails per day.

Requests above this number will be rejected unless you switch to a paid model. The start of paid billing for excess limits on the Scaled Tier is scheduled for April 1, 2027. The sources do not disclose the exact pricing grid for each subsequent request on the Scaled Tier after exhausting the free five thousand calls.

The control infrastructure is built on several levels. The Google Cloud Agent Gateway, launched simultaneously with the services, verifies agent identifiers through the Agent Registry system. Anonymous calls are impossible. Every request to the MCP server is tied to a specific registered agent.

All passing traffic is checked for prompt injections using the built-in Model Armor filter. The filter analyzes incoming requests and blocks those containing attempts to bypass system instructions. If an agent tries to pass malicious code through email search parameters, Model Armor drops the connection.

The Workspace AI Tools Addendum document explicitly prohibits the permanent storage of raw Workspace data. A developer cannot download an email archive via MCP and save it in a database to train third-party AI models later. The architecture forces the agent to work with data on the fly, constantly requesting context through the gateway. A complex agent quickly exhausts the 5,000 request limit. Moving to the Scaled Tier removes the hard restriction but adds a financial burden for every call over the quota.

Traditional software is exempt from restrictions

Traditional software is officially exempt from the Addendum rules and continues to work through standard REST APIs.

Traditional software includes backup scripts and deterministic CRM integrations with hardcoded scheduled tasks. Suppose a corporate system collects daily sales reports and sends them to managers exactly at midnight. If the system operates on a strict algorithm without the participation of a language model making autonomous decisions, it does not fall under the new restrictions. The main condition for such systems is the use of their own OAuth clients and static templates.

The situation is different for AI agents. An agent receives an email from a dissatisfied customer, analyzes the tone of the text, collects the history of past interactions from a database, and generates a personalized response. Such a script is classified as an AI Agent and must follow the rules. For agents specifically, a custom SMTP call remains the only way to break the LLM loop on the blocked sending tool. The logic splits. Reading goes through the legal MCP, while sending is delegated to a classic deterministic script.

The boundary between traditional software and an AI agent lies in the decision-making method. If the code strictly dictates the sequence of actions, it is traditional software. The script receives a trigger and generates a template email. The system then sends it via the REST API. There is no variability here.

If the code passes the context to an LLM and asks the model to choose the next tool, it is an AI agent. The model decides the recipient, the content of the message, and the exact moment to send it. Calling the SMTP server from a fixed function returns the sending operation to the category of deterministic actions. The model only prepares the text, while the physical sending occurs according to a strictly defined scenario.

Redirecting email sending to a custom SMTP call

Solving the problem comes down to architectural isolation of the problematic node. The language model should not try to send an email through Google Workspace tools. Instead, the model is provided with its own local tool that executes a direct SMTP request.

A massive metal vault door is propped up from below by a simple white plastic wedge

The agent calls a local function and passes the recipient address along with the message content. The function connects to the SMTP server, authorizes using an app password, and sends the email bypassing the proprietary gmailmcp.googleapis.com gateway.

Implementation requires the OpenAI library and access to a model supporting function calling, such as gpt-4o-mini. First, you need to define the tool schema in JSON format.

import smtplib
from email.message import EmailMessage
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY"
)

tools = [{
    "type": "function",
    "function": {
        "name": "send_email_smtp",
        "description": "Sends an email via a custom SMTP server.",
        "parameters": {
            "type": "object",
            "properties": {
                "to_email": {
                    "type": "string",
                    "description": "Recipient address"
                },
                "subject": {
                    "type": "string",
                    "description": "Email subject"
                },
                "body": {
                    "type": "string",
                    "description": "Email body"
                }
            },
            "required": ["to_email", "subject", "body"]
        }
    }
}]
Enter fullscreen mode Exit fullscreen mode

Then the sending function itself is written. It accepts arguments from the model and performs the physical connection to the mail server. In a real project, authorization parameters are moved to environment variables.

def execute_smtp_send(to_email, subject, body):
    msg = EmailMessage()
    msg.set_content(body)
    msg['Subject'] = subject
    msg['From'] = "app_email@gmail.com"
    msg['To'] = to_email

    try:
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.login("app_email@gmail.com", "app_password")
        server.send_message(msg)
        server.quit()
        return "Email sent successfully."
    except Exception as e:
        return f"Sending error: {str(e)}"
Enter fullscreen mode Exit fullscreen mode

Upon receiving a request to send an email, the model formats a JSON with arguments and stops generation. The server application intercepts this JSON, validates the recipient, and calls the deterministic code. If the SMTP server returns an authorization error, the model receives this error text, but it does not try to repeatedly hit the closed MCP endpoint.

This approach has a technical limitation. The method will not work for fully autonomous agents without a human at the screen. Sensitive actions, like sending messages or changing access rights, require mandatory interactive confirmation by the user through the form elicitation mechanism in MCP.

A direct custom SMTP call completely bypasses this Google security perimeter. The official documentation is silent on how fully autonomous server AI agents should function in headless mode. Moving sending to SMTP places the responsibility on the developer to verify content and prevent spam.

Separating tools by access level

The hybrid approach requires rebuilding the application architecture. Reading emails and creating drafts work through MCP and consume the limit of 5,000 requests per day. Searching for emails and analyzing message threads work normally. Saving drafts is also not blocked by the server. The model gets full access to incoming information.

The custom SMTP call is used exclusively for automatic sending. If business logic requires a completed action from the agent, sending is hidden behind its own local tool. Headless mode limitations require adding an intermediate verification step on the server side. Raw generated text must not fly out to clients without review. The developer configures the system so that the email first goes into a moderation queue. A human reviews the text and clicks the approval button. Only then does the server code call the SMTP function. This step protects against sanctions from email providers and prevents the accidental mass mailing of hallucinations. The team maintains full control over the agent's behavior.

Top comments (0)