zendesk_preview_macro
Preview macro effects on tickets without applying changes. See the result payload from Zendesk before committing.
Instructions
Preview the effect a macro would have (without applying it). Returns the result payload from Zendesk's apply preview endpoint.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| macro_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/zendesk_mcp/tools/macros.py:109-111 (handler)The tool handler function decorated with @mcp.tool(). Calls _preview_macro_data(macro_id) to preview macro effects via Zendesk API.
def zendesk_preview_macro(macro_id: int) -> str: """Preview the effect a macro would have (without applying it). Returns the result payload from Zendesk's apply preview endpoint.""" return _preview_macro_data(macro_id) - src/zendesk_mcp/tools/macros.py:102-102 (registration)The registration function register_macro_tools(mcp) that uses the @mcp.tool() decorator to register zendesk_preview_macro as an MCP tool.
def register_macro_tools(mcp) -> None: - src/zendesk_mcp/server.py:46-46 (registration)Where register_macro_tools(mcp) is called in the server main() function to register all macro tools including zendesk_preview_macro.
register_macro_tools(mcp) - The helper function _preview_macro_data(macro_id) that performs the actual HTTP call to Zendesk's /api/v2/macros/{id}/apply.json endpoint to preview macro effects.
def _preview_macro_data(macro_id: int) -> str: try: subdomain, token = get_oauth_session() except ConfigError as e: return str(e) url = f"https://{subdomain}.zendesk.com/api/v2/macros/{macro_id}/apply.json" try: response = httpx.get(url, headers={"Authorization": f"Bearer {token}"}, timeout=30) response.raise_for_status() return json.dumps(response.json().get("result", {}), indent=2) except Exception as e: if "404" in str(e): return f"Macro #{macro_id} not found or not accessible with current credentials." return f"Zendesk API error: {e}" - src/zendesk_mcp/client.py:19-26 (helper)Helper get_oauth_session() used by _preview_macro_data to retrieve subdomain and oauth token for the API request.
def get_oauth_session() -> tuple[str, str]: """Return (subdomain, oauth_token) for direct API calls. Raises ConfigError if unconfigured.""" cfg = load_config() subdomain = cfg.get("subdomain", "").strip() token = cfg.get("oauth_token", "").strip() if not subdomain or not token: raise ConfigError("Zendesk not configured. Run: zendesk-mcp setup") return subdomain, token