Skip to main content
Glama

get_post

Retrieve a specific post by its ID from a Beehiiv publication using the MCP server, enabling structured access to content via the Beehiiv API v2. Input includes publication_id and post_id for precise data fetching.

Instructions

Retrieve a single post by ID.

Args:
    publication_id: ID of the publication
    post_id:        ID of the post

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYes
publication_idYes

Implementation Reference

  • The main handler function for the 'get_post' tool. It is decorated with @mcp.tool() for registration, fetches post data from the Beehiiv API using the helper function, and returns a formatted string with title, subtitle, URL, status, and authors.
    @mcp.tool()
    async def get_post(publication_id: str, post_id: str) -> str:
        """
        Retrieve a single post by ID.
    
        Args:
            publication_id: ID of the publication
            post_id:        ID of the post
        """
        path = f"/publications/{publication_id}/posts/{post_id}"
        data = await beehiiv_request("GET", path)
        if not data or "data" not in data:
            return "Failed to fetch the post."
        post = data["data"]
        return (
            f"Title: {post.get('title')}\n"
            f"Subtitle: {post.get('subtitle')}\n"
            f"URL: {post.get('web_url')}\n"
            f"Status: {post.get('status')}\n"
            f"Authors: {post.get('authors')}"
        )
  • Supporting utility function 'beehiiv_request' used by the get_post handler to make 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)}
  • The @mcp.tool() decorator registers the get_post function as an MCP tool.
    @mcp.tool()
Install Server

Other Tools

Related Tools

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/reymerekar7/beehiiv-mcp-server'

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