File size: 1,465 Bytes
bdcdaf4 cc826a1 bdcdaf4 | 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 | """
文本清理插件 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="结果说明")
@mcp_tool(
name="text-clean",
title="文本清理",
description="清理文本内容,支持多种清理操作",
annotations={
"readOnlyHint": False,
"destructiveHint": False,
}
)
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) |