get_available_templates
Retrieve a list of all available presentation templates to choose from when creating a new slideshow.
Instructions
Get all available presentation templates.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- slidespeak.py:81-105 (handler)The main handler function for the 'get_available_templates' tool. Decorated with @mcp.tool(), it fetches available presentation templates from the /presentation/templates API endpoint and formats them into a readable string.
@mcp.tool() async def get_available_templates() -> str: """Get all available presentation templates.""" templates_endpoint = "/presentation/templates" if not API_KEY: return "API Key is missing. Cannot process any requests." templates_data = await _make_api_request("GET", templates_endpoint) if not templates_data: return "Unable to fetch templates due to an API error. Check server logs." if not isinstance(templates_data, list): return f"Unexpected response format received for templates: {type(templates_data).__name__}" formatted_templates = "Available templates:\n" for template in templates_data: name = template.get("name", "default") images = template.get("images", {}) cover = images.get("cover", "No cover image URL") content = images.get("content", "No content image URL") formatted_templates += f"- {name}\n Cover: {cover}\n Content: {content}\n\n" return formatted_templates.strip() - slidespeak.py:81-81 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 81, automatically registering it with the FastMCP server instance named 'mcp'.
@mcp.tool() - slidespeak.py:28-78 (helper)The _make_api_request helper function used by get_available_templates to make the GET request to the /presentation/templates endpoint. Handles HTTP calls, logging, and error handling.
async def _make_api_request( method: Literal["GET", "POST"], endpoint: str, payload: Optional[dict[str, Any]] = None, timeout: float = DEFAULT_TIMEOUT ) -> Optional[dict[str, Any]]: """ Makes an HTTP request to the SlideSpeak API. Args: method: HTTP method ('GET' or 'POST'). endpoint: API endpoint path (e.g., '/presentation/templates'). payload: JSON payload for POST requests. Ignored for GET. timeout: Request timeout in seconds. Returns: The parsed JSON response as a dictionary on success, None on failure. """ if not API_KEY: logging.error("API Key is missing. Cannot make API request.") return None headers = { "User-Agent": USER_AGENT, "Accept": "application/json", "X-API-Key": API_KEY, } url = f"{API_BASE}{endpoint}" req_start = time.time() async with httpx.AsyncClient() as client: try: if method == "POST": response = await client.post(url, json=payload, headers=headers, timeout=timeout) else: response = await client.get(url, headers=headers, timeout=timeout) elapsed = time.time() - req_start logging.info(f"{method} {url} | status={response.status_code} | elapsed={elapsed:.2f}s") response.raise_for_status() return response.json() except httpx.HTTPStatusError as e: logging.error(f"HTTP error {method} {url}: {e.response.status_code} - {e.response.text}") except httpx.RequestError as e: logging.error(f"Request error {method} {url}: {str(e)}") except Exception as e: logging.error(f"Unexpected error {method} {url}: {str(e)}") return None