import asynciofrom mcp_rank import MCPRankClientasync def main(): async with MCPRankClient(api_key="sk_mcp_rank_...") as client: # Search for tools results = await client.search("send email") for server in results["servers"]: print(f"{server['name']}: {server['description']}")asyncio.run(main())
The SDK includes an Agent class that wraps OpenAI or Anthropic clients with automatic tool discovery:
from openai import OpenAIfrom mcp_rank import Agent# Create an agent with automatic tool discoveryagent = Agent(OpenAI(), api_key="sk_mcp_rank_...")# Run a task - tools are discovered and used automaticallyresponse = agent.run("Search the web for latest AI news")print(response)
Let your agent access user’s Google data (Gmail, Calendar, Drive) through our secure proxy. MCP Rank stores OAuth tokens server-side, so you never handle sensitive credentials.
from openai import OpenAIfrom mcp_rank import Agent# Create agent with user_id for server-side token managementagent = Agent( OpenAI(), api_key="sk_mcp_rank_...", user_id="user_123", # Your user's ID in your system auto_auth=True, # Opens browser when auth needed)# If the task needs Google access:# 1. Browser opens automatically for OAuth# 2. User authorizes (tokens stored server-side)# 3. Request completesresponse = agent.run("Send an email to team@company.com about the meeting")print(response)
For custom UIs or more control over the auth flow:
from mcp_rank import MCPRankClientasync def main(): client = MCPRankClient( api_key="sk_mcp_rank_...", user_id="user_123", ) # Initialize - gets MCP Identity Token from server await client.initialize() # Check if user has connected Google info = await client.get_proxy_info("google") if not info["can_access"]: # Create auth session session = await client.create_auth_session("google") print(f"Please open: {session['auth_url']}") # Poll for completion (or redirect in web app) while True: status = await client.check_session_status(session["session_id"]) if status["status"] == "complete": break await asyncio.sleep(1) # Refresh tokens after auth await client.initialize() # Make API calls on behalf of the user profile = await client.proxy_get("google", "gmail/v1/users/me/profile") print(f"User email: {profile['emailAddress']}")asyncio.run(main())