twist_inbox_get_count
Retrieve the count of unread messages in a Twist workspace inbox for the authenticated user, enabling efficient inbox management.
Instructions
Gets inbox count in a workspace for the authenticated user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/inbox.py:173-200 (handler)The handler function that executes the tool logic: retrieves the Twist token from context, fetches workspace ID from env, calls twist_request to the 'inbox/get_count' API endpoint, and returns the count data or error message.def twist_inbox_get_count( ctx: Context ) -> Union[str, dict]: """Gets inbox count in a workspace for the authenticated user. """ token = ctx.request_context.lifespan_context.twist_token workspace_id = os.getenv("TWIST_WORKSPACE_ID") if not workspace_id: logger.error("TWIST_WORKSPACE_ID environment variable is required") return "Error: TWIST_WORKSPACE_ID environment variable is required" params = {"workspace_id": workspace_id} try: logger.info(f"Getting inbox count for workspace ID: {workspace_id}") count_data = twist_request("inbox/get_count", params=params, token=token) if not count_data: logger.info("Failed to get inbox count") return "Failed to get inbox count" logger.info(f"Retrieved inbox count: {count_data}") return count_data except Exception as error: logger.error(f"Error getting inbox count: {error}") return f"Error getting inbox count: {str(error)}"
- main.py:42-48 (registration)Registers all functions starting with 'twist_' from src.inbox and src.threads modules as MCP tools using FastMCP's tool decorator, including twist_inbox_get_count.# Register all tools from tool modules for module in [src.inbox, src.threads]: for name, func in inspect.getmembers(module, inspect.isfunction): if name.startswith('twist_') and func.__module__ == module.__name__: logger.info(f"Registering tool: {name}") mcp.tool()(func)
- src/api.py:28-64 (helper)Helper function used by the handler to make authenticated HTTP requests to the Twist API, specifically called with 'inbox/get_count' endpoint.def twist_request(endpoint, params=None, token=None, method="GET"): """ Make an API request to Twist. Args: endpoint (str): API endpoint to call (without the base URL) params (dict, optional): Dictionary of parameters to include in the request token (str, optional): Authentication token (if None, uses the one from get_api_client) method (str, optional): HTTP method to use (default: "GET") Returns: dict: Response data as a dictionary Raises: Exception: If the API request fails """ if token is None: token = get_api_client() base_url = "https://api.twist.com/api/v3/" headers = {"Authorization": f"Bearer {token}"} url = f"{base_url}{endpoint}" try: if method == "GET": response = requests.get(url, params=params, headers=headers) elif method == "POST": response = requests.post(url, data=params, headers=headers) else: raise ValueError(f"Unsupported HTTP method: {method}") response.raise_for_status() # Raise an exception for 4XX/5XX responses return response.json() except requests.exceptions.RequestException as e: logger.error(f"Twist API request failed: {e}") raise