| """ | |
| 文本清理插件 MCP工具定义 | |
| """ | |
| from app.mcp.decorators import mcp_tool | |
| from pydantic import BaseModel, Field | |
| from typing import List | |
| from .core import do_clean | |
| class CleanInput(BaseModel): | |
| """文本清理工具输入参数""" | |
| text: str = Field(description="待清理的文本内容") | |
| operations: List[str] = Field( | |
| default=["trim", "normalize_spaces"], | |
| description="清理操作列表:trim、remove_empty_lines、normalize_spaces、remove_extra_newlines" | |
| ) | |
| class CleanOutput(BaseModel): | |
| """文本清理工具输出结果""" | |
| success: bool = Field(description="操作是否成功") | |
| output: str | None = Field(description="清理后的文本") | |
| message: str = Field(description="结果说明") | |
| async def clean_text(params: CleanInput) -> CleanOutput: | |
| """清理文本内容。 | |
| 支持的清理操作: | |
| - trim: 去除首尾空白 | |
| - remove_empty_lines: 移除空行 | |
| - normalize_spaces: 规范化空格 | |
| - remove_extra_newlines: 移除多余换行 | |
| Args: | |
| params: 包含文本和清理操作列表 | |
| Returns: | |
| CleanOutput: 清理后的文本 | |
| """ | |
| result = await do_clean(params.text, params.operations) | |
| return CleanOutput(**result) |