AWS HealthOmics Model Context Protocol Server SDK

0.0.34 · active · verified Mon Apr 13

The `awslabs-aws-healthomics-mcp-server` library provides a Python SDK for implementing the AWS HealthOmics Model Context Protocol (MCP) server. It enables developers to build custom servers that interact with AWS HealthOmics workflows, leveraging FastAPI for the web service aspect. Currently at version `0.0.34`, it is an AWS Labs project in active development, with releases potentially occurring frequently due to its early versioning.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to implement a basic AWS HealthOmics Model Context Protocol (MCP) server using the SDK. It defines a custom server class inheriting from `HealthOmicsMCPServer`, implements the `get_model_context` method to return model-specific information, and sets up a FastAPI application instance using `create_app`. The resulting `app` can be run with Uvicorn. It includes comments on how to run and test the server locally, along with considerations for AWS authentication.

import os
from typing import Dict, Any
from healthomics_mcp_server.server import HealthOmicsMCPServer
from healthomics_mcp_server.model import ModelContext, ModelContextType
from healthomics_mcp_server.app import create_app

# Configure AWS credentials for boto3 if not using environment variables or instance profiles
# os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_ID')
# os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_ACCESS_KEY')
# os.environ['AWS_REGION'] = os.environ.get('AWS_REGION', 'us-east-1')

class MyCustomMCPServer(HealthOmicsMCPServer):
    async def get_model_context(self, model_id: str) -> ModelContext:
        """Implement logic to retrieve a model's context based on its ID."""
        print(f"[MCP Server] Request received for model context: {model_id}")
        
        # In a real application, you would fetch this from a database, S3, or another service.
        # For this example, we return a predefined context based on an environment variable.
        if model_id == os.environ.get('EXAMPLE_MODEL_ID', 'example-model-123'):
            return ModelContext(
                id=model_id,
                type=ModelContextType.DEFAULT,
                properties={
                    "workflow_id": "wf-abc123def456",
                    "reference_genome": "hg38",
                    "sample_type": "blood"
                }
            )
        
        # For any other model_id, return a generic or empty context
        return ModelContext(
            id=model_id,
            type=ModelContextType.DEFAULT, # Or another specific type like ModelContextType.EMPTY
            properties={}
        )

    async def get_health(self) -> Dict[str, Any]:
        """Provide health status of the server."""
        print("[MCP Server] Health check requested.")
        return {"status": "ok", "server_id": "my-omics-server-v1"}

# Instantiate your custom server implementation
server_instance = MyCustomMCPServer()

# Create the FastAPI application instance by passing your server_instance
app = create_app(server_instance)

# --- To run this application: ---
# 1. Save the code above as `main.py`.
# 2. Make sure uvicorn is installed: `pip install awslabs-aws-healthomics-mcp-server[uvicorn]`
# 3. Run from your terminal: `uvicorn main:app --host 0.0.0.0 --port 8000 --reload`
# 4. Access the health endpoint: `http://localhost:8000/health`
# 5. Get model context (replace `example-model-123` with your desired ID):
#    `http://localhost:8000/model-context/example-model-123`
#    Set EXAMPLE_MODEL_ID in your environment for a specific test: `export EXAMPLE_MODEL_ID=my-custom-model`

view raw JSON →