Spaces:
Running
Running
File size: 2,412 Bytes
944fd03 542f4c2 9e2c10a 944fd03 542f4c2 944fd03 542f4c2 944fd03 542f4c2 944fd03 542f4c2 9e2c10a 944fd03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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') |