list_publications
Retrieve all accessible publications using the API key to manage or analyze content within the Beehiiv platform.
Instructions
List all publications accessible with this API key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- beehiiv_server.py:51-60 (handler)The handler function for the 'list_publications' tool, decorated with @mcp.tool() for registration. It fetches and formats the list of publications from the Beehiiv API.
@mcp.tool() async def list_publications() -> str: """ List all publications accessible with this API key. """ data = await beehiiv_request("GET", "/publications") if not data or "data" not in data: return "Failed to fetch publications." pubs = data["data"] return "\n".join(f"{p['id']}: {p['name']}" for p in pubs) - beehiiv_server.py:17-50 (helper)Supporting helper utility 'beehiiv_request' used by the list_publications handler to perform authenticated HTTP requests to the Beehiiv API.
async def beehiiv_request( method: str, path: str, params: Optional[dict[str, Any]] = None, json_body: Optional[dict[str, Any]] = None ) -> Optional[dict[str, Any]]: """ Helper to call the beehiiv API v2. Args: method: HTTP method (GET, POST, etc.) path: API path (e.g. '/publications') params: Query parameters json_body: Request JSON body """ headers = { "Authorization": f"Bearer {BEEHIIV_API_KEY}", "Content-Type": "application/json" } url = f"{BASE_URL}{path}" async with httpx.AsyncClient() as client: try: response = await client.request( method, url, headers=headers, params=params, json=json_body, timeout=30.0 ) response.raise_for_status() return response.json() except httpx.HTTPError as e: return {"error": str(e)}