Skip to main content
Glama

login

Authenticate with Microsoft Graph API using device code flow to access Microsoft 365 services across multiple tenants. Manage multi-tenant accounts through a single flexible interface.

Instructions

Authenticate with Microsoft using device code flow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoForce a new login even if already logged in

Implementation Reference

  • src/auth-tools.ts:7-57 (registration)
    Registration of the 'login' MCP tool, including its description, input schema (force parameter), and complete handler function that implements device code authentication flow using AuthManager.
    server.tool( 'login', 'Authenticate with Microsoft using device code flow', { force: z.boolean().default(false).describe('Force a new login even if already logged in'), }, async ({ force }) => { try { if (!force) { const loginStatus = await authManager.testLogin(); if (loginStatus.success) { return { content: [ { type: 'text', text: JSON.stringify({ status: 'Already logged in', ...loginStatus, }), }, ], }; } } const text = await new Promise<string>((resolve, reject) => { authManager.acquireTokenByDeviceCode(resolve).catch(reject); }); return { content: [ { type: 'text', text: JSON.stringify({ error: 'device_code_required', message: text.trim(), }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Authentication failed: ${(error as Error).message}` }), }, ], }; } } );
  • src/server.ts:80-84 (registration)
    Conditional registration of auth tools (including 'login') via registerAuthTools call during server initialization.
    const shouldRegisterAuthTools = !this.options.http || this.options.enableAuthTools; if (shouldRegisterAuthTools) { // Pass graphClient to enable the graph-request tool registerAuthTools(this.server, this.authManager, this.graphClient); }
  • Zod input schema for the 'login' tool defining the optional 'force' boolean parameter.
    force: z.boolean().default(false).describe('Force a new login even if already logged in'), },
  • The executor/handler function for the 'login' tool. Handles checking current login status, forcing new login if specified, initiating device code flow, and returning appropriate MCP content responses.
    async ({ force }) => { try { if (!force) { const loginStatus = await authManager.testLogin(); if (loginStatus.success) { return { content: [ { type: 'text', text: JSON.stringify({ status: 'Already logged in', ...loginStatus, }), }, ], }; } } const text = await new Promise<string>((resolve, reject) => { authManager.acquireTokenByDeviceCode(resolve).catch(reject); }); return { content: [ { type: 'text', text: JSON.stringify({ error: 'device_code_required', message: text.trim(), }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Authentication failed: ${(error as Error).message}` }), }, ], }; } }

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/ForITLLC/forit-microsoft-graph'

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