list-sessions
Retrieve active or past sessions on the CodeAnalysis MCP Server to track and manage code analysis tasks, syntax evaluations, and workflow progress efficiently.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Inline handler for the 'list-sessions' MCP tool. Fetches all active session IDs using getSessionIds(), extracts summary info (tools used count and last activity timestamp) for each session, formats a success response with the list, or error response on failure.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, }; } });
- src/features/session-manager/index.ts:245-297 (registration)Registers the 'list-sessions' tool on the MCP server within the registerSessionTools function, using an empty input schema and inline handler.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 an array of all active session IDs from the global 'sessions' Map, used by the list-sessions handler to identify sessions to summarize.export function getSessionIds(): string[] { return Array.from(sessions.keys()); }