trakt_authenticate
Initiates OAuth authentication with Trakt.tv to authorize Plex media activity scrobbling and tracking.
Instructions
Start Trakt.tv OAuth authentication process
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | No | Optional state parameter for OAuth flow |
Implementation Reference
- src/trakt/mcp-functions.ts:71-98 (handler)The main handler function 'traktAuthenticate' that executes the tool logic. It initializes the Trakt client (if not already done), generates an OAuth auth URL via the client, and returns the URL along with instructions for the user to complete authorization.
/** * MCP Function: trakt_authenticate * Start OAuth authentication flow */ async traktAuthenticate(state?: string): Promise<Record<string, unknown>> { this.initializeTraktClient(); try { const authUrl = this.traktClient.generateAuthUrl(state); return { success: true, authUrl, instructions: [ '1. Open the provided URL in your browser', '2. Authorize the application on Trakt.tv', '3. Copy the authorization code from the callback', '4. Use trakt_complete_auth with the code to complete setup' ], message: 'Visit the auth URL and complete authorization, then use trakt_complete_auth with the code' }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Authentication initialization failed' }; } } - src/trakt/tool-registry.ts:12-14 (registration)Registers the 'trakt_authenticate' tool with the ToolRegistry, binding it to the traktAuthenticate method on TraktMCPFunctions and wrapping the response.
registry.register("trakt_authenticate", (args) => traktFunctions.traktAuthenticate(args.state as string | undefined).then(wrapResponse) ); - src/trakt/tool-schemas.ts:6-16 (schema)Defines the input schema for the 'trakt_authenticate' tool, including an optional 'state' string parameter for the OAuth flow.
export const TRAKT_TOOL_SCHEMAS = [ { name: "trakt_authenticate", description: "Start Trakt.tv OAuth authentication process", inputSchema: { type: "object" as const, properties: { state: { type: "string", description: "Optional state parameter for OAuth flow" }, }, }, }, - src/trakt/mcp-functions.ts:50-69 (helper)Helper method 'initializeTraktClient' that sets up the Trakt client with config from environment variables. Called by traktAuthenticate before proceeding.
private initializeTraktClient(): void { if (this.isInitialized) return; const config: TraktConfig = { baseUrl: process.env.TRAKT_BASE_URL || DEFAULT_TRAKT_API_URL, clientId: process.env.TRAKT_CLIENT_ID || '', clientSecret: process.env.TRAKT_CLIENT_SECRET || '', redirectUri: process.env.TRAKT_REDIRECT_URI || 'urn:ietf:wg:oauth:2.0:oob', accessToken: process.env.TRAKT_ACCESS_TOKEN, refreshToken: process.env.TRAKT_REFRESH_TOKEN }; if (!config.clientId || !config.clientSecret) { throw new Error('TRAKT_CLIENT_ID and TRAKT_CLIENT_SECRET environment variables are required'); } this.traktClient = new TraktClient(config); this.syncEngine = new TraktSyncEngine(this.traktClient, this.plexClient); this.isInitialized = true; }