From 45196f352f3ee60de8e8e9e3a2081dc440d9ab04 Mon Sep 17 00:00:00 2001 From: Anto01 Date: Fri, 17 Apr 2026 11:08:24 -0400 Subject: [PATCH] fix: force UTF-8 on MCP stdio for Windows compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows Python defaults stdout to cp1252. Any non-ASCII char in tool responses (emojis, ≥, →, etc.) crashes the MCP server with a UnicodeEncodeError. Explicitly reconfigure stdin/stdout/stderr to UTF-8 at startup. No-op on Linux/macOS. Noticed when Claude Code called atocore_search and atocore_memory_list and both crashed on ⏳ / ≥ characters that came back in the response. Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/atocore_mcp.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/atocore_mcp.py b/scripts/atocore_mcp.py index 9474e13..13f382d 100644 --- a/scripts/atocore_mcp.py +++ b/scripts/atocore_mcp.py @@ -37,6 +37,17 @@ import urllib.error import urllib.parse import urllib.request +# Force UTF-8 on stdio — MCP protocol expects UTF-8 but Windows Python +# defaults stdout to cp1252, which crashes on any non-ASCII char (emojis, +# ≥, →, etc.) in tool responses. This call is a no-op on Linux/macOS +# where UTF-8 is already the default. +try: + sys.stdin.reconfigure(encoding="utf-8") + sys.stdout.reconfigure(encoding="utf-8") + sys.stderr.reconfigure(encoding="utf-8") +except Exception: + pass + # --- Configuration --- ATOCORE_URL = os.environ.get("ATOCORE_URL", "http://dalidou:8100").rstrip("/")