Skip to main content

MCP server providing Polars API reference and usage guides for efficient Polars query development

Project description

Polars MCP Server

MCP server providing Polars API reference documentation via introspection of the installed Polars package and additional information via conceptual guides.

Features

  • Polars API searchable by keyword
  • Full documentation for any Polars function, method, or class
  • Conceptual guides for Polars usage patterns
  • pandas to Polars translation guide
  • Always up-to-date with your installed Polars version
  • No external dependencies or pre-built docs needed

Installation

Important: This server introspects the installed Polars package. Install the same Polars version you use in your project to ensure accurate documentation.

From PyPI

# Or install with latest Polars
uv pip install polars-mcp polars

# Install with your project's Polars version
uv pip install polars-mcp polars==1.35.0

From source

# Clone repository
git clone https://github.com/r-brink/polars-mcp
cd polars-mcp

# Install with uv
uv pip install .

Usage

Add to your MCP settings configuration file.

With uvx

{
    "mcpServers": {
        "polars-mcp": {
            "command": "uvx",
            "args": [
                "--with",
                "polars", # set your Polars version here
                "polars-mcp"
            ]
        }
    }
}

When installing from source

{
    "mcpServers": {
        "polars-mcp": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/polars-mcp",
                "run",
                "polars_mcp.py"
            ]
        }
    }
}

Refer to the documentation on the Model Context Protocol website on how to connect to local MCP servers for an extensive guide.

Standalone Testing

# Test the server
python polars_mcp.py --help

# Run with MCP inspector
npx @modelcontextprotocol/inspector uv run polars_mcp.py

Available Tools

polars_get_guide

Get conceptual guides about Polars usage patterns.

Parameters:

  • guide (str): Which guide to retrieve
    • 'contexts' - Expression contexts (select, filter, group_by, with_columns, over)
    • 'expressions' - Expression system and composition patterns
    • 'lazy-api' - Lazy evaluation and query optimization
    • 'pandas-to-polars' - Complete pandas to Polars translation guide

Example:

Guide: "pandas-to-polars"
Returns: Complete guide with side-by-side pandas/Polars comparisons

polars_search_api

Search for Polars API elements by keyword.

Parameters:

  • query (str): Search term (e.g., "groupby", "filter", "lazy")
  • limit (int, optional): Max results (default: 20)
  • response_format (str, optional): "markdown" or "json" (default: "markdown")

Example:

Query: "group by"
Returns: List of all group by-related functions and methods

polars_get_docstring

Get complete documentation for a specific API element.

Parameters:

  • name (str): Full name (e.g., "DataFrame.filter", "col", "LazyFrame")
  • response_format (str, optional): "markdown" or "json" (default: "markdown")

Example:

Name: "DataFrame.filter"
Returns: Full documentation with signature and examples

Available Guides

polars://guides/contexts

Guide to Polars expression contexts:

  • What contexts are (select, filter, group_by, with_columns)
  • When to use each context
  • How contexts affect expression evaluation
  • Common patterns for each context

polars://guides/expressions

Complete guide to the Polars expression system:

  • What expressions are and how they work
  • Composition patterns (chaining, operators, nesting)
  • Expression expansion
  • Common patterns (aggregations, window functions, conditionals)

polars://guides/lazy-api

Guide to lazy evaluation:

  • Eager (DataFrame) vs Lazy (LazyFrame)
  • Query optimization (predicate pushdown, projection pushdown)
  • When to use each approach
  • Best practices for large datasets

polars://guides/pandas-to-polars

  • Side-by-side syntax comparisons for all common operations
  • Reading data, column selection, filtering, sorting
  • Group by aggregations and window functions
  • Joins (including semi/anti joins)
  • String, datetime, and missing value operations
  • Complete worked examples
  • Anti-patterns to avoid
  • Performance optimization checklist

This guide is specifically optimized for LLMs to quickly translate pandas code to efficient Polars queries.

Why This Server?

  • Always current: Documentation reflects your installed Polars version
  • Lightweight: No large pre-built documentation databases
  • Comprehensive: Combines API reference with conceptual guides
  • Migration-friendly: Includes complete pandas translation guide
  • Fast: Uses introspection for instant access to documentation

Project Structure

polars-mcp/
├── polars_mcp.py              # Main server
├── pyproject.toml             # Dependencies
├── guides/                    # Conceptual
│   ├── lazy-api.md           # Lazy API guide
│   ├── expressions.md        # Expression patterns
│   ├── contexts.md           # Context behaviors
│   └── pandas-to-polars.md   # pandas to Polars
└── README.md

Contributing

Contributions welcome! Please submit issues or pull requests.

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

polars_mcp-0.2.1.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

polars_mcp-0.2.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file polars_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: polars_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polars_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5012a0d2ff73e1d9a8197d84bdee8dc4d23fe48c0ddd6a1c64448913d264da60
MD5 855d1de372b062df09f09d6c94374528
BLAKE2b-256 15c8ba962099443a76b67df6fc7932aa193bb84eebc89261cf0c8b0b9523e559

See more details on using hashes here.

File details

Details for the file polars_mcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: polars_mcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polars_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dbb5cbe2e24c49352b72c01eaeb146a7a33aa57c5c72e119f957f9efa3bd840
MD5 35ae1dfa80419c53b339d0e9b9aefe5b
BLAKE2b-256 aaa13a52578b09c220c62e6ec54474c43ae845b6995c9daf16d8c42c44aea168

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