Quick-Data MCP Server

repository·main·Indexed 41 days ago

https://github.com/disler/quick-data-mcp

An MCP (Model Context Protocol) server that provides AI agents with data analysis capabilities for .json and .csv files. It includes tools for dataset loading, statistical segmentation, correlation analysis, time series analysis, and data quality validation. The server supports data visualization via create_chart, custom Python execution with pandas and numpy, and provides dynamic resources and adaptive prompts for guided analytics workflows.

Tokens
24.3K
Snippets
66
Records
94
Agent score
100%

What's inside Quick-Data

  1. Understand automatic schema discovery

    main

    The system uses DatasetSchema and ColumnInfo to automatically categorize data types and suggest analyses. This allows the AI to understand the structure and potential utility of a dataset without manual configuration.

    Column Roles

    Columns are assigned a suggested_role based on their characteristics:

    • numerical: Numeric data types.
    • temporal: Datetime/date types.
    • categorical: Low-cardinality data (where unique values < 50% of total rows).
    • identifier: High-cardinality data where every value is unique.

    Analysis Suggestions

    Based on the discovered roles, the system suggests specific analysis types:

    • Correlation Analysis: Suggested if there are $\ge 2$ numerical columns.
    • Segmentation Analysis: Suggested if categorical columns are present.
    • Time Series Analysis: Suggested if temporal columns are present.
  2. How MCP components (Tools, Resources, and Prompts) work together

    main

    The Model Context Protocol (MCP) server architecture relies on three primary building blocks to extend AI capabilities. Understanding when to use each is key to building effective agentic workflows:

    • Tools: Use these when you want the AI to DO something. Tools are functions that the AI can call to perform atomic actions (e.g., creating a task, writing a file).
    • Resources: Use these when you want the AI to READ information. Resources provide data access to the AI, such as user profiles, configuration files, or status updates.
    • Prompts: Use these to create Reusable Agentic Workflows (ADWs). Prompts are pre-built conversation templates that provide structured starting points for repeatable, domain-specific workflows (e.g., a structured code review template).

    By combining these—using a Prompt to initiate a workflow, Tools to execute actions within that workflow, and Resources to provide context—you can build powerful, scalable agentic systems.

  3. Core Design Principles of the Generic Data Analytics MCP Server

    main

    The Generic Data Analytics MCP Server is designed to be dataset-agnostic, meaning it does not rely on hardcoded schemas. It follows four core principles:

    1. Dataset Agnostic: Works with any structured data (JSON/CSV) by automatically discovering column types, relationships, and constraints.
    2. Schema Discovery: Performs dynamic column detection and type inference (categorical vs. numerical vs. temporal) to suggest appropriate analyses.
    3. Adaptive Analytics: Automatically selects analysis techniques based on data characteristics, such as using segmentation for categorical columns, correlation for numerical data, or time series analysis for temporal columns.
    4. Conversational Guidance: Provides AI prompts that offer context-aware suggestions and interactive tutorials for complex operations.
  4. Understand the architecture benefits of the Generic Data Analytics MCP Server

    main

    The Quick-Data MCP server is designed as a universal data analysis platform rather than a tool for a specific dataset. Its architecture provides several key benefits:

    • True Reusability: The server is dataset agnostic. It works with any structured data (customer data, sales, surveys, inventory, etc.) without hardcoding dataset-specific assumptions.
    • Modular Excellence: It uses a data layer abstraction where Pandas operations are applied identically across any structured data. Analysis tools (correlation, segmentation) and visualization tools adapt automatically to the columns and data types provided.
    • AI-Guided Discovery: The server enables interactive exploration. The AI can suggest analyses based on actual data characteristics and use context-aware prompts that reference real column names and patterns.
    • Scalability: The system is designed to scale from small CSV files (e.g., 100 rows) to larger enterprise datasets (e.g., 100K rows).
  5. How MCP primitives (Tools, Resources, and Prompts) work

    main

    The Model Context Protocol (MCP) provides three primary primitives for interacting with LLMs via a server:

    1. Tools: Functions that an LLM can actively call to perform actions (e.g., math, fetching weather, or running tasks). Use the @mcp.tool() decorator.
    2. Resources: Data that an LLM can read to gain context (e.g., configuration files, user profiles, or database schemas). Use the @mcp.resource(uri) decorator. Resources can use URI templates like users://{user_id}/profile.
    3. Prompts: Reusable conversation templates that provide structured instructions or context to the LLM. Use the @mcp.prompt() decorator.

    Use FastMCP to manage these primitives easily.

    from mcp.server.fastmcp import FastMCP
    
    mcp = FastMCP("Demo Server")
    
    @mcp.tool()
    def add(a: int, b: int) -> int:
        return a + b
    
    @mcp.resource("config://app-settings")
    def get_config() -> dict:
        return {"version": "1.0.0"}
    
    @mcp.prompt()
    def review_code(code: str) -> str:
        return f"Review this: {code}"
  6. Performance and dataset size considerations

    main

    When designing custom analytics tasks, keep the following constraints in mind to ensure efficient execution:

    Constraints

    • Timeout: A hard 30 second timeout is enforced to prevent infinite loops.
    • Memory: Subprocess memory is typically limited to 512MB.
    • Overhead: Subprocess isolation adds approximately 100ms of overhead per call.
    • Serialization: Datasets are transferred via JSON, which is efficient for datasets <10MB.

    Dataset Size Guidelines

    • Small (<1MB): Optimal; execution typically takes <1 second.
    • Medium (1-10MB): Good performance; execution typically takes 1-3 seconds.
    • Large (>10MB): Performance may degrade. It is highly recommended to sample the dataset first using existing tools before running complex custom code.
  7. How the Dual Access Pattern works for Tool-Only MCP Clients

    main

    To ensure compatibility with MCP clients that do not support the Resource protocol, the server implements a Dual Access Pattern. This pattern provides two ways to access the same data:

    1. Resource-Enabled Clients: Use standard MCP resources via URIs (e.g., @mcp.resource()).
    2. Tool-Only Clients: Use a parallel set of tools prefixed with resource_* (e.g., @mcp.tool()).

    This ensures that even if a client cannot read dynamic resources like datasets://loaded, it can still call the tool resource_datasets_loaded() to retrieve the exact same information.

    Resource-Enabled Clients:           Tool-Only Clients:
    ├── @mcp.resource()                ├── @mcp.tool() 
    ├── datasets://loaded              ├── resource_datasets_loaded()
    ├── analytics://memory_usage        ├── resource_analytics_memory_usage()
    └── datasets://{name}/schema       └── resource_datasets_schema(name)
  8. Manage MCP server lifecycle with async context managers

    main

    Use the lifespan parameter in FastMCP to manage application startup and shutdown logic. By passing an @asynccontextmanager function, you can initialize resources like database connections or caches before the server starts and ensure they are gracefully closed when the server shuts down.

    from contextlib import asynccontextmanager
    from typing import AsyncIterator
    
    @asynccontextmanager
    async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
        """Manage application lifecycle with startup/shutdown logic."""
        # Startup
        print("Starting MCP server...")
        db_connection = await create_db_connection()
        cache = {}
        
        context = AppContext(db_connection=db_connection, cache=cache)
        
        try:
            yield context
        finally:
            # Cleanup
            print("Shutting down MCP server...")
            await db_connection.close()
    
    mcp = FastMCP("Demo Server", lifespan=app_lifespan)
  9. Security and Isolation model for custom code execution

    main

    To ensure safety when executing arbitrary Python code, the execute_custom_analytics_code tool employs several isolation layers:

    • Process Isolation: Code is executed in a separate Python subprocess using uv run.
    • Resource Limits: A hard 30-second timeout is enforced to prevent infinite loops or resource exhaustion.
    • File System Sandbox: The subprocess has no access to the host file system.
    • Data Handling: Datasets are passed to the subprocess as serialized JSON data, meaning the subprocess has read-only access to a copy of the data, not a direct reference to the live memory of the MCP server.
    • Library Restriction: Only a specific set of safe libraries (pandas, numpy, plotly) are pre-installed and available for use.
  10. Explore extension pathways for the MCP server

    main

    The generic architecture allows for several advanced extension paths to increase the server's capabilities:

    Advanced Analytics Integration

    • ML Pipeline: Implement automatic feature engineering and model suggestions based on the loaded data.
    • Statistical Testing: Add support for A/B testing, significance testing, and hypothesis validation.
    • Forecasting: Implement time series forecasting that triggers when temporal patterns are detected in the data.

    Enterprise Features

    • Multi-Dataset Workflows: Enable intelligent joining and comparison of multiple datasets.
    • Automated Reporting: Generate business reports containing insights and recommendations.
    • Real-Time Updates: Support streaming new data to update analyses automatically.

    Collaboration Tools

    • Insight Sharing: Export findings in business-friendly formats.
    • Analysis Templates: Allow users to save and reuse specific analysis workflows across different datasets.
    • Team Dashboards: Implement collaborative analytics with role-based access control.
  11. Declare inline dependencies using PEP 723 metadata

    main

    You can declare a script's dependencies directly within the file using PEP 723 script metadata. This allows uv to automatically set up the correct environment whenever the script is run.

    Use the /// script block at the top of your file to define requires-python and dependencies.

    #!/usr/bin/env python3
    # /// script
    # requires-python = ">=3.10"
    # dependencies = [
    #     "mcp[cli]>=1.9.2",
    #     "pydantic>=2.0.0",
    #     "httpx>=0.25.0"
    # ]
    # ///
    
    """MCP Server with inline dependencies."""
    
    from mcp.server import FastMCP
    # Rest of server implementation...
  12. Run Python scripts with `uv run python`

    main

    Use uv run python to execute Python scripts with automatic environment management. This approach eliminates the need for manual virtual environment activation and ensures dependency isolation.

    Execution Options

    • Basic execution: uv run python script.py
    • Add dependencies on-the-fly: Use the --with flag to inject packages without modifying project files: uv run --with <package> python script.py
    • Specify Python version: uv run --python 3.12 python script.py
    • Use alternative package indexes: uv run --index-url <url> python script.py
    • Verbose mode: uv run --verbose python main.py
    # Basic script execution
    uv run python script.py
    
    # Add dependencies on-the-fly
    uv run --with mcp[cli] python script.py
    
    # Specify Python version
    uv run --python 3.12 python script.py