# NitroStack

> A decorator-driven TypeScript framework for MCP servers, with dependency injection, auth and React widgets built in

- Category: Agents & Automation / Agent Frameworks & Builders
- Language: TypeScript
- Licence: Apache-2.0
- Repository: https://github.com/nitrocloudofficial/nitrostack
- Website: https://nitrostack.ai
- Canonical page: https://ai-tldr.dev/tools/nitrostack/

## In short

NitroStack is an open-source TypeScript framework for building Model Context Protocol (MCP) servers — the backends that expose tools, resources and prompts to AI assistants. It sits in the Agent Frameworks & Builders category of the Agents & Automation tools and is open-source, written in TypeScript and licensed Apache-2.0. To get started: scaffold a new project.

## Overview

NitroStack is an open-source TypeScript framework for building Model Context Protocol (MCP) servers — the backends that expose tools, resources and prompts to AI assistants. Instead of wiring a server together by hand from a protocol SDK, you declare each tool as a decorated class method with a Zod input schema, and the framework handles registration, validation and the server runtime. Its README describes it as an opinionated, batteries-included framework, and the design borrows heavily from enterprise backend frameworks: modules, a dependency-injection container, guards, interceptors, pipes and exception filters.

The project is split into three npm packages: `@nitrostack/core` (decorators, DI and the server runtime), `@nitrostack/cli` (scaffolding, the dev server and code generators) and `@nitrostack/widgets` (a React SDK for interactive tool-output UIs). A companion desktop app, NitroStudio, is downloaded separately from the NitroStack site; you open a project folder in it to run the dev server, execute tools, inspect request and response payloads, preview widgets and chat with the server through a built-in AI assistant.

Two things distinguish it from a bare MCP SDK. Authentication is part of the framework — JWT, OAuth 2.1 and API keys are supported out of the box and applied per tool with guards. And a tool can carry a widget: a React component attached with a `@Widget` decorator, so the result renders as an interactive UI rather than raw JSON. A single decorator stack on one method can therefore define the API, validate input, enforce auth, cache the result and pick its UI.

Servers can speak STDIO for local clients, Streamable HTTP, and legacy SSE for older clients, and the CLI builds a production bundle you can run with Node.js, Docker or PM2. The framework is licensed Apache-2.0.

## What it does

- Decorator-driven definitions: tools, resources and prompts are declared on TypeScript classes with Zod schemas for end-to-end type safety
- Modules and a dependency-injection container with singleton, transient and scoped lifecycles
- Built-in JWT, OAuth 2.1 and API-key authentication, applied per tool with guards
- An enterprise-style middleware pipeline: guards, interceptors, pipes, exception filters and caching
- UI widgets: React components attached to tool outputs so a result renders as an interactive view
- A CLI that scaffolds projects from templates, runs a hot-reloading dev server, generates tools, modules and guards, and builds a production bundle

## Getting started

NitroStack needs Node.js 20.18 or newer and npm 9 or newer. The CLI scaffolds a working MCP server you can run immediately and connect to any MCP-compatible client.

1. Scaffold a new project

   The CLI's `init` command creates the project; the docs list `typescript-starter`, `typescript-pizzaz` and `typescript-oauth` templates. The result has an entry point in `src/index.ts`, a root module in `src/app.module.ts`, feature modules under `src/modules/` and widget components under `src/widgets/`.

```bash
npx @nitrostack/cli init my-server
```

2. Start the dev server

   Install dependencies and start developing; the dev server hot-reloads as you edit. If the port is taken, the docs suggest `nitrostack-cli dev --port 3002`.

```bash
cd my-server
npm install
npm run dev
```

3. Define a tool

   A tool is a decorated method with a Zod input schema. Guards, caching and a widget are further decorators on the same method.

```ts
import { McpApp, Module, ToolDecorator as Tool, z, ExecutionContext } from '@nitrostack/core';

export class SearchTools {
  @Tool({
    name: 'search_products',
    description: 'Search the product catalog',
    inputSchema: z.object({
      query: z.string().describe('Search query'),
      maxResults: z.number().default(10)
    })
  })
  @UseGuards(ApiKeyGuard)
  @Cache({ ttl: 300 })
  @Widget('product-grid')
  async search(input: { query: string; maxResults: number }, ctx: ExecutionContext) {
    ctx.logger.info('Searching products', { query: input.query });
    return this.productService.search(input.query, input.maxResults);
  }
}
```

4. Generate code and test it in NitroStudio

   With the CLI installed globally, `generate` scaffolds tools, resources, prompts, modules, guards, middleware and more. Then download NitroStudio from nitrostack.ai/studio and open the project folder to execute tools, inspect payloads and chat with your server.

```bash
npm i -g @nitrostack/cli
nitrostack-cli generate tool <name>
```

5. Build and run for production

   `nitrostack-cli build` writes a production build to `dist/`, which the deployment checklist runs with Node.js directly (or under Docker or PM2).

```bash
nitrostack-cli build
node dist/index.js
```

## When to use it

- Reach for it when an MCP server is growing past a handful of tools and you want modules, dependency injection and middleware instead of one long file of handlers
- Reach for it when your MCP tools need real authentication — JWT, OAuth 2.1 or API keys — enforced per tool
- Reach for it when tool results should render as interactive UI in the client, such as a product grid, rather than as plain JSON
- Reach for it when your team already writes decorator-and-DI TypeScript backends and wants the same structure for AI-facing services
