"""
Fresh Linkedin Profile Data MCP Server

使用 FastMCP 的 from_openapi 方法自动生成

Version: 1.0.0
Transport: stdio
"""
import os
import json
import httpx
from fastmcp import FastMCP

# 服务器版本和配置
__version__ = "1.0.0"
__tag__ = "fresh_linkedin_profile_data/1.0.0"

# API 配置
API_KEY = os.getenv("API_KEY", "")

# 传输协议配置
TRANSPORT = "stdio"


# OpenAPI 规范
OPENAPI_SPEC = """{\n  \"openapi\": \"3.0.0\",\n  \"info\": {\n    \"title\": \"Fresh Linkedin Profile Data\",\n    \"version\": \"1.0.0\",\n    \"description\": \"RapidAPI: freshdata-freshdata-default/fresh-linkedin-profile-data\"\n  },\n  \"servers\": [\n    {\n      \"url\": \"https://fresh-linkedin-profile-data.p.rapidapi.com\"\n    }\n  ],\n  \"paths\": {\n    \"/get-company-by-linkedinurl\": {\n      \"get\": {\n        \"summary\": \"Get Company by URL\",\n        \"description\": \"1 credit per call.\",\n        \"operationId\": \"get_company_by_url\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/company/apple/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/enrich-lead\": {\n      \"get\": {\n        \"summary\": \"Enrich Lead\",\n        \"description\": \"1 credit per call. Using each extra option will cost another 0.5 credits. Maximum: 3 credits.\",\n        \"operationId\": \"enrich_lead\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/cjfollini/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_skills\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_certifications\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_publications\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_honors\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_volunteers\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_projects\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_patents\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_courses\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_organizations\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_profile_status\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_company_public_url\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-company-by-id\": {\n      \"get\": {\n        \"summary\": \"Get Company by ID\",\n        \"description\": \"1 credit per call.\",\n        \"operationId\": \"get_company_by_id\",\n        \"parameters\": [\n          {\n            \"name\": \"company_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 162479\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/find-custom-headcount\": {\n      \"post\": {\n        \"summary\": \"Find Custom Headcount\",\n        \"description\": \"Discover the count of employees within a specific company who meet designated criteria. 1 credit per call.\",\n        \"operationId\": \"find_custom_headcount\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-company-jobs-count\": {\n      \"get\": {\n        \"summary\": \"Count  Job Openings\",\n        \"description\": \"Get the number of job openings a company has posted on LinkedIn. 1 credit per call.\",\n        \"operationId\": \"count__job_openings\",\n        \"parameters\": [\n          {\n            \"name\": \"company_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 162479\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/google-profiles\": {\n      \"post\": {\n        \"summary\": \"Google Profiles\",\n        \"description\": \"**2** credits per call.\",\n        \"operationId\": \"google_profiles\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-profile-pdf-cv\": {\n      \"get\": {\n        \"summary\": \"Get Profile PDF CV\",\n        \"description\": \"**1 credit per call.**\",\n        \"operationId\": \"get_profile_pdf_cv\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-opentowork-status\": {\n      \"get\": {\n        \"summary\": \"Get Open to Work Status\",\n        \"description\": \"**1 credit per call.**\",\n        \"operationId\": \"get_open_to_work_status\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-companies\": {\n      \"post\": {\n        \"summary\": \"Search Companies\",\n        \"description\": \"Step 1: Use this endpoint to make a search using your criteria. This endpoint will return a \\\\\",\n        \"operationId\": \"search_companies\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-search-results\": {\n      \"get\": {\n        \"summary\": \"Get Search Results\",\n        \"description\": \"Get search results. Please make sure the search is \\\\\",\n        \"operationId\": \"get_search_results\",\n        \"parameters\": [\n          {\n            \"name\": \"request_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: dd1b29063de8927b31fa523d36432b61\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"page\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 1\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-employees\": {\n      \"post\": {\n        \"summary\": \"Search Leads\",\n        \"description\": \"Find and scrape lead details with advanced filters.\",\n        \"operationId\": \"search_leads\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-posts\": {\n      \"post\": {\n        \"summary\": \"Search Posts\",\n        \"description\": \"2 credits per call.\",\n        \"operationId\": \"search_posts\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-post-reactions\": {\n      \"get\": {\n        \"summary\": \"Get Post's Reactions\",\n        \"description\": \"1 credit per call.\",\n        \"operationId\": \"get_post's_reactions\",\n        \"parameters\": [\n          {\n            \"name\": \"urn\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 7267273010393358336\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"type\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Default value: ALL. Possible values: ALL,LIKE,EMPATHY,APPRECIATION,INTEREST,PRAISE.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"page\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: 1\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-post-comments\": {\n      \"get\": {\n        \"summary\": \"Get Post's Comments\",\n        \"description\": \"1 credit per call.\",\n        \"operationId\": \"get_post's_comments\",\n        \"parameters\": [\n          {\n            \"name\": \"urn\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 7267273010393358336\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"sort_by\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Default value: Most relevant. Possible values: Most relevant, Most recent.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"page\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: 1\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"pagination_token\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: \",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/profile-latest-post-date\": {\n      \"get\": {\n        \"summary\": \"Get Profile Latest Post Date\",\n        \"description\": \"Find out when he/she posted recently.\",\n        \"operationId\": \"get_profile_latest_post_date\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: https://www.linkedin.com/in/ajjames/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-profile-recent-activity-time\": {\n      \"get\": {\n        \"summary\": \"Detect Activity Time\",\n        \"description\": \"Get the time of the latest profile activity. 2 credits per call.\",\n        \"operationId\": \"detect_activity_time\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-decision-makers\": {\n      \"post\": {\n        \"summary\": \"Search Decision Makers\",\n        \"description\": \"Search for decision makers of any company.\",\n        \"operationId\": \"search_decision_makers\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/big-search-employee\": {\n      \"post\": {\n        \"summary\": \"Lead Search at Scale\",\n        \"description\": \"Find and scrape leads at scale\",\n        \"operationId\": \"lead_search_at_scale\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-jobs-v2\": {\n      \"post\": {\n        \"summary\": \"Search Jobs V2\",\n        \"description\": \"Using a simpler payload. 1 credit per call.\",\n        \"operationId\": \"search_jobs_v2\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/check-search-status\": {\n      \"get\": {\n        \"summary\": \"Check Search Status\",\n        \"description\": \"Get the status of your search using the request_id given in step 1.\",\n        \"operationId\": \"check_search_status\",\n        \"parameters\": [\n          {\n            \"name\": \"request_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: dd1b29063de8927b31fa523d36432b61\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-post-details\": {\n      \"get\": {\n        \"summary\": \"Get Post Details\",\n        \"description\": \"Scrape details of a single post based on its URN.\",\n        \"operationId\": \"get_post_details\",\n        \"parameters\": [\n          {\n            \"name\": \"urn\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 7315779816467656705\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-job-details\": {\n      \"get\": {\n        \"summary\": \"Get Job Details\",\n        \"description\": \"Scrape the full job details, including the company basic information. 1 credit per call.\",\n        \"operationId\": \"get_job_details\",\n        \"parameters\": [\n          {\n            \"name\": \"job_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/jobs/view/3766410207/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_skills\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Including skills will cost 1 more credit\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"include_hiring_team\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Including hiring team information will cost 1 more credit\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-company-posts\": {\n      \"get\": {\n        \"summary\": \"Get Company's Posts\",\n        \"description\": \"2 credits per call.\",\n        \"operationId\": \"get_company's_posts\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/company/amazon/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"start\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Use this param to fetch posts of the next result page: 0 for page 1, 50 for page 2, etc.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": \"0\",\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"pagination_token\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Required when fetching the next result page. Please use the token from the result of your previous call.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"sort_by\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Possible values: top, recent\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-search-companies-results\": {\n      \"get\": {\n        \"summary\": \"Get Companies\",\n        \"description\": \"Get search results. Please make sure the search is \\\\\",\n        \"operationId\": \"get_companies\",\n        \"parameters\": [\n          {\n            \"name\": \"request_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: ba072fac0b38d12378ef5023742f0184s34e1i8n2a7p0m9o\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"page\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: 1\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/check-search-companies-status\": {\n      \"get\": {\n        \"summary\": \"Check Company Search Status\",\n        \"description\": \"Get the status of your search using the request_id given in step 1.\",\n        \"operationId\": \"check_company_search_status\",\n        \"parameters\": [\n          {\n            \"name\": \"request_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: ba072fac0b38d12378ef5023742f0184s34e1i8n2a7p0m9o\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-companies-by-sales-nav-url\": {\n      \"post\": {\n        \"summary\": \"Search Companies by SN URL\",\n        \"description\": \"Provide URL instead of filters.\",\n        \"operationId\": \"search_companies_by_sn_url\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-jobs\": {\n      \"post\": {\n        \"summary\": \"Search Jobs\",\n        \"description\": \"To scrape all results from each search, change the parameter \\\\\",\n        \"operationId\": \"search_jobs\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-company-insights\": {\n      \"get\": {\n        \"summary\": \"Get Company Insights\",\n        \"description\": \"5 credits per call.\",\n        \"operationId\": \"get_company_insights\",\n        \"parameters\": [\n          {\n            \"name\": \"company_id\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: 1035\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-profile-posts\": {\n      \"get\": {\n        \"summary\": \"Get Profile's Posts\",\n        \"description\": \"2 credits per call\",\n        \"operationId\": \"get_profile's_posts\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"type\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Possible values: posts: to scrape posts from tab Posts -- posts or posts reshared by the person comments: to scrape posts from tab Comments -- posts the person commented reactions: to scrape posts from tab Reactions -- posts the person reacted\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"start\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Use this param to fetch posts of the next result page: 0 for page 1, 50 for page 2, etc.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": \"0\",\n              \"enum\": null\n            }\n          },\n          {\n            \"name\": \"pagination_token\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Required when fetching the next result page. Please use the token from the result of your previous call.\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-company-by-domain\": {\n      \"get\": {\n        \"summary\": \"Get Company by Domain\",\n        \"description\": \"1 credit per call.\",\n        \"operationId\": \"get_company_by_domain\",\n        \"parameters\": [\n          {\n            \"name\": \"domain\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: apple.com\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/google-schools\": {\n      \"post\": {\n        \"summary\": \"Search Linkedin School Pages via Google\",\n        \"description\": \"Find up to 100 schools that match your criteria via Google. **2** credits per call.\",\n        \"operationId\": \"search_linkedin_school_pages_via_google\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/google-companies\": {\n      \"post\": {\n        \"summary\": \"Search LinkedIn Company Pages via Google\",\n        \"description\": \"Find up to 100 companies that match your criteria via Google. **2** credits per call.\",\n        \"operationId\": \"search_linkedin_company_pages_via_google\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-year-of-experiences\": {\n      \"get\": {\n        \"summary\": \"Get Years of Experience\",\n        \"description\": \"Get the total number of years of experience of a profile.\",\n        \"operationId\": \"get_years_of_experience\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": false,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-recommendations-received\": {\n      \"get\": {\n        \"summary\": \"Get Recommendation Received\",\n        \"description\": \"Get profile’s recommendations (received). **1 credit per call**.\",\n        \"operationId\": \"get_recommendation_received\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/ajjames\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-companies-instantly\": {\n      \"post\": {\n        \"summary\": \"Search Companies Instantly\",\n        \"description\": \"Search companies in our cached database of 64 million records (updated annually). Instant results. Cost: 1 credit for 10 companies (searches returning fewer than 10 results still consume 1 credit).\",\n        \"operationId\": \"search_companies_instantly\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-recommendations-given\": {\n      \"get\": {\n        \"summary\": \"Get Recommendation Given\",\n        \"description\": \"Get profile’s recommendations (given). **1 credit per call**.\",\n        \"operationId\": \"get_recommendation_given\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/ajjames\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/search-employees-by-sales-nav-url\": {\n      \"post\": {\n        \"summary\": \"Search leads V2\",\n        \"description\": \"Provide search url instead of filters\",\n        \"operationId\": \"search_leads_v2\",\n        \"parameters\": [],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-open-profile-status\": {\n      \"get\": {\n        \"summary\": \"Get Open Profile Status\",\n        \"description\": \"**1 credit per call.**\",\n        \"operationId\": \"get_open_profile_status\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/williamhgates/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/get-extra-profile-data\": {\n      \"get\": {\n        \"summary\": \"Get Extra Profile Data\",\n        \"description\": \"Get more profile’s data fields like languages, top skills, certifications, publications, patents, awards\",\n        \"operationId\": \"get_extra_profile_data\",\n        \"parameters\": [\n          {\n            \"name\": \"linkedin_url\",\n            \"in\": \"query\",\n            \"required\": true,\n            \"description\": \"Example value: https://www.linkedin.com/in/ajjames/\",\n            \"schema\": {\n              \"type\": \"string\",\n              \"default\": null,\n              \"enum\": null\n            }\n          }\n        ],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"Successful response\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {}\n              }\n            }\n          }\n        }\n      }\n    }\n  },\n  \"components\": {\n    \"securitySchemes\": {\n      \"ApiAuth\": {\n        \"type\": \"apiKey\",\n        \"in\": \"header\",\n        \"name\": \"X-RapidAPI-Key\"\n      }\n    }\n  },\n  \"security\": [\n    {\n      \"ApiAuth\": []\n    }\n  ]\n}"""

