#!/usr/bin/env python3
"""
Example of using the evo2 MCP server directly
"""
import asyncio
import json
import os
from pathlib import Path
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
# Create server parameters - using API mode for this example
server_params = StdioServerParameters(
command="python",
args=["-m", "src.server"],
env={
"BIO_MCP_EVO2_EXECUTION_MODE": "api",
"BIO_MCP_EVO2_NIM_API_KEY": os.getenv("NIM_API_KEY", "your-api-key"),
"BIO_MCP_EVO2_MODEL_SIZE": "7b"
}
)
# Connect to server
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize
await session.initialize()
# List available tools
tools = await session.list_tools()
print("Available evo2 tools:")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
print("\n" + "="*50 + "\n")
# Example 1: Generate DNA sequence
print("Example 1: Generating DNA sequence")
result = await session.call_tool(
"evo2_generate",
{
"prompt": "ATCGATCGATCGATCG",
"n_tokens": 50,
"temperature": 1.0,
"top_k": 4
}
)
print("Generated sequence:")
for content in result:
if hasattr(content, 'text'):
print(content.text)
print("\n" + "="*50 + "\n")
# Example 2: Score a sequence
print("Example 2: Scoring a sequence")
result = await session.call_tool(
"evo2_score",
{
"sequence": "ATCGATCGATCGATCGATCGATCG",
"return_logits": False
}
)
print("Score result:")
for content in result:
if hasattr(content, 'text'):
print(content.text)
print("\n" + "="*50 + "\n")
# Example 3: Variant effect prediction
print("Example 3: Variant effect prediction")
result = await session.call_tool(
"evo2_variant_effect",
{
"reference_sequence": "ATCGATCGATCGATCGATCG",
"variant_sequence": "ATCGATCGATCGATCAATCG", # G->A mutation
"context_window": 1000
}
)
print("Variant effect:")
for content in result:
if hasattr(content, 'text'):
print(content.text)
elif hasattr(content, 'error'):
print(f"Error: {content.error}")
if __name__ == "__main__":
asyncio.run(main())