mirror of
https://github.com/jlengrand/ghost-mcp.git
synced 2026-03-10 00:11:21 +00:00
✨ Support deleting users
This commit is contained in:
@@ -82,9 +82,10 @@ 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
|
||||
- `update_user`: Update an existing user's information **(Please note: Ghost has not implemented the ability to update user roles via the API even though they include it in the API documentation)**
|
||||
- `list_users`: List all users with detailed role information
|
||||
- `read_user`: Get comprehensive details of a specific user
|
||||
- `update_user`: Update an existing user's information **(Please note: Ghost has not implemented the ability to update user roles via the API even though they include it in the API documentation)**
|
||||
- `delete_user`: Delete a specific user
|
||||
|
||||
### Members Management
|
||||
- `list_members`: List members with subscription and newsletter details
|
||||
|
||||
@@ -72,6 +72,70 @@ ID: {user.get('id', 'Unknown')}
|
||||
ctx.error(f"Failed to list users: {str(e)}")
|
||||
return str(e)
|
||||
|
||||
async def delete_user(
|
||||
user_id: str,
|
||||
ctx: Context = None
|
||||
) -> str:
|
||||
"""Delete a user from Ghost.
|
||||
|
||||
Args:
|
||||
user_id: ID of the user to delete (required)
|
||||
ctx: Optional context for logging
|
||||
|
||||
Returns:
|
||||
Success message if deletion was successful
|
||||
|
||||
Raises:
|
||||
GhostError: If the Ghost API request fails or if attempting to delete the Owner
|
||||
ValueError: If user_id is not provided
|
||||
"""
|
||||
if not user_id:
|
||||
raise ValueError("user_id is required")
|
||||
|
||||
if ctx:
|
||||
ctx.info(f"Attempting to delete user with ID: {user_id}")
|
||||
|
||||
try:
|
||||
# First get the user to check if they are the Owner
|
||||
if ctx:
|
||||
ctx.debug("Getting user details to check role")
|
||||
headers = await get_auth_headers(STAFF_API_KEY)
|
||||
|
||||
user_data = await make_ghost_request(
|
||||
f"users/{user_id}/",
|
||||
headers,
|
||||
ctx
|
||||
)
|
||||
|
||||
user = user_data.get("users", [{}])[0]
|
||||
roles = [role.get('name') for role in user.get('roles', [])]
|
||||
|
||||
if 'Owner' in roles:
|
||||
error_msg = "Cannot delete the Owner user"
|
||||
if ctx:
|
||||
ctx.error(error_msg)
|
||||
raise GhostError(error_msg)
|
||||
|
||||
# Proceed with deletion
|
||||
if ctx:
|
||||
ctx.debug(f"Making API request to delete user {user_id}")
|
||||
response = await make_ghost_request(
|
||||
f"users/{user_id}/",
|
||||
headers,
|
||||
ctx,
|
||||
http_method="DELETE"
|
||||
)
|
||||
|
||||
return f"""
|
||||
Successfully deleted user:
|
||||
Name: {user.get('name', 'Unknown')}
|
||||
Email: {user.get('email', 'Unknown')}
|
||||
"""
|
||||
except Exception as e:
|
||||
if ctx:
|
||||
ctx.error(f"Failed to delete user: {str(e)}")
|
||||
raise
|
||||
|
||||
async def update_user(
|
||||
user_id: str,
|
||||
name: str = None,
|
||||
|
||||
Reference in New Issue
Block a user