Skip to main content

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).

warning

⚠️ **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!

Create Virtual Env
  • 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

warning

⚠️ 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:

  1. Accessing the SDK: Our SDK resides in a private repository. Correct GCP setup grants you the necessary access.

  2. 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 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

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!
Set-up Env Variables
  1. Open Terminal
  2. Edit Profile: nano ~/.bash_profile or nano ~/.zshrc (for newer versions)
  3. Add Variable:
export MCP_GENAI_API_KEY='your-api-key-here'
  1. Save and Load: Ctrl+O to save, Ctrl+X to exit, then source ~/.bash_profile or source ~/.zshrc

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.