Skip to main content
Glama

get_session_messages

Retrieve and clear messages from persistent scripts in a Frida session to monitor runtime behavior and capture script output during dynamic instrumentation.

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
NameRequiredDescriptionDefault
session_idYesThe ID of the session to retrieve messages from.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'get_session_messages' tool, including registration via @mcp.tool(), input schema definition with Pydantic Field, and the logic to retrieve and clear session messages from global storage.
    @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,
        }
  • Global dictionaries that store session scripts, message queues, thread locks, and persistent scripts, essential for the get_session_messages tool to function.
    # 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
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it retrieves AND clears messages (implying mutation/destructive action), specifies the temporal scope ('since the last call'), and mentions error conditions ('session not found'). It could add more about permissions or rate limits but covers essential behavior.

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

Conciseness5/5

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

The description is front-loaded with the core purpose in the first sentence, followed by a clear returns section. Every sentence earns its place by providing essential information without redundancy, making it highly efficient and well-structured.

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

Completeness5/5

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

Given the tool's moderate complexity, no annotations, and the presence of an output schema (which handles return values), the description is complete enough. It covers purpose, behavior, and error conditions, leaving structured details to the schema while adding valuable context about message clearing and session dependency.

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

Parameters3/5

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

The input schema has 100% description coverage, fully documenting the single parameter 'session_id'. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline of 3 without compensating for any gaps.

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

Purpose5/5

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

The description clearly states the specific action ('Retrieve and clear messages') and resource ('messages sent by persistent scripts in a session'), distinguishing it from sibling tools that focus on processes, devices, or session execution rather than message retrieval.

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

Usage Guidelines4/5

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

The description implies usage context by specifying 'messages sent by persistent scripts in a session,' suggesting it's for monitoring script output. However, it doesn't explicitly state when to use this tool versus alternatives or provide exclusions, leaving some ambiguity about its specific application scenarios.

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/rmorgans/frida-mcp'

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