Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Git files
.git
.gitignore

# Python
__pycache__
*.py[cod]
*$py.class
*.so
.Python
*.egg-info
dist
build
*.egg

# Virtual environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Other
scratch/
README.md
.python-version
uv.lock
smithery.yaml
54 changes: 54 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# GitHub Actions Workflows

This directory contains GitHub Actions workflows for continuous integration and deployment.

## Workflows

### Python Package CI (`python-package.yml`)

Runs on every push to `main` and on all pull requests.

#### Jobs

1. **test** - Runs the e2e test suite
- Sets up Python 3.13
- Installs dependencies including pytest
- Configures Docker Buildx for optimal caching
- Runs the comprehensive e2e test suite (`tests/test_e2e_docker.py`)
- Tests Docker container build, startup, and functionality

2. **lint** - Code quality checks
- Sets up Python 3.13
- Installs Ruff linter
- Runs linting checks on the codebase
- Continues on error to not block the build

3. **docker-build** - Docker image validation
- Sets up Docker Buildx with GitHub Actions caching
- Builds the Docker image
- Tests basic container functionality
- Validates API key requirement
- Confirms container starts successfully

#### Best Practices Implemented

- ✅ **Matrix strategy**: Easy to add multiple Python versions if needed
- ✅ **Dependency caching**: Speeds up workflow runs using pip cache
- ✅ **Docker layer caching**: Uses GitHub Actions cache for Docker builds
- ✅ **Parallel jobs**: Test, lint, and docker-build run in parallel
- ✅ **Latest actions**: Uses latest versions of GitHub Actions (v4, v5)
- ✅ **Clear job names**: Easy to understand what each job does
- ✅ **Fail-fast disabled**: All test scenarios run even if one fails
- ✅ **Continue on error for lint**: Linting doesn't block the build

## Monitoring

Check the [Actions tab](https://github.com/ilyazub/serpapi-mcp-server/actions) in the repository to monitor workflow runs and review results.

## Badge

The build status badge in the README shows the current status of the `python-package.yml` workflow:

```markdown
[![Build](https://github.com/ilyazub/serpapi-mcp-server/actions/workflows/python-package.yml/badge.svg)](https://github.com/ilyazub/serpapi-mcp-server/actions/workflows/python-package.yml)
```
90 changes: 90 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Python Package CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f pyproject.toml ]; then
pip install -e .[test] || true
fi

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run e2e tests
run: |
pytest tests/test_e2e_docker.py -v --tb=short

lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: 'pip'

- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install ruff

- name: Run Ruff linter
run: |
ruff check . --output-format=github
continue-on-error: true

docker-build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: serpapi-mcp-server:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test Docker image
run: |
# Test that container fails without API key
docker run --rm serpapi-mcp-server:test 2>&1 | grep -q "SERPAPI_API_KEY" && echo "✓ API key validation works" || exit 1

# Test that container starts with API key
timeout 3 docker run --rm -e SERPAPI_API_KEY=test_key serpapi-mcp-server:test || [ $? -eq 124 ] && echo "✓ Container starts successfully"
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use Python 3.13 slim image for smaller size
FROM python:3.13-slim

# Set working directory
WORKDIR /app

# Copy project files
COPY pyproject.toml ./
COPY src/ ./src/

# Install dependencies
RUN pip install --no-cache-dir google-search-results>=2.4.2 "mcp[cli]>=1.3.0" python-dotenv httpx

# Set environment variables
ENV PYTHONUNBUFFERED=1

# Expose the MCP server (stdio mode doesn't need ports, but keeping for future HTTP mode)
# No EXPOSE needed for stdio mode

# Run the server
CMD ["python", "-m", "src.serpapi-mcp-server.server"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Cool, thanks! Please add an e2e test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comprehensive e2e test suite in commit 3892965. The tests validate:

  • Docker image builds successfully
  • Container requires SERPAPI_API_KEY environment variable
  • Container starts and runs correctly with API key
  • Python 3.13 is used
  • All dependencies are installed
  • Server module is accessible

All 6 tests pass. Run with: pytest tests/test_e2e_docker.py -v

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 SerpApi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ dependencies = [
"google-search-results>=2.4.2",
"mcp[cli]>=1.3.0",
]

[project.optional-dependencies]
test = [
"pytest>=8.0.0",
]
54 changes: 54 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# End-to-End Tests

This directory contains end-to-end tests for the SerpApi MCP Server.

## Running Tests

### Prerequisites

Install test dependencies:

```bash
pip install pytest
```

### Run All Tests

```bash
pytest tests/ -v
```

### Run Specific Test File

```bash
pytest tests/test_e2e_docker.py -v
```

## Test Coverage

### Docker E2E Tests (`test_e2e_docker.py`)

Tests the Docker container functionality:

- **test_docker_image_exists**: Verifies the Docker image builds successfully
- **test_container_requires_api_key**: Ensures container validates the required `SERPAPI_API_KEY` environment variable
- **test_container_starts_with_api_key**: Confirms container starts properly when API key is provided
- **test_container_python_version**: Validates Python 3.13 is used in the container
- **test_container_has_dependencies**: Checks all required dependencies are installed
- **test_server_module_exists**: Verifies the server module is present and accessible

## CI/CD

These tests are designed to run in CI/CD pipelines and handle environment-specific issues like SSL certificate verification in restricted networks.

### GitHub Actions

The e2e tests run automatically on every push to `main` and on all pull requests via GitHub Actions. See `.github/workflows/python-package.yml` for the workflow configuration.

The workflow includes:
- Running the full e2e test suite
- Code linting with Ruff
- Docker image build and validation
- Dependency and Docker layer caching for faster builds

Check the [Actions tab](https://github.com/ilyazub/serpapi-mcp-server/actions) to monitor test results.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for SerpApi MCP Server."""
Loading
Loading