Skip to main content
Glama

calculate_otp_codes

Generate OTP codes for tokens matching a specified pattern using the otp-mcp-server. Supports TOTP and HOTP algorithms for secure one-time password creation.

Instructions

Calculate the OTP code for all tokens matching the pattern. Args: pattern: Token pattern (part of the name or token number)

Input Schema

NameRequiredDescriptionDefault
patternYes

Input Schema (JSON Schema)

{ "properties": { "pattern": { "title": "Pattern", "type": "string" } }, "required": [ "pattern" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'calculate_otp_codes' MCP tool. It uses find_tokens to locate matching OTP tokens, computes their current OTP codes, formats the output, and raises ToolError if no tokens are found or on computation errors. The @mcp.tool() decorator handles registration and schema inference.
    @mcp.tool() async def calculate_otp_codes(pattern: str) -> str: """ Calculate the OTP code for all tokens matching the pattern. Args: pattern: Token pattern (part of the name or token number) """ codes = [] tokens = find_tokens(pattern) for token in tokens: try: otp = token.calculate() codes.append(f"{token.rowid}# {str(token)} {otp}") except Exception: raise ToolError(f"Error generating OTP code for token {token.rowid}# {str(token)}") if not codes: raise ToolError("No OTP tokens found.") return "\n".join(codes)
  • Helper utility function used by calculate_otp_codes (and others) to filter OTP tokens from the database based on a case-insensitive pattern match in the token string or exact ID match.
    def find_tokens(pattern: str) -> list[Token]: """ Find tokens matching the given pattern. """ db = get_token_db() if not pattern: return db.get_tokens() tokens_list = [] pattern = pattern.lower() for token in db.get_tokens(): tmp = str(token).lower().strip() if pattern in tmp or pattern == f"{token.rowid}#": tokens_list.append(token) return tokens_list

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/andreax79/otp-mcp'

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