Skip to content

sezallagwal/mcpwh

Repository files navigation

Rocket.Chat Minimal MCP Server Generator

A gemini-cli extension that generates minimal MCP servers covering only the Rocket.Chat API endpoints your project needs — solving context bloat.

The Problem

Today, one major problem when adopting MCP is "context bloat" — almost all MCP servers are written to support a large set of service APIs, and anyone adopting them will have most of their token budget consumed by static MCP requirements associated with API calls they will never need. This situation is exacerbated in agentic code generator workflows where every agent is burning tokens in loops unnecessarily while supporting APIs/tools that the project will never use.

The Solution

This generator solves context bloat by letting Rocket.Chat developers generate a production-grade minimal MCP server covering only the subset of APIs required by their project. It automatically parses Rocket.Chat's official OpenAPI specs at runtime, lets you describe what you need in plain English, identifies the relevant API domains, presents endpoints grouped by functionality, recommends the most relevant ones for your use case, and lets you adjust the selection to match your project's exact needs. The output is a multi-file MCP server with auto-generated tests, a shared HTTP client, and authentication handling built in — significantly reducing the cost of all Rocket.Chat code generation projects involving MCP.

Key Features

  • Automatic OpenAPI parsing — Fetches Rocket.Chat's official OpenAPI YAML specs from GitHub at runtime and parses them using @apidevtools/swagger-parser, dereferencing all $refs into a fully resolved spec. No manual endpoint definitions needed.
  • Zero maintenance — When RC adds or changes endpoints, they're available immediately. No manual updates, no version lag.
  • Full API coverage — All 12 Rocket.Chat API domains available out of the box, always in sync with the official spec.
  • Tag-based grouping — Endpoints are organized by semantic tags (e.g., "Chat", "Channels", "DM") so Gemini can quickly identify the right operationIds for workflow composition.
  • Three-tier caching — Parsed specs are cached in memory for instant reuse, persisted to disk (24h TTL) to survive restarts, and fetched from GitHub only on cache miss. Parse once, reuse everywhere.
  • Lazy schema extraction — When browsing endpoints, only lightweight summaries (name, method, path) are extracted. The expensive JSON Schema mapping only runs for the endpoints you actually select for generation.
  • Parallel domain fetching — When multiple API domains are queried (e.g., omnichannel + messaging), all specs are fetched and parsed concurrently rather than one at a time.
  • Domain-indexed lookup — During browsing, the tool builds an index of which endpoints belong to which domain. When generating, it uses this index to search only the relevant spec files instead of scanning all 12.
  • Multi-file output with tests — Template-based TypeScript generation using @modelcontextprotocol/sdk. Each generated server is a complete project: one file per tool, a shared HTTP client for all API calls, per-tool test files, server-level tests, a README with setup instructions, and config files.
  • Minimality report — After generation, shows exactly how much you saved: endpoint count reduction, schema size reduction, and estimated token savings compared to a full-coverage server.
  • Provider abstraction — The generator is built on a SpecProvider interface. Rocket.Chat is the default provider, but the architecture supports any OpenAPI-described API via custom providers (e.g., LocalFileProvider for local spec files).
  • 284 tests — Comprehensive test suite: parser, code generation, workflow composition, 12 end-to-end workflow tests across 9 RC API domains, edge cases, and schema mapper coverage.

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/sezallagwal/mcpGenerator
    cd mcpGenerator
  2. Install dependencies:

    npm install
  3. Register as a gemini-cli extension:

    mkdir -p ~/.gemini/extensions
    ln -s "$(pwd)" ~/.gemini/extensions/mcpGenerator

    This symlinks the project into gemini-cli's extensions directory so it's loaded automatically.

Usage

Launch gemini in any project directory. The extension provides two MCP tools that Gemini uses automatically based on your natural language requests.

Quick Start

Just describe what you want in plain English:

gemini> I need an MCP server that can send messages and manage channels

Gemini will:

  1. Identify the relevant API domains from your description
  2. Fetch all endpoints and pick the operationIds needed for your use case
  3. Ask where to save the project
  4. Compose the workflow, validate, and generate the complete project in one call

See Workflow Details below for the full step-by-step.

Slash Command

You can also use the explicit slash command:

gemini> /generator:generate send alerts based on workspace statistics

Example Prompts

  • "Generate an MCP server for sending messages and managing channels"
  • "I need a support bot that handles live chat and messaging"
  • "Build an MCP server to monitor workspace health and statistics"
  • "Create tools for user management and role assignment"

Workflow Details

