Skip to main content
Glama

create_debug_session

Start a debugging session for Python, JavaScript, or Rust programs to inspect variables, set breakpoints, and trace execution step-by-step.

Instructions

Create a new debugging session

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageYesProgramming language for debugging
nameNoOptional session name
executablePathNoPath to language executable (optional, will auto-detect if not provided)

Implementation Reference

  • Schema definition for the create_debug_session tool, including input parameters: language (required, enum of supported languages), optional name and executablePath.
    { name: 'create_debug_session', description: 'Create a new debugging session', inputSchema: { type: 'object', properties: { language: { type: 'string', enum: supportedLanguages, description: 'Programming language for debugging' }, name: { type: 'string', description: 'Optional session name' }, executablePath: {type: 'string', description: 'Path to language executable (optional, will auto-detect if not provided)'} }, required: ['language'] } },
  • Handler for create_debug_session tool call: validates language support, invokes createDebugSession method, logs creation, returns session ID and success message.
    case 'create_debug_session': {
      // Ensure requested language is among dynamically supported ones
      const supported = await this.getSupportedLanguagesAsync();
      const lang = (args.language || 'python') as DebugLanguage;
      const requested = lang as unknown as string;
      const isContainer = process.env.MCP_CONTAINER === 'true';
      const allowInContainer = isContainer && requested === 'python';
      if (!allowInContainer && !supported.includes(lang)) {
        throw new UnsupportedLanguageError(lang, supported);
      }
    
      const sessionInfo = await this.createDebugSession({
        language: lang,
        name: args.name,
        executablePath: args.executablePath
      });
      
      // Log session creation
      this.logger.info('session:created', {
        sessionId: sessionInfo.id,
        sessionName: sessionInfo.name,
        language: sessionInfo.language,
        executablePath: args.executablePath,
        timestamp: Date.now()
      });
      
      result = { content: [{ type: 'text', text: JSON.stringify({ success: true, sessionId: sessionInfo.id, message: `Created ${sessionInfo.language} debug session: ${sessionInfo.name}` }) }] };
      break;
    }
  • Helper method createDebugSession that creates a new debug session via sessionManager.createSession, handles validation and error logging.
    public async createDebugSession(params: { language: DebugLanguage; name?: string; executablePath?: string; }): Promise<DebugSessionInfo> {
      // Validate language support using dynamic discovery
      const supported = await this.getSupportedLanguagesAsync();
      const requested = params.language as unknown as string;
      const isContainer = process.env.MCP_CONTAINER === 'true';
      const allowInContainer = isContainer && requested === 'python'; // ensure python allowed in container
      if (isLanguageDisabled(requested)) {
        throw new McpError(
          McpErrorCode.InvalidParams,
          `Language '${params.language}' is disabled in this runtime. Available languages: ${supported.join(', ')}`,
        );
      }
      if (!allowInContainer && !supported.includes(requested)) {
        throw new McpError(
          McpErrorCode.InvalidParams, 
          `Language '${params.language}' is not supported. Available languages: ${supported.join(', ')}`
        );
      }
      
      const name = params.name || `${params.language}-debug-${Date.now()}`;
      try {
        const sessionInfo: DebugSessionInfo = await this.sessionManager.createSession({
          language: params.language as DebugLanguage,
          name: name,
          executablePath: params.executablePath  // Use executablePath for consistency
        });
        return sessionInfo;
      } catch (error) {
        const errorMessage = (error as Error).message || String(error);
        this.logger.error('Failed to create debug session', { error: errorMessage, stack: (error as Error).stack });
        throw new McpError(McpErrorCode.InternalError, `Failed to create debug session: ${errorMessage}`);
      }
    }
  • src/server.ts:432-486 (registration)
    Registration of tools list handler, which includes the schema for create_debug_session among other tools.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      this.logger.debug('Handling ListToolsRequest');
      
      // Get supported languages dynamically - deferred until request time
      const supportedLanguages = await this.getSupportedLanguagesAsync();
      
      // Generate dynamic descriptions for path parameters
      const fileDescription = this.getPathDescription('source file');
      const scriptPathDescription = this.getPathDescription('script');
      
      return {
        tools: [
          { name: 'create_debug_session', description: 'Create a new debugging session', inputSchema: { type: 'object', properties: { language: { type: 'string', enum: supportedLanguages, description: 'Programming language for debugging' }, name: { type: 'string', description: 'Optional session name' }, executablePath: {type: 'string', description: 'Path to language executable (optional, will auto-detect if not provided)'} }, required: ['language'] } },
          { name: 'list_supported_languages', description: 'List all supported debugging languages with metadata', inputSchema: { type: 'object', properties: {} } },
          { name: 'list_debug_sessions', description: 'List all active debugging sessions', inputSchema: { type: 'object', properties: {} } },
          { name: 'set_breakpoint', description: 'Set a breakpoint. Setting breakpoints on non-executable lines (structural, declarative) may lead to unexpected behavior', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, file: { type: 'string', description: fileDescription }, line: { type: 'number', description: 'Line number where to set breakpoint. Executable statements (assignments, function calls, conditionals, returns) work best. Structural lines (function/class definitions), declarative lines (imports), or non-executable lines (comments, blank lines) may cause unexpected stepping behavior' }, condition: { type: 'string' } }, required: ['sessionId', 'file', 'line'] } },
          { name: 'start_debugging', description: 'Start debugging a script', inputSchema: { 
              type: 'object', 
              properties: { 
                sessionId: { type: 'string' }, 
                scriptPath: { type: 'string', description: scriptPathDescription }, 
                args: { type: 'array', items: { type: 'string' } }, 
                dapLaunchArgs: { 
                  type: 'object', 
                  properties: { 
                    stopOnEntry: { type: 'boolean' },
                    justMyCode: { type: 'boolean' } 
                  },
                  additionalProperties: true
                },
                dryRunSpawn: { type: 'boolean' },
                adapterLaunchConfig: {
                  type: 'object',
                  description: 'Optional adapter-specific launch configuration overrides',
                  additionalProperties: true
                }
              }, 
              required: ['sessionId', 'scriptPath'] 
            } 
          },
          { name: 'close_debug_session', description: 'Close a debugging session', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'step_over', description: 'Step over', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'step_into', description: 'Step into', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'step_out', description: 'Step out', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'continue_execution', description: 'Continue execution', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'pause_execution', description: 'Pause execution (Not Implemented)', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' } }, required: ['sessionId'] } },
          { name: 'get_variables', description: 'Get variables (scope is variablesReference: number)', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, scope: { type: 'number', description: "The variablesReference number from a StackFrame or Variable" } }, required: ['sessionId', 'scope'] } },
          { name: 'get_local_variables', description: 'Get local variables for the current stack frame. This is a convenience tool that returns just the local variables without needing to traverse stack->scopes->variables manually', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, includeSpecial: { type: 'boolean', description: 'Include special/internal variables like this, __proto__, __builtins__, etc. Default: false' } }, required: ['sessionId'] } },
          { name: 'get_stack_trace', description: 'Get stack trace', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, includeInternals: { type: 'boolean', description: 'Include internal/framework frames (e.g., Node.js internals). Default: false for cleaner output.' } }, required: ['sessionId'] } },
          { name: 'get_scopes', description: 'Get scopes for a stack frame', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, frameId: { type: 'number', description: "The ID of the stack frame from a stackTrace response" } }, required: ['sessionId', 'frameId'] } },
          { name: 'evaluate_expression', description: 'Evaluate expression in the current debug context. Expressions can read and modify program state', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, expression: { type: 'string' }, frameId: { type: 'number', description: 'Optional stack frame ID for evaluation context. Must be a frame ID from a get_stack_trace response. If not provided, uses the current (top) frame automatically' } }, required: ['sessionId', 'expression'] } },
          { name: 'get_source_context', description: 'Get source context around a specific line in a file', inputSchema: { type: 'object', properties: { sessionId: { type: 'string' }, file: { type: 'string', description: fileDescription }, line: { type: 'number', description: 'Line number to get context for' }, linesContext: { type: 'number', description: 'Number of lines before and after to include (default: 5)' } }, required: ['sessionId', 'file', 'line'] } },
        ],
      };
    });

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/debugmcpdev/mcp-debugger'

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