Stagehand UI Tester MCP server

Command-line tool that bridges Claude with Playwright for automated UI testing of React/Next.js components, enabling test generation, execution, and screenshot capture based on component code and natural language instructions.
Back to servers
Provider
Kyle Jeong
Release date
Feb 22, 2025
Language
TypeScript

This MCP Server implements the Model Context Protocol, enabling applications to request language model responses with the proper context, authentication, and model selection. It serves as a crucial bridge between your applications and various language models, providing a standardized way to interact with LLMs.

Installation

Prerequisites

  • Python 3.9 or higher
  • Pip (Python package manager)

Install from PyPI

You can install the MCP Server directly from PyPI:

pip install mcp-server

Install from Source

Alternatively, you can install from source:

git clone https://github.com/mlc-ai/mcp-server.git
cd mcp-server
pip install -e .

Configuration

Before running the server, you'll need to create a configuration file. The MCP server uses YAML for configuration.

Basic Configuration

Create a file named config.yaml with the following structure:

models:
  - name: my-model
    engine: openai
    model: gpt-3.5-turbo
    api_key: ${OPENAI_API_KEY}

This minimal configuration:

  • Defines a model named "my-model"
  • Uses the OpenAI engine
  • Specifies GPT-3.5 Turbo as the model
  • References an environment variable for the API key

Advanced Configuration

For more complex setups, you can configure multiple models and engines:

models:
  - name: gpt4
    engine: openai
    model: gpt-4
    api_key: ${OPENAI_API_KEY}
    
  - name: local-llama
    engine: llama.cpp
    model_path: /path/to/llama-model.gguf
    
  - name: anthropic-claude
    engine: anthropic
    model: claude-2
    api_key: ${ANTHROPIC_API_KEY}

Running the Server

Start the Server

To start the MCP server with your configuration:

mcp-server --config path/to/config.yaml

By default, the server runs on localhost:8000. You can specify a different address:

mcp-server --config path/to/config.yaml --host 0.0.0.0 --port 9000

Environment Variables

The server supports referencing environment variables in the configuration file using ${VARIABLE_NAME} syntax. Set your API keys as environment variables before starting the server:

export OPENAI_API_KEY=your-api-key-here
export ANTHROPIC_API_KEY=your-anthropic-key-here
mcp-server --config config.yaml

Using the Server

API Endpoints

The MCP server provides the following key endpoints:

  • POST /v1/models: List available models
  • POST /v1/chat/completions: Generate chat completions
  • POST /v1/completions: Generate text completions

Example: Chat Completions

To generate a chat completion:

curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "my-model",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'

Example: Using with Client Libraries

You can use OpenAI client libraries by pointing them to your MCP server:

from openai import OpenAI

client = OpenAI(
    api_key="not-needed",  # MCP server handles authentication
    base_url="http://localhost:8000/v1"
)

response = client.chat.completions.create(
    model="my-model",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"}
    ]
)

print(response.choices[0].message.content)

Troubleshooting

Common Issues

  • Connection refused: Ensure the server is running and the port is accessible
  • Model not found: Verify your model name matches the configuration file
  • Authentication error: Check that your API keys are correctly set in environment variables
  • Missing dependencies: Some engines require additional packages to be installed

Logs

To enable debug logs for troubleshooting:

mcp-server --config config.yaml --log-level debug

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later