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
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes |
Input Schema (JSON Schema)
{
"properties": {
"pattern": {
"title": "Pattern",
"type": "string"
}
},
"required": [
"pattern"
],
"type": "object"
}
Implementation Reference
- otp_mcp/tool.py:98-116 (handler)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)
- otp_mcp/tool.py:36-49 (helper)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