mirror of
https://github.com/jlengrand/ghost-mcp.git
synced 2026-03-10 08:21:19 +00:00
✨ Support creating invites
This commit is contained in:
@@ -81,6 +81,7 @@ GHOST_API_URL=your_ghost_api_url GHOST_STAFF_API_KEY=your_staff_api_key npx @mod
|
||||
|
||||
### Users Management
|
||||
- `list_roles`: List all available roles
|
||||
- `create_invite`: Create a new user invitation email and role_id
|
||||
- `list_users`: List all users with detailed role information
|
||||
- `read_user`: Get comprehensive details of a specific user
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ def create_server() -> FastMCP:
|
||||
mcp.tool()(tools.create_newsletter)
|
||||
mcp.tool()(tools.update_newsletter)
|
||||
mcp.tool()(tools.list_roles)
|
||||
mcp.tool()(tools.create_invite)
|
||||
|
||||
# Register prompts
|
||||
@mcp.prompt()
|
||||
|
||||
@@ -38,6 +38,7 @@ from .tools.newsletters import (
|
||||
update_newsletter
|
||||
)
|
||||
from .tools.roles import list_roles
|
||||
from .tools.invites import create_invite
|
||||
|
||||
__all__ = [
|
||||
'search_posts_by_title',
|
||||
@@ -63,5 +64,6 @@ __all__ = [
|
||||
'read_newsletter',
|
||||
'create_newsletter',
|
||||
'update_newsletter',
|
||||
'list_roles'
|
||||
'list_roles',
|
||||
'create_invite'
|
||||
]
|
||||
|
||||
@@ -7,6 +7,7 @@ from .tiers import list_tiers, read_tier, create_tier, update_tier
|
||||
from .offers import list_offers, read_offer, create_offer, update_offer
|
||||
from .newsletters import list_newsletters, read_newsletter, create_newsletter, update_newsletter
|
||||
from .roles import list_roles
|
||||
from .invites import create_invite
|
||||
|
||||
__all__ = [
|
||||
'search_posts_by_title',
|
||||
@@ -33,5 +34,6 @@ __all__ = [
|
||||
'read_newsletter',
|
||||
'create_newsletter',
|
||||
'update_newsletter',
|
||||
'list_roles'
|
||||
'list_roles',
|
||||
'create_invite'
|
||||
]
|
||||
|
||||
75
src/ghost_mcp/tools/invites.py
Normal file
75
src/ghost_mcp/tools/invites.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Invite-related MCP tools for Ghost API."""
|
||||
|
||||
import json
|
||||
from mcp.server.fastmcp import Context
|
||||
|
||||
from ..api import make_ghost_request, get_auth_headers
|
||||
from ..config import STAFF_API_KEY
|
||||
from ..exceptions import GhostError
|
||||
|
||||
async def create_invite(
|
||||
role_id: str,
|
||||
email: str,
|
||||
ctx: Context = None
|
||||
) -> str:
|
||||
"""Create a staff user invite in Ghost.
|
||||
|
||||
Args:
|
||||
role_id: ID of the role to assign to the invited user (required)
|
||||
email: Email address to send the invite to (required)
|
||||
ctx: Optional context for logging
|
||||
|
||||
Returns:
|
||||
String representation of the created invite
|
||||
|
||||
Raises:
|
||||
GhostError: If the Ghost API request fails
|
||||
ValueError: If required parameters are missing or invalid
|
||||
"""
|
||||
if not all([role_id, email]):
|
||||
raise ValueError("Both role_id and email are required for creating an invite")
|
||||
|
||||
if ctx:
|
||||
ctx.info(f"Creating invite for email: {email} with role: {role_id}")
|
||||
|
||||
# Construct invite data
|
||||
invite_data = {
|
||||
"invites": [{
|
||||
"role_id": role_id,
|
||||
"email": email
|
||||
}]
|
||||
}
|
||||
|
||||
try:
|
||||
if ctx:
|
||||
ctx.debug("Getting auth headers")
|
||||
headers = await get_auth_headers(STAFF_API_KEY)
|
||||
|
||||
if ctx:
|
||||
ctx.debug("Making API request to create invite")
|
||||
response = await make_ghost_request(
|
||||
"invites/",
|
||||
headers,
|
||||
ctx,
|
||||
http_method="POST",
|
||||
json_data=invite_data
|
||||
)
|
||||
|
||||
if ctx:
|
||||
ctx.debug("Processing created invite response")
|
||||
|
||||
invite = response.get("invites", [{}])[0]
|
||||
|
||||
return f"""
|
||||
Invite created successfully:
|
||||
Email: {invite.get('email')}
|
||||
Role ID: {invite.get('role_id')}
|
||||
Status: {invite.get('status', 'sent')}
|
||||
Created: {invite.get('created_at', 'Unknown')}
|
||||
Expires: {invite.get('expires', 'Unknown')}
|
||||
ID: {invite.get('id')}
|
||||
"""
|
||||
except Exception as e:
|
||||
if ctx:
|
||||
ctx.error(f"Failed to create invite: {str(e)}")
|
||||
raise
|
||||
Reference in New Issue
Block a user