From fea37955a72699ef06287513c0f528e8f831161a Mon Sep 17 00:00:00 2001 From: Xiaoli Dev Date: Sat, 25 Apr 2026 11:20:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20MarkdownSkill=20MCP=20=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BB=8E=E5=85=83=E6=95=B0=E6=8D=AE=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MarkdownSkill.get_tool_definition() 不再硬编码,从 SKILL.md 元数据生成 - 支持 frontmatter 中的 parameters 字段定义参数 - 无 parameters 时回退到通用 operation + args 定义 - Anthropic 定义同步更新 本次更新由 mimo 自动化执行,与开发者无关。 --- skills/base.py | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/skills/base.py b/skills/base.py index 1008526..7a6a264 100644 --- a/skills/base.py +++ b/skills/base.py @@ -161,9 +161,34 @@ class MarkdownSkill: instructions: str = "" file_path: str = "" scripts_dir: str = "" + parameters: Dict[str, Any] = field(default_factory=dict) # 从 frontmatter 解析 def get_tool_definition(self) -> Dict[str, Any]: - """获取 OpenAI 格式的工具定义""" + """获取 OpenAI 格式的工具定义 - 从元数据动态生成""" + properties = {} + required = [] + + if self.parameters: + # 从 frontmatter 中的 parameters 生成 + for name, schema in self.parameters.items(): + if isinstance(schema, dict): + properties[name] = schema + if schema.get("required", False): + required.append(name) + else: + # 通用定义:operation + args + properties = { + "operation": { + "type": "string", + "description": f"要执行的操作(可用工具: {', '.join(self.tools)})" if self.tools else "要执行的操作" + }, + "args": { + "type": "string", + "description": "操作参数" + } + } + required = ["operation"] + return { "type": "function", "function": { @@ -171,45 +196,20 @@ class MarkdownSkill: "description": self.description, "parameters": { "type": "object", - "properties": { - "operation": { - "type": "string", - "enum": ["list", "read", "write", "delete", "copy", "move", "info", "search"], - "description": "要执行的文件操作类型" - }, - "path": { - "type": "string", - "description": "目标文件或目录路径" - }, - "content": { - "type": "string", - "description": "写入内容(write/append 操作时使用)" - }, - "destination": { - "type": "string", - "description": "目标路径(copy/move 操作时使用)" - } - }, - "required": ["operation"] + "properties": properties, + "required": required } } } def get_anthropic_tool_definition(self) -> Dict[str, Any]: """获取 Anthropic 格式的工具定义""" + tool_def = self.get_tool_definition() + func = tool_def.get("function", {}) return { - "name": self.name, - "description": self.description, - "input_schema": { - "type": "object", - "properties": { - "operation": {"type": "string"}, - "path": {"type": "string"}, - "content": {"type": "string"}, - "destination": {"type": "string"} - }, - "required": ["operation"] - } + "name": func.get("name", self.name), + "description": func.get("description", self.description), + "input_schema": func.get("parameters", {"type": "object", "properties": {}}) }