Skip to main content
Glama
blade47

ShadowGit MCP Server

by blade47
session-handler.ts3.49 kB
/** * Handler for session management - start and end sessions */ import { RepositoryManager } from '../core/repository-manager'; import { SessionClient } from '../core/session-client'; import { log } from '../utils/logger'; import { createErrorResponse } from '../utils/response-utils'; import type { MCPToolResponse } from '../types'; interface StartSessionArgs { repo: string; description: string; } interface EndSessionArgs { sessionId: string; commitHash?: string; } export class SessionHandler { constructor( private repositoryManager: RepositoryManager, private sessionClient: SessionClient ) {} /** * Start a new work session */ async startSession(args: unknown): Promise<MCPToolResponse> { // Validate args if (!this.isStartSessionArgs(args)) { return createErrorResponse( 'Error: Both "repo" and "description" are required for start_session.' ); } // Resolve repository const repoPath = this.repositoryManager.resolveRepoPath(args.repo); if (!repoPath) { return createErrorResponse( `Error: Repository '${args.repo}' not found. Use list_repos() to see available repositories.` ); } // Start session const sessionId = await this.sessionClient.startSession({ repoPath, aiTool: 'MCP Client', description: args.description }); if (sessionId) { log('info', `Session started: ${sessionId}`); return { content: [{ type: 'text', text: `Session started successfully. Session ID: ${sessionId} 📋 **Your Workflow Checklist:** 1. Make your changes 2. Call checkpoint() to commit 3. Call end_session() with this session ID` }] }; } // Fallback if Session API is offline return createErrorResponse( 'Session API is offline. Proceeding without session tracking.' ); } /** * End an active session */ 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.` ); } private isStartSessionArgs(args: unknown): args is StartSessionArgs { return ( typeof args === 'object' && args !== null && 'repo' in args && 'description' in args && typeof (args as StartSessionArgs).repo === 'string' && typeof (args as StartSessionArgs).description === 'string' ); } 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