JavadBayazi commited on
Commit
1be7499
·
1 Parent(s): 94a770b

MCP-enabled Gradio Space using PowerMCP as external dependency

Browse files
Files changed (4) hide show
  1. .gitignore +62 -0
  2. README.md +234 -6
  3. app.py +320 -0
  4. requirements.txt +19 -0
.gitignore ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ venv/
9
+ ENV/
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # IDEs
27
+ .vscode/
28
+ .idea/
29
+ *.swp
30
+ *.swo
31
+ *~
32
+
33
+ # OS
34
+ .DS_Store
35
+ Thumbs.db
36
+
37
+ # Gradio
38
+ flagged/
39
+ gradio_cached_examples/
40
+
41
+ # Logs
42
+ *.log
43
+ logs/
44
+
45
+ # Environment
46
+ .env
47
+ .env.local
48
+
49
+ # Developer documentation (not needed for MCP users)
50
+ DEPLOYMENT.md
51
+ DEPLOYMENT_CHECKLIST.md
52
+ EXAMPLES.md
53
+ IMPLEMENTATION_SUMMARY.md
54
+ QUICKSTART.md
55
+ test_setup.py
56
+ .env.example
57
+ PowerMCP_Tutorial.pdf
58
+
59
+ # Keep README.md as it's required for Hugging Face Space
60
+ INSTALL.md
61
+ MANIFEST.in
62
+ setup.py
README.md CHANGED
@@ -1,12 +1,240 @@
1
  ---
2
- title: PandaPower MCP
3
- emoji: 📈
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.1.0
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: PowerMCP - Power System Analysis MCP Server
3
+ emoji:
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 5.0.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
+ tags:
12
+ - mcp
13
+ - power-systems
14
+ - electrical-engineering
15
+ - simulation
16
+ - model-context-protocol
17
  ---
18
 
