Skip to main content
Glama
0xjcf
by 0xjcf

list-sessions

Retrieve active analysis sessions from the CodeAnalysis MCP Server to manage ongoing code review and development workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

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());
    }
  • 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,
        };
      }
    });

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/0xjcf/MCP_CodeAnalysis'

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