Skip to content

Commit 2ce3666

Browse files
authored
Update mcp_server_sqlite to use robust text encoding by default
The Claude Desktop client will hang in Windows when utilizing extended/multibyte characters in sqlite as a result of decoding errors. The decoding errors are resolved by using UTF-8 encoding. Configuring Windows to use UTF-8 in place of windows-1252 makes the default server behavior consistent with macOS. os.environ PYTHONIOENCODING is checked as to not interfere with an environment override, such as: { "mcpServers": { "sqlite": { "command": "uvx", "args": [ "mcp-server-sqlite", "--db-path", "./example.db" ], "env": { "PYTHONIOENCODING": "utf-8" } } } }
1 parent 926d86c commit 2ce3666

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/sqlite/src/mcp_server_sqlite/server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import sys
13
import sqlite3
24
import logging
35
from contextlib import closing
@@ -9,6 +11,12 @@
911
from pydantic import AnyUrl
1012
from typing import Any
1113

14+
# reconfigure UnicodeEncodeError prone default (i.e. windows-1252) to utf-8
15+
if sys.platform == "win32" and os.environ.get('PYTHONIOENCODING') is None:
16+
sys.stdin.reconfigure(encoding="utf-8")
17+
sys.stdout.reconfigure(encoding="utf-8")
18+
sys.stderr.reconfigure(encoding="utf-8")
19+
1220
logger = logging.getLogger('mcp_sqlite_server')
1321
logger.info("Starting MCP SQLite Server")
1422

0 commit comments

Comments
 (0)