Skip to content

Commit c8821c2

Browse files
Copilotbcollamore
andcommitted
fix: resolve MCP server import issues by using direct module imports
Co-authored-by: bcollamore <[email protected]>
1 parent 0f592e0 commit c8821c2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

tools/mcp/mcp_server.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
#!/usr/bin/env python3
22
import sys, importlib
3+
import os
34
from pathlib import Path
45
from typing import Dict, Any
56
from fastmcp import FastMCP
67

78
mcp = FastMCP("roslyn-analyzers-dev")
89
BASE_DIR = Path(__file__).resolve().parents[2]
910

10-
MODULE_NAME = "tools.mcp.ra_tools"
11+
# Add the MCP directory to path for direct imports
12+
MCP_DIR = Path(__file__).parent
13+
if str(MCP_DIR) not in sys.path:
14+
sys.path.insert(0, str(MCP_DIR))
15+
16+
# Import ra_tools directly
17+
import ra_tools
1118

1219
def _mod():
13-
# Always resolve the current module object
14-
mod = sys.modules.get(MODULE_NAME)
15-
if mod is None:
16-
mod = importlib.import_module(MODULE_NAME)
17-
mod.set_base_dir(str(BASE_DIR))
18-
return mod
20+
# Set the base directory and return the ra_tools module
21+
ra_tools.set_base_dir(str(BASE_DIR))
22+
return ra_tools
1923

2024
@mcp.tool
2125
def hot_reload() -> Dict[str, Any]:
2226
"""Reload tool implementations from disk without restarting the MCP server."""
2327
importlib.invalidate_caches()
24-
mod = sys.modules.get(MODULE_NAME)
25-
if mod is None:
26-
mod = importlib.import_module(MODULE_NAME)
27-
else:
28-
mod = importlib.reload(mod)
29-
mod.set_base_dir(str(BASE_DIR))
30-
return {"status": "ok", "reloaded": MODULE_NAME, "base_dir": str(BASE_DIR)}
28+
global ra_tools
29+
ra_tools = importlib.reload(ra_tools)
30+
ra_tools.set_base_dir(str(BASE_DIR))
31+
return {"status": "ok", "reloaded": "ra_tools", "base_dir": str(BASE_DIR)}
3132

3233
# Thin wrappers: delegate to the current module
3334
@mcp.tool

0 commit comments

Comments
 (0)