feat(api-converter): 添加进销存采购订单API配置并实现本地缓存机制

新增api_config_9p04kww1pu.json配置文件,包含进销存采购订单相关的四个核心
API接口(查询列表、新建、详情、编辑),完善了load_api_configs函数,
增加本地文件缓存机制,支持从本地文件加载配置并在配置变更时同步保存,
优化refresh_api_configs函数以同步清理本地文件缓存。

BREAKING CHANGE: API配置方式调整,引入本地缓存机制可能影响原有部署流程
This commit is contained in:
2026-02-07 15:48:01 +08:00
parent 41c3d7a8fd
commit e18c661368
35 changed files with 2375 additions and 362 deletions

View File

@@ -0,0 +1,483 @@
{
"serverName": "lzwcai_mcp_api_converter",
"description": "业务API集合",
"domainUrl": "https://erp.lzwc.cn/api",
"packageName": "lzwcai-mcp-dyntoolapi",
"version": "1.0.0",
"apiConfig": [
{
"id": "2019327913872793602",
"enterpriseId": "1932095424144715777",
"bizSysId": "1970385781825785858",
"domainUrl": "https://erp.lzwc.cn/api",
"interfaceName": "获取内容列表(进销存-采购订单)",
"businessPrompts": "",
"returnType": "JSON",
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
"header": null,
"apiUrl": "/jxcPurchase/queryPageList",
"parametersFormat": "0",
"method": "POST",
"status": 1,
"version": "v1.0",
"authenticationRequired": 1,
"responseExample": null,
"crudType": "0",
"isView": 0,
"templateType": "markdown",
"viewTemplates": null,
"parameters": [
{
"keyParam": null,
"required": 1,
"paramName": "Authorization",
"paramType": "STRING",
"paramPrompts": "注意Bearer后面有一个空格即Bearer+空格+登录返回的token",
"defaultValue": "Bearer {{token}}",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "header",
"dataFormat": null,
"validity": null,
"sort": "1",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "page",
"paramType": "INTEGER",
"paramPrompts": "当前页码",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "2",
"tags": "0",
"example": "1"
},
{
"keyParam": null,
"required": 0,
"paramName": "limit",
"paramType": "INTEGER",
"paramPrompts": "每页条数",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "3",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "search",
"paramType": "STRING",
"paramPrompts": "搜索关键字",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "4",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "searchList[]",
"paramType": "STRING",
"paramPrompts": "高级搜索条件数组,注意用的时候参数名去掉中括号",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "5",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "sceneId",
"paramType": "INTEGER",
"paramPrompts": "场景ID",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "6",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "type",
"paramType": "INTEGER",
"paramPrompts": "",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019327913872793602",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "7",
"tags": "0",
"example": "10-采购订单"
}
]
},
{
"id": "2019328946728542210",
"enterpriseId": "1932095424144715777",
"bizSysId": "1970385781825785858",
"domainUrl": "https://erp.lzwc.cn/api",
"interfaceName": "新建内容(进销存-采购订单)",
"businessPrompts": "",
"returnType": "JSON",
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
"header": null,
"apiUrl": "/jxcPurchase/add",
"parametersFormat": "0",
"method": "POST",
"status": 1,
"version": "v1.0",
"authenticationRequired": 1,
"responseExample": null,
"crudType": "0",
"isView": 0,
"templateType": "markdown",
"viewTemplates": null,
"parameters": [
{
"keyParam": null,
"required": 1,
"paramName": "Authorization",
"paramType": "STRING",
"paramPrompts": "注意Bearer后面有一个空格即Bearer+空格+登录返回的token",
"defaultValue": "Bearer {{token}}",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "header",
"dataFormat": null,
"validity": null,
"sort": "1",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "entity",
"paramType": "ARRAY",
"paramPrompts": "基本信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "2",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "examineFlowData",
"paramType": "ARRAY",
"paramPrompts": "审批流相关信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "3",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "field",
"paramType": "ARRAY",
"paramPrompts": "字段相关信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "4",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "productList",
"paramType": "ARRAY",
"paramPrompts": "产品列表",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "5",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "expendList",
"paramType": "ARRAY",
"paramPrompts": "扩展数据列表,字段参数参考为空",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019328946728542210",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "6",
"tags": "0",
"example": ""
}
]
},
{
"id": "2019329359485804545",
"enterpriseId": "1932095424144715777",
"bizSysId": "1970385781825785858",
"domainUrl": "https://erp.lzwc.cn/api",
"interfaceName": "获取内容详情(进销存-采购订单)",
"businessPrompts": "",
"returnType": "JSON",
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
"header": null,
"apiUrl": "/jxcPurchase/queryById/{id}",
"parametersFormat": "0",
"method": "POST",
"status": 1,
"version": "v1.0",
"authenticationRequired": 1,
"responseExample": null,
"crudType": "0",
"isView": 0,
"templateType": "markdown",
"viewTemplates": null,
"parameters": [
{
"keyParam": null,
"required": 1,
"paramName": "Authorization",
"paramType": "STRING",
"paramPrompts": "注意Bearer后面有一个空格即Bearer+空格+登录返回的token",
"defaultValue": "Bearer {{token}}",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019329359485804545",
"requestType": "header",
"dataFormat": null,
"validity": null,
"sort": "1",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 1,
"paramName": "id",
"paramType": "STRING",
"paramPrompts": "",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019329359485804545",
"requestType": "path",
"dataFormat": null,
"validity": null,
"sort": "2",
"tags": "0",
"example": ""
}
]
},
{
"id": "2019330096911556610",
"enterpriseId": "1932095424144715777",
"bizSysId": "1970385781825785858",
"domainUrl": "https://erp.lzwc.cn/api",
"interfaceName": "编辑内容(进销存-采购订单)",
"businessPrompts": "",
"returnType": "JSON",
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
"header": null,
"apiUrl": "/jxcPurchase/update",
"parametersFormat": "0",
"method": "POST",
"status": 1,
"version": "v1.0",
"authenticationRequired": 1,
"responseExample": null,
"crudType": "0",
"isView": 0,
"templateType": "markdown",
"viewTemplates": null,
"parameters": [
{
"keyParam": null,
"required": 1,
"paramName": "Authorization",
"paramType": "STRING",
"paramPrompts": "注意Bearer后面有一个空格即Bearer+空格+登录返回的token",
"defaultValue": "Bearer {{token}}",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "header",
"dataFormat": null,
"validity": null,
"sort": "1",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "entity",
"paramType": "STRING",
"paramPrompts": "基本信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "2",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "examineFlowData",
"paramType": "STRING",
"paramPrompts": "审批流相关信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "3",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "field",
"paramType": "STRING",
"paramPrompts": "字段相关信息,参考合同",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "4",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "productList",
"paramType": "STRING",
"paramPrompts": "产品列表",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "5",
"tags": "0",
"example": ""
},
{
"keyParam": null,
"required": 0,
"paramName": "expendList",
"paramType": "STRING",
"paramPrompts": "扩展数据列表,字段参数参考为空",
"defaultValue": "",
"assoKey": null,
"assoApiId": null,
"memory": 0,
"apiId": "2019330096911556610",
"requestType": "formdata",
"dataFormat": null,
"validity": null,
"sort": "6",
"tags": "0",
"example": ""
}
]
}
]
}

