diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 0000000..f7cf25b --- /dev/null +++ b/.mcp.json @@ -0,0 +1,9 @@ +{ + "mcpServers": { + "transpyc-tools": { + "command": "python", + "args": ["MCP/transpyc_mcp/server.py"], + "cwd": "D:\\Users\\TermiNexus\\Desktop\\TransPyC" + } + } +} \ No newline at end of file diff --git a/MCP/README.md b/MCP/README.md index e283bcd..e3eaf33 100644 --- a/MCP/README.md +++ b/MCP/README.md @@ -15,17 +15,18 @@ | `README.md` | 本文件:总览与快速接入 | | `protocol.md` | MCP 协议规范:工具定义、执行约定、输出格式、安全约束 | | `tools/` | 各工具的 JSON schema(可选生成,供客户端加载) | +| `transpyc_mcp/` | MCP 服务器实现(stdio,零依赖) | ## 快速接入 -MCP 服务器(`transpyc-tools`)以 stdio 方式运行于项目根目录: +项目根目录已创建 `.mcp.json`,客户端(IDE/工具)读取后自动注册 MCP 服务器 `transpyc-tools`(服务器代码位于 `MCP/transpyc_mcp/`,stdio 零依赖,也可手动 `python MCP/transpyc_mcp/server.py` 启动): ```json { "mcpServers": { "transpyc-tools": { "command": "python", - "args": ["-m", "transpyc_mcp.server"], + "args": ["MCP/transpyc_mcp/server.py"], "cwd": "D:\\Users\\TermiNexus\\Desktop\\TransPyC" } } diff --git a/transpyc_mcp/__init__.py b/MCP/transpyc_mcp/__init__.py similarity index 100% rename from transpyc_mcp/__init__.py rename to MCP/transpyc_mcp/__init__.py diff --git a/transpyc_mcp/server.py b/MCP/transpyc_mcp/server.py similarity index 98% rename from transpyc_mcp/server.py rename to MCP/transpyc_mcp/server.py index d29122c..70d81ee 100644 --- a/transpyc_mcp/server.py +++ b/MCP/transpyc_mcp/server.py @@ -24,7 +24,18 @@ from typing import Any, Callable # --------------------------------------------------------------------------- # 常量 # --------------------------------------------------------------------------- -_ROOT: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +def _find_root() -> str: + """向上定位项目根(含 Projectrans.py 的目录),兼容服务器位于 MCP/transpyc_mcp 下。""" + d: str = os.path.dirname(os.path.abspath(__file__)) + while True: + if os.path.isfile(os.path.join(d, "Projectrans.py")): + return d + parent: str = os.path.dirname(d) + if parent == d: + return d + d = parent + +_ROOT: str = _find_root() _TOOLS_JSON: str = os.path.join(_ROOT, 'MCP', 'tools', 'tools.json') _COMPILE_TIMEOUT: int = 300 _RUN_TIMEOUT: int = 30