Getting Started
Electronic Access Entitlement for MCP GenAI SDK User
Join the User Group: Request access to the "MCC Solution - MCP Artifacts User - Reader " entitlement via SailPoint. This will grant you permission to use the Python SDK (or future SDKs).
⚠️ **Important Notes
The MCP generative AI server can only be accessed from within the Mayo Clinic network.
Getting Started with GenAI and Python 🐍 💻
Before diving into the exciting world of GenAI, let's make sure you have Python ready to go. Here's the scoop:
Checking for Python
- MacOS: Open your Terminal (find it in Applications or via Spotlight search with Command + Space).
- Windows: Open the Command Prompt (search for "cmd" in the start menu).
Type python and hit Enter/Return.
- Python Power! 🎉 If you see the Python interpreter, you're good to go!
- Whoops! ⚠️ If you see an error like "command python not found", let's get Python installed.
Downloading Python
- Visit the official Python website: https://www.python.org/ and grab the latest version.
- You'll need Python 3.9 or newer to work with GenAI.
- New to Python? No worries! Follow the beginner-friendly installation guide on the website.
Preparing Your Python Playground 🐍 💻
1. Python Checkup
- MacOS: Open your trusty Terminal (find it in Applications or via Spotlight with Command + Space).
- Windows: Fire up the Command Prompt (search for "cmd" in the start menu).
Type python and hit Enter/Return.
- All Set! 🎉 If you see the Python interpreter, you're ready to roll.
- Need Setup? 🛠️ No worries! Download the latest Python from https://www.python.org/ (at least version 3.9 for GenAI). Follow the beginner-friendly installation guide on the website.
2. Optional (but Recommended): Crafting a Virtual Environment
Virtual environments keep your project's dependencies tidy and separate!
- UV
- VENV
- Conda
- Recommended Way to get started
UV
# Mac and Linux, On your Terminal
curl -LsSf https://astral.sh/uv/install.sh | sh
#On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
#Already Have Pip or Pipx install
pip install uv || pipx install uv
# With Homebrew.
brew install uv
# With Pacman.
pacman -S uv
To create a virtual environment:
uv venv # Create a virtual environment at .venv.
To activate the virtual environment:
# On macOS and Linux.
source .venv/bin/activate
# On Windows.
.venv\Scripts\activate
- Using
venv
python -m venv mcp-env
# Activate on Windows:
mcp-env\Scripts\activate
# Activate on macOS/Linux
source mcp-env/bin/activate
- The
CondaWay 🐍- Install Miniconda or Anaconda: Get it from https://www.anaconda.com/products/distribution. These provide the
condatool for environment management. - Create the Environment:
conda create --name mcp-env python=3.9
conda activate mcp-env - Install Miniconda or Anaconda: Get it from https://www.anaconda.com/products/distribution. These provide the
⚠️ Important: Complete GCP Setup First
Before you dive into the GenAI SDK, please ensure you've meticulously followed the GCP setup instructions. This is crucial for two reasons:
-
Accessing the SDK: Our SDK resides in a private repository. Correct GCP setup grants you the necessary access.
-
Smooth Installation: Your Python environment needs the proper configuration to successfully install and use the GenAI package.
Don't skip this step! Taking the time now will prevent installation headaches and ensure a seamless experience with the GenAI SDK.
3. Installing the GenAI Library ✨
Inside your activated environment, Authenticate into GCP using Gcloud;
Run the following on your terminal:
#Set default login
gcloud auth application-default login
#Authenticate into GCP
gcloud auth login
To Install MCP package:
- UV Env
- Othe Python Env
uv pip install mcp --keyring-provider subprocess --extra-index-url https://us-central1-python.pkg.dev/mcp-idp-app-registry-p-13hf/mcp-art-internal-idp-python/simple
pip install mcp --extra-index-url https://us-central1-python.pkg.dev/mcp-idp-app-registry-p-13hf/mcp-art-internal-idp-python/simple
4. Safeguarding Your API Key 🔐
- Get Your Key: Currently, the MCP Technology team provides API keys upon request. We'll have a web portal for generating your own soon!
- Linux/MacOS
- Windows
- Project .env
- Open Terminal
- Edit Profile:
nano ~/.bash_profileornano ~/.zshrc(for newer versions) - Add Variable:
export MCP_GENAI_API_KEY='your-api-key-here'
- Save and Load: Ctrl+O to save, Ctrl+X to exit, then
source ~/.bash_profileorsource ~/.zshrc
- Command Prompt: Run
setx MCP_GENAI_API_KEY "your-api-key-here"(temporary for the session) - Permanent Setup:
- Right-click "This PC" -> "Properties" -> "Advanced system settings" -> "Environment Variables"
- Under "System variables," click "New," name it
MCP_GENAI_API_KEY, and paste your key as the value.
-
Navigate to your project folder.
-
Create
.gitignoreand add.envto it (keeps your key out of version control!) -
Create
.env, and paste the following, replacing with your actual key:MCP_GENAI_API_KEY=abc123 -
install dotenv to be able to access environments variable:
pip install python-dotenvLoad in Python:
import os
from mcp import GenAI
from dotenv import load_dotenv
load_dotenv('.env')
print(os.environ.get("MCP_GENAI_API_KEY"))
client = GenAI(api_key=os.environ.get("MCP_GENAI_API_KEY"))
# ... your code here
5. Your First Request: Let the Magic Begin! 🚀
Create a file called mcp-test.py and add this code (pick a cool example):
import os
from mcp import GenAI
from dotenv import load_dotenv
load_dotenv('.env')
print(os.environ.get("MCP_GENAI_API_KEY"))
client = GenAI(api_key=os.environ.get("MCP_GENAI_API_KEY"))
completion = client.chat.completions.create(
model="mistral",
messages=[
{"role": "system", "content": "You are a medical student with a strong interest in medical history. You have a knack for weaving historical details into compelling narratives."},
{"role": "user", "content": "Write the opening scene of a historical fiction novel where a young medical apprentice, working in a bustling medieval hospital, discovers a hidden scroll containing ancient surgical techniques."}
],
max_tokens=500,
temperature=0.5,
top_p=1.0,
)
print(completion.choices[0].message)
Now Run it with python mcp-test.py.