mcp-win-stdio 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/PKG-INFO +2 -2
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/README.md +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/src/mcp_win_stdio/db/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/src/mcp_win_stdio/db/server.py +60 -18
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-excel/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1/packages/mcp-win-stdio-excel}/src/mcp_win_stdio/excel/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1/packages/mcp-win-stdio-excel}/src/mcp_win_stdio/excel/server.py +114 -31
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-explorer/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1/packages/mcp-win-stdio-explorer}/src/mcp_win_stdio/explorer/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1/packages/mcp-win-stdio-explorer}/src/mcp_win_stdio/explorer/server.py +54 -13
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1/packages/mcp-win-stdio-tsc}/src/mcp_win_stdio/tsc/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/src/mcp_win_stdio/tsc/server.py +11 -2
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/src/mcp_win_stdio/word/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/pyproject.toml +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/db/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/db/server.py +60 -18
- {mcp_win_stdio-0.2.0/packages/mcp-win-stdio-excel → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/excel/__init__.py +1 -1
- {mcp_win_stdio-0.2.0/packages/mcp-win-stdio-excel → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/excel/server.py +114 -31
- {mcp_win_stdio-0.2.0/packages/mcp-win-stdio-explorer → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/explorer/__init__.py +1 -1
- {mcp_win_stdio-0.2.0/packages/mcp-win-stdio-explorer → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/explorer/server.py +55 -14
- {mcp_win_stdio-0.2.0/packages/mcp-win-stdio-tsc → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/tsc/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/tsc/server.py +11 -2
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/word/__init__.py +1 -1
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/word/server.py +32 -9
- mcp_win_stdio-0.2.1/tests/test_audit.py +70 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/.gitignore +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/LICENSE +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/README.md +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/src/mcp_win_stdio/db/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/src/mcp_win_stdio/db/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-excel/README.md +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-excel/src/mcp_win_stdio/excel/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-excel/src/mcp_win_stdio/excel/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-excel/src/mcp_win_stdio/excel/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-explorer/README.md +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-explorer/src/mcp_win_stdio/explorer/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-explorer/src/mcp_win_stdio/explorer/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-explorer/src/mcp_win_stdio/explorer/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/README.md +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/src/mcp_win_stdio/tsc/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/src/mcp_win_stdio/tsc/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-tsc/src/mcp_win_stdio/tsc/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/README.md +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/src/mcp_win_stdio/word/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/src/mcp_win_stdio/word/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/src/mcp_win_stdio/word/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-word/src/mcp_win_stdio/word/server.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/core/config.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/core/discovery.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/core/installer.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/db/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/db/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/excel/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/excel/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/excel/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/explorer/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/explorer/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/explorer/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/__init__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/db_guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/excel_guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/explorer_guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/tsc_guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/guides/word_guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/tsc/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/tsc/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/tsc/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/word/__main__.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/word/cli.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/src/mcp_win_stdio/word/guide.py +0 -0
- {mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/tests/test_cli.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mcp-win-stdio
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Windows-optimized Model Context Protocol (MCP) suite & interactive CLI hub for Claude Desktop & Claude Code CLI (Excel COM, Word layouts, Workspace Explorer, and TypeScript diagnostic watcher).
|
|
5
5
|
Author: Mohan Kumar Indala
|
|
6
6
|
License-Expression: MIT
|
|
@@ -110,7 +110,7 @@ mws
|
|
|
110
110
|
Output:
|
|
111
111
|
```text
|
|
112
112
|
============================================================================
|
|
113
|
-
🚀 mcp-win-stdio — Windows Model Context Protocol Suite (v0.2.
|
|
113
|
+
🚀 mcp-win-stdio — Windows Model Context Protocol Suite (v0.2.1)
|
|
114
114
|
============================================================================
|
|
115
115
|
|
|
116
116
|
Single-Source Hub: C:\Users\User\.mcp-win-stdio
|
|
@@ -61,7 +61,7 @@ mws
|
|
|
61
61
|
Output:
|
|
62
62
|
```text
|
|
63
63
|
============================================================================
|
|
64
|
-
🚀 mcp-win-stdio — Windows Model Context Protocol Suite (v0.2.
|
|
64
|
+
🚀 mcp-win-stdio — Windows Model Context Protocol Suite (v0.2.1)
|
|
65
65
|
============================================================================
|
|
66
66
|
|
|
67
67
|
Single-Source Hub: C:\Users\User\.mcp-win-stdio
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mcp-win-stdio-db"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Unified Database Model Context Protocol (MCP) server for PostgreSQL & MySQL: 20 tools for multi-server querying, DBA operations (create, drop, clone, dump, terminate), and cross-schema auto-resolution."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
{mcp_win_stdio-0.2.0 → mcp_win_stdio-0.2.1}/packages/mcp-win-stdio-db/src/mcp_win_stdio/db/server.py
RENAMED
|
@@ -4,12 +4,14 @@ Unified Database MCP Server for PostgreSQL and MySQL
|
|
|
4
4
|
Part of mcp-win-stdio.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
import decimal
|
|
7
8
|
import os
|
|
8
9
|
import sys
|
|
9
10
|
import json
|
|
10
11
|
import re
|
|
11
12
|
import subprocess
|
|
12
|
-
|
|
13
|
+
import uuid
|
|
14
|
+
from datetime import datetime, date, time
|
|
13
15
|
from pathlib import Path
|
|
14
16
|
from typing import Any, Optional, List, Dict, Union
|
|
15
17
|
from urllib.parse import urlparse, unquote
|
|
@@ -201,11 +203,25 @@ def _resolve_pg_table(cur, table_name: str, schema: Optional[str] = None) -> Dic
|
|
|
201
203
|
|
|
202
204
|
|
|
203
205
|
def _truncate_cell(val: Any, max_chars: int = 500) -> Any:
|
|
204
|
-
"""Truncate massive strings or raw binary data
|
|
205
|
-
if
|
|
206
|
-
return
|
|
207
|
-
|
|
206
|
+
"""Truncate massive strings or raw binary data and serialize rich DB types (Decimal, UUID, datetime)."""
|
|
207
|
+
if val is None:
|
|
208
|
+
return None
|
|
209
|
+
if isinstance(val, (bytes, bytearray, memoryview)):
|
|
208
210
|
return f"<binary data: {len(val)} bytes>"
|
|
211
|
+
if isinstance(val, decimal.Decimal):
|
|
212
|
+
return float(val) if val.is_finite() else str(val)
|
|
213
|
+
if isinstance(val, (datetime, date, time)):
|
|
214
|
+
return val.isoformat()
|
|
215
|
+
if isinstance(val, uuid.UUID):
|
|
216
|
+
return str(val)
|
|
217
|
+
if isinstance(val, (set, tuple)):
|
|
218
|
+
return [_truncate_cell(x, max_chars) for x in val]
|
|
219
|
+
if isinstance(val, dict):
|
|
220
|
+
return {k: _truncate_cell(v, max_chars) for k, v in val.items()}
|
|
221
|
+
if isinstance(val, str):
|
|
222
|
+
if len(val) > max_chars:
|
|
223
|
+
return val[:max_chars] + f"... [truncated {len(val) - max_chars} chars]"
|
|
224
|
+
return val
|
|
209
225
|
return val
|
|
210
226
|
|
|
211
227
|
|
|
@@ -810,11 +826,13 @@ def create_database(database: str, server: Optional[str] = None, encoding: Optio
|
|
|
810
826
|
if info["engine"] == "postgres":
|
|
811
827
|
admin_conn = _get_pg_client(info, dbname="postgres")
|
|
812
828
|
admin_conn.autocommit = True
|
|
829
|
+
db_esc = database.replace('"', '""')
|
|
813
830
|
try:
|
|
814
831
|
with admin_conn.cursor() as cur:
|
|
815
|
-
sql = f'CREATE DATABASE "{
|
|
832
|
+
sql = f'CREATE DATABASE "{db_esc}"'
|
|
816
833
|
if template:
|
|
817
|
-
|
|
834
|
+
tpl_esc = template.replace('"', '""')
|
|
835
|
+
sql += f' TEMPLATE "{tpl_esc}"'
|
|
818
836
|
if encoding:
|
|
819
837
|
sql += f" ENCODING '{encoding}'"
|
|
820
838
|
cur.execute(sql)
|
|
@@ -827,9 +845,10 @@ def create_database(database: str, server: Optional[str] = None, encoding: Optio
|
|
|
827
845
|
return {"success": True, "message": f"Database '{database}' successfully created on PostgreSQL server ({info['host']}:{info['port']}).", "database": database, "engine": "postgres"}
|
|
828
846
|
else:
|
|
829
847
|
conn = _get_mysql_client(info)
|
|
848
|
+
db_esc = database.replace("`", "``")
|
|
830
849
|
try:
|
|
831
850
|
with conn.cursor() as cur:
|
|
832
|
-
sql = f"CREATE DATABASE IF NOT EXISTS `{
|
|
851
|
+
sql = f"CREATE DATABASE IF NOT EXISTS `{db_esc}`"
|
|
833
852
|
if encoding:
|
|
834
853
|
sql += f" CHARACTER SET {encoding}"
|
|
835
854
|
cur.execute(sql)
|
|
@@ -863,22 +882,24 @@ def drop_database(database: str, confirmName: str, force: bool = False, server:
|
|
|
863
882
|
if info["engine"] == "postgres":
|
|
864
883
|
admin_conn = _get_pg_client(info, dbname="postgres")
|
|
865
884
|
admin_conn.autocommit = True
|
|
885
|
+
db_esc = database.replace('"', '""')
|
|
866
886
|
try:
|
|
867
887
|
with admin_conn.cursor() as cur:
|
|
868
888
|
if force:
|
|
869
889
|
cur.execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = %s AND pid <> pg_backend_pid();", (database,))
|
|
870
|
-
cur.execute(f'DROP DATABASE IF EXISTS "{
|
|
890
|
+
cur.execute(f'DROP DATABASE IF EXISTS "{db_esc}" WITH (FORCE);')
|
|
871
891
|
else:
|
|
872
|
-
cur.execute(f'DROP DATABASE "{
|
|
892
|
+
cur.execute(f'DROP DATABASE "{db_esc}";')
|
|
873
893
|
finally:
|
|
874
894
|
admin_conn.close()
|
|
875
895
|
|
|
876
896
|
return {"success": True, "message": f"Database '{database}' successfully dropped on PostgreSQL server ({info['host']}:{info['port']}).", "activeConnectionNow": _ACTIVE_CONNECTION}
|
|
877
897
|
else:
|
|
878
898
|
conn = _get_mysql_client(info)
|
|
899
|
+
db_esc = database.replace("`", "``")
|
|
879
900
|
try:
|
|
880
901
|
with conn.cursor() as cur:
|
|
881
|
-
cur.execute(f"DROP DATABASE IF EXISTS `{
|
|
902
|
+
cur.execute(f"DROP DATABASE IF EXISTS `{db_esc}`;")
|
|
882
903
|
finally:
|
|
883
904
|
conn.close()
|
|
884
905
|
|
|
@@ -892,18 +913,20 @@ def clone_database(sourceDatabase: str, targetDatabase: str, server: Optional[st
|
|
|
892
913
|
if info["engine"] == "postgres":
|
|
893
914
|
admin_conn = _get_pg_client(info, dbname="postgres")
|
|
894
915
|
admin_conn.autocommit = True
|
|
916
|
+
src_esc = sourceDatabase.replace('"', '""')
|
|
917
|
+
tgt_esc = targetDatabase.replace('"', '""')
|
|
895
918
|
try:
|
|
896
919
|
with admin_conn.cursor() as cur:
|
|
897
920
|
try:
|
|
898
|
-
cur.execute(f'ALTER DATABASE "{
|
|
921
|
+
cur.execute(f'ALTER DATABASE "{src_esc}" WITH ALLOW_CONNECTIONS = false;')
|
|
899
922
|
except Exception:
|
|
900
923
|
pass
|
|
901
924
|
cur.execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = %s AND pid <> pg_backend_pid();", (sourceDatabase,))
|
|
902
|
-
cur.execute(f'CREATE DATABASE "{
|
|
925
|
+
cur.execute(f'CREATE DATABASE "{tgt_esc}" WITH TEMPLATE "{src_esc}";')
|
|
903
926
|
finally:
|
|
904
927
|
try:
|
|
905
928
|
with admin_conn.cursor() as cur:
|
|
906
|
-
cur.execute(f'ALTER DATABASE "{
|
|
929
|
+
cur.execute(f'ALTER DATABASE "{src_esc}" WITH ALLOW_CONNECTIONS = true;')
|
|
907
930
|
except Exception:
|
|
908
931
|
pass
|
|
909
932
|
admin_conn.close()
|
|
@@ -914,14 +937,17 @@ def clone_database(sourceDatabase: str, targetDatabase: str, server: Optional[st
|
|
|
914
937
|
return {"success": True, "message": f"Database '{sourceDatabase}' cloned to '{targetDatabase}' successfully via native template cloning.", "source": sourceDatabase, "target": targetDatabase}
|
|
915
938
|
else:
|
|
916
939
|
conn = _get_mysql_client(info)
|
|
940
|
+
src_esc = sourceDatabase.replace("`", "``")
|
|
941
|
+
tgt_esc = targetDatabase.replace("`", "``")
|
|
917
942
|
try:
|
|
918
943
|
with conn.cursor() as cur:
|
|
919
|
-
cur.execute(f"CREATE DATABASE IF NOT EXISTS `{
|
|
944
|
+
cur.execute(f"CREATE DATABASE IF NOT EXISTS `{tgt_esc}`;")
|
|
920
945
|
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = %s;", (sourceDatabase,))
|
|
921
946
|
tables = [r.get("table_name", next(iter(r.values()))) for r in cur.fetchall()]
|
|
922
947
|
for t in tables:
|
|
923
|
-
|
|
924
|
-
cur.execute(f"
|
|
948
|
+
t_esc = str(t).replace("`", "``")
|
|
949
|
+
cur.execute(f"CREATE TABLE `{tgt_esc}`.`{t_esc}` LIKE `{src_esc}`.`{t_esc}`;")
|
|
950
|
+
cur.execute(f"INSERT INTO `{tgt_esc}`.`{t_esc}` SELECT * FROM `{src_esc}`.`{t_esc}`;")
|
|
925
951
|
finally:
|
|
926
952
|
conn.close()
|
|
927
953
|
|
|
@@ -1090,9 +1116,25 @@ def restore_database(database: str, dumpFilePath: str, server: Optional[str] = N
|
|
|
1090
1116
|
"message": f"PostgreSQL database '{database}' successfully restored from '{dumpFilePath}'."
|
|
1091
1117
|
}
|
|
1092
1118
|
else:
|
|
1119
|
+
cmd = [
|
|
1120
|
+
"mysql",
|
|
1121
|
+
"-h", str(info["host"]),
|
|
1122
|
+
"-P", str(info["port"]),
|
|
1123
|
+
"-u", str(info["user"]),
|
|
1124
|
+
]
|
|
1125
|
+
if info.get("password"):
|
|
1126
|
+
cmd.append(f"-p{info['password']}")
|
|
1127
|
+
cmd.append(database)
|
|
1128
|
+
|
|
1129
|
+
with open(fpath, "r", encoding="utf-8", errors="replace") as dump_in:
|
|
1130
|
+
res = subprocess.run(cmd, stdin=dump_in, capture_output=True, text=True)
|
|
1131
|
+
|
|
1132
|
+
if res.returncode != 0:
|
|
1133
|
+
raise RuntimeError(f"mysql restore failed: {res.stderr}")
|
|
1134
|
+
|
|
1093
1135
|
return {
|
|
1094
1136
|
"success": True,
|
|
1095
|
-
"message": f"MySQL
|
|
1137
|
+
"message": f"MySQL database '{database}' successfully restored from '{dumpFilePath}'.",
|
|
1096
1138
|
"dumpFilePath": str(fpath)
|
|
1097
1139
|
}
|
|
1098
1140
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mcp-win-stdio-excel"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Windows-optimized Model Context Protocol (MCP) server for Excel: 20 tools for Pandas queries, RapidFuzz reconciliation, cell editing, and native Excel COM automation (PDF export, recalc, pivots, macros)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -34,6 +34,21 @@ except ImportError:
|
|
|
34
34
|
mcp = FastMCP("excel-tools")
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
def _df_to_clean_records(df: pd.DataFrame) -> List[Dict[str, Any]]:
|
|
38
|
+
"""Convert DataFrame to JSON-safe records, cleanly handling NaT, NaN, Timestamps, and dates."""
|
|
39
|
+
clean = df.astype(object).where(pd.notnull(df), None)
|
|
40
|
+
records = clean.to_dict(orient="records")
|
|
41
|
+
for row in records:
|
|
42
|
+
for k, v in row.items():
|
|
43
|
+
if pd.isna(v):
|
|
44
|
+
row[k] = None
|
|
45
|
+
elif hasattr(v, "isoformat"):
|
|
46
|
+
row[k] = v.isoformat()
|
|
47
|
+
elif isinstance(v, (float, int)) and (math.isnan(v) or math.isinf(v)):
|
|
48
|
+
row[k] = None
|
|
49
|
+
return records
|
|
50
|
+
|
|
51
|
+
|
|
37
52
|
# ==========================================
|
|
38
53
|
# 1. PANDAS & OPENPYXL FAST DATA TOOLS
|
|
39
54
|
# ==========================================
|
|
@@ -91,14 +106,14 @@ def preview_sheet(
|
|
|
91
106
|
|
|
92
107
|
nrows = max(1, min(nrows, 200))
|
|
93
108
|
df = pd.read_excel(file_path, sheet_name=sheet_name or 0, nrows=nrows)
|
|
94
|
-
|
|
109
|
+
rows = _df_to_clean_records(df)
|
|
95
110
|
|
|
96
111
|
return {
|
|
97
112
|
"sheet_name": sheet_name or "First Sheet",
|
|
98
|
-
"preview_row_count": len(
|
|
113
|
+
"preview_row_count": len(rows),
|
|
99
114
|
"columns": list(df.columns),
|
|
100
115
|
"column_types": {col: str(dtype) for col, dtype in df.dtypes.items()},
|
|
101
|
-
"rows":
|
|
116
|
+
"rows": rows,
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
|
|
@@ -131,18 +146,19 @@ def query_rows(
|
|
|
131
146
|
|
|
132
147
|
total_matches = len(df)
|
|
133
148
|
paginated_df = df.iloc[offset : offset + limit]
|
|
134
|
-
|
|
149
|
+
rows = _df_to_clean_records(paginated_df)
|
|
135
150
|
|
|
136
151
|
return {
|
|
137
152
|
"total_matches": total_matches,
|
|
138
153
|
"offset": offset,
|
|
139
154
|
"limit": limit,
|
|
140
|
-
"returned_rows": len(
|
|
155
|
+
"returned_rows": len(rows),
|
|
141
156
|
"columns": list(df.columns),
|
|
142
|
-
"rows":
|
|
157
|
+
"rows": rows,
|
|
143
158
|
}
|
|
144
159
|
|
|
145
160
|
|
|
161
|
+
|
|
146
162
|
@mcp.tool()
|
|
147
163
|
def read_range(
|
|
148
164
|
file_path: str,
|
|
@@ -177,16 +193,17 @@ def read_range(
|
|
|
177
193
|
usecols=columns,
|
|
178
194
|
)
|
|
179
195
|
|
|
180
|
-
|
|
196
|
+
rows = _df_to_clean_records(df)
|
|
181
197
|
return {
|
|
182
198
|
"start_row": start_row,
|
|
183
|
-
"end_row": start_row + len(
|
|
184
|
-
"row_count": len(
|
|
199
|
+
"end_row": start_row + len(rows) - 1,
|
|
200
|
+
"row_count": len(rows),
|
|
185
201
|
"columns": list(df.columns),
|
|
186
|
-
"rows":
|
|
202
|
+
"rows": rows,
|
|
187
203
|
}
|
|
188
204
|
|
|
189
205
|
|
|
206
|
+
|
|
190
207
|
@mcp.tool()
|
|
191
208
|
def summarize_column(
|
|
192
209
|
file_path: str,
|
|
@@ -255,7 +272,8 @@ def search_text(
|
|
|
255
272
|
results = []
|
|
256
273
|
|
|
257
274
|
for idx in matched_indices:
|
|
258
|
-
|
|
275
|
+
cleaned_row_list = _df_to_clean_records(df.iloc[[idx]])
|
|
276
|
+
row_data = cleaned_row_list[0] if cleaned_row_list else {}
|
|
259
277
|
matching_cols = [col for col in df.columns if str(search_term).lower() in str(df.at[idx, col]).lower()]
|
|
260
278
|
results.append({
|
|
261
279
|
"excel_row_number": idx + 2,
|
|
@@ -284,8 +302,13 @@ def create_workbook(
|
|
|
284
302
|
if not data:
|
|
285
303
|
raise ValueError("Data list cannot be empty.")
|
|
286
304
|
|
|
305
|
+
out_dir = os.path.dirname(os.path.abspath(file_path))
|
|
306
|
+
if out_dir:
|
|
307
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
308
|
+
|
|
287
309
|
df = pd.DataFrame(data)
|
|
288
310
|
with pd.ExcelWriter(file_path, engine="openpyxl") as writer:
|
|
311
|
+
|
|
289
312
|
df.to_excel(writer, sheet_name=sheet_name, index=False)
|
|
290
313
|
ws = writer.sheets[sheet_name]
|
|
291
314
|
for col in ws.columns:
|
|
@@ -495,9 +518,15 @@ def export_to_csv(
|
|
|
495
518
|
if not os.path.exists(file_path):
|
|
496
519
|
raise FileNotFoundError(f"File not found: {file_path}")
|
|
497
520
|
|
|
521
|
+
out_dir = os.path.dirname(os.path.abspath(output_csv_path))
|
|
522
|
+
if out_dir:
|
|
523
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
524
|
+
|
|
525
|
+
|
|
498
526
|
df = pd.read_excel(file_path, sheet_name=sheet_name or 0)
|
|
499
527
|
df.to_csv(output_csv_path, index=False)
|
|
500
528
|
|
|
529
|
+
|
|
501
530
|
return {
|
|
502
531
|
"status": "success",
|
|
503
532
|
"input_excel": file_path,
|
|
@@ -793,6 +822,10 @@ def reconcile_and_merge(
|
|
|
793
822
|
all_unmatched.append(r)
|
|
794
823
|
df_unmatched = pd.DataFrame(all_unmatched) if all_unmatched else pd.DataFrame([{"Message": "No unmatched exceptions"}])
|
|
795
824
|
|
|
825
|
+
out_dir = os.path.dirname(os.path.abspath(output_file_path))
|
|
826
|
+
if out_dir:
|
|
827
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
828
|
+
|
|
796
829
|
with pd.ExcelWriter(output_file_path, engine="openpyxl") as writer:
|
|
797
830
|
df_reconciled.to_excel(writer, sheet_name="1_Reconciled_Matches", index=False)
|
|
798
831
|
df_fuzzy.to_excel(writer, sheet_name="2_Probable_Fuzzy_Matches", index=False)
|
|
@@ -843,22 +876,33 @@ def recalculate_and_save(file_path: str) -> Dict[str, Any]:
|
|
|
843
876
|
raise FileNotFoundError(f"File not found: {abs_path}")
|
|
844
877
|
|
|
845
878
|
pythoncom.CoInitialize()
|
|
846
|
-
excel =
|
|
847
|
-
|
|
848
|
-
excel.DisplayAlerts = False
|
|
849
|
-
|
|
879
|
+
excel = None
|
|
880
|
+
wb = None
|
|
850
881
|
try:
|
|
882
|
+
excel = win32com.client.DispatchEx("Excel.Application")
|
|
883
|
+
excel.Visible = False
|
|
884
|
+
excel.DisplayAlerts = False
|
|
851
885
|
wb = excel.Workbooks.Open(abs_path)
|
|
852
886
|
excel.CalculateFull()
|
|
853
887
|
wb.Save()
|
|
854
888
|
wb.Close()
|
|
889
|
+
wb = None
|
|
855
890
|
return {
|
|
856
891
|
"status": "success",
|
|
857
892
|
"message": "Workbook formulas recalculated and saved using native Microsoft Excel.",
|
|
858
893
|
"file_path": abs_path,
|
|
859
894
|
}
|
|
860
895
|
finally:
|
|
861
|
-
|
|
896
|
+
if wb:
|
|
897
|
+
try:
|
|
898
|
+
wb.Close(False)
|
|
899
|
+
except Exception:
|
|
900
|
+
pass
|
|
901
|
+
if excel:
|
|
902
|
+
try:
|
|
903
|
+
excel.Quit()
|
|
904
|
+
except Exception:
|
|
905
|
+
pass
|
|
862
906
|
pythoncom.CoUninitialize()
|
|
863
907
|
|
|
864
908
|
|
|
@@ -881,12 +925,17 @@ def export_to_pdf(
|
|
|
881
925
|
if not os.path.exists(abs_input):
|
|
882
926
|
raise FileNotFoundError(f"Input file not found: {abs_input}")
|
|
883
927
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
excel.DisplayAlerts = False
|
|
928
|
+
out_dir = os.path.dirname(abs_output)
|
|
929
|
+
if out_dir:
|
|
930
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
888
931
|
|
|
932
|
+
pythoncom.CoInitialize()
|
|
933
|
+
excel = None
|
|
934
|
+
wb = None
|
|
889
935
|
try:
|
|
936
|
+
excel = win32com.client.DispatchEx("Excel.Application")
|
|
937
|
+
excel.Visible = False
|
|
938
|
+
excel.DisplayAlerts = False
|
|
890
939
|
wb = excel.Workbooks.Open(abs_input)
|
|
891
940
|
# xlTypePDF = 0
|
|
892
941
|
if sheet_name and sheet_name in [s.Name for s in wb.Sheets]:
|
|
@@ -896,13 +945,23 @@ def export_to_pdf(
|
|
|
896
945
|
wb.ExportAsFixedFormat(0, abs_output)
|
|
897
946
|
|
|
898
947
|
wb.Close(False)
|
|
948
|
+
wb = None
|
|
899
949
|
return {
|
|
900
950
|
"status": "success",
|
|
901
951
|
"message": f"Successfully exported to PDF: {abs_output}",
|
|
902
952
|
"pdf_path": abs_output,
|
|
903
953
|
}
|
|
904
954
|
finally:
|
|
905
|
-
|
|
955
|
+
if wb:
|
|
956
|
+
try:
|
|
957
|
+
wb.Close(False)
|
|
958
|
+
except Exception:
|
|
959
|
+
pass
|
|
960
|
+
if excel:
|
|
961
|
+
try:
|
|
962
|
+
excel.Quit()
|
|
963
|
+
except Exception:
|
|
964
|
+
pass
|
|
906
965
|
pythoncom.CoUninitialize()
|
|
907
966
|
|
|
908
967
|
|
|
@@ -920,26 +979,38 @@ def refresh_data_and_pivots(file_path: str) -> Dict[str, Any]:
|
|
|
920
979
|
raise FileNotFoundError(f"File not found: {abs_path}")
|
|
921
980
|
|
|
922
981
|
pythoncom.CoInitialize()
|
|
923
|
-
excel =
|
|
924
|
-
|
|
925
|
-
excel.DisplayAlerts = False
|
|
926
|
-
|
|
982
|
+
excel = None
|
|
983
|
+
wb = None
|
|
927
984
|
try:
|
|
985
|
+
excel = win32com.client.DispatchEx("Excel.Application")
|
|
986
|
+
excel.Visible = False
|
|
987
|
+
excel.DisplayAlerts = False
|
|
928
988
|
wb = excel.Workbooks.Open(abs_path)
|
|
929
989
|
wb.RefreshAll()
|
|
930
990
|
excel.CalculateUntilAsyncQueriesDone()
|
|
931
991
|
wb.Save()
|
|
932
992
|
wb.Close()
|
|
993
|
+
wb = None
|
|
933
994
|
return {
|
|
934
995
|
"status": "success",
|
|
935
996
|
"message": "All data connections and PivotTables refreshed successfully.",
|
|
936
997
|
"file_path": abs_path,
|
|
937
998
|
}
|
|
938
999
|
finally:
|
|
939
|
-
|
|
1000
|
+
if wb:
|
|
1001
|
+
try:
|
|
1002
|
+
wb.Close(False)
|
|
1003
|
+
except Exception:
|
|
1004
|
+
pass
|
|
1005
|
+
if excel:
|
|
1006
|
+
try:
|
|
1007
|
+
excel.Quit()
|
|
1008
|
+
except Exception:
|
|
1009
|
+
pass
|
|
940
1010
|
pythoncom.CoUninitialize()
|
|
941
1011
|
|
|
942
1012
|
|
|
1013
|
+
|
|
943
1014
|
@mcp.tool()
|
|
944
1015
|
def run_vba_macro(
|
|
945
1016
|
file_path: str,
|
|
@@ -957,26 +1028,38 @@ def run_vba_macro(
|
|
|
957
1028
|
raise FileNotFoundError(f"File not found: {abs_path}")
|
|
958
1029
|
|
|
959
1030
|
pythoncom.CoInitialize()
|
|
960
|
-
excel =
|
|
961
|
-
|
|
962
|
-
excel.DisplayAlerts = False
|
|
963
|
-
|
|
1031
|
+
excel = None
|
|
1032
|
+
wb = None
|
|
964
1033
|
try:
|
|
1034
|
+
excel = win32com.client.DispatchEx("Excel.Application")
|
|
1035
|
+
excel.Visible = False
|
|
1036
|
+
excel.DisplayAlerts = False
|
|
965
1037
|
wb = excel.Workbooks.Open(abs_path)
|
|
966
1038
|
macro_args = args or []
|
|
967
1039
|
macro_res = excel.Application.Run(macro_name, *macro_args)
|
|
968
1040
|
wb.Save()
|
|
969
1041
|
wb.Close()
|
|
1042
|
+
wb = None
|
|
970
1043
|
return {
|
|
971
1044
|
"status": "success",
|
|
972
1045
|
"macro_name": macro_name,
|
|
973
1046
|
"macro_result": str(macro_res) if macro_res is not None else None,
|
|
974
1047
|
}
|
|
975
1048
|
finally:
|
|
976
|
-
|
|
1049
|
+
if wb:
|
|
1050
|
+
try:
|
|
1051
|
+
wb.Close(False)
|
|
1052
|
+
except Exception:
|
|
1053
|
+
pass
|
|
1054
|
+
if excel:
|
|
1055
|
+
try:
|
|
1056
|
+
excel.Quit()
|
|
1057
|
+
except Exception:
|
|
1058
|
+
pass
|
|
977
1059
|
pythoncom.CoUninitialize()
|
|
978
1060
|
|
|
979
1061
|
|
|
1062
|
+
|
|
980
1063
|
@mcp.tool()
|
|
981
1064
|
def get_active_excel_window() -> Dict[str, Any]:
|
|
982
1065
|
"""
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mcp-win-stdio-explorer"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Lightweight Model Context Protocol (MCP) server for token-safe workspace exploration: collapsible directory trees, dynamic .gitignore resolution, in-file grep, RapidFuzz fuzzy search, and AST code outline."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|