Skip to main content
Glama

Check Authentication Status

check_auth

Verify authentication status with Brightspace. Use when checking login state or resolving authentication errors from other tools.

Instructions

Check if you are authenticated with Brightspace. Run the brightspace-auth CLI first to authenticate. Use this when the user asks if they're logged in, if authentication is working, or when other tools return auth errors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the check_auth tool. Checks if a valid token exists via TokenManager. If none, attempts auto-reauthentication via AuthRunner. Returns success/failure status with expiry details.
    async () => {
      log("DEBUG", "check_auth tool called");
    
      let token = await tokenManager.getToken();
    
      if (!token) {
        log("INFO", "check_auth: No valid token, attempting auto-reauthentication...");
    
        const success = await authRunner.run();
        if (success) {
          token = await tokenManager.getToken();
        }
    
        if (!token) {
          log("INFO", "check_auth: Auto-reauthentication failed or produced no valid token");
    
          const content: Array<{ type: "text"; text: string }> = [
            {
              type: "text",
              text: "Not authenticated. Auto-reauthentication was attempted but failed. " +
                "Please run `brightspace-auth` manually in your terminal to log in. " +
                "Make sure your credentials in .env are correct and your internet connection is stable.",
            },
          ];
          const notice = getUpdateNotice();
          if (notice) content.push({ type: "text", text: notice });
          return { content };
        }
    
        log("INFO", "check_auth: Auto-reauthentication succeeded");
      }
    
      const expiresIn = Math.round((token.expiresAt - Date.now()) / 1000 / 60);
      log("INFO", `check_auth: Token valid, expires in ~${expiresIn} minutes`);
    
      const content: Array<{ type: "text"; text: string }> = [
        {
          type: "text",
          text: `Authenticated with Brightspace. Token expires in ~${expiresIn} minutes. Source: ${token.source}.`,
        },
      ];
      const notice = getUpdateNotice();
      if (notice) content.push({ type: "text", text: notice });
      return { content };
    }
  • The tool registration metadata/schema: title and description for the check_auth tool. No input schema since it's a zero-argument tool.
    {
      title: "Check Authentication Status",
      description:
        "Check if you are authenticated with Brightspace. " +
        "Run the brightspace-auth CLI first to authenticate. " +
        "Use this when the user asks if they're logged in, if authentication is working, " +
        "or when other tools return auth errors.",
    },
  • src/index.ts:110-165 (registration)
    Registration of the check_auth tool on the MCP server using server.registerTool(). Registers the tool name, description metadata, and the async handler function.
    server.registerTool(
      "check_auth",
      {
        title: "Check Authentication Status",
        description:
          "Check if you are authenticated with Brightspace. " +
          "Run the brightspace-auth CLI first to authenticate. " +
          "Use this when the user asks if they're logged in, if authentication is working, " +
          "or when other tools return auth errors.",
      },
      async () => {
        log("DEBUG", "check_auth tool called");
    
        let token = await tokenManager.getToken();
    
        if (!token) {
          log("INFO", "check_auth: No valid token, attempting auto-reauthentication...");
    
          const success = await authRunner.run();
          if (success) {
            token = await tokenManager.getToken();
          }
    
          if (!token) {
            log("INFO", "check_auth: Auto-reauthentication failed or produced no valid token");
    
            const content: Array<{ type: "text"; text: string }> = [
              {
                type: "text",
                text: "Not authenticated. Auto-reauthentication was attempted but failed. " +
                  "Please run `brightspace-auth` manually in your terminal to log in. " +
                  "Make sure your credentials in .env are correct and your internet connection is stable.",
              },
            ];
            const notice = getUpdateNotice();
            if (notice) content.push({ type: "text", text: notice });
            return { content };
          }
    
          log("INFO", "check_auth: Auto-reauthentication succeeded");
        }
    
        const expiresIn = Math.round((token.expiresAt - Date.now()) / 1000 / 60);
        log("INFO", `check_auth: Token valid, expires in ~${expiresIn} minutes`);
    
        const content: Array<{ type: "text"; text: string }> = [
          {
            type: "text",
            text: `Authenticated with Brightspace. Token expires in ~${expiresIn} minutes. Source: ${token.source}.`,
          },
        ];
        const notice = getUpdateNotice();
        if (notice) content.push({ type: "text", text: notice });
        return { content };
      }
    );
  • TokenManager.getToken() helper used by check_auth to retrieve cached or stored tokens. Returns null if no valid token exists (expired or within refresh buffer).
    async getToken(): Promise<TokenData | null> {
      // Check memory cache first
      if (this.cachedToken && this.isValid(this.cachedToken)) {
        log("DEBUG", "Returning cached token");
        return this.cachedToken;
      }
    
      // Try loading from disk
      const storedToken = await this.sessionStore.load();
      if (storedToken && this.isValid(storedToken)) {
        log("DEBUG", "Loaded valid token from session store");
        this.cachedToken = storedToken;
        return storedToken;
      }
    
      log("DEBUG", "No valid token available");
      return null;
    }
  • AuthRunner helper that launches the brightspace-auth CLI as a child process for automatic reauthentication when the token is missing or expired.
    export class AuthRunner {
      private running = false;
      private readonly scriptPath: string;
      private readonly projectRoot: string;
    
      constructor() {
        // Resolve paths relative to this file's compiled location (build/auth/auth-runner.js)
        const thisDir = path.dirname(fileURLToPath(import.meta.url));
        this.scriptPath = path.resolve(thisDir, "..", "auth-cli.js");
        this.projectRoot = path.resolve(thisDir, "..", "..");
      }
    
      /**
       * Spawn the auth CLI and wait for it to complete.
       * Returns true if authentication succeeded, false otherwise.
       * Prevents concurrent auth attempts via a simple mutex.
       */
      async run(): Promise<boolean> {
        if (this.running) {
          log("DEBUG", "Auth already running, skipping duplicate attempt");
          return false;
        }
    
        this.running = true;
        try {
          log("INFO", "Auto-launching brightspace-auth...");
    
          return await new Promise<boolean>((resolve) => {
            execFile(
              process.execPath, // use the same Node binary
              [this.scriptPath],
              {
                timeout: AUTH_TIMEOUT_MS,
                cwd: this.projectRoot,
                env: { ...process.env },
              },
              (error, _stdout, _stderr) => {
                if (error) {
                  log("ERROR", "Auto-auth process failed", error.message);
                  resolve(false);
                } else {
                  log("INFO", "Auto-auth completed successfully");
                  resolve(true);
                }
              },
            );
          });
        } finally {
          this.running = false;
        }
      }
    }
Behavior4/5

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

No annotations provided, but description implies read-only check and suggests appropriate usage context. Lacks detail on return value or potential error states, but sufficient for simple auth check.

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

Conciseness5/5

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

Three sentences, dramatically front-loaded. First sentence states purpose, second gives prerequisites, third lists use cases. No wasted words.

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

Completeness5/5

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

For a zero-parameter, no output schema tool, description fully explains what it does, prerequisites, and when to use it. Complements sibling tools well.

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

Parameters4/5

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

No parameters defined; schema covers 100%. Description does not add parameter info, but with zero parameters, baseline is 4 per guidelines.

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

Purpose5/5

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

Description clearly states the tool checks authentication status with Brightspace. Distinct from siblings which handle file downloads, course content, etc.

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

Usage Guidelines5/5

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

Explicitly instructs to run a CLI first, specifies when to use: when user asks about login status or when auth errors occur from other tools.

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

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/RohanMuppa/brightspace-mcp-server'

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