View File

@@ -138,13 +138,32 @@ def load_api_configs():
config_key = f"business{business_uuid}" config_key = f"business{business_uuid}"
logger.info(f"租户配置变量名: {config_key}") logger.info(f"租户配置变量名: {config_key}")
# 构建租户专属的配置文件路径
memory_config_path = os.path.join(current_dir, f"api_config_{business_uuid}.json")
# 检查内存中是否已有该租户的配置 # 检查内存中是否已有该租户的配置
if config_key in business_configs: if config_key in business_configs:
logger.info(f"从内存中获取租户 {business_uuid} 的配置") logger.info(f"从内存中获取租户 {business_uuid} 的配置")
return business_configs[config_key] return business_configs[config_key]
# 内存中没有,从业务平台获取 # 内存中没有,尝试从本地文件加载
logger.info(f"内存中没有租户 {business_uuid} 的配置,开始从业务平台获取...") if os.path.exists(memory_config_path):
try:
logger.info(f"尝试从本地文件加载租户配置: {memory_config_path}")
with open(memory_config_path, "r", encoding="utf-8") as f:
config = json.load(f)
logger.info(f"成功从本地文件加载租户 {business_uuid} 的配置,包含 {len(config.get('apiConfig', []))} 个API配置")
# 存储到内存中
business_configs[config_key] = config
logger.info(f"配置已加载到内存变量: {config_key}")
return config
except Exception as e:
logger.warning(f"从本地文件加载配置失败: {str(e)},将从业务平台重新获取")
# 本地文件不存在或加载失败,从业务平台获取
logger.info(f"本地文件不存在,开始从业务平台获取租户 {business_uuid} 的配置...")
try: try:
# 从环境变量获取API ID列表 # 从环境变量获取API ID列表
@@ -181,6 +200,15 @@ def load_api_configs():
logger.info(f"配置已存储到内存变量: {config_key}") logger.info(f"配置已存储到内存变量: {config_key}")
logger.info(f"当前内存中共有 {len(business_configs)} 个租户配置") logger.info(f"当前内存中共有 {len(business_configs)} 个租户配置")
# 保存到本地文件作为备份
try:
logger.info(f"保存配置到本地文件: {memory_config_path}")
with open(memory_config_path, "w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=2)
logger.info("配置文件保存成功")
except Exception as save_error:
logger.warning(f"保存配置到本地文件失败(不影响运行): {str(save_error)}")
return config return config
except Exception as e: except Exception as e:
@@ -639,7 +667,7 @@ def refresh_api_configs():
这个函数实现了配置的热加载功能,支持两种模式: 这个函数实现了配置的热加载功能,支持两种模式:
- 文件模式:当检测到配置文件变化时会被调用 - 文件模式:当检测到配置文件变化时会被调用
- 内存模式:强制重新从业务平台获取配置并更新内存 - 内存模式:强制重新从业务平台获取配置并更新内存和本地文件
全局变量更新: 全局变量更新:
- api_configs: 重新加载的API配置 - api_configs: 重新加载的API配置
@@ -658,7 +686,7 @@ def refresh_api_configs():
# 获取配置模式 # 获取配置模式
config_mode = os.getenv('configMode', 'memory').lower() config_mode = os.getenv('configMode', 'memory').lower()
# 内存模式下需要清除当前租户的缓存配置,强制重新获取 # 内存模式下需要清除当前租户的缓存配置和本地文件,强制重新获取
if config_mode == 'memory': if config_mode == 'memory':
business_uuid = os.getenv('businessUuid') business_uuid = os.getenv('businessUuid')
if business_uuid: if business_uuid:
@@ -666,6 +694,16 @@ def refresh_api_configs():
if config_key in business_configs: if config_key in business_configs:
logger.info(f"清除租户 {business_uuid} 的缓存配置") logger.info(f"清除租户 {business_uuid} 的缓存配置")
del business_configs[config_key] del business_configs[config_key]
# 删除本地配置文件,强制从业务平台重新获取
current_dir = os.path.dirname(os.path.abspath(__file__))
memory_config_path = os.path.join(current_dir, f"api_config_{business_uuid}.json")
if os.path.exists(memory_config_path):
try:
os.remove(memory_config_path)
logger.info(f"已删除本地配置文件: {memory_config_path}")
except Exception as e:
logger.warning(f"删除本地配置文件失败: {str(e)}")
# 重新加载API配置 # 重新加载API配置
api_configs = load_api_configs() api_configs = load_api_configs()

View File

@@ -2,11 +2,11 @@ import os
os.environ["modelId"] = "1946471611735015425" os.environ["modelId"] = "1946471611735015425"
os.environ["bizSysId"] = "1970385781825785858" os.environ["bizSysId"] = "1970385781825785858"
os.environ["bizSysApiIds"] = "[\"1970386761072058369\",\"1970386761185304578\",\"1970386761583763457\",\"1970386761420185602\"]" os.environ["bizSysApiIds"] = "[\"2019327913872793602\",\"2019328946728542210\",\"2019329359485804545\",\"2019330096911556610\"]"
os.environ["businessUuid"] = "u9ua9ss2l8c" os.environ["businessUuid"] = "9p04kww1pu"
os.environ["LZWCAI_CORP_MANAGER_URL"] = "http://192.168.2.236:8088" os.environ["LZWCAI_CORP_MANAGER_URL"] = "http://192.168.2.236:8088"
# 导入模块 # 导入模块
from lzwcai_mcp_api_converter.src.create_mcp import run_main from lzwcai_mcp_api_converter.src.create_mcp import run_main
if __name__ == "__main__": if __name__ == "__main__":
run_main() run_main()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,223 @@
2025-12-31 12:57:27 - root - INFO - [logger_config.py:151] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\logs
2025-12-31 12:57:27 - root - INFO - [logger_config.py:152] - 日志配置 - 级别: INFO, 文件大小限制: 10MB, 备份数量: 5
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:347] - 开始运行 MCP SQL Executor 服务器
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:299] - ============================================================
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:300] - 正在启动 MCP 服务器: lzwcai-mcp-sqlexecutor
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:301] - 版本: 0.1.0
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:302] - ============================================================
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:306] - 环境配置 - Database ID: 16
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:307] - 环境配置 - Skill ID:
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:308] - 环境配置 - Backend Base URL: http://192.168.11.24:8088
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:309] - ============================================================
2025-12-31 12:57:27 - mcp_services - INFO - [main.py:314] - MCP 服务器已启动,等待客户端连接...
2025-12-31 12:57:28 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 12:57:28 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 12:57:28 - mcp_services - INFO - [main.py:119] - 初始化查询配置(数据源: api...
2025-12-31 12:57:28 - mcp_services - INFO - [main.py:278] - 调用第三方APIskill_id:
2025-12-31 12:57:28 - lzwcai_mcp_sqlexecutor.utils.api_client - INFO - [api_client.py:71] - 正在调用API: http://192.168.11.24:8088/datasource/skill/getBySkillId/
2025-12-31 12:57:29 - httpx - INFO - [_client.py:1025] - HTTP Request: GET http://192.168.11.24:8088/datasource/skill/getBySkillId/ "HTTP/1.1 404 "
2025-12-31 12:57:29 - lzwcai_mcp_sqlexecutor.utils.api_client - ERROR - [api_client.py:97] - API请求失败 (HTTP 404): http://192.168.11.24:8088/datasource/skill/getBySkillId/
2025-12-31 12:57:29 - lzwcai_mcp_sqlexecutor.utils.api_client - ERROR - [api_client.py:98] - 错误响应: {"timestamp":"2025-12-31T12:57:30.248+08:00","status":404,"error":"Not Found","path":"/datasource/skill/getBySkillId/"}
2025-12-31 12:57:29 - mcp_services - ERROR - [main.py:292] - API调用失败: API请求失败 (HTTP 404): http://192.168.11.24:8088/datasource/skill/getBySkillId/
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 80, in get_skill_by_id
response.raise_for_status()
File "D:\anaconda3\Lib\site-packages\httpx\_models.py", line 829, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 ' for url 'http://192.168.11.24:8088/datasource/skill/getBySkillId/'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 281, in call_third_party_api
raw_result = get_skill_by_id(skill_id)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 208, in get_skill_by_id
return default_client.get_skill_by_id(skill_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 99, in get_skill_by_id
raise Exception(error_msg)
Exception: API请求失败 (HTTP 404): http://192.168.11.24:8088/datasource/skill/getBySkillId/
2025-12-31 12:57:29 - mcp_services - WARNING - [main.py:131] - API获取失败降级使用本地配置: API请求失败 (HTTP 404): http://192.168.11.24:8088/datasource/skill/getBySkillId/
2025-12-31 12:57:29 - mcp_services - INFO - [main.py:55] - 成功加载 3 个业务查询配置
2025-12-31 12:57:29 - mcp_services - ERROR - [main.py:92] - 生成工具模式失败: 2006300000000000001, 错误: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 12:57:29 - mcp_services - ERROR - [main.py:170] - 列出工具失败: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 162, in handle_list_tools
tool = generate_tool_schema_from_query(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 12:57:29 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 12:57:29 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 12:57:29 - mcp_services - ERROR - [main.py:92] - 生成工具模式失败: 2006300000000000001, 错误: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 12:57:29 - mcp_services - ERROR - [main.py:170] - 列出工具失败: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 162, in handle_list_tools
tool = generate_tool_schema_from_query(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 12:57:54 - root - INFO - [logger_config.py:151] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\logs
2025-12-31 12:57:54 - root - INFO - [logger_config.py:152] - 日志配置 - 级别: INFO, 文件大小限制: 10MB, 备份数量: 5
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:347] - 开始运行 MCP SQL Executor 服务器
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:299] - ============================================================
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:300] - 正在启动 MCP 服务器: lzwcai-mcp-sqlexecutor
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:301] - 版本: 0.1.0
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:302] - ============================================================
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:306] - 环境配置 - Database ID: 16
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:307] - 环境配置 - Skill ID:
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:308] - 环境配置 - Backend Base URL: http://192.168.11.24:8088
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:309] - ============================================================
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:314] - MCP 服务器已启动,等待客户端连接...
2025-12-31 12:57:54 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:119] - 初始化查询配置(数据源: local...
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:55] - 成功加载 3 个业务查询配置
2025-12-31 12:57:54 - mcp_services - INFO - [main.py:123] - 本地配置: 3 条
2025-12-31 12:57:54 - mcp_services - ERROR - [main.py:92] - 生成工具模式失败: 2006300000000000001, 错误: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 12:57:54 - mcp_services - ERROR - [main.py:170] - 列出工具失败: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 162, in handle_list_tools
tool = generate_tool_schema_from_query(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 15:00:31 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 15:00:31 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 15:00:31 - mcp_services - ERROR - [main.py:92] - 生成工具模式失败: 2006300000000000001, 错误: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 15:00:31 - mcp_services - ERROR - [main.py:170] - 列出工具失败: 'businessName'
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 162, in handle_list_tools
tool = generate_tool_schema_from_query(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 80, in generate_tool_schema_from_query
tool_name = query['businessName']
~~~~~^^^^^^^^^^^^^^^^
KeyError: 'businessName'
2025-12-31 15:00:34 - mcp_services - INFO - [main.py:329] - MCP 服务器已关闭
2025-12-31 15:00:53 - root - INFO - [logger_config.py:151] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\logs
2025-12-31 15:00:53 - root - INFO - [logger_config.py:152] - 日志配置 - 级别: INFO, 文件大小限制: 10MB, 备份数量: 5
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:347] - 开始运行 MCP SQL Executor 服务器
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:299] - ============================================================
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:300] - 正在启动 MCP 服务器: lzwcai-mcp-sqlexecutor
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:301] - 版本: 0.1.0
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:302] - ============================================================
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:306] - 环境配置 - Database ID: 29
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:307] - 环境配置 - Skill ID:
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:308] - 环境配置 - Backend Base URL: http://lzwcai-demp-corp-manager:8086
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:309] - ============================================================
2025-12-31 15:00:53 - mcp_services - INFO - [main.py:314] - MCP 服务器已启动,等待客户端连接...
2025-12-31 15:00:54 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 15:00:54 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 15:00:54 - mcp_services - INFO - [main.py:119] - 初始化查询配置(数据源: api...
2025-12-31 15:00:54 - mcp_services - INFO - [main.py:278] - 调用第三方APIskill_id:
2025-12-31 15:00:54 - lzwcai_mcp_sqlexecutor.utils.api_client - INFO - [api_client.py:71] - 正在调用API: http://lzwcai-demp-corp-manager:8086/datasource/skill/getBySkillId/
2025-12-31 15:00:56 - lzwcai_mcp_sqlexecutor.utils.api_client - ERROR - [api_client.py:103] - API请求异常: http://lzwcai-demp-corp-manager:8086/datasource/skill/getBySkillId/, 错误: [Errno 11001] getaddrinfo failed
2025-12-31 15:00:56 - mcp_services - ERROR - [main.py:292] - API调用失败: API请求异常: http://lzwcai-demp-corp-manager:8086/datasource/skill/getBySkillId/, 错误: [Errno 11001] getaddrinfo failed
Traceback (most recent call last):
File "D:\anaconda3\Lib\site-packages\httpx\_transports\default.py", line 101, in map_httpcore_exceptions
yield
File "D:\anaconda3\Lib\site-packages\httpx\_transports\default.py", line 250, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
raise exc from None
File "D:\anaconda3\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpcore\_sync\connection.py", line 99, in handle_request
raise exc
File "D:\anaconda3\Lib\site-packages\httpcore\_sync\connection.py", line 76, in handle_request
stream = self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpcore\_sync\connection.py", line 122, in _connect
stream = self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpcore\_backends\sync.py", line 205, in connect_tcp
with map_exceptions(exc_map):
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "D:\anaconda3\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [Errno 11001] getaddrinfo failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 74, in get_skill_by_id
response = self.client.get(
^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 1053, in get
return self.request(
^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 825, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 914, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 942, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 979, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_client.py", line 1014, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\site-packages\httpx\_transports\default.py", line 249, in handle_request
with map_httpcore_exceptions():
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "D:\anaconda3\Lib\site-packages\httpx\_transports\default.py", line 118, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\main.py", line 281, in call_third_party_api
raw_result = get_skill_by_id(skill_id)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 208, in get_skill_by_id
return default_client.get_skill_by_id(skill_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcp_sqlexecutor\lzwcai_mcp_sqlexecutor\utils\api_client.py", line 104, in get_skill_by_id
raise Exception(error_msg)
Exception: API请求异常: http://lzwcai-demp-corp-manager:8086/datasource/skill/getBySkillId/, 错误: [Errno 11001] getaddrinfo failed
2025-12-31 15:00:56 - mcp_services - WARNING - [main.py:131] - API获取失败降级使用本地配置: API请求异常: http://lzwcai-demp-corp-manager:8086/datasource/skill/getBySkillId/, 错误: [Errno 11001] getaddrinfo failed
2025-12-31 15:00:56 - mcp_services - INFO - [main.py:55] - 成功加载 0 个业务查询配置
2025-12-31 15:00:56 - mcp_services - INFO - [main.py:165] - 成功生成 0 个 MCP 工具
2025-12-31 15:00:56 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2025-12-31 15:00:56 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2025-12-31 15:00:56 - mcp_services - INFO - [main.py:165] - 成功生成 0 个 MCP 工具

File diff suppressed because one or more lines are too long

View File

@@ -7,7 +7,7 @@ name = "lzwcai-mcp-sqlexecutor"
version = "0.1.6" version = "0.1.6"
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.13" requires-python = ">=3.10"
license = {text = "MIT"} license = {text = "MIT"}
authors = [ authors = [
{name = "lzwcai", email = "your-email@example.com"}, {name = "lzwcai", email = "your-email@example.com"},
@@ -17,7 +17,7 @@ classifiers = [
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.10",
] ]
dependencies = [ dependencies = [
"httpx>=0.28.1", "httpx>=0.28.1",

View File

@@ -4,9 +4,9 @@ Runs the MCP server for SQL query execution
""" """
import os import os
os.environ["databaseId"] = "12" os.environ["databaseId"] = "162"
os.environ["skillId"] = "2013848312313335809" os.environ["skillId"] = "2008360664955854850"
os.environ["backendBaseUrl"] = "http://192.168.11.24:8088" os.environ["backendBaseUrl"] = "http://192.168.2.236:8088"
if __name__ == "__main__": if __name__ == "__main__":
# Import and run the actual MCP server # Import and run the actual MCP server
from lzwcai_mcp_sqlexecutor.main import main from lzwcai_mcp_sqlexecutor.main import main

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "lzwcai-mcp-sqlexecutor" name = "lzwcai-mcp-sqlexecutor"
version = "0.1.10" version = "0.1.11"
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"

File diff suppressed because one or more lines are too long

View File

@@ -240,3 +240,56 @@
2026-01-16 12:39:34 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: MetricTrendAndTurningPointWarning 2026-01-16 12:39:34 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: MetricTrendAndTurningPointWarning
2026-01-16 12:39:34 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API... 2026-01-16 12:39:34 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-16 12:39:35 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功 2026-01-16 12:39:35 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:362] - 开始运行 MCP SQL Executor 服务器
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:313] - ============================================================
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:314] - 正在启动 MCP 服务器: lzwcai-mcpskills-analyzeOrder
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:315] - 版本: 0.1.0
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:316] - ============================================================
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:320] - 环境配置 - Database ID: 57
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:321] - 环境配置 - Datasource ID: 57
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:322] - 环境配置 - Skill ID:
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:323] - 环境配置 - Backend Base URL: http://192.167.30.2:8088
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:324] - ============================================================
2026-01-29 13:30:19 - mcp_services - INFO - [main.py:329] - MCP 服务器已启动,等待客户端连接...
2026-01-29 13:30:21 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2026-01-29 13:30:21 - mcp_services - INFO - [main.py:119] - 初始化查询配置(数据源: local...
2026-01-29 13:30:21 - mcp_services - INFO - [main.py:55] - 成功加载 6 个业务查询配置
2026-01-29 13:30:21 - mcp_services - INFO - [main.py:123] - 本地配置: 6 条
2026-01-29 13:30:21 - mcp_services - INFO - [main.py:165] - 成功生成 6 个 MCP 工具
2026-01-29 13:30:22 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: OrderDelayWarningAnalysis
2026-01-29 13:30:22 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:30:22 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:30:25 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: WorkOrderProgressAndAnomalyNodes
2026-01-29 13:30:25 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:30:25 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:362] - 开始运行 MCP SQL Executor 服务器
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:313] - ============================================================
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:314] - 正在启动 MCP 服务器: lzwcai-mcpskills-analyzeOrder
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:315] - 版本: 0.1.0
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:316] - ============================================================
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:320] - 环境配置 - Database ID: 57
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:321] - 环境配置 - Datasource ID: 57
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:322] - 环境配置 - Skill ID:
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:323] - 环境配置 - Backend Base URL: http://192.167.30.2:8088
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:324] - ============================================================
2026-01-29 13:36:26 - mcp_services - INFO - [main.py:329] - MCP 服务器已启动,等待客户端连接...
2026-01-29 13:36:27 - mcp_services - INFO - [main.py:156] - 收到列出工具请求
2026-01-29 13:36:27 - mcp_services - INFO - [main.py:119] - 初始化查询配置(数据源: local...
2026-01-29 13:36:27 - mcp_services - INFO - [main.py:55] - 成功加载 6 个业务查询配置
2026-01-29 13:36:27 - mcp_services - INFO - [main.py:123] - 本地配置: 6 条
2026-01-29 13:36:27 - mcp_services - INFO - [main.py:165] - 成功生成 6 个 MCP 工具
2026-01-29 13:36:28 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: OrderDelayWarningAnalysis
2026-01-29 13:36:28 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:36:28 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:36:30 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: WorkOrderProgressAndAnomalyNodes
2026-01-29 13:36:30 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:36:30 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:36:33 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: SupplyChainRiskWarning
2026-01-29 13:36:33 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:36:34 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:36:38 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: EfficiencyOutputLossDashboard
2026-01-29 13:36:38 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:36:38 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功
2026-01-29 13:36:41 - mcp_services - INFO - [main.py:190] - 收到工具调用请求: MetricTrendAndTurningPointWarning
2026-01-29 13:36:41 - mcp_services - INFO - [main.py:225] - 正在调用测试SQL API...
2026-01-29 13:36:41 - mcp_services - INFO - [main.py:227] - 测试SQL API调用成功

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "lzwcai-mcpskills-mfg-data-agent" name = "lzwcai-mcpskills-mfg-data-agent"
version = "0.1.4" version = "0.1.6"
description = "制造业数据智能体 - MCP server for manufacturing data intelligence with dynamic tool generation" description = "制造业数据智能体 - MCP server for manufacturing data intelligence with dynamic tool generation"
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "lzwcai-mcpskills-mfg-data-agentv2" name = "lzwcai-mcpskills-mfg-data-agentv2"
version = "0.1.5" version = "0.1.6"
description = "制造业数据智能体 - MCP server for manufacturing data intelligence with dynamic tool generation" description = "制造业数据智能体 - MCP server for manufacturing data intelligence with dynamic tool generation"
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"

View File

@@ -0,0 +1,89 @@
2026-01-28 09:58:33 - root - INFO - [logger_config.py:112] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\logs
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:154] - Initializing server 'mcpskills_template_server'
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:380] - Registering handler for ListToolsRequest
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:441] - Registering handler for CallToolRequest
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:304] - ==================================================
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:305] - MCP Skills Template Server 启动
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:306] - ==================================================
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:311] - 命令行参数: {'mode': 'local', 'json_path': None}
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:314] - 使用模式: local
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:82] - 从本地加载 7 条配置: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\tools_config.json
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:136] - 已加载 7 个工具配置
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:321] - 开始运行 MCP Server (stdio 模式)
2026-01-28 09:58:33 - asyncio - DEBUG - [proactor_events.py:634] - Using proactor: IocpProactor
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: root=InitializedNotification(method='notifications/initialized', params=None, jsonrpc='2.0')
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B64BFE0>
2026-01-28 09:58:34 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type ListToolsRequest
2026-01-28 09:58:34 - lzwcai_mcpskills_template.main - INFO - [main.py:142] - 收到 ListTools 请求,当前配置数量: 7
2026-01-28 09:58:34 - lzwcai_mcpskills_template.main - INFO - [main.py:161] - ListTools 响应: 返回 7 个工具
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B59CFE0>
2026-01-28 09:58:36 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:58:36 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_mixed, arguments=None
2026-01-28 09:58:36 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_mixed
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B39D7C0>
2026-01-28 09:58:55 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:58:55 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_error, arguments=None
2026-01-28 09:58:55 - lzwcai_mcpskills_template.main - ERROR - [main.py:190] - 工具执行失败: 这是一个演示用的模拟错误!执行被中断。
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 186, in handle_call_tool
result_contents = execute_tool(name, arguments or {}, tool_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 259, in execute_tool
raise ValueError("这是一个演示用的模拟错误!执行被中断。")
ValueError: 这是一个演示用的模拟错误!执行被中断。
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B6164E0>
2026-01-28 09:59:01 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:01 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_resource, arguments=None
2026-01-28 09:59:01 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_resource
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B64BF80>
2026-01-28 09:59:04 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:04 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_image, arguments=None
2026-01-28 09:59:04 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_image
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B36DD90>
2026-01-28 09:59:09 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:09 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_image, arguments=None
2026-01-28 09:59:09 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_image
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:13 - root - INFO - [logger_config.py:112] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\logs
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:154] - Initializing server 'mcpskills_template_server'
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:380] - Registering handler for ListToolsRequest
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:441] - Registering handler for CallToolRequest
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:322] - ==================================================
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:323] - MCP Skills Template Server 启动
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:324] - ==================================================
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:329] - 命令行参数: {'mode': 'local', 'json_path': None}
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:332] - 使用模式: local
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:83] - 从本地加载 8 条配置: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\tools_config.json
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:137] - 已加载 8 个工具配置
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:339] - 开始运行 MCP Server (stdio 模式)
2026-01-28 10:02:13 - asyncio - DEBUG - [proactor_events.py:634] - Using proactor: IocpProactor
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: root=InitializedNotification(method='notifications/initialized', params=None, jsonrpc='2.0')
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A58E3F0>
2026-01-28 10:02:40 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type ListToolsRequest
2026-01-28 10:02:40 - lzwcai_mcpskills_template.main - INFO - [main.py:143] - 收到 ListTools 请求,当前配置数量: 8
2026-01-28 10:02:40 - lzwcai_mcpskills_template.main - INFO - [main.py:162] - ListTools 响应: 返回 8 个工具
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A66FAD0>
2026-01-28 10:02:44 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 10:02:44 - lzwcai_mcpskills_template.main - INFO - [main.py:172] - 收到 CallTool 请求: name=demo_complex, arguments={"user_info": {}}
2026-01-28 10:02:44 - lzwcai_mcpskills_template.main - INFO - [main.py:189] - 工具执行成功: demo_complex
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A1DAF00>
2026-01-28 10:02:50 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 10:02:50 - lzwcai_mcpskills_template.main - INFO - [main.py:172] - 收到 CallTool 请求: name=demo_mixed, arguments=None
2026-01-28 10:02:50 - lzwcai_mcpskills_template.main - INFO - [main.py:189] - 工具执行成功: demo_mixed
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent

