Skip to main content
Glama
martechery

Google Ads MCP Server

by martechery

end_session

Terminate a Google Ads API session and remove stored credentials to manage authentication in multi-tenant environments.

Instructions

End a session and clear credentials (multi-tenant mode).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_keyYesUUID v4 session key

Implementation Reference

  • Handler function for end_session tool: checks multi-tenant mode, validates session_key, calls endSessionConn to delete the session from connections map, returns success status, and logs events.
    async (input: any) => {
      const startTs = Date.now();
      if (process.env.ENABLE_RUNTIME_CREDENTIALS !== 'true') {
        const out = { content: [{ type: 'text', text: 'Multi-tenant mode not enabled' }] };
        logEvent('end_session', startTs, { requestId: input?.request_id, error: { code: 'ERR_NOT_ENABLED', message: 'Multi-tenant mode not enabled' } });
        return out;
      }
      try {
        validateSessionKey(String(input?.session_key || ''));
      } catch (e: any) {
        const msg = e?.message || String(e);
        logEvent('end_session', startTs, { sessionKey: input?.session_key, requestId: input?.request_id, error: { code: 'ERR_INPUT', message: String(msg) } });
        return { content: [{ type: 'text', text: `Error: ${msg}` }] };
      }
      endSessionConn(String(input.session_key));
      const out = { content: [{ type: 'text', text: JSON.stringify({ status: 'session_ended' }) }] };
      logEvent('end_session', startTs, { sessionKey: input?.session_key, requestId: input?.request_id });
      return out;
  • Registration of the end_session tool using addTool, providing name, description, EndSessionZ schema, and inline handler.
    addTool(
      server,
      'end_session',
      'End a session and clear credentials (multi-tenant mode).',
      EndSessionZ,
      async (input: any) => {
        const startTs = Date.now();
        if (process.env.ENABLE_RUNTIME_CREDENTIALS !== 'true') {
          const out = { content: [{ type: 'text', text: 'Multi-tenant mode not enabled' }] };
          logEvent('end_session', startTs, { requestId: input?.request_id, error: { code: 'ERR_NOT_ENABLED', message: 'Multi-tenant mode not enabled' } });
          return out;
        }
        try {
          validateSessionKey(String(input?.session_key || ''));
        } catch (e: any) {
          const msg = e?.message || String(e);
          logEvent('end_session', startTs, { sessionKey: input?.session_key, requestId: input?.request_id, error: { code: 'ERR_INPUT', message: String(msg) } });
          return { content: [{ type: 'text', text: `Error: ${msg}` }] };
        }
        endSessionConn(String(input.session_key));
        const out = { content: [{ type: 'text', text: JSON.stringify({ status: 'session_ended' }) }] };
        logEvent('end_session', startTs, { sessionKey: input?.session_key, requestId: input?.request_id });
        return out;
      }
    );
  • Zod schema for end_session input: requires session_key as string.
    export const EndSessionZ = z.object({
      session_key: z.string().describe('UUID v4 session key'),
    });
  • Core helper function endSession that deletes the session from the connections Map and emits an event.
    export function endSession(sessionKey: string): void {
      connections.delete(sessionKey);
      try { emitMcpEvent({ timestamp: nowIso(), tool: 'session_ended', session_key: sessionKey, response_time_ms: 0, reason: 'explicit' }); } catch (e) { void e; }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions clearing credentials, which hints at destructive behavior, but fails to detail critical aspects like whether this action is reversible, what happens to active operations, or any side effects. For a tool that likely terminates sessions, this is a significant gap in transparency.

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 a single, efficient sentence that front-loads the core action ('End a session') and adds necessary context ('clear credentials in multi-tenant mode') without waste. Every word earns its place, making it highly concise and well-structured.

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 tool's complexity as a session termination operation with no annotations and no output schema, the description is incomplete. It lacks details on behavioral outcomes, error conditions, or return values, leaving gaps for an AI agent to understand the full context of use. This is inadequate for a potentially destructive tool.

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?

The input schema has 100% description coverage, with the single parameter 'session_key' documented as a UUID v4. The description adds no additional meaning beyond this, such as where to obtain the session key or format details. Baseline 3 is appropriate since the schema does the heavy lifting, but the description doesn't compensate or enhance understanding.

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 action ('End a session') and the resource ('session'), with the additional context of clearing credentials in multi-tenant mode. It distinguishes from siblings like 'manage_auth' or 'set_session_credentials' by focusing on termination rather than management or creation. However, it doesn't explicitly differentiate from all siblings, keeping it at a 4 rather than a 5.

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?

The description provides no guidance on when to use this tool versus alternatives like 'manage_auth' or 'refresh_access_token', nor does it mention prerequisites or exclusions. It implies usage in multi-tenant mode but lacks explicit context for selection among siblings, resulting in minimal guidance.

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/martechery/mcp-google-ads-ts'

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