Skip to content

Commit 0c126c7

Browse files
committed
fix: resolve Windows compatibility issues in mcp_servers.py
- Fix environment variable name from STATA-MCP-CLIENT to STATA_MCP_CLIENT - Disable help functionality on Windows systems to prevent crashes - Disable ado package installation on Windows systems - Add strict_mode parameter to write_dofile function - Fix grammar typos in comments
1 parent d12a92c commit 0c126c7

File tree

9 files changed

+323
-135
lines changed

9 files changed

+323
-135
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ requires-python = ">=3.11"
1010
license = {text = "Apache-2.0"}
1111
dependencies = [
1212
"python-dotenv>=1.1.1",
13-
"mcp[cli]>=1.16.0",
13+
"mcp[cli]>=1.20.0",
1414
"pandas>=2.3.0",
1515
"pexpect>=4.9.0",
1616
# "flask>=2.3.0",

src/stata_mcp/core/data_info/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import json
1111
from abc import ABC, abstractmethod
12+
from os import PathLike
1213
from pathlib import Path
1314
from typing import Any, Dict, List
1415
from urllib.parse import urlparse
15-
from os import PathLike
1616

1717
import numpy as np
1818
import pandas as pd

src/stata_mcp/core/data_info/csv.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,20 @@ def _read_data(self) -> pd.DataFrame:
116116
# Generate default column names
117117
self.kwargs['names'] = [f'V{i+1}' for i in range(num_cols)]
118118

119-
# Read the CSV file
120-
df = pd.read_csv(file_path, **self.kwargs)
119+
# Read the CSV file with error handling for invalid parameters
120+
try:
121+
df = pd.read_csv(file_path, **self.kwargs)
122+
except TypeError as e:
123+
if "unexpected keyword argument" in str(e):
124+
# Filter out problematic parameters and retry with basic ones
125+
basic_kwargs = {k: v for k, v in self.kwargs.items()
126+
if k in {'sep', 'header', 'encoding', 'names'}}
127+
print(f"Warning: Retrying CSV read with filtered parameters due to: {e}")
128+
df = pd.read_csv(file_path, **basic_kwargs)
129+
else:
130+
raise
131+
except Exception as e:
132+
raise ValueError(f"Error reading CSV file {file_path}: {str(e)}")
121133

122134
return df
123135

src/stata_mcp/core/stata/builtin_tools/ado_install/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __post_initialization(self):
3434
... self.github_mirror = "https://github.com" # Fake var
3535
...
3636
... def install(self, package: str):
37-
... return f"Installing {package} with {self.custom_setting}"
37+
... ...
3838
"""
3939
pass
4040

@@ -56,3 +56,15 @@ def install(self, package: str) -> str: pass
5656
@abstractmethod
5757
def check_install(message: str) -> bool:
5858
...
59+
60+
@staticmethod
61+
def check_installed_from_msg(msg: str) -> bool:
62+
state_with_prompt = msg.split("\n")[0]
63+
state_str = state_with_prompt.split(":")[-1].strip()
64+
if isinstance(state := eval(state_str), bool):
65+
return state
66+
else:
67+
return False
68+
69+
def _install_msg_template(self, runner_result: str) -> str:
70+
return f"Installation State: {self.check_install(runner_result)}\n" + runner_result

src/stata_mcp/core/stata/builtin_tools/ado_install/github_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GITHUB_Install(AdoInstallBase):
1515
def install(self, package: str) -> str:
1616
install_command = f"github install {package}{self.REPLACE_MESSAGE}"
1717
runner_result = self.controller.run(install_command)
18-
return f"Installation State: {self.check_install(runner_result)}\n" + runner_result
18+
return self._install_msg_template(runner_result)
1919

2020
@property
2121
def IS_EXIST_GITHUB(self) -> bool:

src/stata_mcp/core/stata/builtin_tools/ado_install/net_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def install(self, package: str, directory_or_url: str = None) -> str:
1717

1818
install_command = f"net install {package}{self.REPLACE_MESSAGE}{from_message}"
1919
runner_result = self.controller.run(install_command)
20-
return f"Installation State: {self.check_install(runner_result)}\n" + runner_result
20+
return self._install_msg_template(runner_result)
2121

2222
@staticmethod
2323
def check_install(message: str) -> bool:

src/stata_mcp/core/stata/builtin_tools/ado_install/ssc_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SSC_Install(AdoInstallBase):
1414
def install(self, package: str) -> str:
1515
install_command = f"ssc install {package}{self.REPLACE_MESSAGE}"
1616
runner_result = self.controller.run(install_command)
17-
return f"Installation State: {self.check_install(runner_result)}\n" + runner_result
17+
return self._install_msg_template(runner_result)
1818

1919
@staticmethod
2020
def check_install(message: str) -> bool:

0 commit comments

Comments
 (0)