get_session_messages
Retrieve and clear messages sent by persistent scripts in a Frida MCP session for runtime analysis and debugging purposes.
Instructions
Retrieve and clear messages sent by persistent scripts in a session.
Returns:
A list of messages captured since the last call, or an error if the session is not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | The ID of the session to retrieve messages from. |
Implementation Reference
- src/frida_mcp/cli.py:725-769 (handler)The primary handler function for the 'get_session_messages' tool. Decorated with @mcp.tool() for registration and input validation via Pydantic Field. It safely retrieves and clears asynchronous messages from persistent Frida scripts in a session using thread locks.@mcp.tool() def get_session_messages( session_id: str = Field( description="The ID of the session to retrieve messages from." ), ) -> Dict[str, Any]: """Retrieve and clear messages sent by persistent scripts in a session. Returns: A list of messages captured since the last call, or an error if the session is not found. """ if session_id not in _scripts: # Check if it was a session that had persistent scripts but might have been cleared or detached if ( session_id in global_persistent_scripts and not global_persistent_scripts[session_id] ): return { "status": "success", "messages": [], "info": "Session had persistent scripts that might be finished or detached.", } raise ValueError( f"Session with ID {session_id} not found or no persistent scripts active." ) if session_id not in _message_locks or session_id not in _script_messages: # This case should ideally not happen if session_id is in _scripts from create_interactive_session return { "status": "error", "error": f"Message queue or lock not found for session {session_id}.", } lock = _message_locks[session_id] with lock: messages = list(_script_messages[session_id]) # Make a copy _script_messages[session_id].clear() # Clear the queue return { "status": "success", "session_id": session_id, "messages_retrieved": len(messages), "messages": messages, }
- src/frida_mcp/cli.py:77-82 (helper)Global state variables (_scripts, _script_messages, _message_locks, global_persistent_scripts) that store session data, message queues, locks for thread-safety, and persistent script lists used by get_session_messages and related functions.# Global dictionary to store scripts and their messages # This allows us to retrieve messages from scripts after they've been created _scripts = {} _script_messages = {} _message_locks = {} global_persistent_scripts = {} # Added for managing persistent scripts
- src/frida_mcp/cli.py:635-644 (helper)The on_persistent_message callback defined within execute_in_session, which populates the _script_messages queue for the session when keep_alive=True, enabling get_session_messages to retrieve them.def on_persistent_message(message, data): with lock: _script_messages[session_id].append( { "type": message["type"], "payload": message.get("payload"), "data": data, } )