"""
Details tools for ThePornDB MCP Service.
Provides functionality for retrieving detailed content information.
"""
import logging
from mcp.server.fastmcp import Context
from mcp.server.session import ServerSession
from mcp.types import CallToolResult, TextContent
from ..models import MediaData, DetailResponse
from ..api import ThePornDBAPI
logger = logging.getLogger(__name__)
async def get_content_details(
content_id: str,
content_type: str,
ctx: Context[ServerSession, None] = None
):
"""
Get complete details for a specific content item by ID.
Args:
content_id: Unique content identifier
content_type: Content type ("scene", "movie", or "jav")
ctx: MCP context (injected automatically)
Returns:
MediaData with complete content details
Raises:
CallToolResult: With error if validation fails or content not found
"""
# Input validation
if not content_id or not content_id.strip():
return CallToolResult(
content=[TextContent(
type="text",
text="Error: Content ID cannot be empty. Please provide a valid content ID."
)],
isError=True
)
# Content type validation
valid_types = ["scene", "movie", "jav"]
if content_type not in valid_types:
return CallToolResult(
content=[TextContent(
type="text",
text=f"Error: Content type must be one of: {', '.join(valid_types)}"
)],
isError=True
)
# Get API client from context
if ctx and hasattr(ctx, 'request_context'):
api = ctx.request_context.lifespan_context.api
else:
return CallToolResult(
content=[TextContent(
type="text",
text="Error: Server context not available"
)],
isError=True
)
await ctx.info(f"Fetching details for {content_type}/{content_id}")
try:
# Call API
result = api.fetch_data(content_id, content_type)
if result is None:
return CallToolResult(
content=[TextContent(
type="text",
text=f"Error: Content not found. The {content_type} with ID '{content_id}' does not exist."
)],
isError=True
)
await ctx.info(f"Successfully retrieved details for {content_type}/{content_id}")
return result
except Exception as e:
logger.error(f"Error fetching content details: {e}")
return CallToolResult(
content=[TextContent(
type="text",
text=f"Error: Failed to fetch content details - {str(e)}"
)],
isError=True
)