Skip to content

Commit d84d46f

Browse files
committed
error handling
1 parent 9b8a955 commit d84d46f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/mcp_server_metatool/server.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ def extract_imports(code: str) -> list[str]:
6565

6666
return list(imports)
6767
except Exception as e:
68-
print(f"Error parsing imports: {e}")
69-
return []
68+
raise RuntimeError(f"Error parsing imports: {e}") from e
7069

7170

7271
def install_dependencies(dependencies: list[str]):
7372
"""Install required dependencies using uv pip."""
7473
try:
75-
print(f"Checking dependencies: {dependencies}")
7674
subprocess.run(["uv", "pip", "install"] + dependencies, check=True)
7775
except subprocess.CalledProcessError as e:
78-
print(f"Failed to install dependencies: {e}")
76+
raise RuntimeError(f"Failed to install dependencies: {e}") from e
7977

8078

8179
async def get_custom_mcp_servers() -> list[StdioServerParameters]:
@@ -103,9 +101,19 @@ async def get_custom_mcp_servers() -> list[StdioServerParameters]:
103101
script_path = temp_file.name
104102

105103
# Extract dependencies from the code
106-
dependencies = extract_imports(params["code"])
107-
if dependencies:
108-
install_dependencies(dependencies)
104+
try:
105+
dependencies = extract_imports(params["code"])
106+
if dependencies:
107+
try:
108+
install_dependencies(dependencies)
109+
except Exception as e:
110+
print(
111+
f"Failed to install dependencies for server {code_uuid}: {e}"
112+
)
113+
continue
114+
except Exception as e:
115+
print(f"Failed to extract imports for server {code_uuid}: {e}")
116+
continue
109117

110118
params["command"] = "uv"
111119
params["args"] = ["run", script_path] + params.get("additionalArgs", [])

0 commit comments

Comments
 (0)