Skip to main content
Glama

ask_chatgpt_tool

Send a prompt to ChatGPT and receive the AI-generated reply. This tool lets MCP-compatible assistants access ChatGPT.

Instructions

Send a prompt to ChatGPT and return the response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes

Implementation Reference

  • Core logic handler for 'ask_chatgpt_tool'. Cleans the prompt, activates ChatGPT, sends the message via keystroke, and awaits the response.
    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)}")
  • The MCP tool function 'ask_chatgpt_tool' defined as an async function that delegates to ask_chatgpt() with the provided prompt string.
    async def ask_chatgpt_tool(prompt: str) -> str:
        """Send a prompt to ChatGPT and return the response."""
        return await ask_chatgpt(prompt)
  • Registration point: @mcp.tool() decorator registers 'ask_chatgpt_tool' within setup_mcp_tools() called from the main entry point.
    def setup_mcp_tools(mcp: FastMCP):
        """MCP 도구들을 설정"""
        
        @mcp.tool()
        async def ask_chatgpt_tool(prompt: str) -> str:
            """Send a prompt to ChatGPT and return the response."""
            return await ask_chatgpt(prompt)
  • Helper function send_message_with_keystroke that types the prompt into the ChatGPT app using AppleScript System Events keystroke.
    def send_message_with_keystroke(self, message):
        """AppleScript를 사용해서 직접 키스트로크로 메시지 전송"""
        time.sleep(0.5)
        self._type_with_applescript(message)
    
    def _type_with_applescript(self, text):
        """AppleScript를 사용해서 텍스트 입력"""
        escaped_text = text.replace('"', '\\"').replace("\\", "\\\\")
        
        script = f'''
        tell application "System Events"
            tell process "ChatGPT"
                -- 먼저 백스페이스
                key code 51
                delay 0.1
                
                -- 텍스트 입력 (각 문자를 개별적으로)
                set textToType to "{escaped_text}"
                repeat with i from 1 to length of textToType
                    set currentChar to character i of textToType
                    keystroke currentChar
                    delay 0.01
                end repeat
                
                -- Enter 키 입력
                key code 36
            end tell
        end tell
        '''
        
        subprocess.run(['osascript', '-e', script], capture_output=True, text=True)
  • Helper function activate_chatgpt used to focus the ChatGPT desktop app before sending a message.
    def activate_chatgpt(self):
        """ChatGPT Desktop 앱 활성화"""
        subprocess.run(['osascript', '-e', 'tell application "ChatGPT" to activate'])
        time.sleep(1)
    
    def new_chat(self):
        """새 ChatGPT 채팅창 열기"""
        # ChatGPT 앱을 활성화
        self.activate_chatgpt()
        
        # 메뉴를 통해 새 채팅 열기 시도
        script = '''
        tell application "System Events"
            tell process "ChatGPT"
                try
                    -- 메뉴바에서 File > New Chat 클릭
                    click menu item "New Chat" of menu "File" of menu bar 1
                    return "success_menu"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description carries the full burden of behavioral disclosure, but it only states the basic action. No mention of side effects, statelessness, authentication, rate limits, or output format, leaving significant gaps for an agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no waste. However, more informative content could be included without sacrificing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simplicity of the tool (one parameter, no output schema), the description provides the core action. However, it lacks details about response format, error conditions, or conversation state, which are relevant even for a simple tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description implies that the 'prompt' parameter is the text sent to ChatGPT, but it adds no extra meaning beyond the schema's type and title. With 0% schema coverage, the description should compensate but does not provide additional semantic or syntactic details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (send a prompt) and the resource (ChatGPT), explicitly mentioning the response. However, it does not differentiate from siblings like get_chatgpt_response_tool or new_chatgpt_chat_tool, missing explicit distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus siblings. An agent cannot determine whether to use ask_chatgpt_tool, get_chatgpt_response_tool, or new_chatgpt_chat_tool based on the description alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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