# 创建 HTTP 客户端
# 设置默认 headers
default_headers = {}


# RapidAPI 必需的 headers
if API_KEY:
    default_headers["X-RapidAPI-Key"] = API_KEY
    default_headers["X-RapidAPI-Host"] = "fresh-linkedin-profile-data.p.rapidapi.com"
else:
    print("⚠️  警告: 未设置 API_KEY 环境变量")
    print("   RapidAPI 需要 API Key 才能正常工作")
    print("   请设置: export API_KEY=你的RapidAPI-Key")

# 对于 POST/PUT/PATCH 请求，自动添加 Content-Type
default_headers["Content-Type"] = "application/json"




client = httpx.AsyncClient(
    base_url="https://fresh-linkedin-profile-data.p.rapidapi.com", 
    timeout=30.0
)


# 从 OpenAPI 规范创建 FastMCP 服务器
openapi_dict = json.loads(OPENAPI_SPEC)
mcp = FastMCP.from_openapi(
    openapi_spec=openapi_dict,
    client=client,
    name="fresh_linkedin_profile_data",
    version=__version__
)


# 注册请求拦截器，为所有请求添加 RapidAPI headers
_original_request = client.request

async def _add_rapidapi_headers(method, url, **kwargs):
    """拦截所有请求，添加必需的 RapidAPI headers"""
    # 确保 headers 存在
    if 'headers' not in kwargs:
        kwargs['headers'] = {}
    
    # 添加 RapidAPI 必需的 headers
    if API_KEY:
        kwargs['headers']['X-RapidAPI-Key'] = API_KEY
        kwargs['headers']['X-RapidAPI-Host'] = "fresh-linkedin-profile-data.p.rapidapi.com"
    else:
        print("⚠️  警告: API_KEY 未设置，请求可能失败")
    
    # 对于 POST/PUT/PATCH，添加 Content-Type
    if method.upper() in ['POST', 'PUT', 'PATCH']:
        if 'Content-Type' not in kwargs['headers']:
            kwargs['headers']['Content-Type'] = 'application/json'
    
    return await _original_request(method, url, **kwargs)

# 替换 request 方法
client.request = _add_rapidapi_headers


def main():
    """主入口点"""
    print(f"🚀 启动 Fresh Linkedin Profile Data MCP 服务器")
    print(f"📦 版本: {__tag__}")
    print(f"🔧 传输协议: {TRANSPORT}")
    
    print()
    
    # 运行服务器
    
    mcp.run(transport="stdio")
    


if __name__ == "__main__":
    main()