Skip to content

feat: integrate and test lifecycle hooks, ControllerDecorator, and InitialTool - #1

Open
hemantj-cloud wants to merge 2 commits into
nitrocloudofficial:mainfrom
hemantj-cloud:feat/lifecycle-controller-initial-tool
Open

hemantj-cloud wants to merge 2 commits into
nitrocloudofficial:mainfrom
hemantj-cloud:feat/lifecycle-controller-initial-tool

Conversation

@hemantj-cloud

Copy link
Copy Markdown

Overview

This Pull Request integrates and validates the new NitroStack SDK features—specifically Lifecycle Hooks, @ControllerDecorator with prefixing, and the @InitialTool decorator—into the test-all-mcp showcase repository.

Detailed Changes

1. Lifecycle Hooks Integration

  • Created StationLifecycleService which implements all 5 NestJS-style lifecycle interfaces exposed by @nitrostack/core:
    • OnModuleInit (onModuleInit)
    • OnApplicationBootstrap (onApplicationBootstrap)
    • OnModuleDestroy (onModuleDestroy)
    • BeforeApplicationShutdown (beforeApplicationShutdown)
    • OnApplicationShutdown (onApplicationShutdown)
  • Added console logs inside each method to trace and print hook execution times and signals during application start and stop.
  • Registered the lifecycle service under providers in SpaceStationModule.

2. Controller Decorator & Tool Prefixing

  • Created StationLogController decorated with @ControllerDecorator('log') to showcase automatic tool prefix mapping.
    • Exposes a get_events tool, which is automatically compiled and registered on the MCP server as log_get_events.
  • Refactored existing controller classes (SpaceStationTools, SpaceStationResources, SpaceStationPrompts, and CalculatorTools) to use the @ControllerDecorator() decorator.

3. Initial Tool Decorator

  • Flagged the station_status tool in SpaceStationTools with the @InitialTool() decorator to declare it as a startup-invoked tool.

4. Automated Verification Suite

  • Configured a new "test" script in package.json pointing to Node's native ESM test runner: node --test dist/**/*.test.js.
  • Created src/space-station.test.ts containing automated test cases to test:
    • Sequential execution of all 5 lifecycle hook methods on startup/shutdown.
    • Prefix registration of log_get_events.
    • Proper execution of the prefixed tool.
    • @InitialTool metadata presence.

🔬 Test Run Results

▶ Space Station System - NitroStack New Features Tests
  ✔ 1. Lifecycle Hooks, Tool Registration, and Prefixing (10.873583ms)
✔ Space Station System - NitroStack New Features Tests (11.284541ms)

🚀 [LIFECYCLE] StationLifecycleService: onModuleInit - Module is initializing...
🛰️ [LIFECYCLE] StationLifecycleService: onApplicationBootstrap - Application has bootstrapped!
🛑 [LIFECYCLE] StationLifecycleService: onModuleDestroy - Module is being destroyed...
🔌 [LIFECYCLE] StationLifecycleService: beforeApplicationShutdown - Before application shutdown (signal: undefined)...
💀 [LIFECYCLE] StationLifecycleService: onApplicationShutdown - Application shutdown complete (signal: undefined).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant