Skip to content

Multi architecture docker build for Glean MCP #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Version control
.git
.gitignore
.gitattributes

# Build artifacts
build
node_modules
coverage
.nyc_output

# Development files
.vscode
.idea
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Docker files
Dockerfile
.dockerignore
docker-compose*

# CI/CD
.github

# Misc
.DS_Store
*.md
!README.md
113 changes: 113 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Docker Build and Deploy

on:
push:
branches:
- main
- feature/multi-arch-docker-build
tags:
- 'v*'
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
NODE_VERSION: '20'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test

build-and-deploy:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
# gleanwork/mcp-server
ghcr.io/gleanwork/mcp-server
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha,format=long

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

# - name: Login to DockerHub
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
DOCKER_HASH=${{ github.sha }}

cleanup:
name: Cleanup
needs: build-and-deploy
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'

steps:
- name: Remove old packages
uses: actions/delete-package-versions@v4
with:
package-name: glean-mcp-server
owner: gleanwork
package-type: container
min-versions-to-keep: 10
delete-only-untagged-versions: true
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax=docker/dockerfile:1.4

# Build stage
FROM --platform=$BUILDPLATFORM node:20.11-bullseye AS builder

# Add metadata
LABEL org.opencontainers.image.source="https://github.com/aaronsb/glean-mcp-server"
LABEL org.opencontainers.image.description="Glean MCP Server"
LABEL org.opencontainers.image.licenses="MIT"

# Install build dependencies
ENV NODE_ENV=development
RUN apt-get update && apt-get install -y \
git \
build-essential \
python3 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app

# Copy package files first for better layer caching
COPY package.json package-lock.json ./
RUN npm ci --ignore-scripts

# Copy source and build
COPY . .
# Run TypeScript compiler and set permissions separately
RUN npx tsc && chmod +x build/index.js

# Production stage
FROM node:20.11-bullseye
ENV NODE_ENV=production
WORKDIR /app

# Set docker hash as environment variable
ARG DOCKER_HASH=unknown
ENV DOCKER_HASH=$DOCKER_HASH

# Copy only necessary files from builder
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json /app/package-lock.json ./
RUN npm ci --only=production --ignore-scripts && \
chmod +x build/index.js && \
mkdir -p /app/logs && \
chown -R 1000:1000 /app

# Copy and set up entrypoint
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Switch to non-root user
USER 1000:1000

ENTRYPOINT ["docker-entrypoint.sh"]
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @gleanwork/mcp-server

