mirror of
https://github.com/jlengrand/ghost-mcp.git
synced 2026-03-10 08:21:19 +00:00
✨ Support deleting post
This commit is contained in:
@@ -94,6 +94,10 @@ async def make_ghost_request(
|
||||
response = await client.put(url, headers=headers, json=json_data)
|
||||
elif http_method == "POST":
|
||||
response = await client.post(url, headers=headers, json=json_data)
|
||||
elif http_method == "DELETE":
|
||||
response = await client.delete(url, headers=headers)
|
||||
if response.status_code == 204: # Success with no content
|
||||
return {} # Return empty dict for successful delete
|
||||
else: # Default to GET
|
||||
response = await client.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
@@ -41,12 +41,12 @@ def create_server() -> FastMCP:
|
||||
mcp.resource("post://{post_id}")(resources.handle_post_resource)
|
||||
mcp.resource("blog://info")(resources.handle_blog_info)
|
||||
|
||||
# Register tools with preprocessing for create_post
|
||||
mcp.tool()(tools.search_posts_by_title)
|
||||
mcp.tool()(tools.list_posts)
|
||||
mcp.tool()(tools.read_post)
|
||||
mcp.tool()(tools.update_post)
|
||||
mcp.tool()(tools.create_post)
|
||||
mcp.tool()(tools.search_posts_by_title)
|
||||
mcp.tool()(tools.update_post)
|
||||
mcp.tool()(tools.delete_post)
|
||||
mcp.tool()(tools.list_users)
|
||||
mcp.tool()(tools.read_user)
|
||||
mcp.tool()(tools.list_members)
|
||||
|
||||
@@ -1076,6 +1076,57 @@ Updated At: {post.get('updated_at', 'Unknown')}
|
||||
ctx.error(f"Failed to update post: {str(e)}")
|
||||
return str(e)
|
||||
|
||||
async def delete_post(post_id: str, ctx: Context = None) -> str:
|
||||
"""Delete a blog post.
|
||||
|
||||
Args:
|
||||
post_id: The ID of the post to delete
|
||||
ctx: Optional context for logging
|
||||
|
||||
Returns:
|
||||
Success message if post was deleted
|
||||
|
||||
Raises:
|
||||
GhostError: If there is an error accessing the Ghost API or the post doesn't exist
|
||||
"""
|
||||
if ctx:
|
||||
ctx.info(f"Deleting post with ID: {post_id}")
|
||||
|
||||
try:
|
||||
if ctx:
|
||||
ctx.debug("Getting auth headers")
|
||||
headers = await get_auth_headers(STAFF_API_KEY)
|
||||
|
||||
# First verify the post exists
|
||||
if ctx:
|
||||
ctx.debug(f"Verifying post exists: {post_id}")
|
||||
try:
|
||||
await make_ghost_request(f"posts/{post_id}/", headers, ctx)
|
||||
except GhostError as e:
|
||||
if "404" in str(e):
|
||||
error_msg = f"Post with ID {post_id} not found"
|
||||
if ctx:
|
||||
ctx.error(error_msg)
|
||||
return error_msg
|
||||
raise
|
||||
|
||||
# Make the delete request
|
||||
if ctx:
|
||||
ctx.debug(f"Deleting post: {post_id}")
|
||||
await make_ghost_request(
|
||||
f"posts/{post_id}/",
|
||||
headers,
|
||||
ctx,
|
||||
http_method="DELETE"
|
||||
)
|
||||
|
||||
return f"Successfully deleted post with ID: {post_id}"
|
||||
|
||||
except GhostError as e:
|
||||
if ctx:
|
||||
ctx.error(f"Failed to delete post: {str(e)}")
|
||||
return str(e)
|
||||
|
||||
async def search_posts_by_title(query: str, exact: bool = False, ctx: Context = None) -> str:
|
||||
"""Search for posts by title.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user