end_session
Finalize your work session to resume automatic commits. Use after checkpoint to properly close the session.
Instructions
End your work session to resume ShadowGit auto-commits. MUST be called AFTER checkpoint to properly close your work session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID from start_session | |
| commitHash | No | Commit hash from checkpoint (optional) |
Implementation Reference
- src/handlers/session-handler.ts:78-112 (handler)The endSession method on SessionHandler - the main handler logic for the end_session tool. Validates that sessionId is provided, then delegates to SessionClient.endSession() to make the HTTP API call.
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.` ); } - EndSessionArgs interface - defines the input schema for end_session: sessionId (required string) and commitHash (optional string).
interface EndSessionArgs { sessionId: string; commitHash?: string; } - src/types.ts:44-52 (schema)SessionEndRequest and SessionEndResponse interfaces - the types used for the HTTP API request/response for ending a session.
export interface SessionEndRequest { sessionId: string; commitHash?: string; } export interface SessionEndResponse { success: boolean; error?: string; } - src/shadowgit-mcp-server.ts:141-158 (registration)Tool registration for end_session in the ListToolsRequestSchema handler - defines the tool name, description, and inputSchema (sessionId required, commitHash optional).
{ 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'], }, } - src/shadowgit-mcp-server.ts:182-183 (registration)Tool dispatch in the CallToolRequestSchema handler - routes the 'end_session' tool name to sessionHandler.endSession(args).
case 'end_session': return await this.sessionHandler.endSession(args); - src/core/session-client.ts:64-100 (helper)SessionClient.endSession() - the low-level HTTP client that sends a POST request to the Session API's /session/end endpoint with sessionId and optional commitHash.
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; }