"""Leaderboard benchmark data -- 200 popular MCP servers graded."""

# (server_id, display_name, score) sorted by score descending
LEADERBOARD = [
    ("postgres", "PostgreSQL MCP Server", 100.0),
    ("awkoy-notion", "Notion MCP (awkoy)", 100.0),
    ("danhilse-notion", "Notion MCP (danhilse)", 100.0),
    ("zapier-mcp", "zapier/zapier-mcp", 100.0),
    ("mysql-mcp", "MySQL MCP Server", 99.7),
    ("ros-mcp", "ROS MCP Server", 99.7),
    ("dagster-mcp", "Dagster MCP", 99.7),
    ("sqlite", "SQLite MCP Server", 99.7),
    ("axiom-mcp", "Axiom MCP Server", 99.4),
    ("homeassistant-mcp", "Home Assistant MCP", 99.4),
    ("e2b", "E2B MCP Server", 99.1),
    ("bigquery-mcp", "BigQuery MCP", 99.1),
    ("windbg", "WinDbg MCP", 99.1),
    ("kafka-mcp", "kafka-mcp", 98.5),
    ("codex-mcp", "Codex MCP Server", 98.5),
    ("google-tasks-mcp", "Google Tasks MCP", 97.9),
    ("weather-mcp", "OpenWeather MCP Server", 97.6),
    ("colab", "Google Colab MCP", 97.6),
    ("mcp-gdrive", "Google Drive MCP (isaacphi)", 97.3),
    ("zoom-transcript-mcp", "Zoom Transcript MCP", 97.3),
    ("flightradar-mcp", "Flightradar24 MCP", 97.3),
    ("slack", "Slack MCP Server", 97.3),
    ("mcp-youtube", "mcp-youtube", 97.3),
    ("lancedb-mcp", "LanceDB MCP (Official)", 97.0),
    ("prometheus-mcp", "Prometheus MCP Server", 96.7),
    ("ytt-mcp", "ytt-mcp (YouTube Transcript)", 96.1),
    ("splunk-mcp", "Splunk MCP (Official)", 96.1),
    ("mcp-installer", "MCP Installer", 95.5),
    ("sourcegraph-mcp", "Sourcegraph MCP (Official)", 94.6),
    ("twilio-mcp", "Twilio SMS", 94.5),
    ("elasticsearch-mcp", "Elasticsearch MCP Server", 94.5),
    ("pinecone-official", "Pinecone Assistant MCP", 94.3),
    ("vault-mcp", "HashiCorp Vault MCP", 93.4),
    ("shadcn", "shadcn-ui MCP", 93.4),
    ("git", "Git MCP Server", 93.1),
    ("mark3labs-filesystem", "Filesystem MCP Server (mark3labs)", 93.1),
    ("flyio-mcp", "Fly.io MCP (Official)", 91.4),
    ("hf-mcp", "HuggingFace MCP", 91.3),
    ("puppeteer", "Puppeteer MCP Server", 91.2),
    ("dynatrace-mcp", "Dynatrace MCP", 90.8),
    ("box-mcp", "Box MCP Server", 90.4),
    ("eslint-mcp", "ESLint MCP Server", 90.0),
    ("metabase-mcp", "Metabase MCP (Community)", 89.9),
    ("browsermcp", "BrowserMCP", 89.2),
    ("calclavia-obsidian", "Obsidian MCP (calclavia)", 88.6),
    ("discord-v3-mcp", "Discord MCP", 88.4),
    ("jina-mcp", "Jina AI MCP", 88.0),
    ("anyquery", "Anyquery", 87.4),
    ("polygon-mcp", "Polygon.io MCP", 87.0),
    ("groq-mcp", "Groq MCP Server", 85.6),
    ("fastapi-mcp", "FastAPI-MCP", 85.6),
    ("clickup-mcp", "ClickUp MCP Server", 85.3),
    ("zendesk-mcp", "Zendesk MCP Server", 84.7),
    ("mixpanel-moonbirdai", "moonbirdai/mixpanel-mcp-server", 84.5),
    ("trello-mcp", "delorenj/mcp-server-trello", 84.4),
    ("discord-hanweg", "Discord MCP (hanweg)", 84.4),
    ("ghidra", "GhidraMCP", 84.4),
    ("godot-mcp", "Godot MCP", 84.3),
    ("mcp-feedback-enhanced", "MCP Feedback Enhanced", 83.4),
    ("brave", "Brave Search MCP Server", 82.6),
    ("deepwiki-mcp", "DeepWiki MCP", 82.3),
    ("dbhub", "dbhub", 82.3),
    ("airflow-mcp", "Apache Airflow MCP", 82.0),
    ("time", "Time MCP Server", 81.7),
    ("langfuse-mcp", "Langfuse MCP (Official)", 81.4),
    ("korotovsky-slack", "Slack MCP (korotovsky)", 81.1),
    ("klaviyo-mcp", "Klaviyo MCP (Community)", 81.1),
    ("square-mcp", "Square MCP Server (Official)", 80.7),
    ("doppler-mcp", "Doppler MCP (Official)", 80.4),
    ("xiaohongshu", "Xiaohongshu MCP Server", 80.2),
    ("sequentialthinking", "Sequential Thinking", 79.9),
    ("googlemaps", "Google Maps MCP Server", 79.9),
    ("github", "GitHub MCP Server", 79.6),
    ("qdrant", "Qdrant MCP", 78.9),
    ("newrelic-mcp", "New Relic MCP (Official)", 78.7),
    ("memory", "Memory MCP Server", 78.4),
    ("hubspot-mcp", "HubSpot MCP Server", 76.8),
    ("sentry", "Sentry MCP Server", 76.6),
    ("linkedin", "LinkedIn MCP", 76.6),
    ("universal-db", "Universal DB MCP", 76.6),
    ("spotify-mcp", "Spotify MCP", 76.6),
    ("line-bot-mcp", "LINE Bot MCP Server", 76.3),
    ("chunkhound", "chunkhound", 76.3),
    ("gsc-mcp", "Google Search Console MCP", 76.0),
    ("circleci-mcp", "CircleCI MCP Server", 75.8),
    ("fetch", "Fetch MCP Server", 74.4),
    ("kagi-mcp", "Kagi Search MCP", 74.2),
    ("monday-mcp", "monday.com MCP", 74.2),
    ("upstash-mcp", "Upstash MCP (Official)", 74.1),
    ("obsidian", "Obsidian MCP (MarkusPfundstein)", 73.5),
    ("temporal-mcp", "Temporal MCP (Community)", 72.7),
    ("mem0", "Mem0 MCP", 72.7),
    ("whatsapp", "WhatsApp MCP", 72.4),
    ("planetscale-mcp", "planetscale/mcp-server", 72.4),
    ("pinecone-sirmews", "Pinecone MCP", 70.9),
    ("webex-mcp", "Webex (Cisco)", 69.7),
    ("dbt-mcp", "dbt MCP (Official)", 69.7),
    ("browserbase", "Browserbase MCP", 69.6),
    ("weaviate", "Weaviate MCP", 69.5),
    ("telegram-mcp", "Telegram MCP (chigwell)", 68.8),
    ("linear", "Linear MCP", 68.8),
    ("gmail-mcp", "Gmail MCP", 68.2),
    ("airtable-mcp", "Airtable MCP Server", 68.0),
    ("discord-barryyip", "Discord MCP (barryyip0625)", 67.9),
    ("vercel-next", "Vercel Next DevTools", 67.3),
    ("playwright", "Playwright MCP Server", 67.0),
    ("serena", "Serena", 67.0),
    ("algolia-mcp", "Algolia MCP (Official)", 66.4),
    ("duckduckgo-mcp", "DuckDuckGo MCP", 66.1),
    ("web-eval-agent", "Web Eval Agent", 66.1),
    ("google-sheets", "Google Sheets MCP", 65.8),
    ("mobile-mcp", "Mobile MCP", 65.8),
    ("gitlab-mcp", "GitLab MCP Server", 65.5),
    ("mcp-taskmanager", "MCP Taskmanager", 65.2),
    ("filesystem", "Filesystem MCP Server", 64.9),
    ("chrome-devtools", "Chrome DevTools MCP Server", 64.9),
    ("sendgrid-mcp", "SendGrid MCP", 64.7),
    ("redis-mcp", "Redis MCP Server", 64.6),
    ("loom-mcp", "Loom MCP (Community)", 64.5),
    ("opensearch-mcp", "OpenSearch MCP Server (Official)", 64.3),
    ("genai-toolbox", "Google genai-toolbox", 64.3),
    ("amplitude-mcp", "Amplitude MCP (Official)", 64.1),
    ("milvus-mcp", "Milvus MCP (Official)", 63.9),
    ("excel", "Excel MCP Server", 63.8),
    ("neon", "Neon MCP", 63.7),
    ("supabase", "Supabase MCP", 63.5),
    ("pagerduty-mcp", "PagerDuty MCP Server", 63.4),
    ("playwright-ms", "Playwright MCP (Microsoft)", 63.3),
    ("influxdb-mcp", "InfluxDB MCP Server (Official)", 62.8),
    ("stripe", "Stripe Agent Toolkit MCP Server", 62.5),
    ("atlassian", "Atlassian MCP Server", 62.2),
    ("figma", "Figma-Context-MCP", 61.9),
    ("chroma", "Chroma MCP", 61.9),
    ("azure-devops", "Azure DevOps MCP", 61.9),
    ("asana-mcp", "Asana MCP Server", 60.8),
    ("unity-mcp", "CoderGamester/mcp-unity", 60.0),
    ("mongodb-lens", "MongoDB Lens", 60.0),
    ("salesforce-mcp", "Salesforce CLI MCP", 60.0),
    ("terraform", "Terraform MCP", 59.5),
    ("markdownify", "Markdownify MCP", 59.1),
    ("magic-mcp", "magic-mcp", 58.3),
    ("arxiv-mcp", "arXiv MCP Server", 57.4),
    ("argocd-mcp", "ArgoCD MCP", 57.2),
    ("exa", "Exa MCP Server", 57.1),
    ("chart", "Chart MCP Server", 56.5),
    ("apple-docs", "Apple Docs MCP", 56.2),
    ("plaid-mcp", "Plaid AI Coding Toolkit", 55.9),
    ("firebase-mcp", "Firebase MCP Server (Official)", 55.7),
    ("perplexity", "Perplexity MCP Server", 55.6),
    ("snowflake-mcp", "Snowflake MCP Server", 55.5),
    ("google-workspace", "Google Workspace MCP", 54.8),
    ("mcp-everything", "MCP Everything (Reference)", 54.6),
    ("blender", "Blender MCP Server", 54.2),
    ("minimax", "MiniMax MCP", 52.6),
    ("aws", "AWS MCP Server", 52.2),
    ("wandb-mcp", "W&amp;B MCP Server (Official)", 52.2),
    ("github-official", "GitHub MCP Server (Official)", 52.1),
    ("postman-mcp", "Postman MCP Server", 52.1),
    ("bitwarden-mcp", "Bitwarden", 51.4),
    ("cloudflare", "Cloudflare Radar MCP Server", 51.4),
    ("mslearn", "Microsoft Learn MCP", 51.3),
    ("freshdesk-mcp", "Freshdesk MCP (Community)", 49.8),
    ("databricks-mcp", "Databricks MCP", 49.7),
    ("ea-playwright", "Playwright MCP (executeautomation)", 49.4),
    ("pal", "PAL MCP Server", 49.0),
    ("alexander-supabase", "Supabase MCP (alexander-zuev)", 48.4),
    ("tavily", "Tavily MCP Server", 48.1),
    ("n8n-mcp", "n8n-mcp", 47.7),
    ("kubernetes", "Kubernetes MCP", 45.9),
    ("mcp-chrome", "mcp-chrome", 44.9),
    ("snyk-mcp", "Snyk MCP (Official)", 43.3),
    ("mongodb", "MongoDB MCP", 42.0),
    ("prefect-mcp", "Prefect MCP (Official)", 40.3),
    ("ga4", "Google Analytics (GA4) MCP Server", 40.0),
    ("sentry-official", "Sentry MCP (Official)", 40.0),
    ("infisical-mcp", "Infisical MCP (Official)", 39.6),
    ("context7", "Context7 MCP Server", 39.5),
    ("suekou-notion", "Notion MCP (suekou)", 36.4),
    ("firecrawl", "Firecrawl MCP Server", 35.8),
    ("railway-mcp", "Railway MCP (Official)", 35.4),
    ("okta-mcp", "Okta MCP Server (Official)", 34.7),
    ("contentful-mcp", "Contentful MCP (Official)", 33.4),
    ("apify", "Apify Actors MCP", 32.7),
    ("auth0-mcp", "auth0/auth0-mcp-server", 31.8),
    ("confluence-mcp", "Confluence MCP (aashari)", 31.7),
    ("desktop-commander", "Desktop Commander MCP Server", 30.8),
    ("jira-mcp", "Jira MCP (aashari)", 30.2),
    ("xero-mcp", "Xero MCP (Official)", 29.7),
    ("datadog-mcp", "Datadog MCP Server", 28.2),
    ("resend", "Resend MCP", 27.9),
    ("todoist-mcp", "Todoist", 27.6),
    ("cloudinary-mcp", "Cloudinary", 27.3),
    ("docker-mcp", "Docker MCP", 27.0),
    ("google-calendar-mcp", "Google Calendar", 26.7),
    ("miro-mcp", "Miro MCP Server", 26.4),
    ("shopify", "Shopify MCP Server", 26.1),
    ("drawio", "Draw.io MCP Server", 24.9),
    ("grafana", "Grafana MCP", 21.9),
    ("confluent-mcp", "Confluent Kafka MCP", 19.8),
    ("notion", "Notion MCP Server", 19.8),
]

LEADERBOARD_URL = "https://0-co.github.io/company/leaderboard.html"


def get_leaderboard_position(score):
    """Return (rank, total, servers_above, servers_below) for a given score.

    rank: 1-indexed position (1 = best)
    total: total servers in leaderboard
    servers_above: list of (name, score) for the 2 servers immediately above
    servers_below: list of (name, score) for the 2 servers immediately below
    """
    scores = [s[2] for s in LEADERBOARD]
    total = len(scores)

    # Find rank (1-indexed, higher score = better rank)
    # Count how many leaderboard entries have a strictly higher score,
    # then add 1. Ties share the same rank position.
    rank = 1
    for s in scores:
        if s > score:
            rank += 1

    # Get neighboring servers
    # "above" = those with higher scores (better rank)
    idx = rank - 1  # 0-indexed insertion point
    servers_above = [(LEADERBOARD[i][1], LEADERBOARD[i][2]) for i in range(max(0, idx - 2), idx)]
    servers_below = [(LEADERBOARD[i][1], LEADERBOARD[i][2]) for i in range(idx, min(total, idx + 2))]

    return rank, total, servers_above, servers_below
