UNPKG

teams-mcp-server

Version:

Microsoft Teams MCP server with direct messaging support

60 lines (59 loc) 2.6 kB
import { debugLog } from '../utils/logger.js'; export function createAuthStatusTool(authManager, teamsClient) { return { name: 'teams_auth_status', description: 'Check authentication status and initiate authentication if needed', inputSchema: { type: 'object', properties: {}, required: [] }, handler: async () => { try { const isAuthenticated = await authManager.isAuthenticated(); if (!isAuthenticated) { debugLog('Not authenticated. Initiating authentication flow...'); const token = await authManager.getToken(); if (!token) { debugLog('Failed to get token after authentication attempt'); return { content: [{ type: 'text', text: 'Authentication failed. Please check your Azure app configuration and try again.' }] }; } debugLog('Token acquired successfully'); } const userProfile = await teamsClient.getUserProfile(); const rateLimitStats = teamsClient.getRateLimitStats(); return { content: [{ type: 'text', text: JSON.stringify({ authenticated: true, user: { id: userProfile.id, displayName: userProfile.displayName, email: userProfile.mail || userProfile.userPrincipalName }, rateLimit: { requestsUsed: rateLimitStats.requestsUsed, requestsRemaining: rateLimitStats.requestsRemaining, resetInMinutes: Math.ceil(rateLimitStats.windowResetInMs / 60000) } }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Authentication status check failed: ${error.message}` }] }; } } }; }