Skip to main content
Glama

sessions_end

End a debug session and clean up resources by providing the session ID. This tool from Debug-MCP helps manage debugging sessions efficiently.

Instructions

End a debug session and clean up resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesThe debug session ID

Implementation Reference

  • MCP tool handler for 'sessions_end': validates sessionId, calls SessionManager.end_session_async(), handles errors, returns JSON response as TextContent.
    async def _handle_sessions_end(self, arguments: dict) -> list[TextContent]:
        """
        Handler for sessions_end tool.
        
        Ends a debug session and cleans up resources.
        """
        try:
            session_id = arguments.get("sessionId")
            if not session_id:
                return [
                    TextContent(
                        type="text",
                        text=json.dumps({
                            "error": {
                                "type": "ValueError",
                                "message": "sessionId is required",
                            }
                        }),
                    )
                ]
    
            response = await self.session_manager.end_session_async(session_id)
            result = response.model_dump()
    
            return [
                TextContent(
                    type="text",
                    text=json.dumps(result),
                )
            ]
        except KeyError as e:
            return [
                TextContent(
                    type="text",
                    text=json.dumps({
                        "error": {
                            "type": "SessionNotFound",
                            "message": str(e),
                        }
                    }),
                )
            ]
        except Exception as e:
            logger.exception("Error ending session")
            return [
                TextContent(
                    type="text",
                    text=json.dumps({
                        "error": {
                            "type": type(e).__name__,
                            "message": str(e),
                        }
                    }),
                )
            ]
  • Tool registration in list_tools(): defines name, description, and inputSchema requiring 'sessionId' string.
    Tool(
        name="sessions_end",
        description="End a debug session and clean up resources",
        inputSchema={
            "type": "object",
            "properties": {
                "sessionId": {
                    "type": "string",
                    "description": "The debug session ID",
                },
            },
            "required": ["sessionId"],
        },
    ),
  • Pydantic model for output response: simple confirmation {ended: true}.
    class EndSessionResponse(BaseModel):
        """Response confirming session ended."""
        ended: bool = True
  • Core SessionManager.end_session(): terminates DAP wrapper or subprocess, updates status to COMPLETED, removes session from manager.
    def end_session(self, session_id: str) -> EndSessionResponse:
        """
        End a debug session and clean up resources.
    
        Args:
            session_id: Session ID
    
        Returns:
            End confirmation response
        """
        session = self.get_session(session_id)
    
        # Clean up DAP wrapper if using DAP
        if session.dap_wrapper:
            try:
                session.dap_wrapper.terminate()
            except Exception:
                pass
    
        # Clean up subprocess if running (bdb mode)
        if session.process and session.process.poll() is None:
            # Try graceful termination first
            try:
                terminate_cmd = json.dumps({"command": "terminate"}) + '\n'
                session.process.stdin.write(terminate_cmd)
                session.process.stdin.flush()
                session.process.wait(timeout=5)
            except Exception:
                pass
    
            # Force terminate if still running
            if session.process.poll() is None:
                session.process.terminate()
                try:
                    session.process.wait(timeout=5)
                except subprocess.TimeoutExpired:
                    session.process.kill()
                    session.process.wait()
    
        # Update status
        session.update_status(SessionStatus.COMPLETED)
    
        # Remove from active sessions
        del self.sessions[session_id]
    
        return EndSessionResponse(ended=True)
  • Async wrapper end_session_async(): bridges sync end_session to async MCP handler via asyncio.to_thread.
    async def end_session_async(self, session_id: str) -> EndSessionResponse:
        """
        Async wrapper for end_session.
        
        Runs the synchronous end_session in a thread pool to avoid blocking.
        """
        return await asyncio.to_thread(self.end_session, session_id)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'clean up resources', hinting at a destructive action, but doesn't specify if this is irreversible, what resources are cleaned up, or any side effects (e.g., terminating processes). This is inadequate for a tool that likely performs a mutation with potential impacts.

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 a single, efficient sentence that is front-loaded with the core action ('End a debug session') and includes a useful outcome ('clean up resources'). There is no wasted verbiage, making it highly concise and well-structured.

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

Completeness2/5

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

Given the complexity of ending a debug session (a likely destructive operation), no annotations, and no output schema, the description is incomplete. It lacks details on behavior, error conditions, or what happens post-execution, leaving significant gaps for the agent to understand the tool's full context.

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, with the parameter 'sessionId' clearly documented. The description adds no additional meaning beyond the schema, such as format examples or constraints, so it meets the baseline of 3 where the schema does the heavy lifting.

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 tool's purpose with a specific verb ('End') and resource ('a debug session'), and it adds the outcome ('clean up resources'). However, it doesn't explicitly differentiate from sibling tools like sessions_continue or sessions_state, which might also affect session states, so it's not a perfect 5.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active session), exclusions (e.g., not for paused sessions), or refer to sibling tools like sessions_create for starting sessions, leaving the agent with no usage context.

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/Kaina3/Debug-MCP'

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