Skip to main content
Glama

complete_authentication

Validate user authentication using a device code to access Microsoft Graph API for managing Outlook, Calendar, OneDrive, and Contacts.

Instructions

Complete the authentication process after the user has entered the device code

Args:
    flow_cache: The flow data returned from authenticate_account (the _flow_cache field)

Returns:
    Account information if authentication was successful

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
flow_cacheYes

Implementation Reference

  • The complete_authentication tool handler: completes Microsoft account authentication using device flow after user input. Decorated with @mcp.tool for automatic registration with the FastMCP server.
    @mcp.tool
    def complete_authentication(flow_cache: str) -> dict[str, str]:
        """Complete the authentication process after the user has entered the device code
    
        Args:
            flow_cache: The flow data returned from authenticate_account (the _flow_cache field)
    
        Returns:
            Account information if authentication was successful
        """
        import ast
    
        try:
            flow = ast.literal_eval(flow_cache)
        except (ValueError, SyntaxError):
            raise ValueError("Invalid flow cache data")
    
        app = auth.get_app()
        result = app.acquire_token_by_device_flow(flow)
    
        if "error" in result:
            error_msg = result.get("error_description", result["error"])
            if "authorization_pending" in error_msg:
                return {
                    "status": "pending",
                    "message": "Authentication is still pending. The user needs to complete the authentication process.",
                    "instructions": "Please ensure you've visited the URL and entered the code, then try again.",
                }
            raise Exception(f"Authentication failed: {error_msg}")
    
        # Save the token cache
        cache = app.token_cache
        if isinstance(cache, auth.msal.SerializableTokenCache) and cache.has_state_changed:
            auth._write_cache(cache.serialize())
    
        # Get the newly added account
        accounts = app.get_accounts()
        if accounts:
            # Find the account that matches the token we just got
            for account in accounts:
                if (
                    account.get("username", "").lower()
                    == result.get("id_token_claims", {})
                    .get("preferred_username", "")
                    .lower()
                ):
                    return {
                        "status": "success",
                        "username": account["username"],
                        "account_id": account["home_account_id"],
                        "message": f"Successfully authenticated {account['username']}",
                    }
            # If exact match not found, return the last account
            account = accounts[-1]
            return {
                "status": "success",
                "username": account["username"],
                "account_id": account["home_account_id"],
                "message": f"Successfully authenticated {account['username']}",
            }
    
        return {
            "status": "error",
            "message": "Authentication succeeded but no account was found",
        }
  • The @mcp.tool decorator registers the complete_authentication function as an MCP tool.
    @mcp.tool
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the tool completes authentication and returns account info on success, but fails to disclose critical behavioral traits: error handling (e.g., what happens if authentication fails), side effects (e.g., session creation), permissions required, or rate limits. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the core purpose stated first, followed by structured Args and Returns sections. Every sentence adds value, but minor verbosity in the parameter explanation (e.g., parenthetical detail) slightly reduces efficiency, preventing a perfect score.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (authentication completion, a mutation), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It omits details on failure modes, return format beyond 'Account information', and broader context like security implications, making it insufficient for safe and effective use by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that 'flow_cache' is 'The flow data returned from authenticate_account (the _flow_cache field)', clarifying its source and purpose beyond the schema's generic 'Flow Cache' title. However, it doesn't detail the parameter's format, constraints, or how to obtain it fully, leaving gaps in documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Complete the authentication process after the user has entered the device code.' It specifies the verb ('complete') and resource ('authentication process'), and distinguishes it from sibling 'authenticate_account' by handling the final step after device code entry. However, it doesn't explicitly differentiate from all other authentication-related tools (though none are listed), keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by referencing 'after the user has entered the device code' and dependency on 'authenticate_account' for the flow_cache, providing some context. However, it lacks explicit guidance on when to use this vs. alternatives (e.g., if other auth methods exist) or clear prerequisites, leaving room for ambiguity in a broader toolset.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/elyxlz/microsoft-mcp'

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