Connect AI Agents to SciRouter
Step-by-step guides for Claude Desktop, Claude Code, Cursor, OpenAI Assistants, LangChain, and custom agent frameworks.
Prerequisites
- Get a free API key at scirouter.ai/register (500 credits/month)
- Install the SciRouter package:
pip install scirouter - Set your API key as an environment variable or pass it directly
pip install scirouter
export SCIROUTER_API_KEY="sk-sci-YOUR_KEY"bashClaude Desktop
Claude Desktop supports MCP servers natively. Add SciRouter to your config file:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json{
"mcpServers": {
"scirouter": {
"command": "python",
"args": ["-m", "scirouter.mcp"],
"env": {
"SCIROUTER_API_KEY": "sk-sci-YOUR_KEY"
}
}
}
}jsonRestart Claude Desktop. You'll see SciRouter tools in the tool picker. Try asking: “What are the molecular properties of aspirin?”
Claude Code
Add to your project's .claude/settings.json:
{
"mcpServers": {
"scirouter": {
"command": "python",
"args": ["-m", "scirouter.mcp"],
"env": {
"SCIROUTER_API_KEY": "sk-sci-YOUR_KEY"
}
}
}
}jsonCursor
Add to .cursor/mcp.json in your project root:
{
"mcpServers": {
"scirouter": {
"command": "python",
"args": ["-m", "scirouter.mcp"],
"env": {
"SCIROUTER_API_KEY": "sk-sci-YOUR_KEY"
}
}
}
}jsonOpen Cursor settings → MCP to verify the server is connected and tools are available.
OpenAI Assistants / GPTs
Register SciRouter tools as OpenAI function-calling tools. The /v1/tools endpoint returns all tools in OpenAI function schema format:
import httpx
import openai
# Get SciRouter tool schemas (OpenAI-compatible)
tools_resp = httpx.get(
"https://scirouter.ai/v1/tools",
headers={"Authorization": "Bearer sk-sci-YOUR_KEY"}
)
scirouter_tools = tools_resp.json()["tools"]
# Create an OpenAI assistant with SciRouter tools
client = openai.OpenAI()
assistant = client.beta.assistants.create(
name="Science Assistant",
instructions="You are a scientific computing assistant. Use SciRouter tools to analyze proteins, molecules, and drug candidates.",
model="gpt-4o",
tools=[{"type": "function", "function": t} for t in scirouter_tools]
)
print(f"Assistant created with {len(scirouter_tools)} tools")pythonWhen the assistant calls a tool, forward the request to SciRouter:
# Handle tool calls from the assistant
def handle_tool_call(tool_name, arguments):
"""Forward OpenAI tool calls to SciRouter API."""
response = httpx.post(
f"https://scirouter.ai/v1/{tool_name}",
headers={"Authorization": "Bearer sk-sci-YOUR_KEY"},
json=arguments,
timeout=60
)
return response.json()pythonLangChain / LangGraph
Use SciRouter as a LangChain tool provider:
from langchain.tools import Tool
import httpx
SCIROUTER_KEY = "sk-sci-YOUR_KEY"
BASE = "https://scirouter.ai"
HEADERS = {"Authorization": f"Bearer {SCIROUTER_KEY}"}
def fold_protein(sequence: str) -> str:
"""Predict 3D protein structure from amino acid sequence."""
r = httpx.post(f"{BASE}/v1/proteins/fold",
headers=HEADERS, json={"sequence": sequence}, timeout=60)
return r.text
def molecular_properties(smiles: str) -> str:
"""Calculate molecular properties from SMILES string."""
r = httpx.post(f"{BASE}/v1/chemistry/properties",
headers=HEADERS, json={"smiles": smiles}, timeout=60)
return r.text
def adme_predict(smiles: str) -> str:
"""Predict ADME/Tox drug properties for a molecule."""
r = httpx.post(f"{BASE}/v1/pharma/adme",
headers=HEADERS, json={"smiles": smiles}, timeout=60)
return r.text
tools = [
Tool(name="fold_protein", func=fold_protein,
description="Predict 3D protein structure from amino acid sequence"),
Tool(name="molecular_properties", func=molecular_properties,
description="Calculate molecular properties from SMILES"),
Tool(name="adme_predict", func=adme_predict,
description="Predict ADME/Tox properties for a molecule"),
]
# Use with any LangChain agent
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o", temperature=0)
agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS)
result = agent.run("What are the drug properties of aspirin?")pythonCustom Agent Frameworks
SciRouter's MCP server works with any MCP-compatible client. You can also call the REST API directly:
import httpx
class SciRouterToolkit:
"""Minimal SciRouter toolkit for custom agents."""
def __init__(self, api_key: str):
self.client = httpx.Client(
base_url="https://scirouter.ai",
headers={"Authorization": f"Bearer {api_key}"},
timeout=60
)
def call_tool(self, tool_name: str, **kwargs) -> dict:
"""Call any SciRouter tool by name."""
# Map tool names to API endpoints
TOOL_MAP = {
"fold_protein": ("POST", "/v1/proteins/fold"),
"molecular_properties": ("POST", "/v1/chemistry/properties"),
"adme_predict": ("POST", "/v1/pharma/adme"),
"get_target": ("GET", "/v1/targets/{gene}"),
"dock_vina": ("POST", "/v1/docking/vina"),
# ... add more as needed
}
method, path = TOOL_MAP[tool_name]
if method == "GET":
path = path.format(**kwargs)
return self.client.get(path).json()
return self.client.post(path, json=kwargs).json()
def list_tools(self) -> list:
"""Get all available tools as OpenAI function schemas."""
return self.client.get("/v1/tools").json()["tools"]
# Usage
toolkit = SciRouterToolkit("sk-sci-YOUR_KEY")
result = toolkit.call_tool("molecular_properties", smiles="CCO")
print(result)python