Skip to main content

A universal Model Content Protocol (MCP) for Pandas and Polars DataFrames, designed to be used as a tool by Large Language Models (LLMs).

Project description

Rostaing's Model Content Protocol (rostaing-mcp)

PyPI version Python versions License Downloads

A universal Model Content Protocol (MCP) for Pandas and Polars DataFrames, designed to be used as a powerful tool by Large Language Models (LLMs) like GPT-4, Claude, and Mistral.

This package allows LLMs to interact securely with data, performing advanced tasks ranging from simple filtering to statistical hypothesis testing and data visualization (returning viewable images).

Key Features

  • Library Agnostic: Seamlessly handles pandas and polars DataFrames.
  • Visual Intelligence: Generates Plotly charts returning Base64 PNG images, allowing LLMs to "see" and generate charts.
  • Statistical Suite: Built-in support for T-tests, ANOVA, Chi-Squared, Normality tests (Shapiro), and Survival Analysis (Logrank).
  • Smart NLU (Fuzzy Matching): Automatically corrects typos in column names (e.g., understands that "salary" refers to "Salary_USD").
  • Stateful Analysis: Filters and modifications persist within the agent's session context.

Installation

pip install rostaing-mcp

Note: This will also install necessary dependencies like plotly, kaleido (for image generation), pingouin, and scipy.

Quick Start

import pandas as pd
from rostaing_mcp import DataFrameAgent, DataFrameToolHandler

# 1. Create a sample DataFrame
data = {
    'employee_name': ['Rostaing', 'Lucrèce', 'Isnard', 'Charline', 'Dacier', 'Nora'],
    'salary': [100000, 70000, 85000, 60000, 95000, 62000],
    'experience_level': ['Expert', 'Senior', 'Manager', 'Junior', 'Principal', 'Mid-Level'],
    'department': ['AI', 'Sales', 'AI', 'Sales', 'AI', 'Sales']
}
df = pd.DataFrame(data)

# 2. Initialize the core agent (Works with Polars too!)
data_agent = DataFrameAgent(df, source_description="Employee salary data")

# 3. Wrap it in the tool handler
df_tool = DataFrameToolHandler(data_agent)

# --- EXAMPLES OF DIRECT USAGE ---

# A. Inspect Data
print(df_tool.get_schema())

# B. Statistical Test (e.g., T-test between groups)
# Note: Handles fuzzy matching if you type 'Department' instead of 'department'
print(df_tool.perform_t_test(a='salary', group='department')) 

# C. Visualization (Returns Base64 Image string)
# The LLM can call this to generate a chart
image_data = df_tool.plot_bar_chart(x='employee_name', y='salary', color='department')
print("Chart generated successfully (Base64 data ready).")

Integration with LLM Agents (e.g., Upsonic, LangChain)

To let an LLM use all available tools, you can pass the methods dynamically or wrap them in a proxy class.

from upsonic import Agent, Task

# Get the list of all callable tools for the LLM
tools_list = df_tool.get_all_tools() 

task = Task(
    description="Analyze the salary distribution and plot a bar chart by department.",
    tools=tools_list
)

agent = Agent(model="openai/gpt-4o", name="Data Analyst")
result = agent.do(task)
print(result)

Available Tools

📊 Visualization

  • plot_histogram, plot_bar_chart, plot_line_chart
  • plot_scatter_plot, plot_box_plot, plot_violin_plot
  • plot_heatmap, plot_pie_chart, plot_3d_scatter, and more.

🧮 Statistics

  • get_summary_statistics, get_correlation_matrix
  • perform_normality_test (Shapiro-Wilk)
  • perform_t_test (Student's t-test)
  • perform_anova (One-way ANOVA)
  • perform_chi2_test (Independence)
  • perform_logrank_test (Survival analysis)

🛠 Manipulation

  • filter_rows (Complex conditions supported)
  • sort_values
  • select_columns

Useful Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rostaing_mcp-0.1.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rostaing_mcp-0.1.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file rostaing_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: rostaing_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for rostaing_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cbad9a596607501d755323a7db9dcc84591b3b083f8d80c26a3aa131abc37cf2
MD5 8d788382cea582b8190e7f9688a9edb5
BLAKE2b-256 2958447a0c124ed2489d1ff549ea45dbc6824e22d272fbf7e8e474962672dc80

See more details on using hashes here.

File details

Details for the file rostaing_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rostaing_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for rostaing_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5920ab4e5409b503b1dbb11ed334494d90817ab30691999c4d646df0793e8b12
MD5 1f49f3a6179cc9dcf9358ec98a1e48bd
BLAKE2b-256 cf6f12d28bedfc594aee65ae6ece00926ee64af4b881b69fe56e830b6bcf80cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page