NSTOK AI Software Factory MCP Server
Official# NSTOK AI Software Factory MCP Server (TypeScript)
[](https://www.typescriptlang.org/)
[](https://modelcontextprotocol.io/)
[](https://opensource.org/licenses/MIT)
An enterprise-grade **Model Context Protocol (MCP)** server implemented in **TypeScript** that powers the **NSTOK AI Software Factory**. It allows reasoning agents (such as Codex, Antigravity, or Claude) to construct production-ready NSTOK applications directly from PRDs by discovering and reusing existing ecosystem capabilities, UI components, database models, and templates.
---
## šÆ Core Architectural Philosophy
```
SEARCH ā REUSE ā ADAPT ā CREATE
```
The system strictly enforces the principle: **Never generate code from scratch if an existing asset can satisfy or be adapted to the requirement.**
1. **Reuse First**: Prioritize existing business features (`Nstok-feature-*`), UI components (`Nstok-ui`), and database models (`Nstok-db`).
2. **Template First**: Applications start from `Nstok-app-template`; features start from `Nstok-feature-template`.
3. **Knowledge Before Code**: Understand architecture, dependencies, and patterns before mutating code.
4. **Plan Before Mutation**: `Analyze ā Plan ā Approve ā Implement ā Validate`.
5. **Closed Knowledge Loop**: Every newly generated application or feature enriches the central Knowledge Graph (`Nstok-knowledge-master`).
---
## šļø High-Level Architecture
```
āāāāāāāāāāāāāāāāāāāāāāāāā
ā CODEX ā
ā User / PRD / Task ā
āāāāāāāāāāāāā¬āāāāāāāāāāāā
ā MCP (Stdio / SSE)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā NSTOK MCP SERVER ā
ā ā
ā ⢠PRD Analysis ā
ā ⢠Knowledge Graph & Vector ā
ā ⢠Feature & UI Discovery ā
ā ⢠Template Orchestrator ā
ā ⢠Architecture Validator ā
ā ⢠Sandboxed Git Management ā
āāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā¼ ā¼ ā¼
āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā
ā Knowledge ā ā Repositories ā ā Job Runner ā
ā Master ā ā Ecosystem ā ā (Worker) ā
ā ā ā ā ā ā
ā Graph + RAG ā ā UI, DB, Apps ā ā Test / Lint ā
ā & Metadata ā ā & Features ā ā Typecheck ā
āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā
```
---
## š¦ Project Structure
```
nstok-mcp/
āāā src/
ā āāā index.ts # CLI entrypoint (Stdio transport)
ā āāā server.ts # MCP server instance & tool registration
ā ā
ā āāā config/
ā ā āāā environment.ts # Environment variables, security allowlists, timeouts
ā ā
ā āāā domain/ # Core domain models & graph types
ā ā āāā app.ts # Application entity
ā ā āāā feature.ts # Feature & capability interfaces
ā ā āāā component.ts # UI component definitions
ā ā āāā database.ts # DB entities & relations
ā ā āāā repository.ts # Repository metadata & graph relationships
ā ā āāā plan.ts # Structured AppPlan & FeaturePlan schemas
ā ā āāā graph.ts # Graph nodes, edges & traversal results
ā ā
ā āāā services/ # Business logic layers
ā ā āāā knowledge.service.ts # Hybrid search & graph traversal engine
ā ā āāā repository.service.ts # Sandboxed workspace operations & template cloning
ā ā āāā generation.service.ts # PRD analysis & Reuse Decision Engine
ā ā āāā git.service.ts # Git branching, commit, diff & PR workflow
ā ā āāā validation.service.ts # Architecture validator (UI-001, DB-001) & jobs
ā ā āāā audit.service.ts # Audit logging for tracking operations
ā ā
ā āāā tools/ # MCP Tool definitions
ā ā āāā knowledge/ # search_knowledge, find_features, find_ui_components, etc.
ā ā āāā generation/ # analyze_prd, create_app_plan, create_app, etc.
ā ā āāā repository/ # read_file, write_file, search_repo_code, git ops
ā ā āāā validation/ # validate_architecture, run_tests, update_knowledge
ā ā
ā āāā data/
ā āāā seed.ts # Pre-seeded NSTOK ecosystem metadata & graph
ā
āāā tests/
ā āāā knowledge.test.ts # Discovery & graph traversal tests
ā āāā generation.test.ts # PRD analysis & planning tests
ā āāā validation.test.ts # Architecture validation tests
ā āāā server.test.ts # Server instantiation & tool registration tests
ā
āāā package.json
āāā tsconfig.json
āāā README.md
```
---
## š ļø Tool Catalog
### 1. Discovery & Knowledge Tools
| Tool | Description |
| :--- | :--- |
| `search_knowledge` | Hybrid keyword and semantic search across knowledge assets, features, UI, and DB entities. |
| `find_features` | Discover reusable business features (`Nstok-feature-a`, `b`, `c`, etc.) matching capabilities. |
| `find_ui_components` | Find reusable design system components in `Nstok-ui` (`DataTable`, `ProductTable`, `SearchInput`, `Button`, etc.). |
| `find_db_entities` | Search database schemas and entity definitions in `Nstok-db` (`Product`, `Inventory`, `Sale`, `User`, etc.). |
| `find_existing_patterns` | Search established architectural patterns, code conventions, and guidelines in NSTOK. |
| `get_project_context` | Retrieve full repository metadata, contained assets, and graph edges for any NSTOK repo. |
| `get_feature_context` | Deep-dive feature context (routes, UI/DB dependencies, and graph traversal). |
| `get_app_context` | Retrieve full composition details and graph relations for an application. |
### 2. Planning Tools
| Tool | Description |
| :--- | :--- |
| `analyze_prd` | Analyze raw PRD text, extract required capabilities, match reusable vs missing assets, and calculate reuse score. |
| `create_app_plan` | Generate a structured application implementation plan following `SEARCH ā REUSE ā ADAPT ā CREATE`. |
| `create_feature_plan` | Generate a structured feature development plan scaffolded from `Nstok-feature-template`. |
### 3. Generation & Template Tools
| Tool | Description |
| :--- | :--- |
| `clone_app_template` | Clone `Nstok-app-template` baseline into a new application workspace. |
| `clone_feature_template` | Clone `Nstok-feature-template` baseline into a new feature module. |
| `add_feature_to_app` | Link and integrate an existing or new feature module into an application. |
| `create_app` | End-to-end scaffolding orchestrator: clones template, wires reused features, creates missing features, and outputs app composition. |
| `create_feature` | Scaffold a new feature module from template when missing capabilities are required. |
### 4. Repository & Git Tools
| Tool | Description |
| :--- | :--- |
| `read_file` | Safely read file content within an NSTOK repository with audit logging. |
| `write_file` | Safely write or update a file within an NSTOK repository with audit logging. |
| `search_repo_code` | Search for code snippets and symbols within an NSTOK repository. |
| `git_status` | Get git status, active branch, and modified files for a repository. |
| `git_diff` | Inspect git diff before committing changes. |
| `create_branch` | Create a feature branch (`feature/ai/<task>`) adhering to NSTOK git workflow. |
| `create_commit` | Create a structured commit with conventional commit message. |
| `create_pull_request` | Propose a Pull Request to `main` branch for human review and approval. |
### 5. Validation & Knowledge Loop Tools
| Tool | Description |
| :--- | :--- |
| `validate_architecture` | Enforce architecture rules: `UI-001` (no duplicate UI), `DB-001` (Nstok-db access), `ARCH-001`, `DEP-001`. |
| `run_tests` | Run unit and integration test suites in an isolated environment. |
| `run_lint` | Run linting and static analysis on a repository. |
| `run_build` | Run project build and TypeScript compilation. |
| `update_knowledge` | Feed newly generated application or feature metadata back into `Nstok-knowledge-master`. |
---
## ā” Quickstart & Installation
### Prerequisites
- Node.js >= 18 (Tested on Node.js 24)
- npm >= 9
### 1. Installation
```bash
git clone <repository_url> nstok-mcp
cd nstok-mcp
npm install
```
### 2. Build
```bash
npm run build
```
### 3. Run Tests
```bash
npm test
```
### 4. Run Development Server
```bash
npm run dev
```
---
## š Configuration for MCP Clients
### Codex / Antigravity / Claude Desktop Configuration
Add the following snippet to your `mcp_config.json` or `claude_desktop_config.json`:
```json
{
"mcpServers": {
"nstok-software-factory": {
"command": "node",
"args": ["<PATH_TO_NSTOK_MCP>/dist/index.js"],
"env": {
"NODE_ENV": "production",
"ENABLE_AUDIT_LOG": "true"
}
}
}
}
```
---
## š Example End-to-End Workflow
When a developer requests:
> *"Codex, please build `nstok-app-w` based on this PRD: POS with authentication, product catalog, inventory, checkout, and daily sales report."*
The MCP server coordinates the following pipeline:
```
1. analyze_prd("Nstok-app-w", PRD)
āāā Extracted: auth, product, inventory, checkout, payment, sales-report
āāā Reused: Nstok-feature-a, Nstok-feature-b, Nstok-feature-c, checkout-payment
āāā Missing: sales-report (Scaffold Nstok-feature-sales-report)
āāā Reuse Score: 80%
2. create_app_plan("Nstok-app-w", PRD)
āāā Generates structured implementation plan
3. create_branch("Nstok-app-w", "feature/ai/create-nstok-app-w")
4. create_app("Nstok-app-w", PRD)
āāā Clones Nstok-app-template
āāā Links reused features
āāā Scaffolds Nstok-feature-sales-report from Nstok-feature-template
5. validate_architecture("Nstok-app-w")
āāā Checks UI-001 (all UI from Nstok-ui) and DB-001 (all schema from Nstok-db)
6. run_tests("Nstok-app-w") & run_build("Nstok-app-w")
7. create_commit("Nstok-app-w", "feat: initial scaffolding for nstok-app-w")
8. create_pull_request("Nstok-app-w", "feat: nstok-app-w implementation", summary)
9. update_knowledge(...)
āāā Central graph updated so future apps can reuse Nstok-feature-sales-report!
```
---
## š Security Model
- **Repository Allowlist**: Enforces `Nstok-*` repository naming pattern.
- **Path Traversal Protection**: All filesystem reads and writes are sandboxed to the active workspace.
- **Audit Trail**: Every mutation (`write_file`, `create_branch`, `create_commit`, `create_pull_request`) is appended to `audit.log.jsonl`.
- **Command Allowlist**: Strict restrictions on executable commands (`node`, `npm`, `npx`, `git`, `tsc`).
---
## š License
MIT Ā© NSTOK Engineering
TDQS
Scored across 29 tools
Several tools have overlapping purposes: search_knowledge, find_features, find_ui_components, find_db_entities, find_existing_patterns, and search_repo_code all perform search-like operations. Similarly, create_app_plan and create_feature_plan both generate plans. However, descriptions provide some distinction through specific resource types and workflows.
Most tools follow a verb_noun pattern (e.g., search_knowledge, find_features, create_app_plan, clone_app_template). Minor deviations like get_project_context and run_tests are still readable and consistent with the pattern. Overall naming is predictable and consistent.
With 29 tools, the set is heavy and may overwhelm an agent. The high count is somewhat justified by the complex domain of software generation and knowledge management, but several tools appear redundant (e.g., multiple find_ tools, multiple create_plan tools), suggesting over-scoping.
The surface covers search, planning, creation, file operations, git workflow, validation, testing, and knowledge updating, which is comprehensive for a software factory. Minor gaps might include direct code editing tools or more granular git operations (e.g., merge, delete branch), but core workflows appear covered.