Skip to content

Architecture Overview

The Glean PowerShell repository implements a three-layer architecture consisting of a Python-based code generator, a generated PowerShell module, and a PowerShell-based MCP server. The Python generator consumes OpenAPI specifications to produce the PowerShell cmdlets, which are then wrapped by a hand-written runtime for authentication and HTTP handling. The MCP server leverages this module to expose Glean capabilities to AI agents via JSON-RPC. The entire system is orchestrated by a PowerShell build script that manages regeneration, testing, and packaging.

The core of the module is generated from the gleanwork/open-api specification using a deterministic Python generator located in the generator/ directory 1. This generator produces 111 operations (68 client and 43 indexing) as PowerShell cmdlets, ensuring every published operation is covered except those marked for removal. The generated code resides in Public/Client/ and Public/Indexing/, while a small hand-written runtime in Private/ handles HTTP, authentication, retry logic, and pagination. The module manifest Glean.psd1 and loader Glean.psm1 are also generated or managed to support import and alias registration.

diagram

The mcp/ directory contains a Glean MCP server written entirely in PowerShell, which acts as a layer on top of the generated module. This server replicates the functionality of the official @gleanwork MCP server and speaks JSON-RPC 2.0 over stdio to expose Glean as tools to hosts like Claude Code. It maps specific tools such as glean_search and glean_chat to backing cmdlets like Search-GleanSearch and New-GleanChat. An opt-in glean_invoke tool allows calling any of the 111 cmdlets when GLEAN_MCP_ALLOW_INVOKE=1 is set. The server uses the module’s authentication mechanisms, supporting both token and cookie-based sessions, and ensures logging goes to stderr while protocol messages go to stdout.

Development and release workflows are orchestrated by build.ps1, which checks for prerequisites including PowerShell 7.2+, Pester, PSScriptAnalyzer, and Python 3 2. The script first runs the Python generator to create the module from vendored specs, then imports the module and runs the full Pester test suite. The test suite includes a “Contract” test that verifies the generated surface matches the spec by checking parameters, required flags, media types, and HTTP method/path/body for all 111 operations 1. Additional tests cover naming uniqueness, module validity, runtime behavior (auth, retries, paging), and MCP protocol correctness. For packaging, Build-GleanPackage.ps1 creates a versioned, checksummed zip file, and install.ps1 verifies the SHA256 before installation.

diagram