# LambdaTest MCP Server

This project provides a Model Context Protocol (MCP) server for LambdaTest services, with a primary focus on HyperExecute YAML configuration generation and app migration tools. The server enables AI assistants to interact with LambdaTest services through a standardized protocol.

## Architecture

The server is built with a modular architecture, consisting of two main tool categories:

### HyperExecute Tools

1. **HyperExecute YAML Generation Tool**: Generates a HyperExecute YAML file based on project analysis and test runner commands.
2. **HyperExecute Documentation Tool**: Answers queries related to HyperExecute by dynamically fetching information from documentation using RAG (Retrieval-Augmented Generation).
3. **HyperExecute Job Info Tool**: Fetches information about a HyperExecute job by ID.
4. **HyperExecute Job Sessions Tool**: Fetches session information for a HyperExecute job.

### Migration Tools

1. **App Upload Tool**: Uploads mobile applications (APK, IPA, etc.) to LambdaTest for mobile testing.

Each tool can be used independently or in sequence to achieve the desired result.

## Connecting with AI Assistants

The HTTP interface can be used with various AI assistants that support the Model Context Protocol (MCP). Here's how to connect using popular assistants:

### Cline

a) To connect Cline to the LambdaTest REMOTE MCP server:

1. Start Cline with the MCP server URL:
   ```bash
   {
   "mcpServers": {
    "mcp-hyper-stage": {
      "disabled": false,
      "timeout": 60,
      "command": "npx",
      "args": [
        "mcp-remote@latest",
        "https://mcp.lambdatest.com/mcp",
        "--header",
        "username:<LT_USERNAME>",
        "--header",
        "accessKey:<LT_ACCESSKEY>"
      ],
      "transportType": "streamableHTTP"
      }
    }
   }
   ```
   Or configure it in your Cline configuration file.
2. Verify the connection by asking Cline to list available MCP tools
3. You can now use LambdaTest tools directly within Cline

(OR)

b) To connect Cline to the LambdaTest STDIO MCP server from NPM:

1. Start Cline with the MCP server URL:
   ```bash
   "mcp-hyper-stage-stdio": {
      "disabled": false,
      "timeout": 100,
      "command": "npx",
      "args": ["-y", "mcp-lambdatest", "--transport=stdio"],
      "env": {
        "LT_USERNAME": "<LT_USERNAME>",
        "LT_ACCESS_KEY": "<LT_ACCESSKEY>"
      },
      "transportType": "stdio"
    }
   ```
   Or configure it in your Cline configuration file.
2. Verify the connection by asking Cline to list available MCP tools
3. You can now use LambdaTest tools directly within Cline

### Other MCP-Compatible Tools

For any other MCP-compatible tool, use the following URL format:

```
https://mcp.lambdatest.com/mcp
```

Make sure to include your LambdaTest username and access key in the request headers:

- `username`: Your LambdaTest username
- `accesskey`: Your LambdaTest access key

## Authentication

The server supports authentication for the HTTP interface and for LambdaTest API calls:

- **HTTP Interface**: Requires a valid LambdaTest username and access key in the request headers.
- **LambdaTest API Calls**: Can use credentials provided in the request or from environment variables (`LT_USERNAME` and `LT_ACCESS_KEY`).

## MCP Tools

The server provides the following MCP tools:

### HyperExecute Tools

#### 1. generateHyperExecuteYAML

Generates a HyperExecute YAML file based on project analysis and test runner commands.

**Input Parameters:**

- `analysis` (object): Project analysis data containing:
  - `projectLanguage` (string): Project language type (python, java, node, etc.)
  - `frameworks` (string): Test framework (junit, testng, webdriverio, cypress, playwright, cucumber, etc.)
  - `testDirectories` (array): List of test directories
  - `files` (array): List of files in the project
  - `testDiscoveryCommand` (string): Command to discover tests
- `options` (object, optional): HyperExecute configuration options
  - `concurrency` (number, optional): Number of concurrent tests (default: 2)
  - `autosplit` (boolean, optional): Enable auto splitting (default: true)
  - `retryOnFailure` (boolean, optional): Retry failed tests (default: true)
  - `maxRetries` (number, optional): Maximum number of retries (default: 1)
  - `customCommands` (object, optional): Custom commands to include in the YAML
- `outputPath` (string, optional): Path where to save the YAML file

**Output:**

- Generated YAML content

#### 2. answerHyperExecuteQuery

Answers queries related to HyperExecute by dynamically fetching information from documentation.

**Input Parameters:**

- `query` (string): The query about HyperExecute

**Output:**

- Detailed answer to the query based on HyperExecute documentation

#### 3. getHyperExecuteJobInfo

Fetches information about a HyperExecute job by ID.

**Input Parameters:**

- `jobId` (string): The ID of the HyperExecute job to fetch information for
- `lt_username` (string, optional): Username for HyperExecute API (optional if provided via environment variable)
- `lt_access_key` (string, optional): Access key for HyperExecute API (optional if provided via environment variable)

**Output:**

- Detailed job information including status, test results, and execution details

#### 4. getHyperExecuteJobSessions

Fetches session information for a HyperExecute job.

**Input Parameters:**

- `jobId` (string): The ID of the HyperExecute job to fetch sessions for
- `limit` (number, optional): Maximum number of sessions to return (default: 10)
- `lt_username` (string, optional): Username for HyperExecute API (optional if provided via environment variable)
- `lt_access_key` (string, optional): Access key for HyperExecute API (optional if provided via environment variable)

**Output:**

- List of sessions associated with the job, including status and execution details

### Migration Tools

#### 1. upload_app

Uploads an app to LambdaTest for mobile testing.

**Input Parameters:**

- `appFilePath` (string): Absolute path to the app file to upload (APK, IPA, etc.)
- `appUrl` (string): URL of the app to upload instead of a local file
- `name` (string): Name to assign to the uploaded app
- `customId` (string, optional): Custom ID for the app
- `visibility` (string, optional): Visibility setting for the app (individual, team, organization)

**Output:**

- Success status
- App URL for use in capabilities
- App ID
- Status message
