confusables-mcp / app.py
kokluch's picture
Switch to FastMCP only, set host/port, use SSE transport
944fd03
from fastmcp import FastMCP
from confusables import is_confusable, confusable_characters, confusable_regex, normalize
mcp = FastMCP(
"Confusables MCP Server",
host="0.0.0.0",
port=7860
)
@mcp.tool
def is_confusable_tool(str1: str, str2: str) -> bool:
"""
Check if two strings are visually confusable (i.e., they look similar to a human, but may use different Unicode characters).
Args:
str1: The first string to compare.
str2: The second string to compare.
Returns:
True if the two strings are visually confusable, False otherwise.
Example:
gr_is_confusable("rover", "Ʀỏ𝕍3β„›") # True
"""
return is_confusable(str1, str2)
@mcp.tool
def confusable_characters_tool(char: str) -> list[str]:
"""
List all Unicode characters or character sequences that are visually confusable with the given character.
Args:
char: The character to analyze (must be a single character).
Returns:
A list of confusable characters or sequences.
Example:
gr_confusable_characters("c") # ['Δ‹', 'α΄„', '𝔠', ...]
"""
return confusable_characters(char)
@mcp.tool
def confusable_regex_tool(string: str, include_character_padding: bool) -> str:
"""
Generate a regular expression string that matches all visually confusable variants of the input string.
Args:
string: The reference string.
include_character_padding: If True, the regex will allow for character padding (extra confusable characters between the main ones).
Returns:
A regex pattern string.
Example:
gr_confusable_regex("bore", True)
"""
return confusable_regex(string, include_character_padding)
@mcp.tool
def normalize_tool(string: str, prioritize_alpha: bool) -> list[str]:
"""
Return all possible normalized forms of a string, converting confusable Unicode characters to their closest ASCII or Latin-alphabet equivalents.
Args:
string: The string to normalize.
prioritize_alpha: If True, prioritizes conversion to Latin alphabet characters.
Returns:
A list of possible normalized forms.
Example:
gr_normalize("Ʀỏ𝕍3β„›", True) # ['rov3r', 'rover']
"""
return normalize(string, prioritize_alpha)
if __name__ == "__main__":
print("Running server with SSE transport")
mcp.run(transport='sse')