Skip to main content
Glama

trakt_complete_auth

Finalize Trakt.tv login by submitting the authorization code from the OAuth callback to authenticate access.

Instructions

Complete Trakt.tv authentication with authorization code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesAuthorization code from Trakt OAuth callback

Implementation Reference

  • The main handler for the trakt_complete_auth tool. Executes the OAuth token exchange by calling traktClient.exchangeCodeForToken(code), then retrieves the current user info and returns tokens and instructions.
    async traktCompleteAuth(code: string): Promise<Record<string, unknown>> {
      if (!this.isInitialized) {
        return {
          success: false,
          error: 'Trakt client not initialized. Call trakt_authenticate first.'
        };
      }
    
      try {
        const tokens = await this.traktClient.exchangeCodeForToken(code);
        const user = await this.traktClient.getCurrentUser();
    
        return {
          success: true,
          user: {
            username: user.username,
            name: user.name,
            vip: user.vip
          },
          tokens: {
            access_token: tokens.access_token,
            refresh_token: tokens.refresh_token,
            expires_in: tokens.expires_in,
            scope: tokens.scope,
            created_at: tokens.created_at
          },
          message: 'Authentication successful! Add these to your environment config to persist across restarts:',
          env_config: `TRAKT_ACCESS_TOKEN=${tokens.access_token}\nTRAKT_REFRESH_TOKEN=${tokens.refresh_token}`,
          nextSteps: [
            'Add the above TRAKT_ACCESS_TOKEN and TRAKT_REFRESH_TOKEN to your MCP client env config or .env file',
            'Use trakt_get_auth_status to verify authentication',
            'Start syncing with trakt_sync_to_trakt'
          ]
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Token exchange failed'
        };
      }
    }
  • Schema definition for trakt_complete_auth. Defines input schema requiring a 'code' string parameter (the authorization code from Trakt OAuth callback).
    {
      name: "trakt_complete_auth",
      description: "Complete Trakt.tv authentication with authorization code",
      inputSchema: {
        type: "object" as const,
        properties: {
          code: { type: "string", description: "Authorization code from Trakt OAuth callback" },
        },
        required: ["code"],
      },
    },
  • Registration of the trakt_complete_auth tool in the Trakt tool registry. Maps the tool name to a call to traktFunctions.traktCompleteAuth(args.code).
    registry.register("trakt_complete_auth", (args) =>
      traktFunctions.traktCompleteAuth(args.code as string).then(wrapResponse)
    );
  • The TraktClient.exchangeCodeForToken() helper method that performs the actual HTTP POST to /oauth/token to exchange the authorization code for access and refresh tokens.
    async exchangeCodeForToken(code: string): Promise<TraktTokens> {
      try {
        const response = await this.http.post<TraktTokens>('/oauth/token', {
          code,
          client_id: this.config.clientId,
          client_secret: this.config.clientSecret,
          redirect_uri: this.config.redirectUri,
          grant_type: 'authorization_code'
        });
    
        const tokens = response.data;
        tokens.created_at = Math.floor(Date.now() / 1000);
    
        // Store tokens in config
        this.config.accessToken = tokens.access_token;
        this.config.refreshToken = tokens.refresh_token;
    
        return tokens;
      } catch (error) {
        throw new Error(`Token exchange failed: ${error}`);
      }
    }
  • Type definition for TraktTokens, including access_token, refresh_token, expires_in, scope, and created_at fields.
    export interface TraktTokens {
      access_token: string;
      refresh_token: string;
      expires_in: number;
      token_type: string;
      scope: string;
      created_at: number;
    }
Behavior2/5

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

No annotations are provided, so the description must carry the full burden. It only says 'complete authentication', which suggests a mutation, but does not disclose side effects (e.g., token storage), error handling, or rate limits. Minimal behavioral info.

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

Conciseness4/5

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

The description is a single sentence with no wasted words. It is appropriately short but could benefit from more structure or details without being verbose.

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

Completeness3/5

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

Given the tool's simplicity (one parameter, no output schema), the description provides the basic purpose. However, it lacks information about success behavior, failure state, or integration steps, leaving gaps for an agent.

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 description coverage is 100% with a single parameter 'code' described as 'Authorization code from Trakt OAuth callback'. The description adds no additional meaning beyond that, so baseline score of 3 is appropriate.

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 'Complete Trakt.tv authentication with authorization code' clearly states the specific action (complete authentication) and resource (Trakt.tv). It distinguishes from siblings like trakt_authenticate (initiation) and trakt_get_auth_status (status check).

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

Usage Guidelines3/5

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

The description implies usage after obtaining an authorization code but does not explicitly state when to use this tool versus alternatives like trakt_authenticate or trakt_get_auth_status. No when-not-to-use or context provided.

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

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