-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expand file tree
/
Copy pathserver.py
More file actions
82 lines (63 loc) · 2.58 KB
/
server.py
File metadata and controls
82 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from mcp.server.fastmcp import FastMCP
from tools import generate, evaluate, visualize
# Create FastMCP instance
mcp = FastMCP("sdv_mcp")
@mcp.tool()
def sdv_generate(folder_name: str) -> str:
"""Generate synthetic data based on real data using SDV Synthesizer.
This tool reads CSV files from the specified folder, creates a synthetic
version of that data, and saves it to a 'synthetic_data' folder.
Args:
folder_name (str): Path to folder containing CSV data files and metadata.json
Returns:
str: Success message with information about generated tables
"""
try:
return generate(folder_name)
except FileNotFoundError as e:
return f"Error: {str(e)}"
except RuntimeError as e:
return f"Error: {str(e)}"
@mcp.tool()
def sdv_evaluate(folder_name: str) -> dict:
"""Evaluate the quality of synthetic data compared to real data.
This tool compares the synthetic data in the 'synthetic_data' folder
with the real data in the specified folder and generates quality metrics.
Args:
folder_name (str): Path to folder containing the original CSV data files and metadata.json
Returns:
dict: Evaluation results including overall score and detailed properties
"""
try:
result = evaluate(folder_name)
return result
except FileNotFoundError as e:
return {"error": f"File not found: {str(e)}"}
except RuntimeError as e:
return {"error": f"Evaluation failed: {str(e)}"}
@mcp.tool()
def sdv_visualize(
folder_name: str,
table_name: str,
column_name: str,
) -> str:
"""Generate visualization comparing real and synthetic data for a specific column.
This tool creates a visual comparison between the real data in the specified folder
and the synthetic data in the 'synthetic_data' folder for a particular table column.
The visualization is saved as a PNG file in the 'evaluation_plots' folder.
Args:
folder_name (str): Path to folder containing the original CSV data files and metadata.json
table_name (str): Name of the table to visualize (must exist in the metadata)
column_name (str): Name of the column to visualize within the specified table
Returns:
str: Success message with the path to the saved visualization or error message
"""
try:
return visualize(folder_name, table_name, column_name)
except FileNotFoundError as e:
return f"Error: {str(e)}"
except RuntimeError as e:
return f"Error: {str(e)}"
# Run the server
if __name__ == "__main__":
mcp.run(transport="stdio")