We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/subslink326/job-url-analyzer-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
"""LinkedIn enrichment provider."""
import asyncio
import time
from typing import Dict, Any, Optional
import httpx
from opentelemetry import trace
from .base import EnrichmentProvider, EnrichmentResult
from ..config import get_settings
from ..metrics import (
ENRICHMENT_PROVIDER_SUCCESS,
ENRICHMENT_PROVIDER_ERROR,
ENRICHMENT_PROVIDER_DURATION,
)
settings = get_settings()
class LinkedInProvider(EnrichmentProvider):
"""Enrichment provider using LinkedIn API (mock implementation)."""
def __init__(self):
super().__init__("linkedin", enabled=settings.ENABLE_LINKEDIN)
self.api_key = settings.LINKEDIN_API_KEY
# Note: This is a mock implementation since LinkedIn's API
# has strict terms of service regarding automated access
def can_enrich(self, company_data: Dict[str, Any]) -> bool:
"""Check if we have enough data to search LinkedIn."""
if not self.enabled or not self.api_key:
return False
# Need company name or LinkedIn URL
return bool(
company_data.get("name") or
company_data.get("linkedin_url")
)
async def enrich(self, company_data: Dict[str, Any]) -> EnrichmentResult:
"""Mock LinkedIn enrichment."""
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("linkedin_enrich") as span:
start_time = time.time()
# Mock delay to simulate API call
await asyncio.sleep(0.5)
try:
# Mock enriched data
enriched_data = await self._mock_linkedin_data(company_data)
processing_time_ms = int((time.time() - start_time) * 1000)
confidence_score = self._calculate_confidence(company_data, enriched_data)
ENRICHMENT_PROVIDER_SUCCESS.labels(provider=self.name).inc()
ENRICHMENT_PROVIDER_DURATION.labels(provider=self.name).observe(
(time.time() - start_time)
)
span.set_attribute("success", True)
span.set_attribute("confidence_score", confidence_score)
self.logger.info(
"LinkedIn enrichment completed (mock)",
company_name=company_data.get("name"),
enriched_fields=len(enriched_data),
)
return EnrichmentResult(
provider_name=self.name,
success=True,
data=enriched_data,
confidence_score=confidence_score,
processing_time_ms=processing_time_ms,
)
except Exception as e:
processing_time_ms = int((time.time() - start_time) * 1000)
ENRICHMENT_PROVIDER_ERROR.labels(provider=self.name).inc()
span.set_attribute("success", False)
span.set_attribute("error", str(e))
return EnrichmentResult(
provider_name=self.name,
success=False,
data={},
error_message=str(e),
processing_time_ms=processing_time_ms,
)
async def _mock_linkedin_data(self, company_data: Dict[str, Any]) -> Dict[str, Any]:
"""Generate mock LinkedIn data for testing."""
# In a real implementation, this would make actual LinkedIn API calls
# following their terms of service and rate limits
mock_data = {}
# Mock some additional company details that LinkedIn might provide
if company_data.get("name"):
company_name = company_data["name"]
# Mock LinkedIn URL if not present
if not company_data.get("linkedin_url"):
mock_data["linkedin_url"] = f"https://linkedin.com/company/{company_name.lower().replace(' ', '-')}"
# Mock employee count if not present
if not company_data.get("employee_count"):
mock_data["employee_count_range"] = "201-500"
# Mock industry if not present
if not company_data.get("industry"):
mock_data["industry"] = "Technology"
return mock_data