- Notifications
You must be signed in to change notification settings - Fork190
Open
Description
I'm trying to integrate excel-mcp-server with a Python code through stdio mode, but I consistently get a ValueError related to stdin being closed unexpectedly.
Code snippet -
def call_excel_mcp_tool(command: dict, timeout: int = 15):
proc = subprocess.Popen(
["uvx", "excel-mcp-server", "stdio"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1 # Line-buffered
)
stdout_lines = []stderr_lines = []json_response = {}def read_stdout(pipe): for line in pipe: cleaned = line.strip() stdout_lines.append(cleaned) print("[MCP STDOUT]", cleaned) try: json_response.update(json.loads(cleaned)) except json.JSONDecodeError: passdef read_stderr(pipe): for line in pipe: cleaned = line.strip() stderr_lines.append(cleaned) print("[MCP STDERR]", cleaned)threading.Thread(target=read_stdout, args=(proc.stdout,), daemon=True).start()threading.Thread(target=read_stderr, args=(proc.stderr,), daemon=True).start()try: proc.stdin.write(json.dumps(command) + "\n") proc.stdin.flush() # Wait a bit instead of killing immediately start_time = time.time() while time.time() - start_time < timeout: if json_response: break time.sleep(0.1) proc.terminate() # Graceful stop instead of killexcept Exception as e: print("Exception:", e) proc.kill()return json_response if json_response else { "error": "No valid JSON response", "stderr": stderr_lines, "raw_stdout": stdout_lines}
Metadata
Metadata
Assignees
Labels
No labels