add_token
Create and configure a new OTP token with customizable parameters like secret key, issuer, account, type, algorithm, and period for secure authentication.
Instructions
Add a new OTP token.
Args:
secret: Base32 encoded secret key
issuer: Issuer of the OTP token
account: Accout for the OTP token
type: Type of the OTP token (TOTP or HOTP) (default is TOTP)
algorithm: Hashing algorithm to use (SHA1, SHA256, SHA512, MD5) (default is SHA1)
counter: Counter value for HOTP tokens (default is 0)
digits: Number of digits in the OTP code (default is 6)
period: Time period for TOTP tokens in seconds (default is 30)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account | Yes | Account for the OTP token | |
| algorithm | No | SHA1 | |
| counter | No | Counter value for HOTP tokens | |
| digits | No | Number of digits in the OTP code | |
| issuer | Yes | Issuer of the OTP token | |
| period | No | Time period for TOTP tokens in seconds | |
| secret | Yes | Secret key Base32 | |
| type | No | TOTP |
Implementation Reference
- otp_mcp/tool.py:119-162 (handler)The 'add_token' tool handler function, decorated with @mcp.tool() for registration. It defines the input schema via Pydantic Field descriptions and Literals, parses the secret, creates a Token object, and inserts it into the token database.@mcp.tool() async def add_token( secret: str = Field(description="Secret key Base32"), issuer: str = Field(description="Issuer of the OTP token"), account: str = Field(description="Account for the OTP token"), type: Literal[TOKEN_TYPES] = "TOTP", algorithm: Literal[ALGORITHMS] = "SHA1", counter: int = Field(0, description="Counter value for HOTP tokens"), digits: int = Field(6, description="Number of digits in the OTP code"), period: int = Field(30, description="Time period for TOTP tokens in seconds"), ) -> str: """ Add a new OTP token. Args: secret: Base32 encoded secret key issuer: Issuer of the OTP token account: Accout for the OTP token type: Type of the OTP token (TOTP or HOTP) (default is TOTP) algorithm: Hashing algorithm to use (SHA1, SHA256, SHA512, MD5) (default is SHA1) counter: Counter value for HOTP tokens (default is 0) digits: Number of digits in the OTP code (default is 6) period: Time period for TOTP tokens in seconds (default is 30) """ try: db = get_token_db() token = Token( uri=None, type=TokenType[type] if type else TokenType.TOTP, algorithm=algorithm, counter=counter, digits=digits, issuer=issuer, issuer_int=None, issuer_ext=None, label=account, period=period, secret=Secret.from_base32(secret), token_db=db, ) db.insert(token) return "Token added successfully." except Exception: raise ToolError("Error adding OTP token. Please check the provided parameters.")
- otp_mcp/tool.py:119-119 (registration)Registration of the 'add_token' tool using the @mcp.tool() decorator.@mcp.tool()
- otp_mcp/tool.py:121-129 (schema)Input schema definition for the 'add_token' tool using Pydantic Fields and Literal types for validation.secret: str = Field(description="Secret key Base32"), issuer: str = Field(description="Issuer of the OTP token"), account: str = Field(description="Account for the OTP token"), type: Literal[TOKEN_TYPES] = "TOTP", algorithm: Literal[ALGORITHMS] = "SHA1", counter: int = Field(0, description="Counter value for HOTP tokens"), digits: int = Field(6, description="Number of digits in the OTP code"), period: int = Field(30, description="Time period for TOTP tokens in seconds"), ) -> str: