list-sessions
Retrieve active analysis sessions from the CodeAnalysis MCP Server to manage ongoing code review and development workflows.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The core handler function for the 'list-sessions' tool. It fetches all active session IDs using getSessionIds(), retrieves context for each session, computes session info (tools used, last activity), formats a success response with active sessions count and details, or error response if failed.server.tool("list-sessions", {}, async () => { try { const sessionIds = getSessionIds(); const sessionInfo = sessionIds.map((id) => { const session = getSession(id); const context = session.getContext(); return { sessionId: id, toolsUsed: context.history.length, lastActivity: context.history.length > 0 ? context.history[context.history.length - 1].timestamp : null, }; }); const result = createSuccessResponse( { activeSessions: sessionIds.length, sessions: sessionInfo, }, "list-sessions" ); 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), "list-sessions" ), null, 2 ), }, ], isError: true, }; } });
- Helper function that returns all active session IDs from the global sessions Map, used by the list-sessions handler.export function getSessionIds(): string[] { return Array.from(sessions.keys()); }
- src/features/session-manager/index.ts:245-297 (registration)Registers the 'list-sessions' tool on the MCP server with no input parameters and the inline handler function.server.tool("list-sessions", {}, async () => { try { const sessionIds = getSessionIds(); const sessionInfo = sessionIds.map((id) => { const session = getSession(id); const context = session.getContext(); return { sessionId: id, toolsUsed: context.history.length, lastActivity: context.history.length > 0 ? context.history[context.history.length - 1].timestamp : null, }; }); const result = createSuccessResponse( { activeSessions: sessionIds.length, sessions: sessionInfo, }, "list-sessions" ); 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), "list-sessions" ), null, 2 ), }, ], isError: true, }; } });