Skip to main content
Glama
vargahis

monarch-mcp

check_auth_status

Verify authentication status with Monarch Money to determine if user credentials are valid before accessing financial data.

Instructions

Check if already authenticated with Monarch Money.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The check_auth_status tool handler function that checks for authentication tokens in the keyring and environment variables, returning a status message about the current authentication state.
    @mcp.tool()
    def check_auth_status() -> str:
        """Check if already authenticated with Monarch Money."""
        try:
            # Check if we have a token in the keyring
            token = secure_session.load_token()
            if token:
                status = "Authentication token found in secure keyring storage\n"
            else:
                status = "No authentication token found in keyring\n"
    
            email = os.getenv("MONARCH_EMAIL")
            if email:
                status += f"Environment email: {email}\n"
    
            status += (
                "\nTry get_accounts to test connection or run login_setup.py if needed."
            )
    
            return status
        except Exception as e:  # pylint: disable=broad-exception-caught
            return f"Error checking auth status: {e}"
  • The @mcp.tool() decorator that registers check_auth_status as an MCP tool with the FastMCP server instance.
    @mcp.tool()
  • The load_token() method in SecureMonarchSession class that retrieves the authentication token from the system keyring, which is called by check_auth_status to verify authentication state.
    def load_token(self) -> Optional[str]:
        """Load the authentication token from the system keyring."""
        try:
            token = keyring.get_password(KEYRING_SERVICE, KEYRING_USERNAME)
            if token:
                logger.info("Token loaded from keyring")
                return token
            logger.info("No token found in keyring")
            return None
        except Exception as e:  # pylint: disable=broad-exception-caught
            logger.error("Failed to load token from keyring: %s", e)
            return None
  • The SecureMonarchSession class that manages Monarch Money sessions securely using the system keyring, providing token storage, retrieval, and cleanup functionality used by check_auth_status.
    class SecureMonarchSession:
        """Manages Monarch Money sessions securely using the system keyring."""
    
        def save_token(self, token: str) -> None:
            """Save the authentication token to the system keyring."""
            try:
                keyring.set_password(KEYRING_SERVICE, KEYRING_USERNAME, token)
                logger.info("Token saved securely to keyring")
    
                # Clean up any old insecure files
                self._cleanup_old_session_files()
    
            except Exception as e:
                logger.error("Failed to save token to keyring: %s", e)
                raise
    
        def load_token(self) -> Optional[str]:
            """Load the authentication token from the system keyring."""
            try:
                token = keyring.get_password(KEYRING_SERVICE, KEYRING_USERNAME)
                if token:
                    logger.info("Token loaded from keyring")
                    return token
                logger.info("No token found in keyring")
                return None
            except Exception as e:  # pylint: disable=broad-exception-caught
                logger.error("Failed to load token from keyring: %s", e)
                return None
    
        def delete_token(self) -> None:
            """Delete the authentication token from the system keyring."""
            try:
                keyring.delete_password(KEYRING_SERVICE, KEYRING_USERNAME)
                logger.info("Token deleted from keyring")
    
                # Also clean up any old insecure files
                self._cleanup_old_session_files()
    
            except keyring.errors.PasswordDeleteError:
                logger.info("No token found in keyring to delete")
            except Exception as e:  # pylint: disable=broad-exception-caught
                logger.error("Failed to delete token from keyring: %s", e)
    
        def get_authenticated_client(self) -> Optional[MonarchMoney]:
            """Get an authenticated MonarchMoney client."""
            token = self.load_token()
            if not token:
                return None
    
            try:
                client = MonarchMoney(token=token)
                logger.info("MonarchMoney client created with stored token")
                return client
            except Exception as e:  # pylint: disable=broad-exception-caught
                logger.error("Failed to create MonarchMoney client: %s", e)
                return None
    
        def save_authenticated_session(self, mm: MonarchMoney) -> None:
            """Save the session from an authenticated MonarchMoney instance."""
            if mm.token:
                self.save_token(mm.token)
            else:
                logger.warning("MonarchMoney instance has no token to save")
    
        def _cleanup_old_session_files(self) -> None:
            """Clean up old insecure session files."""
            cleanup_paths = [
                ".mm/mm_session.pickle",
                "monarch_session.json",
                ".mm",  # Remove the entire directory if empty
            ]
    
            for path in cleanup_paths:
                try:
                    if os.path.exists(path):
                        if os.path.isfile(path):
                            os.remove(path)
                            logger.info("Cleaned up old insecure session file: %s", path)
                        elif os.path.isdir(path) and not os.listdir(path):
                            os.rmdir(path)
                            logger.info("Cleaned up empty session directory: %s", path)
                except Exception as e:  # pylint: disable=broad-exception-caught
                    logger.warning("Could not clean up %s: %s", path, e)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states what the tool does ('Check if already authenticated') without adding context such as what 'authenticated' means in this system, potential error responses, or side effects (e.g., if it triggers re-authentication). This is inadequate for a tool that likely interacts with authentication state.

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?

The description is a single, clear sentence: 'Check if already authenticated with Monarch Money.' It is front-loaded with the core purpose, has zero wasted words, and is appropriately sized for a simple tool with no parameters.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, output schema exists), the description is minimally complete. It states the purpose but lacks context about authentication state management, error handling, or integration with sibling tools. With an output schema, it doesn't need to explain return values, but more behavioral detail would improve completeness.

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?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description doesn't add parameter details, which is appropriate here. A baseline of 4 is applied as it effectively handles the lack of parameters without introducing confusion.

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: 'Check if already authenticated with Monarch Money.' It specifies the verb ('Check') and the resource/condition ('authenticated with Monarch Money'), making the intent unambiguous. However, it doesn't differentiate from sibling tools, as there's no explicit mention of alternatives like 'setup_authentication' for when not authenticated.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., use before other data-fetching tools), exclusions, or refer to sibling tools like 'setup_authentication' for handling unauthenticated states. This leaves the agent without context for tool selection.

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/vargahis/monarch-mcp'

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