diff --git a/src/maisaka/mcp_config.json.template b/config/mcp_config.json.template similarity index 100% rename from src/maisaka/mcp_config.json.template rename to config/mcp_config.json.template diff --git a/src/maisaka/mcp_config.json b/src/maisaka/mcp_config.json deleted file mode 100644 index 959b4eed..00000000 --- a/src/maisaka/mcp_config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "mcpServers": { - "tavily": { - "command": "npx", - "args": [ - "-y", - "mcp-remote", - "https://mcp.tavily.com/mcp/?tavilyApiKey=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" - ], - "env": {} - } - } -} \ No newline at end of file diff --git a/src/maisaka/mcp_client/__init__.py b/src/mcp_module/__init__.py similarity index 79% rename from src/maisaka/mcp_client/__init__.py rename to src/mcp_module/__init__.py index bd996975..ab8fa632 100644 --- a/src/maisaka/mcp_client/__init__.py +++ b/src/mcp_module/__init__.py @@ -1,12 +1,12 @@ """ -MaiSaka - MCP (Model Context Protocol) 客户端包 +MCP (Model Context Protocol) 客户端包。 提供 MCPManager 用于管理 MCP 服务器连接、发现工具、调用工具。 用法: from .manager import MCPManager - manager = await MCPManager.from_config("mcp_config.json") + manager = await MCPManager.from_config("config/mcp_config.json") if manager: tools = manager.get_openai_tools() # 获取 OpenAI 格式工具列表 result = await manager.call_tool(name, args) # 调用工具 diff --git a/src/maisaka/mcp_client/config.py b/src/mcp_module/config.py similarity index 84% rename from src/maisaka/mcp_client/config.py rename to src/mcp_module/config.py index 50acbb6f..f4bfa763 100644 --- a/src/maisaka/mcp_client/config.py +++ b/src/mcp_module/config.py @@ -1,6 +1,6 @@ """ -MaiSaka - MCP 配置加载与验证 -从 mcp_config.json 读取 MCP 服务器定义,解析为结构化配置对象。 +MCP 配置加载与验证。 +从 config/mcp_config.json 读取 MCP 服务器定义,解析为结构化配置对象。 配置格式示例: { @@ -21,12 +21,16 @@ MaiSaka - MCP 配置加载与验证 - url: SSE 传输(连接远程服务器) """ +from dataclasses import dataclass, field +from pathlib import Path +from typing import Optional import json import os -from dataclasses import dataclass, field -from typing import Optional -from ..console import console +from src.maisaka.console import console + + +DEFAULT_MCP_CONFIG_PATH = Path(__file__).resolve().parents[2] / "config" / "mcp_config.json" @dataclass @@ -54,7 +58,7 @@ class MCPServerConfig: return "unknown" -def load_mcp_config(config_path: str = "mcp_config.json") -> list[MCPServerConfig]: +def load_mcp_config(config_path: str = str(DEFAULT_MCP_CONFIG_PATH)) -> list[MCPServerConfig]: """ 从配置文件加载 MCP 服务器列表。 @@ -76,7 +80,7 @@ def load_mcp_config(config_path: str = "mcp_config.json") -> list[MCPServerConfi mcp_servers = data.get("mcpServers", {}) if not isinstance(mcp_servers, dict): - console.print("[warning]⚠️ mcp_config.json 中 mcpServers 格式无效[/warning]") + console.print("[warning]⚠️ MCP 配置中的 mcpServers 格式无效[/warning]") return [] configs: list[MCPServerConfig] = [] diff --git a/src/maisaka/mcp_client/connection.py b/src/mcp_module/connection.py similarity index 99% rename from src/maisaka/mcp_client/connection.py rename to src/mcp_module/connection.py index a69073fb..57401950 100644 --- a/src/maisaka/mcp_client/connection.py +++ b/src/mcp_module/connection.py @@ -6,7 +6,8 @@ MaiSaka - 单个 MCP 服务器连接管理 from contextlib import AsyncExitStack from typing import Any, Optional -from ..console import console +from src.maisaka.console import console + from .config import MCPServerConfig # ──────────────────── MCP SDK 可选导入 ──────────────────── diff --git a/src/maisaka/mcp_client/manager.py b/src/mcp_module/manager.py similarity index 97% rename from src/maisaka/mcp_client/manager.py rename to src/mcp_module/manager.py index 1efba099..8be0a4d7 100644 --- a/src/maisaka/mcp_client/manager.py +++ b/src/mcp_module/manager.py @@ -5,8 +5,9 @@ MaiSaka - MCP 管理器 from typing import Optional -from ..console import console -from .config import MCPServerConfig, load_mcp_config +from src.maisaka.console import console + +from .config import DEFAULT_MCP_CONFIG_PATH, MCPServerConfig, load_mcp_config from .connection import MCPConnection, MCP_AVAILABLE # 内置工具名称集合 —— MCP 工具不允许与这些名称冲突 @@ -43,7 +44,7 @@ class MCPManager: @classmethod async def from_config( cls, - config_path: str = "mcp_config.json", + config_path: str = str(DEFAULT_MCP_CONFIG_PATH), ) -> Optional["MCPManager"]: """ 从配置文件创建并初始化 MCPManager。