Skip to main content

Python client + MCP server adapter for Glean (search, chat, read documents). Provides a reusable HTTP client plus simple sync helper functions.

Project description

Glean MCP Server & Python Package

Simple, focused implementation providing:

  • Cookie-based client (glean_mcp.cookie_client.GleanClient) — uses browser session cookies
  • Token-based client (glean_mcp.token_client.TokenBasedGleanClient) — uses API tokens for server-to-server auth
  • MCP server (python -m glean_mcp.server) — auto-detects authentication method; ready for Docker

Links: Releases · Cookie Guide · Token Auth Guide

Install

pip install -U glean-mcp

Package Layout

src/
└── glean_mcp/
    ├── cookie_client.py      # Cookie-based authentication client
    ├── token_client.py       # Token-based authentication client
    ├── server.py             # MCP server with auto-detection
    └── glean_filter.py       # Response filtering utilities

Quick Start

MCP Server (local or Docker)

The MCP server automatically detects your authentication method.

# Choose ONE (token preferred)
export GLEAN_API_TOKEN="your-api-token"   # preferred
# OR
export GLEAN_COOKIES="your-browser-cookies"

# Set your Glean instance
export GLEAN_BASE_URL="https://your-company-be.glean.com"  # or set GLEAN_INSTANCE=your-company

# Run the MCP server locally
python -m glean_mcp.server

Docker (example):

docker run --pull always --rm \
  -e GLEAN_API_TOKEN="$GLEAN_API_TOKEN" \
  -e GLEAN_BASE_URL="$GLEAN_BASE_URL" \
  ghcr.io/alankyshum/glean-mcp-server:latest

Upgrade: use --pull always (Docker) or pip install -U glean-mcp (pip).

Library Usage (async)

Cookie-based:

from glean_mcp import GleanClient

client = GleanClient(base_url, cookies)
results = await client.search("onboarding docs")
await client.close()

Token-based:

from glean_mcp import TokenBasedGleanClient

client = TokenBasedGleanClient(base_url, api_token)
results = await client.search("onboarding docs")
await client.close()

Auto-detection (same logic as server):

from glean_mcp import create_glean_client

client = create_glean_client()  # Uses env vars; prefers token
results = await client.search("onboarding docs")
await client.close()

Authentication

Two supported methods:

🍪 Cookies (original)

  • Use browser cookies from your Glean session
  • Requires GLEAN_COOKIES
  • Uses /api/v1/ endpoints
  • See Cookie Guide

🔑 Token (recommended)

  • Use Glean API tokens for server-to-server authentication
  • Requires GLEAN_API_TOKEN
  • Uses /rest/api/v1/ endpoints
  • More secure for automated/production environments
  • See Token Auth Guide

🤖 Auto-detection rules

  1. If GLEAN_API_TOKEN is set → token-based auth
  2. Else if GLEAN_COOKIES is set → cookie-based auth
  3. If both are set → token preferred
  4. If neither is set → error with guidance

Environment Variables

Required for server/library:

Optional (server behavior):

  • GLEAN_DEFAULT_PAGE_SIZE (default: 14)
  • GLEAN_DEFAULT_SNIPPET_SIZE (default: 215)
  • GLEAN_TOOL_DESCRIPTION (tool description text)
  • GLEAN_AUTO_OPEN_BROWSER (default: true)

Development

git clone https://github.com/alankyshum/glean-mcp-server.git
cd glean-mcp-server
python -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
pytest -q

Versioning & Publishing

  • Semantic versioning; breaking changes bump MAJOR
  • Tag vX.Y.Z after updating version strings; CI publishes to PyPI/GHCR if versions match

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glean_mcp-3.1.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glean_mcp-3.1.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file glean_mcp-3.1.0.tar.gz.

File metadata

  • Download URL: glean_mcp-3.1.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for glean_mcp-3.1.0.tar.gz
Algorithm Hash digest
SHA256 65a37edc3297a8dad2d8ec5a492e45119ff6c88c62f9b38e520df96994eb66f6
MD5 8b65a7a63c9744e7a5a31decb12d78ab
BLAKE2b-256 aad0edf52685c23b40375658f3f1bacef7c26f4c21ecf3fdaf9b387696e6e716

See more details on using hashes here.

File details

Details for the file glean_mcp-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: glean_mcp-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for glean_mcp-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd76059fd6dac6b2b77edc52112d0e01114fa49268f05a3b334fd87c11d0f9ef
MD5 40ee4dc424c9ed2eddc28fce341ce8e2
BLAKE2b-256 a5fb286e6cb4b49a9e8b5aa0e2498df691d16b71dfc3b1e9521e898fe25716fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page