View File

@@ -0,0 +1,89 @@
2026-01-28 09:58:33 - root - INFO - [logger_config.py:112] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\logs
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:154] - Initializing server 'mcpskills_template_server'
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:380] - Registering handler for ListToolsRequest
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:441] - Registering handler for CallToolRequest
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:304] - ==================================================
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:305] - MCP Skills Template Server 启动
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:306] - ==================================================
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:311] - 命令行参数: {'mode': 'local', 'json_path': None}
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:314] - 使用模式: local
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:82] - 从本地加载 7 条配置: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\tools_config.json
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:136] - 已加载 7 个工具配置
2026-01-28 09:58:33 - lzwcai_mcpskills_template.main - INFO - [main.py:321] - 开始运行 MCP Server (stdio 模式)
2026-01-28 09:58:33 - asyncio - DEBUG - [proactor_events.py:634] - Using proactor: IocpProactor
2026-01-28 09:58:33 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: root=InitializedNotification(method='notifications/initialized', params=None, jsonrpc='2.0')
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B64BFE0>
2026-01-28 09:58:34 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type ListToolsRequest
2026-01-28 09:58:34 - lzwcai_mcpskills_template.main - INFO - [main.py:142] - 收到 ListTools 请求,当前配置数量: 7
2026-01-28 09:58:34 - lzwcai_mcpskills_template.main - INFO - [main.py:161] - ListTools 响应: 返回 7 个工具
2026-01-28 09:58:34 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B59CFE0>
2026-01-28 09:58:36 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:58:36 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_mixed, arguments=None
2026-01-28 09:58:36 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_mixed
2026-01-28 09:58:36 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B39D7C0>
2026-01-28 09:58:55 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:58:55 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_error, arguments=None
2026-01-28 09:58:55 - lzwcai_mcpskills_template.main - ERROR - [main.py:190] - 工具执行失败: 这是一个演示用的模拟错误!执行被中断。
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 186, in handle_call_tool
result_contents = execute_tool(name, arguments or {}, tool_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 259, in execute_tool
raise ValueError("这是一个演示用的模拟错误!执行被中断。")
ValueError: 这是一个演示用的模拟错误!执行被中断。
2026-01-28 09:58:55 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B6164E0>
2026-01-28 09:59:01 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:01 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_resource, arguments=None
2026-01-28 09:59:01 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_resource
2026-01-28 09:59:01 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B64BF80>
2026-01-28 09:59:04 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:04 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_image, arguments=None
2026-01-28 09:59:04 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_image
2026-01-28 09:59:04 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x0000029E6B36DD90>
2026-01-28 09:59:09 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 09:59:09 - lzwcai_mcpskills_template.main - INFO - [main.py:171] - 收到 CallTool 请求: name=demo_image, arguments=None
2026-01-28 09:59:09 - lzwcai_mcpskills_template.main - INFO - [main.py:187] - 工具执行成功: demo_image
2026-01-28 09:59:09 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:13 - root - INFO - [logger_config.py:112] - 日志系统初始化完成 - 日志目录: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\logs
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:154] - Initializing server 'mcpskills_template_server'
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:380] - Registering handler for ListToolsRequest
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:441] - Registering handler for CallToolRequest
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:322] - ==================================================
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:323] - MCP Skills Template Server 启动
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:324] - ==================================================
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:329] - 命令行参数: {'mode': 'local', 'json_path': None}
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:332] - 使用模式: local
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:83] - 从本地加载 8 条配置: E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\tools_config.json
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:137] - 已加载 8 个工具配置
2026-01-28 10:02:13 - lzwcai_mcpskills_template.main - INFO - [main.py:339] - 开始运行 MCP Server (stdio 模式)
2026-01-28 10:02:13 - asyncio - DEBUG - [proactor_events.py:634] - Using proactor: IocpProactor
2026-01-28 10:02:13 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: root=InitializedNotification(method='notifications/initialized', params=None, jsonrpc='2.0')
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A58E3F0>
2026-01-28 10:02:40 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type ListToolsRequest
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type ListToolsRequest
2026-01-28 10:02:40 - lzwcai_mcpskills_template.main - INFO - [main.py:143] - 收到 ListTools 请求,当前配置数量: 8
2026-01-28 10:02:40 - lzwcai_mcpskills_template.main - INFO - [main.py:162] - ListTools 响应: 返回 8 个工具
2026-01-28 10:02:40 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A66FAD0>
2026-01-28 10:02:44 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 10:02:44 - lzwcai_mcpskills_template.main - INFO - [main.py:172] - 收到 CallTool 请求: name=demo_complex, arguments={"user_info": {}}
2026-01-28 10:02:44 - lzwcai_mcpskills_template.main - INFO - [main.py:189] - 工具执行成功: demo_complex
2026-01-28 10:02:44 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:582] - Received message: <mcp.shared.session.RequestResponder object at 0x000001407A1DAF00>
2026-01-28 10:02:50 - mcp.server.lowlevel.server - INFO - [server.py:619] - Processing request of type CallToolRequest
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:621] - Dispatching request of type CallToolRequest
2026-01-28 10:02:50 - lzwcai_mcpskills_template.main - INFO - [main.py:172] - 收到 CallTool 请求: name=demo_mixed, arguments=None
2026-01-28 10:02:50 - lzwcai_mcpskills_template.main - INFO - [main.py:189] - 工具执行成功: demo_mixed
2026-01-28 10:02:50 - mcp.server.lowlevel.server - DEBUG - [server.py:662] - Response sent

