How salemove/glia-functions-tools works
1. This repository is a CLI and tooling suite for Glia Functions, a serverless functions platform built around the workerd JavaScript runtime. The codebase is centered on managing Glia-hosted functions, scaffolding projects, bundling code, and integrating with the Glia API.
2. The main runtime surface is the Node.js CLI. The primary executable is bin/glia-functions.js, with src/index.js and older root entrypoints kept for compatibility. The CLI can run in interactive mode or command mode, and it also exposes a separate MCP server mode for AI assistants.
3. CLI dispatch is layered: src/cli handles argument parsing, command routing, interactive prompts, and error handling; src/commands contains the actual command implementations. This separation is the main boundary between user interaction and business logic.
4. The command set is organized by domain:
- function lifecycle: create, update, delete, list, invoke, deploy, fetch logs, update env vars
- versions and deployment: create-and-deploy version, deploy project
- profiles and site switching: create/list/update/switch/view/delete profiles
- schedules: create/update/delete/list cron-based triggers
- KV store operations
- applet and project scaffolding
- local dev server and request handling
5. Shared platform behavior lives in src/lib and src/utils. src/lib/api.js is the primary API boundary to Glia services, while adjacent modules add retry, caching, offline behavior, validation, and config handling. These libraries are used by most commands, so they form the core service layer beneath the CLI.
6. Authentication and environment state flow through config/profile management. The README’s GLIA_KEY_ID, GLIA_KEY_SECRET, GLIA_SITE_ID, and bearer token support are reflected in profile commands and config utilities. In practice, the CLI reads credentials and profile/site selection, derives an API context, then reuses that context across function and project operations.
7. Project scaffolding is template-driven. src/templates contains reusable project/function/applet templates, base package definitions, and template inheritance artifacts. src/utils/template-* and related managers/processors handle selecting a template, expanding variables, generating files, and validating the resulting project manifest.
8. The templates are not just boilerplate; they represent distinct project archetypes and deployment shapes. Examples include basic functions, API integrations, KV store functions, export handlers, and React-based applets. Some templates inherit from base templates, which means the architecture supports layered generation rather than one-off copies.
9. Local development and packaging are handled as a separate workflow from remote deployment. The repo includes esbuild configuration, a local dev command, request simulation helpers, and code validation utilities. The intended flow is: author function code, bundle it into an output file, test it locally against a simulated runtime, then create/deploy a version to Glia.
10. The MCP server is a distinct subsystem under mcp-server/ and is also invokable from the CLI. It exposes Glia Functions operations over STDIO for AI assistants, acting as a protocol adapter over the same underlying API/command capabilities rather than a separate backend.
11. examples/ contains standalone example projects and applets that demonstrate integration patterns such as AI, AWS Bedrock, HubSpot, SMS/IVR flows, S3 export, and Teams presence. These examples are consumer-facing reference implementations, not part of the CLI’s execution path, but they clarify how generated projects are expected to be structured.
12. There is a clear compatibility boundary between the modern src/* architecture and older legacy entrypoints/utilities. The README marks root-level index.js, commands/, and utils/ as deprecated or removed in favor of bin/ and src/, so an architecture diagram should show the modern path as primary and legacy paths as backward-compatibility only.
13. Supporting infrastructure includes Jest-based tests, GitHub Actions workflows, and documentation generation scripts. These do not affect runtime behavior, but they reinforce that the repository is a packaged developer toolchain with heavy emphasis on command correctness, template generation, and API integration.
Main entry points: index.js Commands index · project-template-manager.js Template manager · api.js API client · project-deployer.js Project deployer
Components 26
CLI runtime
Primary executable path, argument handling, and command dispatch.
- CLI entry · Primary executable for the Node.js CLI.
bin/glia-functions.js - Main entry · Modern package entrypoint with compatibility support.
src/index.js - CLI core · Parses arguments, routes commands, and handles interactive flow.
src/cli/index.js - Router · Dispatches parsed input to command implementations.
src/cli/command-router.js
Commands
User-facing operations organized by domain.
- Commands index · Exports the command surface for CLI wiring.
src/commands/index.js - Create func · Creates a new Glia function project or function artifact.
src/commands/createFunction.js - Update func · Updates an existing function definition or code bundle.
src/commands/updateFunction.js - Invoke func · Runs a function through the Glia platform context.
src/commands/invokeFunction.js - Profiles · Manages credentials, site selection, and profile switching.
src/commands/profiles/index.js - Deploy project · Deploys a local project as a Glia Functions project.
src/commands/projects/deployProject.js - Create applet · Scaffolds or creates an applet-based function project.
src/commands/applets/createApplet.js - Schedules · Creates, updates, lists, and deletes cron-triggered schedules.
src/commands/schedules/index.js - KV store · Base operations for key-value store commands.
src/commands/kv-store/base.js - Export handler · Wires up export handler scaffolding and setup flow.
src/commands/exports/setupExportHandler.js - Start MCP · Launches the MCP server mode from the CLI.
src/commands/startMcpServer.js
Service layer
Shared API, config, validation, cache, and deployment behavior.
- API client · Primary boundary to Glia services and remote operations.
src/lib/api.js - Config · Resolves credentials, profile state, and API context.
src/lib/config.js - Project deployer · Coordinates project packaging and deployment steps.
src/lib/project-deployer.js - Validator · Validates project structure and manifests before deployment.
src/lib/project-validator.js
Templates
Project and applet scaffolding assets plus template processing.
- Template manager · Selects and expands project templates into files.
src/utils/project-template-manager.js - Template engine · Interpolates variables and materializes template output.
src/utils/template-engine.js - Basic function · Representative starter template for a plain function project.
src/templates/projects/basic-function - React applet · Representative applet archetype with React-based UI.
src/templates/applets/react-app
Adapters
MCP server, examples, and compatibility entrypoints.
- MCP server · STDIO adapter exposing Glia Functions operations to assistants.
mcp-server/server.js - Examples · Standalone example implementations showing common integration patterns.
examples/README.md - Legacy entry · Deprecated root-level entrypoint kept for backward compatibility.
index.js
Connections 29
- CLI entry → Main entry: boots · CLI executable loads the modern package entrypoint.
- Main entry → CLI core: starts · Entrypoint hands control to the CLI runtime.
- CLI core → Router: routes · CLI core delegates command selection and dispatch.
- Router → Commands index: dispatches · Router resolves requested commands from the registry.
- Commands index → Create func: includes · Command surface includes function creation.
- Commands index → Update func: includes · Command surface includes function updates.
- Commands index → Invoke func: includes · Command surface includes function invocation.
- Commands index → Profiles: includes · Command surface includes profile management.
- Commands index → Deploy project: includes · Command surface includes project deployment.
- Commands index → Create applet: includes · Command surface includes applet scaffolding.
- Commands index → Schedules: includes · Command surface includes schedule management.
- Commands index → KV store: includes · Command surface includes KV store operations.
- Commands index → Export handler: includes · Command surface includes export handler setup.
- Commands index → Start MCP: includes · Command surface includes MCP server mode.
- Create func → Config: uses · Function commands resolve credentials and site context.
- Update func → API client: calls · Function updates go through the Glia API boundary.
- Invoke func → API client: calls · Invocation uses platform API operations.
- Profiles → Config: writes · Profile commands manage local auth and site state.
- Deploy project → Project deployer: orchestrates · Project deployment command delegates to deployment logic.
- Project deployer → Validator: checks · Deployment validates the project before publishing.
- Project deployer → API client: publishes · Deployer sends packaged artifacts through the API.
- Create applet → Template manager: scaffolds · Applet creation pulls from template selection and expansion.
- Template manager → Template engine: renders · Template manager uses the rendering engine to expand files.
- Template manager → Basic function: selects · Project template manager can materialize starter project archetypes.
- Template manager → React applet: selects · Template manager can materialize applet archetypes.
- Start MCP → MCP server: launches · CLI command starts the dedicated MCP server process.
- MCP server → API client: adapts · MCP server exposes the same underlying Glia API capabilities.
- Examples → Basic function: demonstrates · Examples document expected project shapes and integrations.
- Legacy entry → Main entry: compat · Legacy entrypoint points to the modern entry path.