tapdb-maxcompute-mcp 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl

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.
@@ -1,7 +1,7 @@
1
1
  import logging
2
2
  import os
3
3
  from typing import Any
4
-
4
+ import json
5
5
  import mcp.server.stdio
6
6
  import mcp.types as types
7
7
  from mcp.server import NotificationOptions, Server
@@ -46,9 +46,20 @@ class MaxCompute:
46
46
  def _list_tables(self) -> list[str]:
47
47
  return [table.name for table in self.project.list_tables()]
48
48
 
49
- def _execute_query(self, query: str) -> list[dict[str, Any]]:
49
+ def _execute_query(self,
50
+ query: str,
51
+ save_file_path = None) -> list[dict[str, Any]]:
50
52
  """Execute a SQL query and return results as a list of dictionaries"""
51
53
  logger.debug(f"Executing query: {query}")
54
+
55
+ save_file = None
56
+ if save_file_path is not None:
57
+ try:
58
+ save_file = open(save_file_path, "w")
59
+ except:
60
+ raise IOError(f"无法打开文件进行写入 : {save_file_path}")
61
+
62
+
52
63
  try:
53
64
  with self.project.execute_sql(query).open_reader() as reader:
54
65
  if query.strip().upper().startswith('DESC'):
@@ -56,10 +67,18 @@ class MaxCompute:
56
67
 
57
68
  results = [dict(row) for row in reader]
58
69
  logger.debug(f"Read query returned {len(results)} rows")
59
- return results
70
+
71
+ if save_file is not None:
72
+ save_file.write(json.dumps(results))
73
+ return []
74
+ else:
75
+ return results
60
76
  except Exception as e:
61
77
  logger.error(f"Database error executing query: {e}")
62
78
  raise
79
+ finally:
80
+ if save_file is not None:
81
+ save_file.close()
63
82
 
64
83
 
65
84
  async def main():
@@ -99,6 +118,7 @@ async def main():
99
118
  "type": "object",
100
119
  "properties": {
101
120
  "query": {"type": "string", "description": "The read-only SQL query"},
121
+ "save_file_path": {"type": "string", "description": "结果写入到本地的文件路径。以json的格式写入。返回值将是一个空list",},
102
122
  },
103
123
  "required": ["query"],
104
124
  },
@@ -127,7 +147,10 @@ async def main():
127
147
 
128
148
  sql_text = arguments["query"]
129
149
  validate_readonly_sql(sql_text)
130
- results = maxcompute._execute_query(sql_text)
150
+
151
+ save_file_path = arguments.get("save_file_path",None)
152
+
153
+ results = maxcompute._execute_query(sql_text,save_file_path)
131
154
  return [types.TextContent(type="text", text=str(results))]
132
155
  else:
133
156
  raise ValueError(f"Unknown tool: {name}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tapdb-maxcompute-mcp
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: A MCP server for MaxCompute(tapdb revised)
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -40,6 +40,7 @@ The server offers 3 core tools:
40
40
  - Execute a read-only query on the MaxCompute project, such as SELECT or DESC query is allowed.
41
41
  - Input:
42
42
  - `query` (string): The read only SQL query
43
+ - `save_file_path` (string,opitional): local file that save the query results as json list
43
44
  - Returns: Query results as array of objects
44
45
 
45
46
  #### Schema Tools
@@ -0,0 +1,7 @@
1
+ tapdb_maxcompute_mcp/__init__.py,sha256=j0-l3GKDkk17_-h9EfvAsxZ4eskj7qEusam9RPq3hGM,215
2
+ tapdb_maxcompute_mcp/server.py,sha256=EUbs2LwyY-Z2dgZKp-7f_pohInf_g4-8K876CFZskic,6626
3
+ tapdb_maxcompute_mcp-0.1.9.dist-info/METADATA,sha256=DOqiaABJRmW4QECYc6FsF0mg5xkyvlDJ-bAAhrhR7SI,2525
4
+ tapdb_maxcompute_mcp-0.1.9.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
5
+ tapdb_maxcompute_mcp-0.1.9.dist-info/entry_points.txt,sha256=uooKPBbMis_h5b1_XYKUwF4yzpnJl8UGO0-22lPj-z8,67
6
+ tapdb_maxcompute_mcp-0.1.9.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ tapdb_maxcompute_mcp-0.1.9.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- tapdb_maxcompute_mcp/__init__.py,sha256=j0-l3GKDkk17_-h9EfvAsxZ4eskj7qEusam9RPq3hGM,215
2
- tapdb_maxcompute_mcp/server.py,sha256=Xjg8Tc9NSJ1OR--RBYmiTGAGoHl_N-HcSfBuA1Im5Gg,5798
3
- tapdb_maxcompute_mcp-0.1.7.dist-info/METADATA,sha256=g3QdhqJw67WBQm4-YGZ3968mqPNXY7h1ngsz5p5wiVA,2429
4
- tapdb_maxcompute_mcp-0.1.7.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
5
- tapdb_maxcompute_mcp-0.1.7.dist-info/entry_points.txt,sha256=uooKPBbMis_h5b1_XYKUwF4yzpnJl8UGO0-22lPj-z8,67
6
- tapdb_maxcompute_mcp-0.1.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
- tapdb_maxcompute_mcp-0.1.7.dist-info/RECORD,,