View File

@@ -0,0 +1,8 @@
2026-01-28 09:58:55 - lzwcai_mcpskills_template.main - ERROR - [main.py:190] - 工具执行失败: 这是一个演示用的模拟错误!执行被中断。
Traceback (most recent call last):
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 186, in handle_call_tool
result_contents = execute_tool(name, arguments or {}, tool_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yh-ai\project\lzwcai-szyg\lzwcai-mcp-server-package\lzwcai_mcpskills_template\lzwcai_mcpskills_template\main.py", line 259, in execute_tool
raise ValueError("这是一个演示用的模拟错误!执行被中断。")
ValueError: 这是一个演示用的模拟错误!执行被中断。

View File

@@ -12,6 +12,7 @@ import os
import logging import logging
import argparse import argparse
import anyio import anyio
import asyncio
import mcp.types as types import mcp.types as types
from mcp.server import NotificationOptions, Server from mcp.server import NotificationOptions, Server
@@ -182,32 +183,27 @@ async def handle_call_tool(
raise ValueError(f"未知工具: {name}") raise ValueError(f"未知工具: {name}")
# TODO: 在这里实现你的工具逻辑 # TODO: 在这里实现你的工具逻辑
# 示例:简单返回参数
try: try:
result = execute_tool(name, arguments or {}, tool_config) # execute_tool 现在是 async 的
result_contents = await execute_tool(name, arguments or {}, tool_config)
logger.info(f"工具执行成功: {name}") logger.info(f"工具执行成功: {name}")
return result_contents
except Exception as e: except Exception as e:
logger.error(f"工具执行失败: {e}", exc_info=True) logger.error(f"工具执行失败: {e}", exc_info=True)
result = {"error": str(e), "tool_name": name} # 重新抛出异常,以便 MCP SDK 能够捕获并将其格式化为错误响应
raise e
return [
types.TextContent(
type="text",
text=json.dumps(result, ensure_ascii=False, indent=2)
)
]
def execute_tool(name: str, arguments: dict, config: dict) -> dict: async def execute_tool(name: str, arguments: dict, config: dict) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
""" """
执行工具逻辑 执行工具逻辑并返回 MCP 内容列表 (Async)
TODO: 根据实际需求修改此函数
""" """
# 示例实现 # 1. 示例Hello World (返回纯文本)
if name == "example_hello_world": if name == "example_hello_world":
return {"message": f"Hello, {arguments.get('name', 'World')}!"} msg = f"Hello, {arguments.get('name', 'World')}!"
return [types.TextContent(type="text", text=msg)]
# 2. 示例:计算器 (返回 JSON 格式的文本)
elif name == "example_calculator": elif name == "example_calculator":
a = float(arguments.get("a", 0)) a = float(arguments.get("a", 0))
b = float(arguments.get("b", 0)) b = float(arguments.get("b", 0))
@@ -224,14 +220,82 @@ def execute_tool(name: str, arguments: dict, config: dict) -> dict:
else: else:
result = "未知运算符" result = "未知运算符"
return {"result": result, "expression": f"{a} {op} {b}"} output = {"result": result, "expression": f"{a} {op} {b}"}
return [types.TextContent(type="text", text=json.dumps(output, ensure_ascii=False))]
# 3. 演示:纯文本
elif name == "demo_text":
return [types.TextContent(type="text", text="这是一个标准的纯文本输出示例。")]
# 4. 演示:图片输出
elif name == "demo_image":
# 这是一个 1x1 的红色像素点的 Base64
red_dot_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
return [
types.ImageContent(
type="image",
data=red_dot_base64,
mimeType="image/png"
)
]
# 5. 演示:资源输出
elif name == "demo_resource":
# 模拟返回一个嵌入式资源
return [
types.EmbeddedResource(
type="resource",
resource=types.TextResourceContents(
uri="file:///logs/app.log",
text="[INFO] System started\n[WARN] Low memory",
mimeType="text/plain"
)
)
]
# 6. 演示:错误状态 (带 observation)
elif name == "demo_error":
# 尝试模拟用户要求的带 observation 的错误结构
# 注意:标准 MCP 协议中 TextContent 可能不支持 observation 字段
# 这里演示如何抛出异常,这是最标准的错误反馈方式
raise ValueError("执行失败: 网络超时,请检查连接")
# 如果客户端支持非标准字段,可以尝试返回如下结构(需 SDK 支持):
# return [
# types.TextContent(type="text", text="执行失败") # 无法直接添加 observation
# ]
# 7. 演示:混合输出 (文本 + 图片)
elif name == "demo_mixed":
red_dot_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
return [
types.TextContent(type="text", text="下面是一张图片:"),
types.ImageContent(
type="image",
data=red_dot_base64,
mimeType="image/png"
),
types.TextContent(type="text", text="图片展示完毕。")
]
# 8. 演示:复杂参数
elif name == "demo_complex":
user_info = arguments.get("user_info", {})
tags = arguments.get("tags", [])
# 模拟异步处理
await asyncio.sleep(0.1)
result_text = f"接收到复杂参数:\n用户: {json.dumps(user_info, ensure_ascii=False)}\n标签: {tags}"
return [types.TextContent(type="text", text=result_text)]
# 默认返回参数 # 默认返回参数
return { default_result = {
"tool_name": name, "tool_name": name,
"arguments": arguments, "arguments": arguments,
"message": "工具执行成功(默认实现)" "message": "工具执行成功(默认实现)"
} }
return [types.TextContent(type="text", text=json.dumps(default_result, ensure_ascii=False, indent=2))]
async def run_server(): async def run_server():

View File

@@ -61,6 +61,23 @@ def convert_param_to_schema_property(param: dict) -> tuple[str, dict, bool]:
elif param_type == "number": elif param_type == "number":
property_schema["type"] = "number" property_schema["type"] = "number"
elif param_type == "boolean":
property_schema["type"] = "boolean"
# Boolean default handling
if default_value is not None and str(default_value).lower() in ("true", "false", "1", "0"):
property_schema["default"] = str(default_value).lower() in ("true", "1")
elif param_type == "array":
property_schema["type"] = "array"
# Simple array of strings by default if no item type specified
# For more complex arrays, we might need extended config in sqlParams
property_schema["items"] = {"type": "string"}
elif param_type == "object":
property_schema["type"] = "object"
# Allow any object structure by default
property_schema["additionalProperties"] = True
else: else:
# 默认当作 string 处理 # 默认当作 string 处理

View File

@@ -12,5 +12,47 @@
"description": "示例工具 - 简单计算器", "description": "示例工具 - 简单计算器",
"toolPrompt": "执行简单的数学计算", "toolPrompt": "执行简单的数学计算",
"sqlParams": "[{\"type\":\"number\",\"name\":\"a\",\"displayName\":\"数字A\",\"required\":true},{\"type\":\"number\",\"name\":\"b\",\"displayName\":\"数字B\",\"required\":true},{\"type\":\"select\",\"name\":\"operation\",\"displayName\":\"运算符\",\"required\":true,\"options\":[\"+\",\"-\",\"*\",\"/\"]}]" "sqlParams": "[{\"type\":\"number\",\"name\":\"a\",\"displayName\":\"数字A\",\"required\":true},{\"type\":\"number\",\"name\":\"b\",\"displayName\":\"数字B\",\"required\":true},{\"type\":\"select\",\"name\":\"operation\",\"displayName\":\"运算符\",\"required\":true,\"options\":[\"+\",\"-\",\"*\",\"/\"]}]"
},
{
"id": "demo_001",
"name": "demo_text",
"description": "演示纯文本输出",
"toolPrompt": "返回一段简单的文本信息",
"sqlParams": "[]"
},
{
"id": "demo_002",
"name": "demo_image",
"description": "演示图片输出",
"toolPrompt": "返回一张 Base64 编码的图片",
"sqlParams": "[]"
},
{
"id": "demo_003",
"name": "demo_resource",
"description": "演示资源输出",
"toolPrompt": "返回一个嵌入式资源",
"sqlParams": "[]"
},
{
"id": "demo_004",
"name": "demo_error",
"description": "演示错误状态",
"toolPrompt": "触发一个执行错误",
"sqlParams": "[]"
},
{
"id": "demo_005",
"name": "demo_mixed",
"description": "演示混合输出",
"toolPrompt": "同时返回文本和图片",
"sqlParams": "[]"
},
{
"id": "demo_006",
"name": "demo_complex",
"description": "演示复杂参数输入",
"toolPrompt": "接受对象和数组类型的参数",
"sqlParams": "[{\"type\":\"object\",\"name\":\"user_info\",\"displayName\":\"用户信息\",\"required\":true},{\"type\":\"array\",\"name\":\"tags\",\"displayName\":\"标签列表\",\"required\":false}]"
} }
] ]

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "lzwcai_mcpskills_template" name = "lzwcai_mcpskills_template"
version = "0.1.0" version = "0.1.1"
description = "MCP Server 模板项目 - 用于快速创建新的 MCP 服务" description = "MCP Server 模板项目 - 用于快速创建新的 MCP 服务"
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"