19
+ # PowerMCP - Power System Analysis MCP Server
20
+
21
+ [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-blue)](https://modelcontextprotocol.io/)
22
+ [![Gradio](https://img.shields.io/badge/Gradio-5.0+-orange)](https://gradio.app/)
23
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
24
+
25
+ This is an **MCP-enabled Hugging Face Space** for **PowerMCP** - an open-source collection of Model Context Protocol (MCP) servers for power system software. This Space can be added as an MCP tool to Claude Desktop, Cursor, or any other MCP-compatible client with a single click!
26
+
27
+ ## 🌟 What is PowerMCP?
28
+
29
+ PowerMCP enables Large Language Models (LLMs) to directly interact with power system applications through the Model Context Protocol. It bridges the gap between AI and power system analysis, facilitating:
30
+
31
+ - **Intelligent Power Flow Analysis**: Let AI perform complex power system simulations
32
+ - **Automated Contingency Analysis**: AI-driven evaluation of grid contingencies
33
+ - **Dynamic Simulation**: Transient stability and time-domain analysis
34
+ - **Energy System Optimization**: Network expansion and optimal power flow
35
+ - **Professional Report Generation**: AI-generated analysis reports
36
+
37
+ ## 🔧 Supported Power System Tools
38
+
39
+ ### 🔌 pandapower
40
+ Python-based power system analysis focusing on power flow and contingency analysis.
41
+ - Create and manage power networks
42
+ - AC/DC power flow calculations
43
+ - N-1 and N-2 contingency analysis
44
+ - Network modification and optimization
45
+
46
+ ### ⚡ PyPSA (Python for Power System Analysis)
47
+ Energy system optimization and network expansion planning.
48
+ - Multi-period optimization
49
+ - Unit commitment and economic dispatch
50
+ - Network expansion planning
51
+ - Renewable integration analysis
52
+
53
+ ### 🌊 ANDES
54
+ Dynamic simulation and transient stability analysis.
55
+ - Time-domain simulation
56
+ - Transient stability analysis
57
+ - Small-signal stability
58
+ - Dynamic model library
59
+
60
+ ## 🚀 Quick Start
61
+
62
+ ### Option 1: Install from GitHub (Local MCP Server)
63
+
64
+ ```bash
65
+ # Install PowerMCP
66
+ pip install git+https://github.com/Power-Agent/PowerMCP.git
67
+
68
+ # Configure Claude Desktop (macOS)
69
+ # Edit: ~/Library/Application Support/Claude/claude_desktop_config.json
70
+ {
71
+ "mcpServers": {
72
+ "pandapower": {
73
+ "command": "powermcp-pandapower"
74
+ }
75
+ }
76
+ }
77
+
78
+ # Restart Claude Desktop and start using PowerMCP!
79
+ ```
80
+
81
+ See [INSTALL.md](INSTALL.md) for detailed installation instructions.
82
+
83
+ ### Option 2: Use Hugging Face Space as MCP Tool
84
+
85
+ 1. **Install an MCP Client**:
86
+ - [Claude Desktop](https://claude.ai/download)
87
+ - [Cursor](https://cursor.sh/)
88
+ - [Windsurf](https://codeium.com/windsurf)
89
+ - VS Code with Cline extension
90
+
91
+ 2. **Add PowerMCP to Your Client**:
92
+ - Click the **MCP badge** on this Space
93
+ - Select "Add to MCP tools"
94
+ - Confirm when prompted
95
+ - The tools will be available instantly in your MCP client!
96
+
97
+ 3. **Use PowerMCP in Your AI Assistant**:
98
+ ```
99
+ Ask Claude: "Create a power network and run power flow analysis"
100
+ Ask Cursor: "Load test_case.json and perform N-1 contingency analysis"
101
+ ```
102
+
103
+ ### Option 2: Use Web Interface
104
+
105
+ 1. Select a power system tool (pandapower, PyPSA, or ANDES)
106
+ 2. Click "List Available Tools" to see all functions
107
+ 3. Enter the tool name and arguments in JSON format
108
+ 4. Click "Execute Tool" to run
109
+ 5. View results in JSON format
110
+
111
+ ## 📖 Example Usage
112
+
113
+ ### In MCP Clients (Claude Desktop, Cursor, etc.)
114
+
115
+ ```python
116
+ # Create and analyze a power network
117
+ create_empty_network(server="pandapower")
118
+ load_network(file_path="test_case.json", server="pandapower")
119
+ run_power_flow(server="pandapower", algorithm="nr")
120
+ get_network_info(server="pandapower")
121
+
122
+ # Run contingency analysis
123
+ run_contingency_analysis(
124
+ server="pandapower",
125
+ contingency_type="N-1",
126
+ elements=["line", "trafo"]
127
+ )
128
+
129
+ # PyPSA optimization
130
+ create_network(name="my_network", server="pypsa")
131
+ add_bus(network_name="my_network", bus_id="bus1", v_nom=380.0, server="pypsa")
132
+ run_optimization(network_name="my_network", server="pypsa")
133
+
134
+ # ANDES dynamic simulation
135
+ run_power_flow(file_path="kundur_full.json", server="andes")
136
+ run_time_domain_simulation(
137
+ file_path="kundur_full.json",
138
+ end_time=10.0,
139
+ step_size=0.01,
140
+ server="andes"
141
+ )
142
+ ```
143
+
144
+ ### In Web Interface
145
+
146
+ #### Create an Empty Network
147
+ ```json
148
+ Tool Name: create_empty_network
149
+ Arguments: {}
150
+ ```
151
+
152
+ #### Load a Network
153
+ ```json
154
+ Tool Name: load_network
155
+ Arguments: {"file_path": "PowerMCP/pandapower/test_case.json"}
156
+ ```
157
+
158
+ #### Run Power Flow
159
+ ```json
160
+ Tool Name: run_power_flow
161
+ Arguments: {"algorithm": "nr"}
162
+ ```
163
+
164
+ ## 🎯 Available Tools by Server
165
+
166
+ ### pandapower Tools
167
+ - `create_empty_network()` - Create new empty network
168
+ - `load_network(file_path)` - Load from JSON/pickle
169
+ - `run_power_flow(algorithm, ...)` - Power flow analysis
170
+ - `run_contingency_analysis(contingency_type, elements)` - N-1/N-2 analysis
171
+ - `get_network_info()` - Network statistics
172
+
173
+ ### PyPSA Tools
174
+ - `create_network(name, snapshots, crs)` - Create PyPSA network
175
+ - `add_bus(network_name, bus_id, v_nom, x, y, carrier)` - Add bus
176
+ - `add_generator(network_name, generator_id, bus, p_nom, ...)` - Add generator
177
+ - `run_optimization(network_name)` - Optimal power flow
178
+ - `get_network_info(network_name)` - Network information
179
+
180
+ ### ANDES Tools
181
+ - `run_power_flow(file_path)` - Power flow with ANDES
182
+ - `run_time_domain_simulation(file_path, end_time, step_size)` - Dynamic simulation
183
+ - `get_bus_results()` - Bus voltage/angle results
184
+
185
+ ## 💻 Development
186
+
187
+ ### Deploy Your Own Space
188
+
189
+ 1. Fork this repository
190
+ 2. Create a new Space on [Hugging Face](https://huggingface.co/new-space)
191
+ 3. Choose Gradio SDK and link your repository
192
+ 4. The Space will automatically get the MCP badge!
193
+
194
+ ### Running Locally
195
+
196
+ ```bash
197
+ git clone https://github.com/Power-Agent/PowerMCP.git
198
+ cd PowerMCP
199
+ pip install -r requirements.txt
200
+ python app.py
201
+ ```
202
+
203
+ ### Local MCP Configuration
204
+
205
+ For Claude Desktop (`~/Library/Application Support/Claude/claude_desktop_config.json`):
206
+
207
+ ```json
208
+ {
209
+ "mcpServers": {
210
+ "pandapower": {
211
+ "command": "/usr/local/bin/python3",
212
+ "args": ["/path/to/PowerMCP/PowerMCP/pandapower/panda_mcp.py"]
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## 🔗 Resources
219
+
220
+ - **GitHub**: [Power-Agent/PowerMCP](https://github.com/Power-Agent/PowerMCP)
221
+ - **MCP Docs**: [modelcontextprotocol.io](https://modelcontextprotocol.io/)
222
+ - **Tutorial**: [PowerMCP Tutorial](https://github.com/Power-Agent/PowerMCP/blob/main/PowerMCP_Tutorial.pdf)
223
+ - **Gradio MCP Guide**: [Building MCP Servers](https://www.gradio.app/guides/building-mcp-server-with-gradio)
224
+
225
+ ## 🎥 Video Demos
226
+
227
+ - [Contingency Evaluation](https://www.youtube.com/watch?v=MbF-SlBI4Ws)
228
+ - [Load Growth Evaluation](https://www.youtube.com/watch?v=euFUvhhV5dM)
229
+
230
+ ## 📄 License
231
+
232
+ MIT License - See [LICENSE](LICENSE) file for details
233
+
234
+ ## 🤝 Contributing
235
+
236
+ Contributions welcome! PowerMCP is community-driven. Help us accelerate AI adoption in power systems.
237
+
238
+ ---
239
+
240
+ Built with ❤️ by the PowerMCP Community
app.py ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ PowerMCP Hugging Face Space - MCP Server Interface
3
+ This application provides a Gradio interface for interacting with PowerMCP servers.
4
+ """
5
+
6
+ import gradio as gr
7
+ import json
8
+ from typing import Dict, Any, List, Optional
9
+ import importlib
10
+ import traceback
11
+
12
+ class PowerMCPInterface:
13
+ """Interface for interacting with PowerMCP servers"""
14
+
15
+ def __init__(self):
16
+ self.servers = {}
17
+ self.current_states = {} # Store network states per server
18
+ self._initialize_servers()
19
+
20
+ def _initialize_servers(self):
21
+ """Initialize all available MCP servers"""
22
+ # Try to import each server from installed PowerMCP package
23
+ servers_config = {
24
+ "pandapower": "PowerMCP.pandapower.panda_mcp",
25
+ "pypsa": "PowerMCP.PyPSA.pypsa_mcp",
26
+ "andes": "PowerMCP.ANDES.andes_mcp",
27
+ }
28
+
29
+ for server_name, module_path in servers_config.items():
30
+ try:
31
+ module = importlib.import_module(module_path)
32
+ if hasattr(module, 'mcp'):
33
+ self.servers[server_name] = module.mcp
34
+ print(f"✓ Loaded {server_name} server")
35
+ except Exception as e:
36
+ print(f"✗ Could not load {server_name}: {str(e)}")
37
+
38
+ def get_available_servers(self) -> List[str]:
39
+ """Get list of available servers"""
40
+ return list(self.servers.keys())
41
+
42
+ def get_tools_for_server(self, server_name: str) -> List[Dict[str, str]]:
43
+ """Get list of available tools for a specific server"""
44
+ if server_name not in self.servers:
45
+ return []
46
+
47
+ server = self.servers[server_name]
48
+ tools = []
49
+
50
+ # FastMCP stores tools in list_tools()
51
+ if hasattr(server, 'list_tools'):
52
+ try:
53
+ tool_list = server.list_tools()
54
+ for tool in tool_list:
55
+ tools.append({
56
+ "name": tool.name if hasattr(tool, 'name') else str(tool),
57
+ "description": tool.description if hasattr(tool, 'description') else "No description"
58
+ })
59
+ except Exception as e:
60
+ print(f"Error listing tools: {e}")
61
+
62
+ return tools
63
+
64
+ def call_tool(self, server_name: str, tool_name: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
65
+ """Call a tool on the MCP server"""
66
+ try:
67
+ if server_name not in self.servers:
68
+ return {"error": f"Server '{server_name}' not found"}
69
+
70
+ server = self.servers[server_name]
71
+
72
+ # Get the tool function
73
+ tool_func = None
74
+ if hasattr(server, '_mcp_tools'):
75
+ tool_func = server._mcp_tools.get(tool_name)
76
+
77
+ if tool_func is None:
78
+ return {"error": f"Tool '{tool_name}' not found"}
79
+
80
+ # Execute the tool
81
+ result = tool_func(**arguments)
82
+ return result if isinstance(result, dict) else {"result": str(result)}
83
+
84
+ except Exception as e:
85
+ return {
86
+ "error": str(e),
87
+ "traceback": traceback.format_exc()
88
+ }
89
+
90
+ # Initialize the interface
91
+ interface = PowerMCPInterface()
92
+
93
+ # ============= MCP Tool Functions (for Gradio MCP server mode) =============
94
+
95
+ def create_empty_network(server: str = "pandapower") -> Dict[str, Any]:
96
+ """Create an empty power network.
97
+
98
+ Args:
99
+ server: The power system tool to use (pandapower, pypsa, andes)
100
+
101
+ Returns:
102
+ Dictionary with status and network information
103
+ """
104
+ return interface.call_tool(server, "create_empty_network", {})
105
+
106
+ def load_network(file_path: str, server: str = "pandapower") -> Dict[str, Any]:
107
+ """Load a power network from a file.
108
+
109
+ Args:
110
+ file_path: Path to the network file
111
+ server: The power system tool to use
112
+
113
+ Returns:
114
+ Dictionary with status and network information
115
+ """
116
+ return interface.call_tool(server, "load_network", {"file_path": file_path})
117
+
118
+ def run_power_flow(server: str = "pandapower", algorithm: str = "nr") -> Dict[str, Any]:
119
+ """Run power flow analysis on the loaded network.
120
+
121
+ Args:
122
+ server: The power system tool to use
123
+ algorithm: Power flow algorithm to use
124
+
125
+ Returns:
126
+ Dictionary with power flow results
127
+ """
128
+ return interface.call_tool(server, "run_power_flow", {"algorithm": algorithm})
129
+
130
+ def get_network_info(server: str = "pandapower") -> Dict[str, Any]:
131
+ """Get information about the current network.
132
+
133
+ Args:
134
+ server: The power system tool to use
135
+
136
+ Returns:
137
+ Dictionary with network statistics
138
+ """
139
+ return interface.call_tool(server, "get_network_info", {})
140
+
141
+ # ============= UI Helper Functions =============
142
+
143
+ def format_tools_list(server_name: str) -> str:
144
+ """Format the list of available tools"""
145
+ tools = interface.get_tools_for_server(server_name)
146
+ if not tools:
147
+ return "No tools available for this server"
148
+
149
+ output = f"## Available Tools for {server_name}\n\n"
150
+ for tool in tools:
151
+ output += f"### {tool['name']}\n{tool['description']}\n\n"
152
+
153
+ return output
154
+
155
+ def execute_tool_call(server_name: str, tool_name: str, arguments_json: str) -> str:
156
+ """Execute a tool call and return the result"""
157
+ try:
158
+ # Parse arguments
159
+ if arguments_json.strip():
160
+ arguments = json.loads(arguments_json)
161
+ else:
162
+ arguments = {}
163
+
164
+ # Call the tool
165
+ result = interface.call_tool(server_name, tool_name, arguments)
166
+ return json.dumps(result, indent=2, default=str)
167
+ except json.JSONDecodeError as e:
168
+ return json.dumps({"error": f"Invalid JSON in arguments: {str(e)}"}, indent=2)
169
+ except Exception as e:
170
+ return json.dumps({"error": f"Execution failed: {str(e)}", "traceback": traceback.format_exc()}, indent=2)
171
+
172
+ # Create Gradio interface with MCP server support
173
+ with gr.Blocks(title="PowerMCP Server Interface", theme=gr.themes.Soft()) as demo:
174
+ gr.Markdown("""
175
+ # ⚡ PowerMCP - Power System Analysis MCP Server
176
+
177
+ This is an MCP-enabled Hugging Face Space for **PowerMCP** - an open-source collection of
178
+ Model Context Protocol (MCP) servers for power system software.
179
+
180
+ **Available Tools:**
181
+ - **pandapower**: Power flow, contingency analysis, network management
182
+ - **PyPSA**: Energy system optimization, network expansion
183
+ - **ANDES**: Dynamic simulation, transient stability analysis
184
+
185
+ This Space can be used in two ways:
186
+ 1. **As an MCP tool** in Claude Desktop, Cursor, or other MCP clients (click the MCP badge)
187
+ 2. **Web interface** for manual tool execution and testing
188
+ """)
189
+
190
+ with gr.Tab("🔧 Tool Explorer"):
191
+ with gr.Row():
192
+ with gr.Column(scale=1):
193
+ gr.Markdown("## Server Configuration")
194
+ server_dropdown = gr.Dropdown(
195
+ choices=interface.get_available_servers(),
196
+ value=interface.get_available_servers()[0] if interface.get_available_servers() else None,
197
+ label="Select Power System Tool",
198
+ interactive=True
199
+ )
200
+
201
+ tools_button = gr.Button("📋 List Available Tools", variant="primary")
202
+ tools_output = gr.Markdown(label="Available Tools")
203
+
204
+ with gr.Column(scale=2):
205
+ gr.Markdown("## Execute Tool")
206
+
207
+ tool_name_input = gr.Textbox(
208
+ label="Tool Name",
209
+ placeholder="e.g., create_empty_network",
210
+ lines=1
211
+ )
212
+
213
+ arguments_input = gr.Code(
214
+ label="Arguments (JSON)",
215
+ language="json",
216
+ value="{}",
217
+ lines=5
218
+ )
219
+
220
+ execute_button = gr.Button("▶️ Execute Tool", variant="primary")
221
+
222
+ result_output = gr.Code(
223
+ label="Result",
224
+ language="json",
225
+ lines=15
226
+ )
227
+
228
+ with gr.Tab("📚 Documentation"):
229
+ gr.Markdown("""
230
+ ## PowerMCP Tools Documentation
231
+
232
+ ### pandapower
233
+ A Python-based power system analysis tool focusing on power flow and contingency analysis.
234
+
235
+ **Key Functions:**
236
+ - `create_empty_network()` - Create a new empty network
237
+ - `load_network(file_path)` - Load network from JSON/pickle file
238
+ - `run_power_flow(algorithm, calculate_voltage_angles, max_iteration, tolerance_mva)` - Run power flow analysis
239
+ - `run_contingency_analysis(contingency_type, elements)` - Perform N-1 or N-2 analysis
240
+ - `get_network_info()` - Get network statistics
241
+
242
+ ### PyPSA (Python for Power System Analysis)
243
+ Energy system optimization and network expansion planning.
244
+
245
+ **Key Functions:**
246
+ - `create_network(name, snapshots, crs)` - Create new PyPSA network
247
+ - `add_bus(network_name, bus_id, v_nom, x, y, carrier)` - Add bus to network
248
+ - `add_generator(network_name, generator_id, bus, p_nom, ...)` - Add generator
249
+ - `run_optimization(network_name)` - Run optimal power flow
250
+ - `get_network_info(network_name)` - Get network information
251
+
252
+ ### ANDES
253
+ Dynamic simulation and transient stability analysis.
254
+
255
+ **Key Functions:**
256
+ - `run_power_flow(file_path)` - Run power flow analysis
257
+ - `run_time_domain_simulation(file_path, end_time, step_size)` - Run transient analysis
258
+ - `get_bus_results()` - Get bus voltage and angle results
259
+ - `get_generator_results()` - Get generator output results
260
+
261
+ ## Example Usage in MCP Clients
262
+
263
+ ```python
264
+ # In Claude Desktop or Cursor with PowerMCP enabled:
265
+
266
+ # Create and analyze a network
267
+ create_empty_network(server="pandapower")
268
+ load_network(file_path="test_case.json", server="pandapower")
269
+ run_power_flow(server="pandapower", algorithm="nr")
270
+ get_network_info(server="pandapower")
271
+ ```
272
+
273
+ ## About PowerMCP
274
+
275
+ PowerMCP enables Large Language Models to directly interact with power system
276
+ applications through the Model Context Protocol (MCP). This allows AI assistants
277
+ to perform power system analysis, optimization, and simulation tasks.
278
+
279
+ **Links:**
280
+ - [GitHub Repository](https://github.com/Power-Agent/PowerMCP)
281
+ - [MCP Documentation](https://modelcontextprotocol.io/)
282
+ - [Tutorial](https://huggingface.co/learn/mcp-course)
283
+
284
+ ## Setting Up MCP Client
285
+
286
+ 1. Install Claude Desktop, Cursor, or another MCP-compatible client
287
+ 2. Click the MCP badge on this Space
288
+ 3. Select "Add to MCP tools"
289
+ 4. The tools will be available in your client immediately
290
+
291
+ For local development, see the [PowerMCP README](https://github.com/Power-Agent/PowerMCP).
292
+ """)
293
+
294
+ # Event handlers
295
+ tools_button.click(
296
+ fn=format_tools_list,
297
+ inputs=[server_dropdown],
298
+ outputs=[tools_output]
299
+ )
300
+
301
+ execute_button.click(
302
+ fn=execute_tool_call,
303
+ inputs=[server_dropdown, tool_name_input, arguments_input],
304
+ outputs=[result_output]
305
+ )
306
+
307
+ # Load tools on startup
308
+ demo.load(
309
+ fn=format_tools_list,
310
+ inputs=[server_dropdown],
311
+ outputs=[tools_output]
312
+ )
313
+
314
+ def main():
315
+ """Entry point for powermcp-app command"""
316
+ # Enable MCP server mode - this exposes the Space as an MCP tool
317
+ demo.launch(mcp_server=True)
318
+
319
+ if __name__ == "__main__":
320
+ main()
requirements.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gradio with MCP support
2
+ gradio[mcp]>=5.0.0
3
+
4
+ # PowerMCP - Install from GitHub
5
+ git+https://github.com/Power-Agent/PowerMCP.git
6
+
7
+ # Core dependencies
8
+ numpy>=1.24.0
9
+ pandas>=2.0.0
10
+ scipy>=1.10.0
11
+ networkx>=3.0
12
+ matplotlib>=3.7.0
13
+
14
+ # Additional PyPSA dependencies
15
+ xarray>=2023.0.0
16
+ netcdf4>=1.6.0
17
+
18
+ # Additional ANDES dependencies
19
+ kvxopt>=1.3.0