Skip to main content

Quickstart

MCP Rank is a search engine for AI agent tools. Discover relevant MCP servers for any task and let your agents access user data securely.

Installation

Install the SDK using pip:
pip install mcp-rank

Set Your API Key

Get your API key from the dashboard and set it as an environment variable:
export MCP_RANK_API_KEY="sk_mcp_rank_..."
Or use a .env file:
MCP_RANK_API_KEY=sk_mcp_rank_...
Search for relevant MCP servers:
import asyncio
from mcp_rank import MCPRankClient

async 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())

Use with OpenAI/Anthropic

The SDK includes an Agent class that wraps OpenAI or Anthropic clients with automatic tool discovery:
from openai import OpenAI
from mcp_rank import Agent

# Create an agent with automatic tool discovery
agent = Agent(OpenAI(), api_key="sk_mcp_rank_...")

# Run a task - tools are discovered and used automatically
response = agent.run("Search the web for latest AI news")
print(response)

Access User Data (MCP Identity)

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 OpenAI
from mcp_rank import Agent

# Create agent with user_id for server-side token management
agent = 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 completes
response = agent.run("Send an email to team@company.com about the meeting")
print(response)

Manual Control

For custom UIs or more control over the auth flow:
from mcp_rank import MCPRankClient

async 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())

Next Steps