The workflow is fully automated — Gemini handles endpoint selection, workflow composition, and code generation autonomously based on your description.

  1. Describe your intent — Just say what you want in plain English (e.g., "build a support bot for live chat"). You don't need to know API domain names — Gemini maps your keywords to the right domains automatically.
  2. Endpoint discovery — Gemini calls list_endpoints with the relevant domains, which returns all endpoints grouped by tag. Gemini picks the operationIds it needs for the workflow.
  3. Choose output location — Gemini asks where to save the project (e.g., /tmp/my-rc-server).
  4. Generated! — Gemini passes the workflow steps and configuration directly to generate, which validates, composes, and writes the complete project to disk in one call.

Generated Project Structure

The generator creates an MCP server project:

my-project/
└── mcp-server/
    ├── src/
    │   ├── server.ts          # MCP server entry point
    │   ├── rc-client.ts       # Shared Rocket.Chat HTTP client
    │   ├── tools/
    │   │   └── *.ts           # One file per workflow tool
    │   └── tests/
    │       └── setup.ts       # Test setup
    ├── package.json
    ├── tsconfig.json
    ├── .env.example
    └── README.md

Using the Generated Server

cd my-rc-server
npm install
cp .env.example .env
# Edit .env with your Rocket.Chat credentials

The generated server uses stdio transport. To use it, add it to your MCP client's configuration:

{
  "mcpServers": {
    "my-rc-server": {
      "command": "npm",
      "args": ["start"],
      "cwd": "/path/to/my-rc-server"
    }
  }
}

You can also run npm start directly to test the server on stdio.

Available API Domains

The generator covers all 12 Rocket.Chat API domains (~500-800+ endpoints total):

Domain Description
authentication Login, OAuth, 2FA, tokens
messaging Send messages, threads, reactions, pins
rooms Channels, groups, DMs, room settings
user-management Users, roles, avatars, presence
omnichannel Live chat, agents, visitors, queues
integrations Webhooks, incoming/outgoing integrations
settings Workspace settings, permissions, OAuth apps
statistics Server stats, online users, metrics
notifications Push notifications, preferences
content-management Emoji, custom sounds, assets
marketplace-apps Apps, marketplace, permissions
miscellaneous Server info, DNS, licenses

API specs are fetched from the official Rocket.Chat OpenAPI repo at runtime, so the generator always reflects the latest available endpoints.

Development

Project Structure

mcpGenerator/
├── gemini-extension.json    # Extension manifest
├── GEMINI.md                # Model instructions for Gemini
├── commands/
│   └── generator/
│       └── generate.toml    # /generator:generate slash command
├── src/
│   ├── server.ts            # MCP server (tools: get_capability_guide, get_endpoint_schemas, list_endpoints, compose_workflow, generate)
│   ├── utils.ts             # Shared utilities
│   ├── capability-guide.ts  # Capability guide formatter
│   ├── providers/
│   │   ├── types.ts         # SpecProvider interface + AuthConfig
│   │   ├── rocketchat.ts    # Rocket.Chat provider (default)
│   │   └── local-file.ts    # Local file provider (generic OpenAPI)
│   ├── mcp-server/
│   │   ├── mcpServerCodegen.ts    # Workflow → TypeScript code generator
│   │   ├── mcpServerTemplates.ts  # Shared project scaffolding templates
│   │   ├── workflowComposer.ts    # Workflow validation & composition
│   │   ├── workflow-engine.ts     # Runtime workflow execution engine
│   │   ├── types.ts               # Workflow type definitions
│   │   └── parser/
│   │       ├── index.ts           # OpenAPI parser (provider-based fetch, cache, extract)
│   │       ├── schema-mapper.ts   # OpenAPI → JSON Schema conversion
│   │       └── types.ts           # Parser type definitions
│   └── tests/
│       ├── parser.test.ts              # Parser unit tests
│       ├── generate.test.ts            # Code generation tests
│       ├── workflow.test.ts            # Workflow composition tests
│       ├── workflow-engine.test.ts     # Runtime engine tests
│       ├── capability-guide.test.ts    # Guide formatter tests
│       ├── e2e-workflows.test.ts       # 12 end-to-end workflow tests
│       ├── workflow-edge-cases.test.ts # Composition edge cases
│       ├── parser-coverage.test.ts     # Parser coverage (all domains)
│       └── fixtures/
│           └── workflows.ts            # 12 real-world workflow definitions
├── scripts/
│   └── unregister-mcp.sh   # Remove a generated server from Gemini CLI
├── package.json
└── tsconfig.json

Running Tests

npm test

Building

npm run build

Running in Dev Mode

npm run dev

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors