Skip to main content
Glama
arpitbatra123

Google Tasks MCP Server

authenticate

Generate a Google authentication URL to connect the Google Tasks MCP Server with your Google account for task management through Claude.

Instructions

Get URL to authenticate with Google Tasks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'authenticate' tool. It sets up a temporary HTTP server on port 3000 to handle the OAuth callback, generates the Google authorization URL, starts the server, and returns the URL with instructions to the user.
    async () => { // Make sure any previous server is closed if (authServer) { try { authServer.close(); } catch (error) { console.error('Error closing existing auth server:', error); } authServer = null; } // Create the temporary HTTP server for OAuth callback authServer = http.createServer(async (req, res) => { try { // Parse the URL to get the authorization code const queryParams = url.parse(req.url || '', true).query; const code = queryParams.code; if (code) { console.error('✅ Authorization code received'); // Send success response with the code res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(` <h1>Authorization Code Received</h1> <p>Please copy this code and use it with the 'set-auth-code' tool in Claude:</p> <div style="padding: 10px; background-color: #f0f0f0; border: 1px solid #ccc; margin: 20px 0;"> <code>${code}</code> </div> <p>You can close this window after copying the code.</p> `); // Close the server after a short delay setTimeout(() => { if (authServer) { authServer.close(); authServer = null; } }, 60000); // Keep the server alive for 1 minute } else { res.writeHead(400, { 'Content-Type': 'text/html' }); res.end(` <h1>Authentication Failed</h1> <p>No authorization code received.</p> <p>Please try again.</p> `); } } catch (error) { console.error('Error during authentication:', error); res.writeHead(500, { 'Content-Type': 'text/html' }); res.end(` <h1>Authentication Error</h1> <p>${error instanceof Error ? error.message : String(error)}</p> `); } }); // Start the server authServer.listen(REDIRECT_PORT, () => { console.error(`Temporary authentication server running at http://localhost:${REDIRECT_PORT}/`); console.error('Waiting for authentication...'); }); // Generate the auth URL const authUrl = oauth2Client.generateAuthUrl({ access_type: 'offline', scope: SCOPES, // Force approval prompt to always get a refresh token prompt: 'consent' }); return { content: [ { type: "text", text: `Please visit this URL to authenticate with Google Tasks:\n\n${authUrl}\n\nAfter authenticating, you'll receive a code. Use the 'set-auth-code' tool with that code.`, }, ], }; }
  • src/index.ts:52-136 (registration)
    Registration of the 'authenticate' tool via server.tool call. It has no input parameters (empty schema) and provides a description.
    server.tool( "authenticate", "Get URL to authenticate with Google Tasks", {}, async () => { // Make sure any previous server is closed if (authServer) { try { authServer.close(); } catch (error) { console.error('Error closing existing auth server:', error); } authServer = null; } // Create the temporary HTTP server for OAuth callback authServer = http.createServer(async (req, res) => { try { // Parse the URL to get the authorization code const queryParams = url.parse(req.url || '', true).query; const code = queryParams.code; if (code) { console.error('✅ Authorization code received'); // Send success response with the code res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(` <h1>Authorization Code Received</h1> <p>Please copy this code and use it with the 'set-auth-code' tool in Claude:</p> <div style="padding: 10px; background-color: #f0f0f0; border: 1px solid #ccc; margin: 20px 0;"> <code>${code}</code> </div> <p>You can close this window after copying the code.</p> `); // Close the server after a short delay setTimeout(() => { if (authServer) { authServer.close(); authServer = null; } }, 60000); // Keep the server alive for 1 minute } else { res.writeHead(400, { 'Content-Type': 'text/html' }); res.end(` <h1>Authentication Failed</h1> <p>No authorization code received.</p> <p>Please try again.</p> `); } } catch (error) { console.error('Error during authentication:', error); res.writeHead(500, { 'Content-Type': 'text/html' }); res.end(` <h1>Authentication Error</h1> <p>${error instanceof Error ? error.message : String(error)}</p> `); } }); // Start the server authServer.listen(REDIRECT_PORT, () => { console.error(`Temporary authentication server running at http://localhost:${REDIRECT_PORT}/`); console.error('Waiting for authentication...'); }); // Generate the auth URL const authUrl = oauth2Client.generateAuthUrl({ access_type: 'offline', scope: SCOPES, // Force approval prompt to always get a refresh token prompt: 'consent' }); return { content: [ { type: "text", text: `Please visit this URL to authenticate with Google Tasks:\n\n${authUrl}\n\nAfter authenticating, you'll receive a code. Use the 'set-auth-code' tool with that code.`, }, ], }; } );
  • Helper function used by multiple tools to check if authentication credentials are set before allowing access to Google Tasks API.
    function isAuthenticated() { return credentials !== null; }
  • Empty input schema for the 'authenticate' tool, indicating it takes no parameters.
    {},
  • Comment and helper function declaration for authentication status check, used extensively in other tools.
    // Helper function to check if authenticated function isAuthenticated() { return credentials !== null; }

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/arpitbatra123/mcp-googletasks'

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