clear-session
Clear a specific analysis session by its ID to remove stored data and free resources in the CodeAnalysis MCP Server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | ID of the session to clear |
Implementation Reference
- Registration and handler implementation for the 'clear-session' MCP tool. The handler calls the clearSession helper function, formats the response using createSuccessResponse/createErrorResponse, and returns MCP-formatted content.server.tool( "clear-session", { sessionId: z.string().describe("ID of the session to clear"), }, async ({ sessionId }) => { try { const cleared = clearSession(sessionId); const result = createSuccessResponse( { sessionId, cleared, timestamp: new Date().toISOString(), }, "clear-session" ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( createErrorResponse( error instanceof Error ? error.message : String(error), "clear-session" ), null, 2 ), }, ], isError: true, }; } }
- Input schema validation for the clear-session tool using Zod, requiring a sessionId string.{ sessionId: z.string().describe("ID of the session to clear"), },
- The core clearSession helper function that deletes the specified session from the global sessions Map and returns whether it was successful.export function clearSession(sessionId: string): boolean { if (sessions.has(sessionId)) { sessions.delete(sessionId); return true; } return false; }