feat(workflow): 添加 params 参数支持并优化工具调用处理
- 在输入 schema 中添加 params 字段,允许接收任何类型的额外参数 - 修改 handle_call_tool 函数,提取并合并 params 到 inputs - 支持字典类型 params 的自动合并和其他类型 params 的保留 - 更新版本号从 0.1.5 到 0.1.6
This commit is contained in:
@@ -219,6 +219,13 @@ async def handle_list_tools() -> list[types.Tool]:
|
||||
logger.warning("sqlParams 和 inputJsonSchema 都不存在,使用空 schema")
|
||||
input_schema = {"type": "object", "properties": {}, "required": []}
|
||||
|
||||
# 添加 params 字段到 schema,可以接收任何类型
|
||||
if "properties" not in input_schema:
|
||||
input_schema["properties"] = {}
|
||||
input_schema["properties"]["params"] = {
|
||||
"description": "额外的参数,可以是任何类型"
|
||||
}
|
||||
|
||||
tools.append(
|
||||
types.Tool(
|
||||
name=name,
|
||||
@@ -234,7 +241,7 @@ async def handle_list_tools() -> list[types.Tool]:
|
||||
@server.call_tool()
|
||||
async def handle_call_tool(
|
||||
name: str,
|
||||
arguments: dict | None
|
||||
arguments: dict | None,
|
||||
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
||||
"""调用工具"""
|
||||
logger.info(f"收到 CallTool 请求: name={name}, arguments={json.dumps(arguments, ensure_ascii=False) if arguments else 'None'}")
|
||||
@@ -256,10 +263,25 @@ async def handle_call_tool(
|
||||
workflow_id = tool_config.get("workflowId") or get_workflow_id()
|
||||
logger.info(f"使用工作流ID: {workflow_id}")
|
||||
|
||||
# 提取 params 字段并合并到 inputs
|
||||
inputs = arguments or {}
|
||||
params = inputs.pop("params", None)
|
||||
|
||||
# 如果 params 存在,将其内容合并到 inputs
|
||||
if params is not None:
|
||||
if isinstance(params, dict):
|
||||
# 如果 params 是字典,合并到 inputs
|
||||
inputs.update(params)
|
||||
logger.info(f"params 是字典类型,已合并到 inputs: {json.dumps(params, ensure_ascii=False)}")
|
||||
else:
|
||||
# 如果 params 不是字典,作为 params 字段保留
|
||||
inputs["params"] = params
|
||||
logger.info(f"params 是 {type(params).__name__} 类型,保留为 params 字段")
|
||||
|
||||
# 构建请求数据
|
||||
request_data = {
|
||||
"workflowId": workflow_id,
|
||||
"inputs": arguments or {}
|
||||
"inputs": inputs
|
||||
}
|
||||
|
||||
logger.info(f"执行工作流请求数据: {json.dumps(request_data, ensure_ascii=False, indent=2)}")
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "lzwcai-workflow-to-mcp"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
description = "MCP server for executing business SQL queries with dynamic tool generation"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
Reference in New Issue
Block a user