![](https://badge.mcpx.dev?type=server 'MCP Server')
![CI Build](https://github.com/gleanwork/mcp-server/actions/workflows/ci.yml/badge.svg)
![CI Build](https://github.com/gleanwork/mcp-server/actions/workflows/docker-build.yml/badge.svg)
[![npm version](https://badge.fury.io/js/@gleanwork%2Fmcp-server.svg)](https://badge.fury.io/js/@gleanwork%2Fmcp-server)
[![License](https://img.shields.io/npm/l/@gleanwork%2Fmcp-server.svg)](https://github.com/gleanwork/mcp-server/blob/main/LICENSE)

Expand Down Expand Up @@ -96,6 +96,65 @@ The server communicates via stdio, making it ideal for integration with AI model
node build/index.js
```

## Docker

You can also run the server using Docker:

```bash
docker run -e GLEAN_SUBDOMAIN=your_subdomain -e GLEAN_API_TOKEN=your_api_token ghcr.io/aaronsb/glean-mcp-server
```

### Building Docker Images

The repository includes scripts to build multi-architecture Docker images (AMD64 and ARM64):

#### Standard Build Script

```bash
# Build multi-architecture image locally
./scripts/build.sh

# Build with custom image name and tag
./scripts/build.sh --image-name=myorg/glean-mcp --tag=v1.0.0

# Build and push to registry
./scripts/build.sh --push

# Build for specific platforms
./scripts/build.sh --platforms=linux/amd64,linux/arm64
```

#### Improved Local Development Build Script

For a more developer-friendly experience with better error handling and output management:

```bash
# Build for local development with improved output handling
./scripts/build-local.sh

# Enable verbose mode to see all output
./scripts/build-local.sh --verbose

# Build with custom image name and tag
./scripts/build-local.sh --image-name=myorg/glean-mcp --tag=v1.0.0

# Build and push to registry
./scripts/build-local.sh --push

# Build for specific platforms
./scripts/build-local.sh --platforms=linux/amd64,linux/arm64
```

The `build-local.sh` script provides:

- Redirected output to log files to avoid overwhelming the console
- Clear status indicators with colored success/failure markers
- Extracted and focused error messages for TypeScript compiler issues
- Log file size warnings and viewing tips for large outputs
- Verbose mode option for detailed debugging

The Docker image is built for both AMD64 and ARM64 architectures by default, making it compatible with a wide range of systems including Apple Silicon Macs and standard x86 servers.

## Running in inspect mode

The server can also be run in inspect mode, which provides additional debugging information:
Expand All @@ -117,5 +176,5 @@ MIT License - see the [LICENSE](LICENSE) file for details
## Support

- Documentation: [docs.glean.com](https://docs.glean.com)
- Issues: [GitHub Issues](https://github.com/gleanwork/mcp-server/issues)
- Issues: [GitHub Issues](https://github.com/aaronsb/glean-mcp-server/issues)
- Email: [support@glean.com](mailto:support@glean.com)
5 changes: 5 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e

# Run the MCP server
exec node build/index.js "$@"
98 changes: 98 additions & 0 deletions llms-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# MCP Server Installation Guide for LLM Agents

This guide provides instructions for LLM agents like Cline to install and configure the Glean MCP Server.

## Installation Options

### Option 1: Docker Installation (Recommended)

The Docker installation method is recommended as it provides the simplest setup experience and works across different architectures (amd64 and arm64).

```json
{
"mcpServers": {
"glean": {
"command": "docker",
"args": ["run", "--rm", "-i", "ghcr.io/gleanwork/mcp-server:latest"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
```

### Option 2: Node.js Installation

If Docker is not available, you can install the MCP server using Node.js:

1. Ensure Node.js 18+ is installed
2. Clone the repository
3. Install dependencies
4. Build the project
5. Configure the MCP server

```json
{
"mcpServers": {
"glean": {
"command": "node",
"args": ["/path/to/glean-mcp-server/dist/index.js"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
```

## Environment Variables

The Glean MCP Server does not require any environment variables for basic functionality. However, you may add custom environment variables for specific use cases:

```json
"env": {
"CUSTOM_VARIABLE": "value"
}
```

## Capabilities

The Glean MCP Server provides the following capabilities:

- **Chat Tools**: Tools for interacting with chat-based APIs
- **Search Tools**: Tools for performing searches across various data sources

## Troubleshooting

### Common Issues

1. **Connection Errors**: If you encounter connection errors, ensure the server is running and accessible.

Solution: Check if the Docker container is running or if the Node.js process is active.

2. **Permission Issues**: If you encounter permission issues, ensure the user has the necessary permissions.

Solution: For Docker, ensure the user has permissions to run Docker containers.

3. **Port Conflicts**: If you encounter port conflicts, change the port mapping.

Solution: Modify the Docker run command to use a different port.

### Logs

To view logs for troubleshooting:

- **Docker**: `docker logs <container_id>`
- **Node.js**: Check the console output or configured log files

## Updating

To update to the latest version:

- **Docker**: Pull the latest image: `docker pull ghcr.io/gleanwork/mcp-server:latest`
- **Node.js**: Pull the latest code and rebuild: `git pull && npm install && npm run build`

## Support

If you encounter any issues not covered in this guide, please open an issue on the GitHub repository.
Loading
Loading