This commit is contained in:
shane0411 2025-06-08 04:06:05 +08:00
commit 9b30312c76
3 changed files with 22 additions and 13 deletions

View file

@ -136,9 +136,6 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict):
conn.logger.bind(tag=TAG).info(
f"客户端MCP服务器信息: name={name}, version={version}"
)
await send_mcp_tools_list_request(
conn
) # After initialization, request tool list
return
elif msg_id == 2: # mcpToolsListID
@ -177,6 +174,20 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict):
await mcp_client.add_tool(new_tool)
conn.logger.bind(tag=TAG).debug(f"客户端工具 #{i+1}: {name}")
# 替换所有工具描述中的工具名称
for tool_data in mcp_client.tools.values():
if "description" in tool_data:
description = tool_data["description"]
# 遍历所有工具名称进行替换
for (
sanitized_name,
original_name,
) in mcp_client.name_mapping.items():
description = description.replace(
original_name, sanitized_name
)
tool_data["description"] = description
next_cursor = result.get("nextCursor", "")
if next_cursor:
conn.logger.bind(tag=TAG).info(
@ -222,8 +233,6 @@ async def send_mcp_initialize_message(conn):
"token": token,
}
conn.logger.bind(tag=TAG).info(f"视觉服务信息: {vision}")
payload = {
"jsonrpc": "2.0",
"id": 1, # mcpInitializeID
@ -345,7 +354,7 @@ async def call_mcp_tool(
}
conn.logger.bind(tag=TAG).info(
f"发送客户端mcp工具调用请求: {tool_name},参数: {args}"
f"发送客户端mcp工具调用请求: {actual_name},参数: {args}"
)
await send_mcp_message(conn, payload)
@ -353,7 +362,7 @@ async def call_mcp_tool(
# Wait for response or timeout
raw_result = await asyncio.wait_for(result_future, timeout=timeout)
conn.logger.bind(tag=TAG).info(
f"客户端mcp工具调用 {tool_name} 成功,原始结果: {raw_result}"
f"客户端mcp工具调用 {actual_name} 成功,原始结果: {raw_result}"
)
if isinstance(raw_result, dict):

View file

@ -2,9 +2,8 @@ import os
import yaml
import time
import hashlib
import fcntl
import portalocker
from typing import Dict
from contextlib import contextmanager
class FileLock:
@ -17,15 +16,15 @@ class FileLock:
self.start_time = time.time()
while True:
try:
fcntl.flock(self.file, fcntl.LOCK_EX | fcntl.LOCK_NB)
portalocker.lock(self.file, portalocker.LOCK_EX | portalocker.LOCK_NB)
return self.file
except IOError:
except portalocker.LockException:
if time.time() - self.start_time > self.timeout:
raise TimeoutError("获取文件锁超时")
time.sleep(0.1)
def __exit__(self, exc_type, exc_val, exc_tb):
fcntl.flock(self.file, fcntl.LOCK_UN)
portalocker.unlock(self.file)
class WakeupWordsConfig:

View file

@ -32,4 +32,5 @@ aioconsole==0.8.1
markitdown==0.1.1
mcp-proxy==0.6.0
PyJWT==2.8.0
psutil==7.0.0
psutil==7.0.0
portalocker==2.10.1