Skip to main content
Glama

get_post_content

Extract a post's content, including title, subtitle, and HTML template, as JSON for easy reuse. Specify the post and publication IDs to retrieve structured data via the Beehiiv API.

Instructions

Retrieve a post's content as JSON to use as a template.

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

Returns:
    dict: JSON object containing post title, subtitle, and HTML content template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYes
publication_idYes

Implementation Reference

  • The main handler function for the 'get_post_content' tool. It fetches the post content from the Beehiiv API using the provided publication_id and post_id, extracts title, subtitle, content_structure, and HTML template from the free web content, and returns them as a dictionary. Uses the beehiiv_request helper.
    @mcp.tool()
    async def get_post_content(publication_id: str, post_id: str) -> dict:
        """
        Retrieve a post's content as JSON to use as a template.
    
        Args:
            publication_id: ID of the publication
            post_id: ID of the post
        
        Returns:
            dict: JSON object containing post title, subtitle, and HTML content template
        """
        path = f"/publications/{publication_id}/posts/{post_id}"
        params = {
            "expand[]": "free_web_content"
        }
        
        data = await beehiiv_request("GET", path, params=params)
        
        if not data or "data" not in data:
            return {"error": "Failed to fetch the post."}
        
        post = data["data"]
        content = post.get("content", {})
        free_content = content.get("free", {})
        
        return {
            "title": post.get("title"),
            "subtitle": post.get("subtitle"),
            "content_structure": post.get("content_structure"),
            "html_template": free_content.get("web")
        }
  • The @mcp.tool() decorator registers the get_post_content function as an MCP tool.
    @mcp.tool()
  • Helper function used by get_post_content to make authenticated API requests to Beehiiv.
    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)}
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