Skip to content

Commit 8266408

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 5cab1f0 commit 8266408

15 files changed

Lines changed: 2341 additions & 1721 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# ignore compiled files in packages
1313
/packages/**/*.js.map
1414
/packages/**/*.js
15-
!/packages/igniteui-mcp/igniteui-doc-mcp/scripts/build.js
1615
/scripts/**/*.js.map
1716
/scripts/**/*.js
1817
/spec/**/*.js.map
@@ -30,6 +29,9 @@ packages/core/config/Config.schema.json
3029
!packages/cli/templates/angular/**/files/**/*
3130
!packages/cli/templates/react/**/files/**/*
3231

32+
# bundled MCP server (build artifact)
33+
/packages/cli/mcp/
34+
3335
# Misc
3436
npm-debug.log*
3537
yarn-error.log*

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MCP server source, submodules, and build artifacts
2+
# (bundled into packages/cli/mcp/ via build:mcp-bundle script)
3+
packages/igniteui-mcp/

README.md

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This monorepo contains several packages that combine into the `igniteui-cli`:
3838
| [@igniteui/angular-templates](https://www.npmjs.com/package/@igniteui/angular-templates) | Contains the template definitions for Angular components | [packages/igx-templates](./packages/igx-templates) |
3939
| [@igniteui/angular-schematics](https://www.npmjs.com/package/@igniteui/angular-schematics) | IgniteUI CLI implementation to be used with Angular CLI's schematics engine | [packages/ng-schematics](./packages/ng-schematics) |
4040
| [igniteui-cli](https://www.npmjs.com/package/igniteui-cli) | Standalone IgniteUI CLI tool for React, jQuery and Angular | [packages/cli](./packages/cli) |
41+
| [@igniteui/mcp-server](https://www.npmjs.com/package/@igniteui/mcp-server) | MCP server providing AI assistants with Ignite UI documentation and API reference | [packages/igniteui-mcp/igniteui-doc-mcp](./packages/igniteui-mcp/igniteui-doc-mcp) |
4142

4243
## Table of Contents
4344

@@ -50,6 +51,9 @@ This monorepo contains several packages that combine into the `igniteui-cli`:
5051
* [Generate Ignite UI for React project](#generate-ignite-ui-for-react-project)
5152
* [Adding components](#adding-components)
5253
* [Build and run](#build-and-run)
54+
* [MCP Server](#mcp-server)
55+
* [Using with AI Assistants](#using-with-ai-assistants)
56+
* [Testing with MCP Inspector](#testing-with-mcp-inspector)
5357
* [Schematics](#schematics)
5458
* [Schematic Definitions](#schematic-definitions)
5559
* [Contribution](#contribution)
@@ -137,6 +141,54 @@ ig build
137141
ig start
138142
```
139143

144+
## MCP Server
145+
146+
The CLI includes a bundled [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that provides AI assistants with Ignite UI documentation search, API reference lookup, and scaffolding guidance for Angular, React, Blazor, and Web Components.
147+
148+
Start the MCP server:
149+
```bash
150+
ig mcp
151+
```
152+
153+
The server runs over stdio and supports the following options:
154+
```bash
155+
ig mcp --remote <url> # Use a remote backend instead of the local SQLite database
156+
ig mcp --debug # Enable debug logging to mcp-server.log
157+
```
158+
159+
### Using with AI Assistants
160+
161+
Configure your MCP client (e.g., VS Code, Claude Desktop, Cursor) to use the CLI as the MCP server:
162+
163+
```json
164+
{
165+
"mcpServers": {
166+
"igniteui": {
167+
"command": "ig",
168+
"args": ["mcp"]
169+
}
170+
}
171+
}
172+
```
173+
174+
The MCP server exposes the following tools to AI assistants:
175+
176+
| Tool | Description |
177+
|------|-------------|
178+
| `list_components` | List available Ignite UI component docs for a framework |
179+
| `get_doc` | Fetch full markdown content of a specific component doc |
180+
| `search_docs` | Full-text search across Ignite UI documentation |
181+
| `get_api_reference` | Retrieve the full API reference for a component or class |
182+
| `search_api` | Search API entries by keyword or partial component name |
183+
| `generate_ignite_app` | Return a setup guide for a new Ignite UI project |
184+
185+
### Testing with MCP Inspector
186+
187+
To interactively test and debug the MCP server tools:
188+
```bash
189+
npx @modelcontextprotocol/inspector ig mcp
190+
```
191+
140192
## Schematics
141193
You can also add `Ignite UI for Angular` components to your projects by using the `igniteui/angular-schematics` package. It included schematic definitions for most of the logic present in the [`igniteui-cli`](/packages/cli). These can be called in any existing Angular project or even when creating one. You can learn more about the schematics package on from its [readme](/package/ng-schematics).
142194

@@ -147,12 +199,88 @@ See the [Contribution guide](https://github.com/IgniteUI/igniteui-cli/blob/maste
147199
### Run locally
148200
1. Clone the repository
149201
2. Install dependencies with `yarn install`
150-
3. To build the packages, run `yarn build` in the project `root`.
151-
4. Open in Visual Studio Code
202+
3. Build the MCP server and bundle it into the CLI:
203+
```bash
204+
cd packages/igniteui-mcp/igniteui-doc-mcp
205+
npm install
206+
npm run build
207+
cd ../../..
208+
npm run build:mcp-bundle
209+
```
210+
4. Build the monorepo packages: `npm run build`
211+
5. Open in Visual Studio Code
152212

153213
There is a predefined launch.config file for VS Code in the root folder, so you can use VS Code View/Debug window and choose one of the predefined actions. These include launching the step by step guide, create new project for a particular framework or add components.
154214

155-
5. Hit Start Debugging/F5
215+
6. Hit Start Debugging/F5
216+
217+
#### MCP Server development
218+
219+
The MCP server at `packages/igniteui-mcp/igniteui-doc-mcp` has its own build pipeline, separate from the monorepo. It uses ESM (ES2022, Node16 modules) while the rest of the monorepo uses CommonJS. See [DEVELOPMENT.md](./packages/igniteui-mcp/igniteui-doc-mcp/DEVELOPMENT.md) for the full MCP server development guide.
220+
221+
**Build the MCP server:**
222+
```bash
223+
cd packages/igniteui-mcp/igniteui-doc-mcp
224+
npm install # Install MCP-specific dependencies (separate from yarn workspaces)
225+
npm run build # Compile TypeScript + copy SQLite DB to dist/
226+
```
227+
228+
**Build API reference documentation:**
229+
230+
The MCP server includes API reference docs for Angular, React, and Web Components. Angular and Web Components docs are generated from framework submodules via TypeDoc (submodules are auto-initialized by the build scripts). React uses a pre-built TypeDoc JSON model checked into git.
231+
232+
```bash
233+
cd packages/igniteui-mcp/igniteui-doc-mcp
234+
npm run build:docs:angular # Angular: init submodule → TypeDoc → markdown + index.json
235+
npm run build:docs:webcomponents # Web Components: init submodule → build lib → TypeDoc → markdown + index.json
236+
npm run build:docs:all # Build both
237+
```
238+
239+
> **Note:** Web Components requires a one-time library build (`npm run build:publish` in the submodule) before TypeDoc can run. The build script handles this automatically.
240+
241+
**Bundle MCP into CLI** (from the repo root):
242+
```bash
243+
npm run build:mcp-bundle # Copies dist/ and docs/ into packages/cli/mcp/
244+
```
245+
246+
This copies the compiled MCP server, SQLite documentation database, and API reference docs into the CLI package. The `packages/cli/mcp/` directory is a build artifact (gitignored) and must be regenerated before publishing.
247+
248+
**Test the MCP server locally:**
249+
```bash
250+
npm run build:mcp-bundle
251+
npm run build
252+
node packages/cli/lib/cli.js mcp # Start via CLI
253+
# or directly:
254+
node packages/cli/mcp/dist/index.js # Start the bundled server
255+
```
256+
257+
#### Building CLI package with bundled MCP server
258+
259+
The CLI package includes the MCP server as a bundled build artifact (not an npm dependency). To produce a complete CLI package with full MCP functionality, follow these steps:
260+
261+
```bash
262+
# 1. Install monorepo dependencies
263+
yarn install
264+
265+
# 2. Build the MCP server
266+
cd packages/igniteui-mcp/igniteui-doc-mcp
267+
npm install
268+
npm run build # Compile TypeScript + copy SQLite DB
269+
270+
# 3. Build API reference docs (optional but recommended for full functionality)
271+
npm run build:docs:all # Init submodules + generate Angular + WC API docs via TypeDoc
272+
273+
# 4. Bundle MCP into CLI (from repo root)
274+
cd ../../..
275+
npm run build:mcp-bundle # Copy dist/ + docs/ → packages/cli/mcp/
276+
277+
# 5. Build all packages for publishing
278+
npm run build-pack
279+
```
280+
281+
After step 5, `npm pack` from the repo root or `packages/cli/` will produce a tarball with the MCP server, documentation database, and API reference docs all included.
282+
283+
> **Skipping API docs:** If you skip step 3, the MCP server will still work for `list_components`, `get_doc`, `search_docs`, and `generate_ignite_app` tools using the bundled SQLite database. Only the `get_api_reference` and `search_api` tools require API docs.
156284

157285
## Data Collection
158286

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"jasmine": "node spec/jasmine-runner.js",
2929
"coverage": "nyc report --report-dir",
3030
"lint": "eslint -c eslint.config.mjs ./**/*.ts",
31-
"config-schema": "typescript-json-schema packages/core/types/Config.ts Config -o packages/core/config/Config.schema.json"
31+
"config-schema": "typescript-json-schema packages/core/types/Config.ts Config -o packages/core/config/Config.schema.json",
32+
"build:mcp-bundle": "node scripts/bundle-mcp.js"
3233
},
3334
"nyc": {
3435
"extension": [

packages/cli/lib/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
doc,
1010
generate,
1111
list,
12+
mcp,
1213
newCommand,
1314
start,
1415
test,
@@ -54,6 +55,7 @@ export async function run(args = null) {
5455
.command(test)
5556
.command(list)
5657
.command(upgrade)
58+
.command(mcp)
5759
.version(false) // disable built-in `yargs.version` to override it with our custom option
5860
.options({
5961
version: {

packages/cli/lib/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { default as config } from "./config";
44
export { default as doc } from "./doc";
55
export { default as generate } from "./generate";
66
export { default as list } from "./list";
7+
export { default as mcp } from "./mcp";
78
export { default as newCommand } from "./new";
89
export { default as start } from "./start";
910
export { default as test } from "./test";

packages/cli/lib/commands/mcp.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import { spawn } from "child_process";
4+
import { CommandType, PositionalArgs } from "./types";
5+
import { ArgumentsCamelCase } from "yargs";
6+
7+
const command: CommandType = {
8+
command: "mcp",
9+
describe: "Starts the Ignite UI MCP server for AI assistant integration",
10+
templateManager: null,
11+
builder: (yargs) => {
12+
return yargs
13+
.option("remote", {
14+
describe: "Backend URL for remote mode (uses HTTP instead of local SQLite)",
15+
type: "string",
16+
requiresArg: true
17+
})
18+
.option("debug", {
19+
describe: "Enable debug logging to mcp-server.log",
20+
type: "boolean",
21+
default: false
22+
})
23+
.usage("");
24+
},
25+
async handler(argv: ArgumentsCamelCase<PositionalArgs>) {
26+
const mcpEntry = path.resolve(__dirname, "..", "..", "mcp", "dist", "index.js");
27+
28+
if (!fs.existsSync(mcpEntry)) {
29+
process.stderr.write(
30+
"MCP server bundle not found. Build it first:\n" +
31+
" cd packages/igniteui-mcp/igniteui-doc-mcp && npm install && npm run build && cd ../../..\n" +
32+
" npm run build:mcp-bundle\n"
33+
);
34+
process.exitCode = 1;
35+
return;
36+
}
37+
38+
const args: string[] = [];
39+
if (argv.remote) {
40+
args.push("--remote", argv.remote as string);
41+
}
42+
if (argv.debug) {
43+
args.push("--debug");
44+
}
45+
46+
return new Promise<void>((resolve, reject) => {
47+
const child = spawn(process.execPath, [mcpEntry, ...args], {
48+
stdio: "inherit"
49+
});
50+
51+
child.on("error", (err) => {
52+
process.stderr.write(`Failed to start MCP server: ${err.message}\n`);
53+
reject(err);
54+
});
55+
56+
child.on("exit", (code) => {
57+
process.exitCode = code ?? 0;
58+
resolve();
59+
});
60+
});
61+
}
62+
};
63+
64+
export default command;

packages/cli/lib/commands/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const DOC_COMMAND_NAME = "doc";
1212
export const TEST_COMMAND_NAME = "test";
1313
export const LIST_COMMAND_NAME = "list";
1414
export const UPGRADE_COMMAND_NAME = "upgrade-packages";
15+
export const MCP_COMMAND_NAME = "mcp";
1516

1617
export const ALL_COMMANDS = new Set([
1718
ADD_COMMAND_NAME,
@@ -23,7 +24,8 @@ export const ALL_COMMANDS = new Set([
2324
DOC_COMMAND_NAME,
2425
TEST_COMMAND_NAME,
2526
LIST_COMMAND_NAME,
26-
UPGRADE_COMMAND_NAME
27+
UPGRADE_COMMAND_NAME,
28+
MCP_COMMAND_NAME
2729
]);
2830

2931
export interface PositionalArgs {

packages/cli/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
"migrations/**/*.json",
4040
"schematics/**/*.d.ts",
4141
"schematics/**/*.js",
42-
"schematics/**/*.json"
42+
"schematics/**/*.json",
43+
"mcp/dist/**/*.js",
44+
"mcp/dist/**/*.d.ts",
45+
"mcp/dist/igniteui-docs.db",
46+
"mcp/dist/package.json",
47+
"mcp/docs/**/*.json",
48+
"mcp/docs/**/*.md"
4349
],
4450
"nyc": {
4551
"extension": [
@@ -69,14 +75,18 @@
6975
"@igniteui/angular-templates": "~21.1.1492",
7076
"@igniteui/cli-core": "~14.9.2",
7177
"@inquirer/prompts": "^7.9.0",
78+
"@modelcontextprotocol/sdk": "^1.12.1",
7279
"@types/yargs": "^17.0.33",
7380
"chalk": "^5.3.0",
81+
"dotenv": "^17.2.4",
7482
"glob": "^11.0.0",
7583
"open": "^10.1.0",
7684
"resolve": "^1.22.8",
85+
"sql.js": "^1.14.1",
7786
"through2": "^4.0.2",
7887
"typescript": "~5.5.4",
79-
"yargs": "^17.7.2"
88+
"yargs": "^17.7.2",
89+
"zod": "^3.25.1"
8090
},
8191
"devDependencies": {
8292
"@angular-devkit/core": "^21.0.0",

0 commit comments

Comments
 (0)