get_credential_status
Check authentication status for Google Ads API sessions in multi-tenant environments to verify credential validity before executing operations.
Instructions
Get credential status for a session (multi-tenant mode).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_key | Yes | UUID v4 session key |
Implementation Reference
- src/server-tools.ts:795-820 (handler)The tool handler for 'get_credential_status'. Registers the tool via addTool, validates multi-tenant mode and session key, retrieves credential status using getCredentialStatus helper, formats response as JSON text content, and logs the event.addTool( server, 'get_credential_status', 'Get credential status for a session (multi-tenant mode).', GetCredentialStatusZ, 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('get_credential_status', 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('get_credential_status', startTs, { sessionKey: input?.session_key, requestId: input?.request_id, error: { code: 'ERR_INPUT', message: String(msg) } }); return { content: [{ type: 'text', text: `Error: ${msg}` }] }; } const status = getCredentialStatus(String(input.session_key)); const out = { content: [{ type: 'text', text: JSON.stringify(status) }] }; logEvent('get_credential_status', startTs, { sessionKey: input?.session_key, requestId: input?.request_id }); return out; } );
- src/schemas.ts:87-89 (schema)Zod input schema for the get_credential_status tool, validating the required session_key parameter.export const GetCredentialStatusZ = z.object({ session_key: z.string().describe('UUID v4 session key'), });
- Helper function that checks the connection context for a session key and returns the credential status including presence, expiration time, refresh token availability, and a masked access token.export function getCredentialStatus(sessionKey: string): { has_credentials: boolean; expires_in: number; has_refresh_token: boolean; masked_token: string } { const ttlSec = parseInt(process.env.RUNTIME_CREDENTIAL_TTL || '3600', 10); const ctx = connections.get(sessionKey); if (!ctx) return { has_credentials: false, expires_in: 0, has_refresh_token: false, masked_token: '' }; const token = ctx.credentials.access_token || ''; const masked = token.length > 8 ? `${token.slice(0, 4)}****${token.slice(-4)}` : '****'; return { has_credentials: true, expires_in: ttlSec, has_refresh_token: !!ctx.credentials.refresh_token, masked_token: masked, }; }