How marlonluo2018/pandas-mcp-server works
Project type and purpose
• This is a Python-based MCP (Model Context Protocol) server that exposes Pandas data-processing and Chart.js chart-generation functions over a stdio interface.
• Its primary use case is to let an MCP client load CSV metadata, execute arbitrary (but sandboxed) Pandas code, and produce interactive bar, pie, and line charts as standalone HTML files.
File structure
Top-level files and folders:
• server.py – entry point and MCP server loop
• requirements.txt – external libraries (pandas, chardet, MCP toolkit, etc.)
• metadata_test.py, test_charts.py – unit tests covering read_metadata and chart-generation functions
• templates/ – Chart.js HTML templates (barchart_template, piechart_template, linechart_template)
Patterns and conventions:
• Single-process, modular design: server.py dispatches to handler functions
• Templates folder holds static HTML with placeholders for dynamic data
• Tests mirror production modules for coverage and regression checking
README for additional insights
• Describes four core services:
– read_metadata: CSV introspection (auto-detect encoding/delimiter)
– run_pandas_code: sandboxed execution of user-supplied Pandas snippets
– bar_chart_to_html / pie_chart_to_html / line_chart_to_html: inject data into Chart.js templates, write HTML
• Workflow: MCP client → stdio → server.py → appropriate handler → JSON response (plus file‐path for charts)