Skip to main content
Glama
VapiAI

Vapi MCP Server

Official
by VapiAI

vapi_login

Authenticate with Vapi API by calling this tool first to resolve authentication errors when using other tools.

Instructions

Authenticate with Vapi. Call this first if other tools return authentication errors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler for the vapi_login tool. It checks for existing valid tokens, validates them by making a test API call, handles in-progress auth, or starts a new OAuth flow via startAuthFlow().
    mcpServer.tool(
      'vapi_login',
      'Authenticate with Vapi. Call this first if other tools return authentication errors.',
      {},
      async () => {
        // Check if we have a token and validate it
        if (hasValidToken()) {
          try {
            const client = getVapiClient();
            await client.assistants.list({ limit: 1 });
            return {
              content: [
                {
                  type: 'text' as const,
                  text: 'Already authenticated with Vapi! You can now use other Vapi tools.',
                },
              ],
            };
          } catch {
            // Token is stale — clear it and restart auth
            clearConfig();
            vapiClient = null;
          }
        }
    
        // Check if auth is already in progress
        if (isAuthInProgress()) {
          const url = getAuthUrl();
          return {
            content: [
              {
                type: 'text' as const,
                text: `Authentication in progress. Please complete sign-in:\n\n${url}\n\nAfter signing in, try your request again.`,
              },
            ],
          };
        }
    
        // Start auth flow
        try {
          const authUrl = await startAuthFlow();
          return {
            content: [
              {
                type: 'text' as const,
                text: `Please sign in to Vapi:\n\n${authUrl}\n\nAfter signing in, try your request again.`,
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Failed to start authentication: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • src/index.ts:35-96 (registration)
    The vapi_login tool is registered directly on the McpServer instance in createMcpServer() via mcpServer.tool().
    mcpServer.tool(
      'vapi_login',
      'Authenticate with Vapi. Call this first if other tools return authentication errors.',
      {},
      async () => {
        // Check if we have a token and validate it
        if (hasValidToken()) {
          try {
            const client = getVapiClient();
            await client.assistants.list({ limit: 1 });
            return {
              content: [
                {
                  type: 'text' as const,
                  text: 'Already authenticated with Vapi! You can now use other Vapi tools.',
                },
              ],
            };
          } catch {
            // Token is stale — clear it and restart auth
            clearConfig();
            vapiClient = null;
          }
        }
    
        // Check if auth is already in progress
        if (isAuthInProgress()) {
          const url = getAuthUrl();
          return {
            content: [
              {
                type: 'text' as const,
                text: `Authentication in progress. Please complete sign-in:\n\n${url}\n\nAfter signing in, try your request again.`,
              },
            ],
          };
        }
    
        // Start auth flow
        try {
          const authUrl = await startAuthFlow();
          return {
            content: [
              {
                type: 'text' as const,
                text: `Please sign in to Vapi:\n\n${authUrl}\n\nAfter signing in, try your request again.`,
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Failed to start authentication: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The startAuthFlow() helper function that initiates OAuth flow by starting a local HTTP server for the callback, generating a secure state parameter, constructing the Vapi dashboard auth URL, and opening the browser.
    export function startAuthFlow(): Promise<string> {
      return new Promise((resolve, reject) => {
        if (authInProgress) {
          if (authUrl) {
            resolve(authUrl);
          } else {
            reject(new Error('Auth in progress but no URL available'));
          }
          return;
        }
    
        // Generate random state for security
        const state = crypto.randomUUID();
        authInProgress = true;
    
        // Start local server to receive callback
        authServer = http.createServer(async (req, res) => {
          const url = new URL(req.url || '/', `http://localhost`);
    
          if (url.pathname === '/callback') {
            const returnedState = url.searchParams.get('state');
            const apiKey = url.searchParams.get('api_key');
            const orgId = url.searchParams.get('org_id');
            const email = url.searchParams.get('email');
            const error = url.searchParams.get('error');
    
            // Verify state matches
            if (returnedState !== state) {
              res.writeHead(400, { 'Content-Type': 'text/html' });
              res.end(errorPage('Security Error', 'State mismatch. Please try again.'));
              return;
            }
    
            if (error) {
              res.writeHead(200, { 'Content-Type': 'text/html' });
              res.end(errorPage('Authentication Failed', error));
              cleanupAuth();
              return;
            }
    
            if (apiKey) {
              // Save to config
              saveConfig({ apiKey, orgId: orgId || undefined, email: email || undefined });
    
              res.writeHead(200, { 'Content-Type': 'text/html' });
              res.end(successPage());
              cleanupAuth();
              return;
            }
    
            res.writeHead(400, { 'Content-Type': 'text/plain' });
            res.end('Missing API key');
            return;
          }
    
          res.writeHead(404, { 'Content-Type': 'text/plain' });
          res.end('Not found');
        });
    
        // Find available port and start server
        authServer.listen(0, '127.0.0.1', () => {
          const address = authServer!.address();
          if (!address || typeof address === 'string') {
            authInProgress = false;
            reject(new Error('Failed to start local server'));
            return;
          }
    
          const port = (address as any).port;
          const redirectUri = `http://localhost:${port}/callback`;
          authUrl = `${VAPI_DASHBOARD_URL}/auth/cli?state=${state}&redirect_uri=${encodeURIComponent(redirectUri)}`;
    
          openBrowser(authUrl);
          resolve(authUrl);
    
          // Timeout after 10 minutes
          setTimeout(() => {
            if (authInProgress) {
              cleanupAuth();
            }
          }, 10 * 60 * 1000);
        });
    
        authServer.on('error', (err) => {
          authInProgress = false;
          reject(err);
        });
      });
    }
  • Helper functions supporting vapi_login: hasValidToken() checks VAPI_TOKEN env or stored apiKey; getToken() retrieves the token; isAuthInProgress() checks OAuth state; getAuthUrl() returns the current auth URL; clearConfig() removes stored credentials.
    export function hasValidToken(): boolean {
      // Check environment variable first
      if (process.env.VAPI_TOKEN) {
        return true;
      }
      // Check config file
      const config = loadConfig();
      return !!config.apiKey;
    }
    
    /**
     * Get the API token (from env or config)
     */
    export function getToken(): string | null {
      if (process.env.VAPI_TOKEN) {
        return process.env.VAPI_TOKEN;
      }
      const config = loadConfig();
      return config.apiKey || null;
    }
Behavior2/5

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

No annotations are provided, so the description bears full responsibility for behavioral disclosure. It only states 'Authenticate' without explaining side effects (e.g., session creation, credential storage) or duration of authentication. Minimal insight beyond the tool's name.

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?

A single concise sentence that delivers the core purpose and usage guidance without unnecessary words. It is front-loaded and efficient.

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

Completeness4/5

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

For a simple authentication tool with no parameters and no output schema, the description is mostly complete. It could mention that it authenticates the user for the session, but the provided information is sufficient for an agent to understand when and why to use it.

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

Parameters4/5

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

There are no parameters, so the input schema provides nothing. The description does not need to add parameter info. Per guidelines, zero-parameter tools have a baseline of 4, and the description meets that without requiring additional semantics.

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

Purpose5/5

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

The description clearly states the action 'Authenticate with Vapi' and its purpose as a prerequisite when other tools fail with authentication errors. It distinguishes itself from sibling tools like vapi_logout and others by specifying its role.

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

Usage Guidelines4/5

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

Provides clear context for when to use ('if other tools return authentication errors'). Does not explicitly mention when not to use or alternatives, but the guidance is straightforward for an authentication tool.

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/VapiAI/mcp-server'

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