feat(main): 修改工具输入schema以支持workflow[extraContext]字段

- 将params字段替换为workflow[extraContext]字段用于接收工作流额外上下文参数
- 更新描述信息,明确字段用途为接收工作流额外上下文参数(如环境变量等)
- 修改处理逻辑,提取workflow[extraContext]字段并合并到inputs中
- 当workflow[extraContext]为字典类型时合并到inputs,否则保留为独立字段
- 更新日志信息中的字段名称引用

chore(pyproject): 更新版本号至0.1.7
This commit is contained in:
2026-02-09 19:44:51 +08:00
parent 1b850913e7
commit 32bc05376f
2 changed files with 15 additions and 15 deletions

View File

@@ -219,11 +219,11 @@ async def handle_list_tools() -> list[types.Tool]:
logger.warning("sqlParams 和 inputJsonSchema 都不存在,使用空 schema") logger.warning("sqlParams 和 inputJsonSchema 都不存在,使用空 schema")
input_schema = {"type": "object", "properties": {}, "required": []} input_schema = {"type": "object", "properties": {}, "required": []}
# 添加 params 字段到 schema可以接收任何类型 # 添加 workflow[extraContext] 字段到 schema可以接收任何类型(非必填)
if "properties" not in input_schema: if "properties" not in input_schema:
input_schema["properties"] = {} input_schema["properties"] = {}
input_schema["properties"]["params"] = { input_schema["properties"]["workflow[extraContext]"] = {
"description": "额外的参数,可以是任何类型" "description": "工作流额外的上下文参数(如环境变量等),可以是任何类型,非必填"
} }
tools.append( tools.append(
@@ -263,20 +263,20 @@ async def handle_call_tool(
workflow_id = tool_config.get("workflowId") or get_workflow_id() workflow_id = tool_config.get("workflowId") or get_workflow_id()
logger.info(f"使用工作流ID: {workflow_id}") logger.info(f"使用工作流ID: {workflow_id}")
# 提取 params 字段并合并到 inputs # 提取 workflow[extraContext] 字段并合并到 inputs
inputs = arguments or {} inputs = arguments or {}
params = inputs.pop("params", None) workflow_extra_context = inputs.pop("workflow[extraContext]", None)
# 如果 params 存在,将其内容合并到 inputs # 如果 workflow[extraContext] 存在,将其内容合并到 inputs
if params is not None: if workflow_extra_context is not None:
if isinstance(params, dict): if isinstance(workflow_extra_context, dict):
# 如果 params 是字典,合并到 inputs # 如果 workflow[extraContext] 是字典,合并到 inputs
inputs.update(params) inputs.update(workflow_extra_context)
logger.info(f"params 是字典类型,已合并到 inputs: {json.dumps(params, ensure_ascii=False)}") logger.info(f"workflow[extraContext] 是字典类型,已合并到 inputs: {json.dumps(workflow_extra_context, ensure_ascii=False)}")
else: else:
# 如果 params 不是字典,作为 params 字段保留 # 如果 workflow[extraContext] 不是字典,作为 workflow[extraContext] 字段保留
inputs["params"] = params inputs["workflow[extraContext]"] = workflow_extra_context
logger.info(f"params 是 {type(params).__name__} 类型,保留为 params 字段") logger.info(f"workflow[extraContext] 是 {type(workflow_extra_context).__name__} 类型,保留为 workflow[extraContext] 字段")
# 构建请求数据 # 构建请求数据
request_data = { request_data = {

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "lzwcai-workflow-to-mcp" name = "lzwcai-workflow-to-mcp"
version = "0.1.6" version = "0.1.7"
description = "MCP server for executing business SQL queries with dynamic tool generation" description = "MCP server for executing business SQL queries with dynamic tool generation"
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"