get_chinese_initials
Convert Chinese field names to their pinyin initials during table creation in MySQL. Simplifies database schema design by automating the transformation of Chinese characters into usable identifiers.
Instructions
创建表结构时,将中文字段名转换为拼音首字母字段
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 要获取拼音首字母的汉字文本,以“,”分隔 |
Implementation Reference
- Core tool execution logic: converts Chinese words separated by Chinese commas to uppercase pinyin initials using the pypinyin library and returns as TextContent.async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]: """将中文文本转换为拼音首字母 参数: text (str): 要转换的中文文本,以中文逗号分隔 返回: list[TextContent]: 包含转换结果的TextContent列表 - 每个词的首字母会被转换为大写 - 多个词的结果以英文逗号连接 示例: get_chinese_initials("用户名,密码") [TextContent(type="text", text="YHM,MM")] """ try: if "text" not in arguments: raise ValueError("缺少查询语句") text = arguments["text"] # 将文本按逗号分割 words = text.split(',') # 存储每个词的首字母 initials = [] for word in words: # 获取每个字的拼音首字母 word_pinyin = pinyin(word, style=Style.FIRST_LETTER) # 将每个字的首字母连接起来 word_initials = ''.join([p[0].upper() for p in word_pinyin]) initials.append(word_initials) # 用逗号连接所有结果 return [TextContent(type="text", text=','.join(initials))] except Exception as e: return [TextContent(type="text", text=f"执行查询时出错: {str(e)}")]
- Defines the tool schema with input parameter 'text' (string) describing Chinese text separated by commas for initials extraction.def get_tool_description(self) -> Tool: return Tool( name=self.name, description=self.description, inputSchema={ "type": "object", "properties": { "text": { "type": "string", "description": "要获取拼音首字母的汉字文本,以“,”分隔" } }, "required": ["text"] } )
- src/mysql_mcp_server_pro/handles/base.py:56-61 (registration)Automatic registration mechanism in BaseHandler base class that registers subclasses like GetChineseInitials to ToolRegistry when defined.def __init_subclass__(cls, **kwargs): """子类初始化时自动注册到工具注册表""" super().__init_subclass__(**kwargs) if cls.name: # 只注册有名称的工具 ToolRegistry.register(cls)
- src/mysql_mcp_server_pro/handles/__init__.py:2-2 (registration)Import statement in handles __init__.py that loads the GetChineseInitials class, triggering its automatic registration.from .get_chinese_initials import GetChineseInitials