This project demonstrates ALL NitroStack features using a fun space station management theme.
| Feature | Description | Files |
|---|---|---|
| Tools | MCP tool definitions with Zod schemas | space-station.tools.ts |
| Resources | Static data endpoints | space-station.resources.ts |
| Prompts | AI prompt templates | space-station.prompts.ts |
| Middleware | Request/response pipeline | common/middleware/ |
| Interceptors | Response transformation | common/interceptors/ |
| Pipes | Input validation | common/pipes/ |
| Exception Filters | Centralized error handling | common/filters/ |
| Guards | Access control | common/guards/ |
| Dependency Injection | Services with @Injectable | space-station.service.ts |
| Events | Event emission and handling | common/events/ |
| Caching | Response caching with @Cache | Applied to tools |
| Rate Limiting | Request throttling with @RateLimit | Applied to tools |
| Health Checks | System monitoring | space-station.health.ts |
| Config Module | Configuration management | app.module.ts |
| Widget SDK | Interactive UI widgets | src/widgets/app/ |
The @nitrostack/widgets package provides React hooks and utilities for building interactive tool widgets. This project showcases all Widget SDK features across 6 widgets.
| Feature | Description | Why Use It | Test In Widget |
|---|---|---|---|
| useWidgetSDK | Primary hook for all SDK functionality | Single hook for tool output, actions, and controls | All widgets |
| useTheme | Get current theme (light/dark) | Create theme-aware UIs that match the host app | All widgets |
| useWidgetState | Persistent state with auto-sync | Maintain widget state across re-renders | All widgets |
| useDisplayMode | Get current mode (inline/fullscreen/pip) | Adapt layout based on display context | station-status, system-diagnostic |
| useMaxHeight | Get max height constraint | Constrain scrollable content properly | station-status, mission-control |
| useOpenAiGlobal | Subscribe to window.openai properties | Access locale, userAgent, safeArea reactively | mission-control |
| callTool | Call other MCP tools from widget | Chain tools, fetch additional data interactively | crew-list, system-diagnostic, alerts-dashboard |
| sendFollowUpMessage | Send message to chat | Let users continue conversation from widget | crew-list, mission-control, system-diagnostic |
| openExternal | Open URL in browser | Link to external resources safely | mission-control |
| requestFullscreen | Switch to fullscreen mode | Expand widget for detailed views | station-status |
| requestInline | Switch to inline mode | Collapse back to inline view | station-status |
| requestPip | Switch to picture-in-picture | Float widget while browsing | station-status |
| requestClose | Close the widget | Let users dismiss when done | crew-list |
| getToolInput | Get tool input parameters | Access original request data | Any widget |
| getToolOutput | Get tool response data | Render the tool's result | All widgets |
| getLocale | Get user's locale | Format dates/numbers for locale | mission-control |
| getSafeArea | Get safe area insets | Handle notches, dynamic islands | mission-control, alerts-dashboard |
| getUserAgent | Get device/browser info | Adapt UI for device type | alerts-dashboard |
| prefersReducedMotion | Check motion preference | Disable animations when needed | alerts-dashboard |
| isPrimarilyTouchDevice | Check if touch device | Increase touch targets | alerts-dashboard |
| isHoverAvailable | Check hover support | Show/hide hover effects | alerts-dashboard |
| prefersDarkColorScheme | Check system dark mode | Match system preference | alerts-dashboard |
| Widget | Tool | Features Showcased |
|---|---|---|
station-status |
station_status |
Theme, state, display mode, max height, fullscreen/pip controls |
crew-list |
list_crew |
callTool, sendFollowUpMessage, requestClose, interactive actions |
mission-control |
list_missions |
openExternal, useOpenAiGlobal, getLocale, getSafeArea |
alerts-dashboard |
get_alerts |
Media queries, getUserAgent, touch/hover detection |
system-diagnostic |
list_systems |
Interactive callTool with loading, error handling, sequential calls |
calculator-result |
calculate |
Basic widget with tool output display |
list_crew- List all crew members (with caching, data masking)get_crew_member- Get crew details (with validation pipes)update_crew_status- Update status (requires Officer clearance)
list_missions- List missions (with custom cache keys)get_mission- Get mission details (with validation)create_mission- Create mission (requires Commander clearance)update_mission_status- Update status (with guards)
station_status- Get station overviewlist_systems- List all systemsrun_diagnostic- Run diagnostic (rate limited)
create_alert- Create station alertget_alerts- Get active alerts
station://manifest- Complete crew manifeststation://operations-manual- Standard operating proceduresstation://dashboard-data- Real-time dashboard datastation://emergency-contacts- Emergency contact information
station-briefing- Generate daily briefingmission-planning- Mission planning assistancesystem-diagnostics- System analysisemergency-response- Emergency guidancecrew-wellness- Crew wellness check
src/
βββ app.module.ts # Root module
βββ index.ts # Entry point
βββ common/
β βββ middleware/ # Middleware classes
β β βββ logging.middleware.ts
β β βββ timing.middleware.ts
β β βββ request-id.middleware.ts
β βββ interceptors/ # Interceptor classes
β β βββ response-wrapper.interceptor.ts
β β βββ data-masking.interceptor.ts
β β βββ transform.interceptor.ts
β βββ pipes/ # Pipe classes
β β βββ trim.pipe.ts
β β βββ validation.pipe.ts
β β βββ uppercase.pipe.ts
β βββ filters/ # Exception filters
β β βββ station-exception.filter.ts
β βββ guards/ # Guard classes
β β βββ clearance.guard.ts
β β βββ emergency-protocol.guard.ts
β βββ events/ # Event handlers
β βββ station-events.handler.ts
βββ modules/
β βββ calculator/ # Calculator module
β β βββ calculator.tools.ts
β βββ space-station/
β βββ space-station.module.ts
β βββ space-station.data.ts # Mock data
β βββ space-station.service.ts # DI Services
β βββ space-station.tools.ts # Tools
β βββ space-station.resources.ts
β βββ space-station.prompts.ts
β βββ space-station.health.ts # Health checks
βββ widgets/ # Next.js widget app
βββ app/
β βββ calculator-result/ # Calculator widget
β βββ station-status/ # Station status widget
β βββ crew-list/ # Crew management widget
β βββ mission-control/ # Mission control widget
β βββ alerts-dashboard/ # Alerts widget
β βββ system-diagnostic/ # System diagnostic widget
βββ out/ # Compiled widgets (HTML)
# Development
npm run dev
# Build
npm run build
# Production
npm run startAny tool call will show logging and timing in the console.
Call list_crew or station_status multiple times - you'll see cached responses.
Call run_diagnostic more than 3 times per minute to see rate limiting.
Call get_crew_member to see SSN and medical records masked.
The create_mission tool requires Commander clearance (simulated).
Try get_crew_member with an invalid ID like crew-999.
Try get_crew_member with an invalid ID format like invalid-id.
- Call
station_statustool - Toggle host app between light/dark mode
- Widget colors adapt automatically via
useTheme
- Call
station_statustool - Click "Fullscreen", "PiP", or "Inline" buttons in the widget
- Widget requests display mode change via SDK
- Call
station_statustool - Click different tabs (Overview, Systems, Alerts)
- Widget persists selected tab via
useWidgetState
- Call
list_crewtool - Click "View Details" on any crew member
- Widget calls
get_crew_membertool viacallTool - Or click "Update Status" to call
update_crew_status
- Call
list_crewtool - Click "Ask About [Crew Name]" button
- Widget sends message to chat via
sendFollowUpMessage
- Call
list_missionstool - Click "View Documentation" link
- Opens URL in external browser via
openExternal
- Call
get_alertstool - Toggle "Show Device Info" in the widget
- See
prefersReducedMotion,isPrimarilyTouchDevice,isHoverAvailable,prefersDarkColorSchemevalues
- Call
list_systemstool - Select a system and click "Run Diagnostic"
- Widget shows loading state, then calls
run_diagnostictool - Error handling shown if rate limit exceeded
- Call
list_missionstool - Widget displays locale and safe area insets from SDK
- Useful for devices with notches/dynamic islands
Tools with widgets use special decorator options:
@Tool({
name: 'station_status',
description: 'Get station status',
// Status messages during execution
invocation: {
invoking: 'Loading station status...',
invoked: 'Status loaded'
},
// Example data for widget preview (REQUIRED!)
examples: {
request: {},
response: { stationName: 'ISS-Alpha', stats: {...} }
}
})
@Widget('station-status')Note: The
examples.responseis required for widget previews to render in the client.
MIT