View File

@@ -19,12 +19,12 @@ from mcp.server.models import InitializationOptions
from mcp.server.stdio import stdio_server from mcp.server.stdio import stdio_server
try: try:
from .schema_converter import convert_sql_params_to_input_schema from .schema_converter import convert_sql_params_to_input_schema, sanitize_json_schema
from .utils.api_client import execute_workflow, get_workflow_by_id, extract_final_output from .utils.api_client import execute_workflow, get_workflow_by_id, extract_final_output
from .utils.env_config import get_workflow_id from .utils.env_config import get_workflow_id
from .utils.logger_config import setup_system_logging, get_logger from .utils.logger_config import setup_system_logging, get_logger
except ImportError: except ImportError:
from schema_converter import convert_sql_params_to_input_schema from schema_converter import convert_sql_params_to_input_schema, sanitize_json_schema
from utils.api_client import execute_workflow, get_workflow_by_id, extract_final_output from utils.api_client import execute_workflow, get_workflow_by_id, extract_final_output
from utils.env_config import get_workflow_id from utils.env_config import get_workflow_id
from utils.logger_config import setup_system_logging, get_logger from utils.logger_config import setup_system_logging, get_logger
@@ -174,13 +174,30 @@ async def handle_list_tools() -> list[types.Tool]:
for query in _tools_config: for query in _tools_config:
name = query.get("name", "") name = query.get("name", "")
description = query.get("description") or query.get("toolPrompt") or query.get("uniqueName", "") description = query.get("description") or query.get("toolPrompt") or query.get("uniqueName", "")
sql_params = query.get("sqlParams", "[]")
logger.debug(f"处理工具配置: name={name}, description={description[:50] if description else 'None'}...") logger.debug(f"处理工具配置: name={name}, description={description[:50] if description else 'None'}...")
# 转换参数为 inputSchema # 优先使用 inputJsonSchema,如果不存在则从 sqlParams 转换
input_schema = convert_sql_params_to_input_schema(sql_params) input_json_schema = query.get("inputJsonSchema")
logger.debug(f"工具 {name} 的 inputSchema: {json.dumps(input_schema, ensure_ascii=False)}") if input_json_schema:
try:
# inputJsonSchema 是 JSON 字符串,需要解析
if isinstance(input_json_schema, str):
input_schema = json.loads(input_json_schema)
else:
input_schema = input_json_schema
# 清理 schema确保 enum 只包含字符串
input_schema = sanitize_json_schema(input_schema)
logger.debug(f"使用 inputJsonSchema (已清理): {json.dumps(input_schema, ensure_ascii=False)}")
except (json.JSONDecodeError, TypeError) as e:
logger.warning(f"解析 inputJsonSchema 失败: {e},回退到 sqlParams")
sql_params = query.get("sqlParams", "[]")
input_schema = convert_sql_params_to_input_schema(sql_params)
else:
# 从 sqlParams 转换
sql_params = query.get("sqlParams", "[]")
input_schema = convert_sql_params_to_input_schema(sql_params)
logger.debug(f"从 sqlParams 转换的 inputSchema: {json.dumps(input_schema, ensure_ascii=False)}")
tools.append( tools.append(
types.Tool( types.Tool(

View File

@@ -12,6 +12,41 @@ import json
from typing import Any from typing import Any
def sanitize_json_schema(schema: dict) -> dict:
"""
清理 JSON Schema确保 enum 字段只包含字符串值
Args:
schema: 原始 JSON Schema
Returns:
dict: 清理后的 JSON Schema
"""
if not isinstance(schema, dict):
return schema
# 递归处理 properties
if "properties" in schema and isinstance(schema["properties"], dict):
for prop_name, prop_schema in schema["properties"].items():
if isinstance(prop_schema, dict) and "enum" in prop_schema:
enum_values = prop_schema["enum"]
if isinstance(enum_values, list) and len(enum_values) > 0:
# 检查是否是对象数组
if isinstance(enum_values[0], dict):
# 提取 value 字段
cleaned_enum = [
item.get("value", item.get("label", ""))
for item in enum_values
if isinstance(item, dict)
]
# 过滤空值
prop_schema["enum"] = [v for v in cleaned_enum if v]
# 保留原始数据
prop_schema["x-options"] = enum_values
return schema
def convert_param_to_schema_property(param: dict) -> tuple[str, dict, bool]: def convert_param_to_schema_property(param: dict) -> tuple[str, dict, bool]:
""" """
将单个参数转换为 JSON Schema property 将单个参数转换为 JSON Schema property
@@ -57,7 +92,22 @@ def convert_param_to_schema_property(param: dict) -> tuple[str, dict, bool]:
elif param_type == "select": elif param_type == "select":
property_schema["type"] = "string" property_schema["type"] = "string"
if options: if options:
property_schema["enum"] = options # 处理 options 可能是对象数组 [{label, value}] 或字符串数组的情况
if isinstance(options, list) and len(options) > 0:
if isinstance(options[0], dict):
# 对象数组,提取 value 字段作为 enum过滤空值
enum_values = [
opt.get("value", opt.get("label", ""))
for opt in options
if isinstance(opt, dict)
]
# 过滤掉空字符串
property_schema["enum"] = [v for v in enum_values if v]
# 保留原始 options 供前端使用(如果前端支持)
property_schema["x-options"] = options
else:
# 字符串数组,直接使用,过滤空值
property_schema["enum"] = [v for v in options if v]
elif param_type == "number": elif param_type == "number":
property_schema["type"] = "number" property_schema["type"] = "number"

View File

@@ -7,8 +7,8 @@ import os
if __name__ == "__main__": if __name__ == "__main__":
# 设置环境变量 # 设置环境变量
os.environ["workflowId"] = "2005892514011795457" os.environ["workflowId"] = "2019984063311556609"
os.environ["workflowExecuteKey"] = "wf_ce270212b2ee45ab9c81714a7c243c56" os.environ["workflowExecuteKey"] = "wf_45bd630402664485a2ef5cd3ede5aa53"
os.environ["backendBaseUrl"] = "http://192.168.2.236:8088" os.environ["backendBaseUrl"] = "http://192.168.2.236:8088"
# Import and run the actual MCP server # Import and run the actual MCP server