Skip to main content
Glama
blade47

ShadowGit MCP Server

by blade47

end_session

Close your work session to resume ShadowGit's automatic commit tracking after completing tasks.

Instructions

End your work session to resume ShadowGit auto-commits. MUST be called AFTER checkpoint to properly close your work session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession ID from start_session
commitHashNoCommit hash from checkpoint (optional)

Implementation Reference

  • Main handler function that executes the end_session tool: validates input, calls SessionClient to end the session via API, and formats the MCP response.
      async endSession(args: unknown): Promise<MCPToolResponse> {
        // Validate args
        if (!this.isEndSessionArgs(args)) {
          return createErrorResponse(
            'Error: "sessionId" is required for end_session.'
          );
        }
    
        // End session
        const success = await this.sessionClient.endSession(
          args.sessionId,
          args.commitHash
        );
    
        if (success) {
          log('info', `Session ended: ${args.sessionId}`);
          return {
            content: [{
              type: 'text',
              text: `Session ${args.sessionId} ended successfully.`
            }]
          };
        }
    
        return createErrorResponse(
          `❌ **Failed to End Session**
    ${'='.repeat(50)}
    
    ⚠️ The session may have already ended or expired.
    
    **Note:** Auto-commits may have already resumed.
    
    💡 **NEXT STEP:** You can continue working or start a new session.`
        );
      }
  • MCP protocol input schema definition for the end_session tool, specifying required sessionId and optional commitHash.
      name: 'end_session',
      description: 'End your work session to resume ShadowGit auto-commits. MUST be called AFTER checkpoint to properly close your work session.',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: {
            type: 'string',
            description: 'Session ID from start_session',
          },
          commitHash: {
            type: 'string',
            description: 'Commit hash from checkpoint (optional)',
          },
        },
        required: ['sessionId'],
      },
    }
  • Registration in the tool dispatch switch statement, routing end_session calls to the SessionHandler.
    case 'end_session':
      return await this.sessionHandler.endSession(args);
  • Core helper method that performs the HTTP POST to the Session API endpoint /session/end to actually end the session.
    async endSession(sessionId: string, commitHash?: string): Promise<boolean> {
      try {
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), this.timeout);
    
        const data: SessionEndRequest = { sessionId };
        if (commitHash) {
          data.commitHash = commitHash;
        }
    
        const response = await fetch(`${this.baseUrl}/session/end`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data),
          signal: controller.signal,
        });
    
        clearTimeout(timeoutId);
    
        if (response.ok) {
          const result = await response.json() as SessionEndResponse;
          if (result.success) {
            log('info', `Session ended: ${sessionId}`);
            return true;
          }
        }
        
        log('warn', `Failed to end session: ${response.status} ${response.statusText}`);
      } catch (error) {
        if (error instanceof Error && error.name !== 'AbortError') {
          log('debug', `Failed to end session: ${error.message}`);
        }
      }
      return false;
    }
  • TypeScript interface and runtime validator for end_session arguments in the handler.
    private isEndSessionArgs(args: unknown): args is EndSessionArgs {
      return (
        typeof args === 'object' &&
        args !== null &&
        'sessionId' in args &&
        typeof (args as EndSessionArgs).sessionId === 'string'
      );
    }

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/blade47/shadowgit-mcp'

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