Skip to main content
Glama
lkb2k

Gradle Tomcat MCP Server

by lkb2k

start_tomcat

Launch Tomcat server using Gradle commands to run web applications from a specified directory.

Instructions

Launch Tomcat via Gradle

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gradle_commandNoGradle command to run (default: appRun)appRun
working_directoryNoWorking directory for the Gradle command

Implementation Reference

  • The core handler function that implements the start_tomcat tool logic: spawns the Gradle process for Tomcat, sets up event emitters for logs and errors, and returns process status.
    async startTomcat(gradleCommand = 'appRun', workingDirectory = null) {
      if (this.process) {
        throw new Error('Tomcat is already running');
      }
    
      const workDir = workingDirectory || this.config.workingDirectory || process.cwd();
      const command = gradleCommand || this.config.gradleCommand || 'appRun';
    
      return new Promise((resolve, reject) => {
        try {
          this.process = spawn('./gradlew', [command], {
            cwd: workDir,
            stdio: ['pipe', 'pipe', 'pipe'],
            detached: false
          });
    
          this.startTime = new Date();
    
          this.process.stdout.on('data', (data) => {
            this.emit('stdout', data.toString());
          });
    
          this.process.stderr.on('data', (data) => {
            this.emit('stderr', data.toString());
          });
    
          this.process.on('error', (error) => {
            this.emit('error', error);
            this.cleanup();
            reject(error);
          });
    
          this.process.on('exit', (code, signal) => {
            this.emit('exit', { code, signal });
            this.cleanup();
          });
    
          setTimeout(() => {
            if (this.process && this.process.pid) {
              resolve({
                running: true,
                pid: this.process.pid,
                uptime: this.getUptime(),
                port: this.config.port || null,
                gradle_command: command
              });
            } else {
              reject(new Error('Failed to start Tomcat process'));
            }
          }, 1000);
    
        } catch (error) {
          reject(error);
        }
      });
    }
  • Input schema defining the parameters for the start_tomcat tool: gradle_command (string, default 'appRun') and working_directory (string).
    inputSchema: {
      type: "object",
      properties: {
        gradle_command: {
          type: "string",
          description: "Gradle command to run (default: appRun)",
          default: "appRun"
        },
        working_directory: {
          type: "string",
          description: "Working directory for the Gradle command"
        }
      }
    }
  • Registration of the start_tomcat tool in the TOOLS array, including name, description, and input schema.
    {
      name: "start_tomcat",
      description: "Launch Tomcat via Gradle",
      inputSchema: {
        type: "object",
        properties: {
          gradle_command: {
            type: "string",
            description: "Gradle command to run (default: appRun)",
            default: "appRun"
          },
          working_directory: {
            type: "string",
            description: "Working directory for the Gradle command"
          }
        }
      }
    },
  • Dispatch helper in the handleToolCall switch statement that maps tool arguments to the startTomcat method call.
    case "start_tomcat":
      return await processManager.startTomcat(
        args.gradle_command,
        args.working_directory
      );

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/lkb2k/mcp-gradle'

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