TypeScript

Quick start

Add the NitroStack SDK to a TypeScript project and serve your first tool.

This page adds the SDK to a project you already have. If you're starting from scratch, the Quickstart creates a complete project from a template in one command.

Install the packages

NitroStack relies on TypeScript decorator metadata, so it needs reflect-metadata alongside the core package and Zod.

npm install @nitrostack/core reflect-metadata zod

Turn on decorator metadata

Add these compiler options to tsconfig.json:

tsconfig.json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ES2022"
  }
}

Write a tool

A tool is a method on a class, marked with the @Tool decorator.

src/hello.tools.ts
import { ToolDecorator as Tool, ExecutionContext, z } from '@nitrostack/core';

export class HelloTools {
  @Tool({
    name: 'say_hello',
    description: 'Greet someone by name',
    inputSchema: z.object({
      name: z.string().describe('Who to greet'),
    }),
  })
  async sayHello(input: { name: string }, ctx: ExecutionContext) {
    return { message: `Hello, ${input.name}!` };
  }
}

Group it in a module and start the server

The root module lists the controllers it owns, and @McpApp tells NitroStack which module to start from.

src/app.module.ts
import { McpApp, Module } from '@nitrostack/core';
import { HelloTools } from './hello.tools.js';

@McpApp({
  module: AppModule,
  server: { name: 'hello-server', version: '1.0.0' },
})
@Module({
  name: 'app',
  controllers: [HelloTools],
})
export class AppModule {}
src/index.ts
import 'reflect-metadata'; // Must be first
import { McpApplicationFactory } from '@nitrostack/core';
import { AppModule } from './app.module.js';

const server = await McpApplicationFactory.create(AppModule);
await server.start();

Build and run the entry file with your usual TypeScript setup. The server starts with the defaults from @McpApp; the Bootstrap page lists every option start() accepts.

Next steps

On this page