Skip to main content
Glama
web_context.py1.09 kB
from dotenv import load_dotenv import httpx import json import os from bs4 import BeautifulSoup load_dotenv() USER_AGENT = "docs-app/1.0" SERPER_URL="https://google.serper.dev/search" async def search_web(query: str) -> dict | None: payload = json.dumps({"q": query, "num": 2}) headers = { "X-API-KEY": os.getenv("SERPER_API_KEY"), "Content-Type": "application/json", } async with httpx.AsyncClient() as client: try: response = await client.post( SERPER_URL, headers=headers, data=payload, timeout=30.0 ) response.raise_for_status() return response.json() except httpx.TimeoutException: return {"organic": []} async def fetch_url(url: str): async with httpx.AsyncClient() as client: try: response = await client.get(url, timeout=30.0) soup = BeautifulSoup(response.text, "html.parser") text = soup.get_text() return text except httpx.TimeoutException: return "Timeout error"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/joaowinderfeldbussolotto/MCP-Websearch-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server