Skip to main content

PyPSA MCP: PyPSA Energy Modeling for LLMs

Project description

PyPSA MCP

PyPSA MCP is a Model Context Protocol (MCP) server for creating, analyzing, and optimizing energy system models using PyPSA (Python for Power System Analysis).

A Model Context Protocol (MCP) server that enables Large Language Models (LLMs) like Claude to interact with PyPSA for energy model creation and analysis via natural language.

Demo Example

Below is a demo video showing how to use PyPSA MCP with Claude. The video demonstrates creating a simple two-bus model, running power flow calculations, and performing optimization.

https://github.com/user-attachments/assets/5633a431-7c3b-4a2f-9a9e-395dcbbb2e29

Demo Prompt

You can try this exact prompt with Claude to reproduce the example shown in the video:

I'd like to build an energy system model and perform optimization using PyPSA. Please help me with these steps: 
1. Create a simple two-bus model with: 
   1. Two buses at (0,0) and (100,0) with 220 kV nominal voltage 
   2. A generator at bus1 with 100 MW capacity and 50 €/MWh cost 
   3. A load at bus2 with 80 MW demand
   4. 24 hourly snapshots for January 1, 2025
2. Run a power flow calculation to verify the model 
3. Perform optimization with the highs solver using the kirchhoff formulation 
4. Discuss the results

Overview

PyPSA MCP provides a bridge between Large Language Models and PyPSA, allowing you to:

  1. Create and manage energy system models through natural language
  2. Add network components like buses, generators, and transmission lines
  3. Set up time series data for simulation
  4. Run power flow and optimization calculations
  5. Analyze results

Features

  • Model Management

    • Create new PyPSA energy models
    • List and select from available models
    • Export detailed model summaries
    • Delete models when no longer needed
  • Component Creation

    • Add buses, generators, loads, and other network components
    • Configure component parameters through natural language
    • Modify existing components
    • Organize components into meaningful groups
  • Data and Simulation

    • Set time snapshots for simulation periods
    • Add time series data for loads and generators
    • Run power flow calculations
    • Perform optimization with various solvers and formulations
  • Results Analysis

    • Extract key metrics from simulation results
    • Generate summaries of model performance
    • Export data for further analysis

Installation

Prerequisites

  • Python 3.10 or higher
  • uv (recommended for easy dependency management)

Main Installation (PyPI)

# Install from PyPI
pip install pypsamcp

# Or using uv (recommended)
uv pip install pypsamcp

Running PyPSA MCP

# Run using the installed package
pypsamcp

Configuring in Claude Desktop

  1. Locate Claude Desktop's configuration file (typically in ~/.config/Claude/config.json)

  2. Add PyPSA MCP to the mcpServers section:

    "mcpServers": {
      "PyPSA MCP":{
        "command": "uv",
        "args": [
          "run",
          "--with",
          "pypsamcp",
          "pypsamcp"
        ]
      }
    }
    
  3. Save the configuration file and restart Claude Desktop

Development Installation (from GitHub)

For contributors or users who want to modify the code:

# Clone the repository
git clone https://github.com/cdgaete/pypsa-mcp.git
cd pypsa-mcp

# Install development dependencies with uv
uv pip install -e ".[dev]"

Running in Development Mode

# Run the server directly
python -m pypsamcp.server

Available Tools

The server provides the following MCP tools:

Model Management

create_energy_model(
    id: str,
    name: str = None,
    description: str = None
)
list_models()
delete_model(
    id: str
)
export_model_summary(
    id: str,
    include_components: bool = True,
    include_parameters: bool = True
)

Component Creation

add_bus(
    model_id: str,
    name: str,
    v_nom: float,
    x: float = 0.0,
    y: float = 0.0,
    carrier: str = "AC"
)
add_generator(
    model_id: str,
    name: str,
    bus: str,
    p_nom: float,
    marginal_cost: float = 0.0,
    carrier: str = "generator"
)
add_load(
    model_id: str,
    name: str,
    bus: str,
    p_set: float
)
add_line(
    model_id: str,
    name: str,
    bus0: str,
    bus1: str,
    x: float,
    r: float = 0.0,
    g: float = 0.0,
    b: float = 0.0,
    s_nom: float = 0.0
)
add_storage(
    model_id: str,
    name: str,
    bus: str,
    p_nom: float,
    max_hours: float,
    efficiency_store: float = 1.0,
    efficiency_dispatch: float = 1.0,
    standing_loss: float = 0.0
)

Data and Simulation

set_snapshots(
    model_id: str,
    start_time: str,
    end_time: str,
    freq: str = "H"
)
run_powerflow(
    model_id: str,
    snapshot: str = None
)
run_optimization(
    model_id: str,
    solver_name: str = "glpk",
    formulation: str = "kirchhoff"
)

Example Prompts

Here are some examples of how to use PyPSA MCP with Claude:

Create a new energy system model with three buses, two generators, and a load.
Add a wind generator with 100 MW capacity to bus "bus1" with a marginal cost of 10.
Run a power flow calculation on the current model and show me the results.
Optimize the model using the GLPK solver and summarize the key findings.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built on PyPSA for power system modeling
  • Uses FastMCP for the Model Context Protocol implementation
  • Inspired by the need to make energy system modeling more accessible through natural language interfaces

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

pypsamcp-0.1.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

pypsamcp-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file pypsamcp-0.1.3.tar.gz.

File metadata

  • Download URL: pypsamcp-0.1.3.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pypsamcp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5029e5ad8d32204b318d18d5ff3eec8be51c7e66c9088ae236dbb5d761290adb
MD5 de9b2a3b3fad3353ab1b392654d58d4e
BLAKE2b-256 5207a525187ae91fb6922645dcc75405d104644b6e22639d0236db9771b627c6

See more details on using hashes here.

File details

Details for the file pypsamcp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pypsamcp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pypsamcp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f907d17cd4ac58d69a7b83067141fa7ad274f9d191ff16d87d2b96d434c7d912
MD5 1224a47f5664fb8a55ae9aa2004b8431
BLAKE2b-256 e75459811b4fa51791cb7ccffc798210952bf7b1185384548bacd8632fb72f12

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