ask_chatgpt_tool
Send prompts to ChatGPT via the MCP server to receive AI-generated responses, enabling integration with MCP-compatible assistants for dynamic interactions.
Instructions
Send a prompt to ChatGPT and return the response.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes |
Implementation Reference
- chatgpt_mcp/mcp_tools.py:151-154 (handler)The handler function for the 'ask_chatgpt_tool' MCP tool. It is decorated with @mcp.tool() which registers it with the FastMCP server and delegates the logic to the ask_chatgpt helper function.@mcp.tool() async def ask_chatgpt_tool(prompt: str) -> str: """Send a prompt to ChatGPT and return the response.""" return await ask_chatgpt(prompt)
- chatgpt_mcp/mcp_tools.py:91-116 (helper)The core helper function that implements the logic for sending a prompt to ChatGPT via AppleScript automation on macOS, cleaning the prompt, activating the app, sending keystrokes, waiting for response, and retrieving it.async def ask_chatgpt(prompt: str) -> str: """Send a prompt to ChatGPT and return the response. Args: prompt: The text to send to ChatGPT Returns: ChatGPT's response """ await check_chatgpt_access() try: # 프롬프트에서 개행 문자 제거 및 더블쿼츠를 싱글쿼츠로 변경 cleaned_prompt = prompt.replace('\n', ' ').replace('\r', ' ').replace('"', "'").strip() # Activate ChatGPT and send message using keystroke automation = ChatGPTAutomation() automation.activate_chatgpt() automation.send_message_with_keystroke(cleaned_prompt) # Get the response response = await get_chatgpt_response() return response except Exception as e: raise Exception(f"Failed to send message to ChatGPT: {str(e)}")
- chatgpt_mcp/chatgpt_mcp.py:5-8 (registration)The FastMCP server instance is created and setup_mcp_tools is called to register all tools, including ask_chatgpt_tool.mcp = FastMCP("chatgpt") # Setup MCP tools setup_mcp_tools(mcp)