set-auth-code
Configure Google Tasks access by entering the OAuth authorization code to authenticate with Google's API.
Instructions
Set the authentication code received from Google OAuth flow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The authentication code received from Google |
Implementation Reference
- src/index.ts:145-183 (handler)The handler function for the 'set-auth-code' tool. It exchanges the provided OAuth code for access and refresh tokens using Google OAuth2Client, stores the credentials in memory, closes the temporary auth server, and returns a success message or an error if token retrieval fails.async ({ code }) => { try { const { tokens } = await oauth2Client.getToken(code); oauth2Client.setCredentials(tokens); // Store tokens in memory only credentials = tokens; // Close auth server if it's still running if (authServer) { try { authServer.close(); } catch (error) { console.error('Error closing auth server:', error); } authServer = null; } return { content: [ { type: "text", text: "Authentication successful! You can now use the Google Tasks tools.", }, ], }; } catch (error) { console.error('Error retrieving access token:', error); return { isError: true, content: [ { type: "text", text: `Authentication failed: ${error}`, }, ], }; } }
- src/index.ts:142-144 (schema)Input schema for the 'set-auth-code' tool, defining a required 'code' parameter as a string using Zod.{ code: z.string().describe("The authentication code received from Google"), },
- src/index.ts:139-184 (registration)Registration of the 'set-auth-code' tool using server.tool(), including name, description, input schema, and inline handler function.server.tool( "set-auth-code", "Set the authentication code received from Google OAuth flow", { code: z.string().describe("The authentication code received from Google"), }, async ({ code }) => { try { const { tokens } = await oauth2Client.getToken(code); oauth2Client.setCredentials(tokens); // Store tokens in memory only credentials = tokens; // Close auth server if it's still running if (authServer) { try { authServer.close(); } catch (error) { console.error('Error closing auth server:', error); } authServer = null; } return { content: [ { type: "text", text: "Authentication successful! You can now use the Google Tasks tools.", }, ], }; } catch (error) { console.error('Error retrieving access token:', error); return { isError: true, content: [ { type: "text", text: `Authentication failed: ${error}`, }, ], }; } } );