authenticate
Verify authentication credentials for PocketBase to enable document extraction and storage from Microsoft Learn and GitHub sources.
Instructions
Test authentication with PocketBase using provided credentials
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pocketbaseUrl | Yes | PocketBase server URL (e.g., https://your-pb-instance.com) | |
| Yes | PocketBase admin email for authentication | ||
| password | Yes | PocketBase admin password |
Implementation Reference
- src/index.js:727-837 (handler)The 'authenticate' tool implementation, which tests PocketBase credentials and updates global server configuration if successful.
const authenticateTool = server.tool( 'authenticate', 'Test authentication with PocketBase using provided credentials', { pocketbaseUrl: z.string().url('Invalid URL format').describe('PocketBase server URL (e.g., https://your-pb-instance.com)'), email: z.string().email('Invalid email format').describe('PocketBase admin email for authentication'), password: z.string().min(1, 'Password cannot be empty').describe('PocketBase admin password') }, async ({ pocketbaseUrl, email, password }) => { try { // Create a temporary PocketBase instance for testing const testPb = new PocketBase(pocketbaseUrl); // Attempt authentication using the correct superuser collection const authData = await testPb.collection('_superusers').authWithPassword(email, password); // Test basic functionality by fetching collections const collections = await testPb.collections.getList(1, 10); // Get server health to verify connectivity const healthCheck = await testPb.health.check(); // Update the global configuration if authentication succeeds process.env.POCKETBASE_URL = pocketbaseUrl; process.env.POCKETBASE_EMAIL = email; process.env.POCKETBASE_PASSWORD = password; // Reset configuration to force reload with new credentials configInitialized = false; pb = null; initializeConfig(); return { content: [ { type: 'text', text: `✅ **Authentication Successful!**\n\n` + `**PocketBase Server:** ${pocketbaseUrl}\n` + `**Admin Email:** ${email}\n` + `**Admin ID:** ${authData.record.id}\n` + `**Created:** ${new Date(authData.record.created).toLocaleString()}\n` + `**Token Valid:** ${testPb.authStore.isValid}\n\n` + `**Server Info:**\n` + `- Server Status: ${healthCheck?.message || 'Healthy'}\n` + `- Collections Available: ${collections.totalItems}\n` + `- Sample Collections: ${collections.items.slice(0, 3).map(c => c.name).join(', ')}\n\n` + `🔧 **Configuration Updated** - You can now use other tools that require PocketBase access.\n\n` + `**Available Tools:**\n` + `- \`extract_document\`: Extract and store documents\n` + `- \`list_documents\`: List stored documents\n` + `- \`search_documents\`: Search document content\n` + `- \`get_document\`: Get specific document by ID\n` + `- \`delete_document\`: Delete a document\n` + `- \`ensure_collection\`: Create documents collection if needed\n` + `- \`collection_info\`: Get collection statistics\n` + `- \`connection_status\`: Check current connection status` } ] }; } catch (error) { let errorMessage = error.message; let troubleshooting = ''; let statusCode = error.status || 0; if (statusCode === 400) { errorMessage = 'Invalid credentials - please check your email and password'; troubleshooting = '\n\n**Troubleshooting:**\n' + '• Verify email and password are correct\n' + '• Ensure the account has admin/superuser privileges\n' + '• Check if the admin account exists in PocketBase'; } else if (statusCode === 404) { errorMessage = 'Admin user not found - account may not exist'; troubleshooting = '\n\n**Troubleshooting:**\n' + '• Create an admin account in PocketBase\n' + '• Ensure you\'re using the correct email address\n' + '• Check PocketBase admin dashboard for existing accounts'; } else if (error.message.includes('fetch') || error.message.includes('ECONNREFUSED')) { errorMessage = 'Cannot connect to PocketBase server - please check the URL'; troubleshooting = '\n\n**Troubleshooting:**\n' + '• Verify the PocketBase URL is correct\n' + '• Ensure PocketBase is running and accessible\n' + '• Check for network connectivity issues\n' + '• Verify firewall settings allow connections'; } else if (statusCode === 401) { errorMessage = 'Unauthorized - authentication rejected by server'; troubleshooting = '\n\n**Troubleshooting:**\n' + '• Check if admin authentication is enabled\n' + '• Verify account credentials are correct\n' + '• Ensure PocketBase server is properly configured'; } return { content: [ { type: 'text', text: `❌ **Authentication Failed**\n\n` + `**Error:** ${errorMessage}\n` + `**Server:** ${pocketbaseUrl}\n` + `**Email:** ${email}\n` + `**Status Code:** ${statusCode || 'Unknown'}${troubleshooting}\n\n` + `**Common Solutions:**\n` + `• Make sure PocketBase is running and accessible\n` + `• Verify admin credentials in PocketBase dashboard\n` + `• Check server URL format (include http:// or https://)\n` + `• Ensure no trailing slash in the URL` } ], isError: true }; } }