Skip to content

Commit 200f8fb

Browse files
updated chart view
1 parent ffaa675 commit 200f8fb

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ For support and questions:
339339
## 🙏 Acknowledgments
340340

341341
- [Database Toolbox](https://googleapis.github.io/genai-toolbox/) for multi-database tool integration
342+
342343
- [LLM Sandbox](https://github.com/vndee/llm-sandbox) for secure code execution and agent tool orchestration
343344
- [MCP-UI Specification](https://github.com/idosal/mcp-ui) for unified tool and UI protocol
344345
- [LangGraph](https://github.com/langchain-ai/langgraph) for agent orchestration

backend/composite_data_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def fetch_data():
130130
"y_axis": y_axis
131131
}
132132

133-
ui_resource = mcp_ui_generator.create_chart_ui_resource(vizro_config, title)
133+
ui_resource = mcp_ui_generator.create_chart_ui_resource(vizro_config, title, x_axis, y_axis)
134134

135135
# Return the complete result
136136
result = {
@@ -384,7 +384,7 @@ async def fetch_data():
384384
"data": safe_data,
385385
"x_axis": "bin",
386386
"y_axis": "count"
387-
}, title)
387+
}, title, "bin", "count")
388388

389389
# Return the complete result
390390
result = {

backend/langgraph_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ def _get_system_prompt(self, iteration_count: int = 0, tool_results: List[Dict[s
555555
- **create_chart_from_data**: Creates chart from database query + optional code processing
556556
- **create_table_from_data**: Creates table from database query + optional code processing
557557
- **create_histogram_from_data**: Creates histogram from database query + optional code processing
558-
- **NEVER use the basic create_chart, create_table, or create_histogram tools**
558+
- **FORBIDDEN: NEVER use these deprecated tools:**
559+
- ❌ create_chart (DEPRECATED - requires pre-fetched data)
560+
- ❌ create_table (DEPRECATED - requires pre-fetched data)
561+
- ❌ create_histogram (DEPRECATED - requires pre-fetched data)
559562
- ALWAYS query the database FIRST to get data, THEN create visualizations
560563
- NEVER provide final response without creating requested visualizations
561564
- These tools handle the complete workflow: Database Query → Code Processing → UIResource Generation

backend/langraph_multi_mcp_tools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from langchain_core.callbacks import CallbackManagerForToolRun
1414

1515
from mcp_multi_client import mcp_manager
16-
from visualization_tool import get_visualization_tools
16+
# from visualization_tool import get_visualization_tools # DISABLED - using composite tools instead
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -248,10 +248,10 @@ async def get_all_mcp_langraph_tools() -> List[BaseTool]:
248248

249249
tools = []
250250

251-
# Add visualization tools
252-
visualization_tools = get_visualization_tools()
253-
tools.extend(visualization_tools)
254-
logger.info(f"✅ Added {len(visualization_tools)} visualization tools")
251+
# Add visualization tools (DISABLED - using composite tools instead)
252+
# visualization_tools = get_visualization_tools()
253+
# tools.extend(visualization_tools)
254+
# logger.info(f"✅ Added {len(visualization_tools)} visualization tools")
255255

256256
# Add composite data tools (data + code + UIResource)
257257
try:

backend/mcp_ui_generator.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MCPUIGenerator:
6666
def __init__(self):
6767
self.logger = logging.getLogger(__name__)
6868

69-
def create_chart_ui_resource(self, chart_config: Dict[str, Any], title: str = "Chart") -> Dict[str, Any]:
69+
def create_chart_ui_resource(self, chart_config: Dict[str, Any], title: str = "Chart", x_axis: str = None, y_axis: str = None) -> Dict[str, Any]:
7070
"""
7171
Create a chart UI resource from chart configuration.
7272
@@ -79,7 +79,7 @@ def create_chart_ui_resource(self, chart_config: Dict[str, Any], title: str = "C
7979
"""
8080
try:
8181
# Create a simple chart HTML
82-
chart_html = self._generate_chart_html(chart_config, title)
82+
chart_html = self._generate_chart_html(chart_config, title, x_axis, y_axis)
8383

8484
return createUIResource({
8585
"uri": f"ui://chart/{datetime.now().timestamp()}",
@@ -121,7 +121,7 @@ def create_data_table_ui_resource(self, data: List[Dict[str, Any]], columns: Lis
121121
self.logger.error(f"Failed to create table UI resource: {e}")
122122
return self._create_error_ui_resource(f"Table generation failed: {e}")
123123

124-
def _generate_chart_html(self, chart_config: Dict[str, Any], title: str) -> str:
124+
def _generate_chart_html(self, chart_config: Dict[str, Any], title: str, x_axis: str = None, y_axis: str = None) -> str:
125125
"""Generate HTML for chart visualization."""
126126
# Simple chart HTML using Chart.js or similar
127127
chart_id = f"chart_{datetime.now().timestamp()}"
@@ -132,6 +132,13 @@ def _generate_chart_html(self, chart_config: Dict[str, Any], title: str) -> str:
132132
if not data_points:
133133
return f"<div><h3>{title}</h3><p>No data available for chart</p></div>"
134134

135+
# Fallback to first two keys if x_axis/y_axis not provided
136+
if not x_axis or not y_axis:
137+
first_row = data_points[0] if data_points else {}
138+
keys = list(first_row.keys())
139+
x_axis = x_axis or (keys[0] if len(keys) > 0 else 'x')
140+
y_axis = y_axis or (keys[1] if len(keys) > 1 else 'y')
141+
135142
# Simple HTML chart
136143
html = f"""
137144
<div style="padding: 20px;">
@@ -148,10 +155,10 @@ def _generate_chart_html(self, chart_config: Dict[str, Any], title: str) -> str:
148155
new Chart(ctx, {{
149156
type: 'bar',
150157
data: {{
151-
labels: chartData.map(item => Object.keys(item)[0]),
158+
labels: chartData.map(item => item['{x_axis}']),
152159
datasets: [{{
153160
label: '{title}',
154-
data: chartData.map(item => Object.values(item)[0]),
161+
data: chartData.map(item => item['{y_axis}']),
155162
backgroundColor: 'rgba(54, 162, 235, 0.2)',
156163
borderColor: 'rgba(54, 162, 235, 1)',
157164
borderWidth: 1

backend/visualization_tool.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@ class CreateChartTool(BaseTool):
6161

6262
name: str = "create_chart"
6363
description: str = """
64+
DEPRECATED: Use create_chart_from_data instead.
6465
Create a chart visualization from data and generate a UIResource.
65-
This tool takes data and creates an interactive chart with Chart.js.
66+
This tool requires pre-fetched data and should NOT be used directly.
6667
67-
Use this when you have data and want to create:
68-
- Bar charts for categorical data
69-
- Line charts for time series
70-
- Pie charts for proportional data
71-
- Histograms for distribution data
68+
Use create_chart_from_data for all chart creation needs.
7269
"""
7370
args_schema: type[BaseModel] = CreateChartInput
7471

@@ -119,10 +116,11 @@ class CreateTableTool(BaseTool):
119116

120117
name: str = "create_table"
121118
description: str = """
119+
DEPRECATED: Use create_table_from_data instead.
122120
Create a data table visualization from data and generate a UIResource.
123-
This tool takes data and creates an interactive table with sorting and export capabilities.
121+
This tool requires pre-fetched data and should NOT be used directly.
124122
125-
Use this when you have tabular data and want to display it in a structured format.
123+
Use create_table_from_data for all table creation needs.
126124
"""
127125
args_schema: type[BaseModel] = CreateTableInput
128126

@@ -168,10 +166,11 @@ class CreateHistogramTool(BaseTool):
168166

169167
name: str = "create_histogram"
170168
description: str = """
169+
DEPRECATED: Use create_histogram_from_data instead.
171170
Create a histogram visualization from data and generate a UIResource.
172-
This tool takes numerical data and creates a histogram showing the distribution.
171+
This tool requires pre-fetched data and should NOT be used directly.
173172
174-
Use this when you have numerical data and want to show its distribution.
173+
Use create_histogram_from_data for all histogram creation needs.
175174
"""
176175
args_schema: type[BaseModel] = CreateHistogramInput
177176

docker-compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
version: '3.8'
2-
31
services:
42
# PostgreSQL Database
53
postgres:
64
image: postgres:15-alpine
75
container_name: analytics-postgres
86
environment:
9-
POSTGRES_DB: analytics_db
10-
POSTGRES_USER: analytics
11-
POSTGRES_PASSWORD: password
7+
POSTGRES_DB: loyalty_analytics
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
1210
POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
1311
ports:
1412
- "5432:5432"

0 commit comments

Comments
 (0)