Skip to main content
Glama

get_chatgpt_response_tool

Retrieve responses from ChatGPT after submitting prompts via the ChatGPT MCP Server, enabling AI assistants to interact with the ChatGPT desktop app on macOS.

Instructions

Get the latest response from ChatGPT after sending a message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The @mcp.tool()-decorated handler function implementing the logic for get_chatgpt_response_tool by delegating to get_chatgpt_response().
    @mcp.tool() async def get_chatgpt_response_tool() -> str: """Get the latest response from ChatGPT after sending a message.""" return await get_chatgpt_response()
  • Invokes setup_mcp_tools to register all MCP tools, including get_chatgpt_response_tool.
    # Setup MCP tools setup_mcp_tools(mcp)
  • Helper function containing the core logic: waits for response completion via polling and retrieves conversation text, called by the tool handler.
    async def get_chatgpt_response() -> str: """Get the latest response from ChatGPT after sending a message. Returns: ChatGPT's latest response text """ try: # Wait for response to complete if wait_for_response_completion(): return get_current_conversation_text() else: return "Timeout: ChatGPT response did not complete within the time limit." except Exception as e: raise Exception(f"Failed to get response from ChatGPT: {str(e)}")
  • Polling helper that repeatedly checks if conversation is complete using is_conversation_complete() until timeout.
    def wait_for_response_completion(max_wait_time: int = 300, check_interval: float = 2) -> bool: """Wait for ChatGPT response to complete. Args: max_wait_time: Maximum time to wait in seconds check_interval: How often to check for completion in seconds Returns: True if response completed within time limit, False if timed out """ start_time = time.time() while time.time() - start_time < max_wait_time: if is_conversation_complete(): return True time.sleep(check_interval) return False
  • Checks screen content via ChatGPTAutomation.read_screen_content() for conversationComplete indicator to determine if response is done.
    def is_conversation_complete() -> bool: """Check if ChatGPT conversation is complete using external AppleScript. Returns: True if conversation is complete, False if still in progress """ try: automation = ChatGPTAutomation() screen_data = automation.read_screen_content() if screen_data.get("status") == "success": indicators = screen_data.get("indicators", {}) # Simple check: only use conversationComplete indicator result = indicators.get("conversationComplete", False) print(f"[DEBUG] is_conversation_complete: {result}, indicators: {indicators}") return result else: print(f"[DEBUG] Screen read failed: {screen_data}") # If we can't read the screen, assume not complete for safety return False except Exception as e: print(f"[DEBUG] Exception in is_conversation_complete: {e}") # If any error occurs, assume not complete for safety return False

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xncbf/chatgpt-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server