|
| 1 | +Metadata-Version: 2.4 |
| 2 | +Name: egrid_mcp_agent |
| 3 | +Version: 0.0.0 |
| 4 | +Summary: This is an MCP agent example for power system analysis with open-source tool GridCal and OpenDSS |
| 5 | +Author-email: hinfsynz <szhang.asu@gmail.com> |
| 6 | +License: MIT |
| 7 | +Project-URL: Repository, https://github.com/IEEE-PES-TF-Cloud4PowerGrid/cloud_adoption_tutorials |
| 8 | +Requires-Python: >=3.11 |
| 9 | +Description-Content-Type: text/markdown |
| 10 | +Requires-Dist: requests |
| 11 | +Requires-Dist: botocore |
| 12 | +Requires-Dist: termcolor |
| 13 | +Requires-Dist: InlineAgent |
| 14 | + |
| 15 | +# eGRID MCP AGENT |
| 16 | +This is an MCP version of the eGrid Agentic AI example |
| 17 | +<p align="left"> |
| 18 | + <a href="./README.md/#solution-overview"><img src="https://img.shields.io/badge/AWS-Agentic_AI-orange" /></a> |
| 19 | + <a href="./README.md/#setup-agent-for-mcp-client"><img src="https://img.shields.io/badge/Amazon-Bedrock_Inline_Agent-orange" /></a> |
| 20 | + <a href="./README.md/#setup-for-egrid-analysis-mcp-server"><img src="https://img.shields.io/badge/MCP-FastMCP-blue" /></a> |
| 21 | +</p> |
| 22 | + |
| 23 | + |
| 24 | +## Introduction |
| 25 | +This tutorial demonstrates an MCP agent implementation that integrates multiple power system analysis tools via an MCP server. The server utilizes [FastMCP](https://github.com/jlowin/fastmcp) for its foundation, while the client leverages the [Amazon Bedrock Inline Agent SDK](https://github.com/awslabs/amazon-bedrock-agent-samples/tree/main/src/InlineAgent). The example showcases tool integration using open source power system software such as [OpenDSS (DSS-Python)](https://github.com/dss-extensions/DSS-Python) and [GridCal](https://github.com/SanPen/GridCal) to illustrate the operational workflow. |
| 26 | + |
| 27 | +## Solution Overview |
| 28 | + |
| 29 | + |
| 30 | +## Get Started |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +1. AWS Command Line Interface (CLI), follow instructions [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). Make sure to setup credentials, follow instructions [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html). |
| 34 | +2. Install [UV](https://docs.astral.sh/uv/getting-started/installation/) |
| 35 | +3. Install [Python](https://docs.astral.sh/uv/guides/install-python/) 3.11 or above in UV |
| 36 | +4. Enable Amazon Bedrock [model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html). |
| 37 | + |
| 38 | +> [!NOTE] |
| 39 | +> If you don't set up your AWS profile as instructed in step 1. An exception `botocore.exceptions.ProfileNotFound` will raise |
| 40 | +> when you run `InlineAgent_hello` test below |
| 41 | + |
| 42 | +### Setup Agent for MCP Client |
| 43 | + |
| 44 | +```bash |
| 45 | +# Retrieve the Inline Agent SDK |
| 46 | +git clone https://github.com/awslabs/amazon-bedrock-agent-samples.git |
| 47 | +cd amazon-bedrock-agent-samples/src/InlineAgent |
| 48 | + |
| 49 | +# Activate the virtual environment (install python virtualenv first if not installed) |
| 50 | +python3 -m venv .venv |
| 51 | +source .venv/bin/activate |
| 52 | + |
| 53 | +# Install the SDK packages |
| 54 | +python3 -m pip install -e . |
| 55 | + |
| 56 | +# Test run; ensure you have access to Claude 3.5 Haiku model via Bedrock |
| 57 | +InlineAgent_hello us.anthropic.claude-3-5-haiku-20241022-v1:0 |
| 58 | + |
| 59 | +# Retrieve the tutorial |
| 60 | +git clone https://github.com/IEEE-PES-TF-Cloud4PowerGrid/cloud_adoption_tutorials.git |
| 61 | +cd cloud_adoption_tutorials/egrid_mcp_agent/ |
| 62 | + |
| 63 | +# Install dependencies for the sample |
| 64 | +python3 -m pip install -e . |
| 65 | +``` |
| 66 | + |
| 67 | +### Setup for eGrid Analysis MCP Server |
| 68 | +> [!NOTE] |
| 69 | +> You can host the MCP server for various power system analysis tools either on your local machine or a remote server. |
| 70 | +> When deploying the MCP server on a remote machine, update the **API_BASE_URL** by substituting `localhost` with the server's public IP address or domain name. |
| 71 | +> Verify that TCP port 8000 is open and reachable from the machine running the agent, then transfer the `egrid_mcp_server.py` script to the remote server. |
| 72 | + |
| 73 | + |
| 74 | +```bash |
| 75 | +# install dependencies |
| 76 | +uv add dss-python GridCalEngine numpy matplotlib "fastmcp>=0.1.0" |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +### Start the MCP Server |
| 81 | +```bash |
| 82 | +uv run egrid_mcp_server.py |
| 83 | +``` |
| 84 | + |
| 85 | +### Run MCP client built with Bedrock Inline Agent to Interact with MCP Server |
| 86 | +```bash |
| 87 | +python3 run_egrid_agent_mcp_client.py |
| 88 | +``` |
| 89 | + |
| 90 | +## Expected Results |
| 91 | +### Power Flow Analysis |
| 92 | +You need to download the power flow cases from GridCal project repo ["Grids_and_Profiles/grids/"](https://github.com/SanPen/GridCal/tree/master/Grids_and_profiles) folder |
| 93 | + |
| 94 | + |
| 95 | +<p align=center>Agent Response for Prompt to Run Power Flow Analysis</p> |
| 96 | + |
| 97 | + |
| 98 | +<p align=center>MCP Server Response for Prompt to Run Power Flow Analysis</p> |
0 commit comments