@nitrostack/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +80 -0
  3. package/dist/auth/api-key.d.ts +118 -0
  4. package/dist/auth/api-key.d.ts.map +1 -0
  5. package/dist/auth/api-key.js +168 -0
  6. package/dist/auth/api-key.js.map +1 -0
  7. package/dist/auth/client.d.ts +151 -0
  8. package/dist/auth/client.d.ts.map +1 -0
  9. package/dist/auth/client.js +330 -0
  10. package/dist/auth/client.js.map +1 -0
  11. package/dist/auth/index.d.ts +31 -0
  12. package/dist/auth/index.d.ts.map +1 -0
  13. package/dist/auth/index.js +46 -0
  14. package/dist/auth/index.js.map +1 -0
  15. package/dist/auth/middleware.d.ts +95 -0
  16. package/dist/auth/middleware.d.ts.map +1 -0
  17. package/dist/auth/middleware.js +260 -0
  18. package/dist/auth/middleware.js.map +1 -0
  19. package/dist/auth/pkce.d.ts +53 -0
  20. package/dist/auth/pkce.d.ts.map +1 -0
  21. package/dist/auth/pkce.js +105 -0
  22. package/dist/auth/pkce.js.map +1 -0
  23. package/dist/auth/quick-setup.d.ts +94 -0
  24. package/dist/auth/quick-setup.d.ts.map +1 -0
  25. package/dist/auth/quick-setup.js +210 -0
  26. package/dist/auth/quick-setup.js.map +1 -0
  27. package/dist/auth/secure-secret.d.ts +136 -0
  28. package/dist/auth/secure-secret.d.ts.map +1 -0
  29. package/dist/auth/secure-secret.js +182 -0
  30. package/dist/auth/secure-secret.js.map +1 -0
  31. package/dist/auth/server-integration.d.ts +97 -0
  32. package/dist/auth/server-integration.d.ts.map +1 -0
  33. package/dist/auth/server-integration.js +182 -0
  34. package/dist/auth/server-integration.js.map +1 -0
  35. package/dist/auth/server-metadata.d.ts +51 -0
  36. package/dist/auth/server-metadata.d.ts.map +1 -0
  37. package/dist/auth/server-metadata.js +106 -0
  38. package/dist/auth/server-metadata.js.map +1 -0
  39. package/dist/auth/simple-jwt.d.ts +174 -0
  40. package/dist/auth/simple-jwt.d.ts.map +1 -0
  41. package/dist/auth/simple-jwt.js +162 -0
  42. package/dist/auth/simple-jwt.js.map +1 -0
  43. package/dist/auth/token-store.d.ts +104 -0
  44. package/dist/auth/token-store.d.ts.map +1 -0
  45. package/dist/auth/token-store.js +205 -0
  46. package/dist/auth/token-store.js.map +1 -0
  47. package/dist/auth/token-validation.d.ts +59 -0
  48. package/dist/auth/token-validation.d.ts.map +1 -0
  49. package/dist/auth/token-validation.js +241 -0
  50. package/dist/auth/token-validation.js.map +1 -0
  51. package/dist/auth/types.d.ts +215 -0
  52. package/dist/auth/types.d.ts.map +1 -0
  53. package/dist/auth/types.js +6 -0
  54. package/dist/auth/types.js.map +1 -0
  55. package/dist/core/apikey-module.d.ts +69 -0
  56. package/dist/core/apikey-module.d.ts.map +1 -0
  57. package/dist/core/apikey-module.js +114 -0
  58. package/dist/core/apikey-module.js.map +1 -0
  59. package/dist/core/app-decorator.d.ts +59 -0
  60. package/dist/core/app-decorator.d.ts.map +1 -0
  61. package/dist/core/app-decorator.js +322 -0
  62. package/dist/core/app-decorator.js.map +1 -0
  63. package/dist/core/builders.d.ts +50 -0
  64. package/dist/core/builders.d.ts.map +1 -0
  65. package/dist/core/builders.js +139 -0
  66. package/dist/core/builders.js.map +1 -0
  67. package/dist/core/component.d.ts +111 -0
  68. package/dist/core/component.d.ts.map +1 -0
  69. package/dist/core/component.js +228 -0
  70. package/dist/core/component.js.map +1 -0
  71. package/dist/core/config-module.d.ts +62 -0
  72. package/dist/core/config-module.d.ts.map +1 -0
  73. package/dist/core/config-module.js +94 -0
  74. package/dist/core/config-module.js.map +1 -0
  75. package/dist/core/decorators/cache.decorator.d.ts +61 -0
  76. package/dist/core/decorators/cache.decorator.d.ts.map +1 -0
  77. package/dist/core/decorators/cache.decorator.js +115 -0
  78. package/dist/core/decorators/cache.decorator.js.map +1 -0
  79. package/dist/core/decorators/health-check.decorator.d.ts +80 -0
  80. package/dist/core/decorators/health-check.decorator.d.ts.map +1 -0
  81. package/dist/core/decorators/health-check.decorator.js +153 -0
  82. package/dist/core/decorators/health-check.decorator.js.map +1 -0
  83. package/dist/core/decorators/rate-limit.decorator.d.ts +63 -0
  84. package/dist/core/decorators/rate-limit.decorator.d.ts.map +1 -0
  85. package/dist/core/decorators/rate-limit.decorator.js +129 -0
  86. package/dist/core/decorators/rate-limit.decorator.js.map +1 -0
  87. package/dist/core/decorators.d.ts +190 -0
  88. package/dist/core/decorators.d.ts.map +1 -0
  89. package/dist/core/decorators.js +170 -0
  90. package/dist/core/decorators.js.map +1 -0
  91. package/dist/core/di/container.d.ts +64 -0
  92. package/dist/core/di/container.d.ts.map +1 -0
  93. package/dist/core/di/container.js +105 -0
  94. package/dist/core/di/container.js.map +1 -0
  95. package/dist/core/di/injectable.decorator.d.ts +62 -0
  96. package/dist/core/di/injectable.decorator.d.ts.map +1 -0
  97. package/dist/core/di/injectable.decorator.js +66 -0
  98. package/dist/core/di/injectable.decorator.js.map +1 -0
  99. package/dist/core/errors.d.ts +54 -0
  100. package/dist/core/errors.d.ts.map +1 -0
  101. package/dist/core/errors.js +87 -0
  102. package/dist/core/errors.js.map +1 -0
  103. package/dist/core/events/event-emitter.d.ts +50 -0
  104. package/dist/core/events/event-emitter.d.ts.map +1 -0
  105. package/dist/core/events/event-emitter.js +94 -0
  106. package/dist/core/events/event-emitter.js.map +1 -0
  107. package/dist/core/events/event.decorator.d.ts +48 -0
  108. package/dist/core/events/event.decorator.d.ts.map +1 -0
  109. package/dist/core/events/event.decorator.js +72 -0
  110. package/dist/core/events/event.decorator.js.map +1 -0
  111. package/dist/core/events/log-emitter.d.ts +14 -0
  112. package/dist/core/events/log-emitter.d.ts.map +1 -0
  113. package/dist/core/events/log-emitter.js +20 -0
  114. package/dist/core/events/log-emitter.js.map +1 -0
  115. package/dist/core/filters/exception-filter.decorator.d.ts +40 -0
  116. package/dist/core/filters/exception-filter.decorator.d.ts.map +1 -0
  117. package/dist/core/filters/exception-filter.decorator.js +54 -0
  118. package/dist/core/filters/exception-filter.decorator.js.map +1 -0
  119. package/dist/core/filters/exception-filter.interface.d.ts +39 -0
  120. package/dist/core/filters/exception-filter.interface.d.ts.map +1 -0
  121. package/dist/core/filters/exception-filter.interface.js +2 -0
  122. package/dist/core/filters/exception-filter.interface.js.map +1 -0
  123. package/dist/core/guards/apikey.guard.d.ts +22 -0
  124. package/dist/core/guards/apikey.guard.d.ts.map +1 -0
  125. package/dist/core/guards/apikey.guard.js +11 -0
  126. package/dist/core/guards/apikey.guard.js.map +1 -0
  127. package/dist/core/guards/guard.interface.d.ts +18 -0
  128. package/dist/core/guards/guard.interface.d.ts.map +1 -0
  129. package/dist/core/guards/guard.interface.js +2 -0
  130. package/dist/core/guards/guard.interface.js.map +1 -0
  131. package/dist/core/guards/jwt.guard.d.ts +18 -0
  132. package/dist/core/guards/jwt.guard.d.ts.map +1 -0
  133. package/dist/core/guards/jwt.guard.js +2 -0
  134. package/dist/core/guards/jwt.guard.js.map +1 -0
  135. package/dist/core/guards/oauth.guard.d.ts +35 -0
  136. package/dist/core/guards/oauth.guard.d.ts.map +1 -0
  137. package/dist/core/guards/oauth.guard.js +2 -0
  138. package/dist/core/guards/oauth.guard.js.map +1 -0
  139. package/dist/core/guards/use-guards.decorator.d.ts +25 -0
  140. package/dist/core/guards/use-guards.decorator.d.ts.map +1 -0
  141. package/dist/core/guards/use-guards.decorator.js +32 -0
  142. package/dist/core/guards/use-guards.decorator.js.map +1 -0
  143. package/dist/core/health/health-checks.resource.d.ts +14 -0
  144. package/dist/core/health/health-checks.resource.d.ts.map +1 -0
  145. package/dist/core/health/health-checks.resource.js +29 -0
  146. package/dist/core/health/health-checks.resource.js.map +1 -0
  147. package/dist/core/index.d.ts +57 -0
  148. package/dist/core/index.d.ts.map +1 -0
  149. package/dist/core/index.js +59 -0
  150. package/dist/core/index.js.map +1 -0
  151. package/dist/core/interceptors/interceptor.decorator.d.ts +37 -0
  152. package/dist/core/interceptors/interceptor.decorator.d.ts.map +1 -0
  153. package/dist/core/interceptors/interceptor.decorator.js +51 -0
  154. package/dist/core/interceptors/interceptor.decorator.js.map +1 -0
  155. package/dist/core/interceptors/interceptor.interface.d.ts +31 -0
  156. package/dist/core/interceptors/interceptor.interface.d.ts.map +1 -0
  157. package/dist/core/interceptors/interceptor.interface.js +2 -0
  158. package/dist/core/interceptors/interceptor.interface.js.map +1 -0
  159. package/dist/core/jwt-module.d.ts +51 -0
  160. package/dist/core/jwt-module.d.ts.map +1 -0
  161. package/dist/core/jwt-module.js +52 -0
  162. package/dist/core/jwt-module.js.map +1 -0
  163. package/dist/core/logger.d.ts +18 -0
  164. package/dist/core/logger.d.ts.map +1 -0
  165. package/dist/core/logger.js +53 -0
  166. package/dist/core/logger.js.map +1 -0
  167. package/dist/core/middleware/middleware.decorator.d.ts +39 -0
  168. package/dist/core/middleware/middleware.decorator.d.ts.map +1 -0
  169. package/dist/core/middleware/middleware.decorator.js +53 -0
  170. package/dist/core/middleware/middleware.decorator.js.map +1 -0
  171. package/dist/core/middleware/middleware.interface.d.ts +29 -0
  172. package/dist/core/middleware/middleware.interface.d.ts.map +1 -0
  173. package/dist/core/middleware/middleware.interface.js +2 -0
  174. package/dist/core/middleware/middleware.interface.js.map +1 -0
  175. package/dist/core/module.d.ts +93 -0
  176. package/dist/core/module.d.ts.map +1 -0
  177. package/dist/core/module.js +87 -0
  178. package/dist/core/module.js.map +1 -0
  179. package/dist/core/oauth-module.d.ts +123 -0
  180. package/dist/core/oauth-module.d.ts.map +1 -0
  181. package/dist/core/oauth-module.js +324 -0
  182. package/dist/core/oauth-module.js.map +1 -0
  183. package/dist/core/pipes/pipe.decorator.d.ts +64 -0
  184. package/dist/core/pipes/pipe.decorator.d.ts.map +1 -0
  185. package/dist/core/pipes/pipe.decorator.js +85 -0
  186. package/dist/core/pipes/pipe.decorator.js.map +1 -0
  187. package/dist/core/pipes/pipe.interface.d.ts +41 -0
  188. package/dist/core/pipes/pipe.interface.d.ts.map +1 -0
  189. package/dist/core/pipes/pipe.interface.js +2 -0
  190. package/dist/core/pipes/pipe.interface.js.map +1 -0
  191. package/dist/core/prompt.d.ts +46 -0
  192. package/dist/core/prompt.d.ts.map +1 -0
  193. package/dist/core/prompt.js +76 -0
  194. package/dist/core/prompt.js.map +1 -0
  195. package/dist/core/resource.d.ts +47 -0
  196. package/dist/core/resource.d.ts.map +1 -0
  197. package/dist/core/resource.js +90 -0
  198. package/dist/core/resource.js.map +1 -0
  199. package/dist/core/server.d.ts +129 -0
  200. package/dist/core/server.d.ts.map +1 -0
  201. package/dist/core/server.js +617 -0
  202. package/dist/core/server.js.map +1 -0
  203. package/dist/core/tool.d.ts +108 -0
  204. package/dist/core/tool.d.ts.map +1 -0
  205. package/dist/core/tool.js +241 -0
  206. package/dist/core/tool.js.map +1 -0
  207. package/dist/core/transports/discovery-http-server.d.ts +19 -0
  208. package/dist/core/transports/discovery-http-server.d.ts.map +1 -0
  209. package/dist/core/transports/discovery-http-server.js +54 -0
  210. package/dist/core/transports/discovery-http-server.js.map +1 -0
  211. package/dist/core/transports/http-server.d.ts +108 -0
  212. package/dist/core/transports/http-server.d.ts.map +1 -0
  213. package/dist/core/transports/http-server.js +293 -0
  214. package/dist/core/transports/http-server.js.map +1 -0
  215. package/dist/core/transports/streamable-http.d.ts +177 -0
  216. package/dist/core/transports/streamable-http.d.ts.map +1 -0
  217. package/dist/core/transports/streamable-http.js +1287 -0
  218. package/dist/core/transports/streamable-http.js.map +1 -0
  219. package/dist/core/types.d.ts +195 -0
  220. package/dist/core/types.d.ts.map +1 -0
  221. package/dist/core/types.js +2 -0
  222. package/dist/core/types.js.map +1 -0
  223. package/dist/core/widgets/widget-examples.resource.d.ts +17 -0
  224. package/dist/core/widgets/widget-examples.resource.d.ts.map +1 -0
  225. package/dist/core/widgets/widget-examples.resource.js +28 -0
  226. package/dist/core/widgets/widget-examples.resource.js.map +1 -0
  227. package/dist/core/widgets/widget-registry.d.ts +56 -0
  228. package/dist/core/widgets/widget-registry.d.ts.map +1 -0
  229. package/dist/core/widgets/widget-registry.js +75 -0
  230. package/dist/core/widgets/widget-registry.js.map +1 -0
  231. package/dist/testing/index.d.ts +103 -0
  232. package/dist/testing/index.d.ts.map +1 -0
  233. package/dist/testing/index.js +161 -0
  234. package/dist/testing/index.js.map +1 -0
  235. package/dist/ui-next/index.d.ts +31 -0
  236. package/dist/ui-next/index.d.ts.map +1 -0
  237. package/dist/ui-next/index.js +687 -0
  238. package/dist/ui-next/index.js.map +1 -0
  239. package/package.json +89 -0
@@ -0,0 +1,617 @@
1
+ import { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
4
+ import { createResource } from './resource.js';
5
+ import { createLogger } from './logger.js';
6
+ import { ToolExecutionError, ValidationError, ResourceNotFoundError } from './errors.js';
7
+ import { v4 as uuidv4 } from 'uuid';
8
+ import { isModule, getModuleMetadata } from './module.js';
9
+ import { buildController } from './builders.js';
10
+ import { DIContainer } from './di/container.js';
11
+ /**
12
+ * NitroStackServer - Main server class
13
+ */
14
+ export class NitroStackServer {
15
+ mcpServer;
16
+ tools = new Map();
17
+ resources = new Map();
18
+ prompts = new Map();
19
+ modules = [];
20
+ config;
21
+ logger;
22
+ stats = {
23
+ toolCalls: 0,
24
+ resourceReads: 0,
25
+ promptExecutions: 0,
26
+ errors: 0,
27
+ };
28
+ pendingComponentRegistrations = [];
29
+ /** Transport type used by the server */
30
+ _transportType;
31
+ /** HTTP transport instance (when using http or dual mode) */
32
+ _httpTransport;
33
+ constructor(config) {
34
+ // Default config if not provided (e.g., when instantiated by DI container)
35
+ this.config = config || {
36
+ name: 'nitrostack-server',
37
+ version: '1.0.0',
38
+ };
39
+ this.logger = createLogger({
40
+ level: this.config.logging?.level || 'info',
41
+ file: this.config.logging?.file,
42
+ serviceName: this.config.name,
43
+ enableConsole: false, // CRITICAL: Console disabled for MCP compatibility
44
+ });
45
+ this.mcpServer = new McpServer({
46
+ name: this.config.name,
47
+ version: this.config.version,
48
+ }, {
49
+ capabilities: {
50
+ tools: {},
51
+ resources: {},
52
+ prompts: {},
53
+ },
54
+ });
55
+ this.setupHandlers();
56
+ }
57
+ /**
58
+ * Add a tool to the server
59
+ */
60
+ tool(tool) {
61
+ this.tools.set(tool.name, tool);
62
+ this.logger.info(`Tool registered: ${tool.name}`);
63
+ // Auto-register component if attached
64
+ if (tool.hasComponent()) {
65
+ const component = tool.getComponent();
66
+ // Track async component registration
67
+ const registration = this.registerComponentResource(component).catch(err => {
68
+ this.logger.error(`Failed to register component for tool ${tool.name}: ${err.message}`);
69
+ });
70
+ this.pendingComponentRegistrations.push(registration);
71
+ this.logger.info(`Component auto-registered for tool: ${tool.name} -> ${component.getResourceUri()}`);
72
+ }
73
+ return this;
74
+ }
75
+ /**
76
+ * Register a component as an MCP resource
77
+ */
78
+ async registerComponentResource(component) {
79
+ // Compile component
80
+ await component.compile();
81
+ // Create resource for component
82
+ const resource = createResource({
83
+ uri: component.getResourceUri(),
84
+ name: component.name,
85
+ description: component.description || `UI component for ${component.name}`,
86
+ mimeType: 'text/html',
87
+ handler: async (uri, context) => {
88
+ context.logger.info(`Serving component: ${uri}`);
89
+ // In production, serve the bundled HTML file if available
90
+ if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'prod') {
91
+ try {
92
+ // Check if we have a bundled file for this component
93
+ // The component ID usually matches the widget output name
94
+ const widgetId = component.id;
95
+ // We need to find where the widgets are located relative to the running server
96
+ // In production, we expect them in src/widgets/out or dist/widgets/out
97
+ // Try to find the bundled file
98
+ const fs = await import('fs');
99
+ const path = await import('path');
100
+ // Possible locations for bundled widgets
101
+ const possiblePaths = [
102
+ path.join(process.cwd(), 'src/widgets/out', `${widgetId}.html`),
103
+ path.join(process.cwd(), 'dist/widgets/out', `${widgetId}.html`),
104
+ path.join(process.cwd(), 'widgets/out', `${widgetId}.html`)
105
+ ];
106
+ for (const p of possiblePaths) {
107
+ if (fs.existsSync(p)) {
108
+ const html = fs.readFileSync(p, 'utf-8');
109
+ return {
110
+ type: 'text',
111
+ data: html
112
+ };
113
+ }
114
+ }
115
+ context.logger.warn(`Bundled widget not found for ${widgetId}, falling back to default bundle`);
116
+ }
117
+ catch (error) {
118
+ context.logger.error(`Error serving bundled widget: ${error}`);
119
+ }
120
+ }
121
+ return {
122
+ type: 'text',
123
+ data: component.getBundle(),
124
+ };
125
+ },
126
+ });
127
+ // Add resource metadata - use type assertion for internal property
128
+ const metadata = component.getResourceMetadata();
129
+ if (metadata && Object.keys(metadata).length > 0) {
130
+ const resourceWithMetadata = resource;
131
+ resourceWithMetadata.metadata = metadata;
132
+ }
133
+ // Register resource
134
+ this.resource(resource);
135
+ }
136
+ /**
137
+ * Add a resource to the server
138
+ */
139
+ resource(resource) {
140
+ this.resources.set(resource.uri, resource);
141
+ this.logger.info(`Resource registered: ${resource.uri}`);
142
+ return this;
143
+ }
144
+ /**
145
+ * Add a prompt to the server
146
+ */
147
+ prompt(prompt) {
148
+ this.prompts.set(prompt.name, prompt);
149
+ this.logger.info(`Prompt registered: ${prompt.name}`);
150
+ return this;
151
+ }
152
+ /**
153
+ * Register a module with all its controllers
154
+ * Automatically extracts and registers all tools, resources, and prompts
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * server.module(AuthModule);
159
+ * server.module(ProductsModule);
160
+ * ```
161
+ */
162
+ module(moduleClass) {
163
+ this.modules.push(moduleClass);
164
+ // Check if it's a module
165
+ if (!isModule(moduleClass)) {
166
+ throw new Error(`Class ${moduleClass.name} is not decorated with @Module. Use @Module decorator.`);
167
+ }
168
+ // Get module metadata
169
+ const metadata = getModuleMetadata(moduleClass);
170
+ if (!metadata) {
171
+ throw new Error(`Failed to get metadata for module ${moduleClass.name}`);
172
+ }
173
+ this.logger.info(`Registering module: ${metadata.name}`);
174
+ // Process all controllers in the module
175
+ const controllers = metadata.controllers || [];
176
+ for (const controller of controllers) {
177
+ this.logger.info(` Processing controller: ${controller.name}`);
178
+ // Build all tools, resources, and prompts from controller
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
+ const { tools, resources, prompts } = buildController(controller);
181
+ // Register tools
182
+ tools.forEach(tool => {
183
+ this.tool(tool);
184
+ this.logger.info(` ✓ Tool: ${tool.name}`);
185
+ });
186
+ // Register resources
187
+ resources.forEach(resource => {
188
+ this.resource(resource);
189
+ this.logger.info(` ✓ Resource: ${resource.uri}`);
190
+ });
191
+ // Register prompts
192
+ prompts.forEach(prompt => {
193
+ this.prompt(prompt);
194
+ this.logger.info(` ✓ Prompt: ${prompt.name}`);
195
+ });
196
+ }
197
+ this.logger.info(`Module registered: ${metadata.name} (${controllers.length} controller(s))`);
198
+ return this;
199
+ }
200
+ /**
201
+ * Get server statistics
202
+ */
203
+ getStats() {
204
+ return { ...this.stats };
205
+ }
206
+ /**
207
+ * Create execution context
208
+ */
209
+ createContext(metadata) {
210
+ return {
211
+ logger: this.logger,
212
+ requestId: uuidv4(),
213
+ metadata: metadata || {},
214
+ };
215
+ }
216
+ /**
217
+ * Setup MCP protocol handlers
218
+ */
219
+ setupHandlers() {
220
+ // List tools
221
+ this.mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
222
+ this.logger.debug('Listing tools');
223
+ const tools = await Promise.all(Array.from(this.tools.values()).map((tool) => tool.toMcpTool()));
224
+ return {
225
+ tools,
226
+ };
227
+ });
228
+ // Call tool
229
+ this.mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
230
+ const { name, arguments: args } = request.params;
231
+ const tool = this.tools.get(name);
232
+ if (!tool) {
233
+ throw new ToolExecutionError(name, new Error('Tool not found'));
234
+ }
235
+ // Extract _meta from args if present and add to context metadata
236
+ const argsRecord = (args || {});
237
+ const { _meta, ...toolArgs } = argsRecord;
238
+ const context = this.createContext(_meta);
239
+ try {
240
+ // Pass original args (including _meta) to tool
241
+ const result = await tool.execute(args, context);
242
+ this.stats.toolCalls++;
243
+ // Check if tool has a UI component
244
+ const response = {
245
+ content: [
246
+ {
247
+ type: 'text',
248
+ text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
249
+ },
250
+ ],
251
+ };
252
+ // Add structuredContent and _meta if component is attached
253
+ if (tool.hasComponent()) {
254
+ const component = tool.getComponent();
255
+ // 1. Get structuredContent (for model and widget)
256
+ const transformedData = await component.transformData(result, context);
257
+ response.structuredContent = transformedData;
258
+ // 2. Get _meta (for widget state, hidden from model)
259
+ const widgetMeta = await component.getWidgetMeta(result, context);
260
+ if (widgetMeta) {
261
+ response._meta = widgetMeta;
262
+ }
263
+ context.logger.info(`Tool response includes structured content for component: ${component.id}`);
264
+ }
265
+ return response;
266
+ }
267
+ catch (error) {
268
+ this.stats.errors++;
269
+ const errorMessage = error instanceof Error ? error.message : String(error);
270
+ context.logger.error(`Tool execution failed: ${name}`, { error: errorMessage });
271
+ const formattedError = error instanceof ValidationError || error instanceof ToolExecutionError
272
+ ? error
273
+ : new ToolExecutionError(name, error);
274
+ return {
275
+ content: [
276
+ {
277
+ type: 'text',
278
+ text: `Error: ${formattedError.message}`,
279
+ },
280
+ ],
281
+ isError: true,
282
+ };
283
+ }
284
+ });
285
+ // List resources
286
+ this.mcpServer.setRequestHandler(ListResourcesRequestSchema, async () => {
287
+ this.logger.debug('Listing resources');
288
+ return {
289
+ resources: Array.from(this.resources.values()).map((resource) => resource.toMcpResource()),
290
+ };
291
+ });
292
+ // Read resource
293
+ this.mcpServer.setRequestHandler(ReadResourceRequestSchema, async (request) => {
294
+ const { uri } = request.params;
295
+ const resource = this.resources.get(uri);
296
+ if (!resource) {
297
+ throw new ResourceNotFoundError(uri);
298
+ }
299
+ const context = this.createContext();
300
+ try {
301
+ const content = await resource.fetch(context);
302
+ let responseContent;
303
+ switch (content.type) {
304
+ case 'text':
305
+ responseContent = {
306
+ uri: uri,
307
+ mimeType: resource.mimeType || 'text/plain',
308
+ text: content.data,
309
+ };
310
+ break;
311
+ case 'binary':
312
+ responseContent = {
313
+ uri: uri,
314
+ mimeType: resource.mimeType || 'application/octet-stream',
315
+ blob: content.data.toString('base64'),
316
+ };
317
+ break;
318
+ case 'json':
319
+ responseContent = {
320
+ uri: uri,
321
+ mimeType: resource.mimeType || 'application/json',
322
+ text: JSON.stringify(content.data, null, 2),
323
+ };
324
+ break;
325
+ }
326
+ this.stats.resourceReads++;
327
+ return {
328
+ contents: [responseContent],
329
+ };
330
+ }
331
+ catch (error) {
332
+ const errorMessage = error instanceof Error ? error.message : String(error);
333
+ context.logger.error(`Resource fetch failed: ${uri}`, { error: errorMessage });
334
+ throw error;
335
+ }
336
+ });
337
+ // List prompts
338
+ this.mcpServer.setRequestHandler(ListPromptsRequestSchema, async () => {
339
+ this.logger.debug('Listing prompts');
340
+ return {
341
+ prompts: Array.from(this.prompts.values()).map((prompt) => prompt.toMcpPrompt()),
342
+ };
343
+ });
344
+ // Get prompt
345
+ this.mcpServer.setRequestHandler(GetPromptRequestSchema, async (request) => {
346
+ const { name, arguments: args } = request.params;
347
+ const prompt = this.prompts.get(name);
348
+ if (!prompt) {
349
+ throw new Error(`Prompt not found: ${name}`);
350
+ }
351
+ const context = this.createContext();
352
+ try {
353
+ const result = await prompt.execute(args || {}, context);
354
+ this.stats.promptExecutions++;
355
+ // Transform messages to MCP protocol format
356
+ // MCP expects content to be an object with type and text, not a plain string
357
+ const messages = result.map((msg) => ({
358
+ role: msg.role,
359
+ content: {
360
+ type: 'text',
361
+ text: msg.content,
362
+ },
363
+ }));
364
+ return {
365
+ description: prompt.description,
366
+ messages,
367
+ };
368
+ }
369
+ catch (error) {
370
+ this.stats.errors++;
371
+ const errorMessage = error instanceof Error ? error.message : String(error);
372
+ context.logger.error(`Prompt execution failed: ${name}`, { error: errorMessage });
373
+ throw error;
374
+ }
375
+ });
376
+ // Error handler
377
+ this.mcpServer.onerror = (error) => {
378
+ const errorMessage = error instanceof Error ? error.message : String(error);
379
+ this.logger.error('MCP Server error', { error: errorMessage });
380
+ this.stats.errors++;
381
+ };
382
+ }
383
+ /**
384
+ * Start the server
385
+ * Automatically determines the transport based on NODE_ENV
386
+ *
387
+ * Transport determination:
388
+ * - MCP_TRANSPORT_TYPE env var takes precedence (for explicit control)
389
+ * - NODE_ENV=development or unset → stdio mode
390
+ * - NODE_ENV=production → dual mode (STDIO + HTTP)
391
+ */
392
+ async start() {
393
+ // Check for explicit transport type override
394
+ const explicitTransport = process.env.MCP_TRANSPORT_TYPE;
395
+ // Determine if we're in development mode
396
+ // On Windows, NODE_ENV might not be passed correctly, so we're more lenient
397
+ const nodeEnv = process.env.NODE_ENV?.toLowerCase();
398
+ const isDevelopment = nodeEnv === 'development' || nodeEnv === 'dev' || !nodeEnv;
399
+ // Use explicit transport if set, otherwise infer from NODE_ENV
400
+ const transportType = explicitTransport || (isDevelopment ? 'stdio' : 'dual');
401
+ this._transportType = transportType;
402
+ console.error(`[DEBUG] NitroStackServer.start(): NODE_ENV=${process.env.NODE_ENV}, MCP_TRANSPORT_TYPE=${explicitTransport}, transportType=${transportType}`);
403
+ // Call onModuleInit for all modules
404
+ for (const moduleClass of this.modules) {
405
+ const moduleInstance = DIContainer.getInstance().resolve(moduleClass);
406
+ if (moduleInstance.onModuleInit) {
407
+ await moduleInstance.onModuleInit();
408
+ }
409
+ }
410
+ // If HTTP transport is needed (dual mode), set it up BEFORE calling module.start()
411
+ // This allows modules like OAuthModule to register endpoints on the HTTP server
412
+ if (transportType === 'dual') {
413
+ const port = parseInt(process.env.PORT || '3000');
414
+ const host = process.env.HOST || 'localhost';
415
+ // Create and start HTTP transport first
416
+ const { StreamableHttpTransport } = await import('./transports/streamable-http.js');
417
+ const httpTransport = new StreamableHttpTransport({
418
+ port: port,
419
+ host: host,
420
+ endpoint: '/mcp',
421
+ enableSessions: false, // Disable sessions for dual mode
422
+ enableCors: process.env.ENABLE_CORS !== 'false',
423
+ });
424
+ // Set up tools callback and server config for documentation page
425
+ httpTransport.setToolsCallback(async () => {
426
+ const tools = await Promise.all(Array.from(this.tools.values()).map((tool) => tool.toMcpTool()));
427
+ return tools;
428
+ });
429
+ httpTransport.setServerConfig({
430
+ name: this.config.name,
431
+ version: this.config.version,
432
+ description: this.config.description,
433
+ });
434
+ await httpTransport.start();
435
+ // Store HTTP transport reference BEFORE modules start
436
+ // This allows OAuthModule to register discovery endpoints
437
+ this._httpTransport = httpTransport;
438
+ }
439
+ // Call start for all modules (e.g., OAuthModule to register discovery endpoints)
440
+ // Now _httpTransport is available for OAuthModule to use
441
+ for (const moduleClass of this.modules) {
442
+ const moduleInstance = DIContainer.getInstance().resolve(moduleClass);
443
+ if (moduleInstance.start) {
444
+ await moduleInstance.start();
445
+ }
446
+ }
447
+ // Now complete the transport setup using the determined transportType
448
+ const port = parseInt(process.env.PORT || '3000');
449
+ const host = process.env.HOST || 'localhost';
450
+ await this.startWithTransport(transportType, {
451
+ port,
452
+ host,
453
+ endpoint: '/mcp',
454
+ enableCors: process.env.ENABLE_CORS !== 'false',
455
+ });
456
+ }
457
+ /**
458
+ * Start the server with specified transport
459
+ * @param transportType - 'stdio', 'http', or 'dual' (default: 'stdio')
460
+ * @param transportOptions - Transport-specific options
461
+ */
462
+ async startWithTransport(transportType = 'stdio', transportOptions) {
463
+ this._transportType = transportType;
464
+ try {
465
+ // Wait for all component registrations to complete
466
+ if (this.pendingComponentRegistrations.length > 0) {
467
+ this.logger.info(`Waiting for ${this.pendingComponentRegistrations.length} component(s) to compile...`);
468
+ await Promise.all(this.pendingComponentRegistrations);
469
+ this.pendingComponentRegistrations = []; // Clear after completion
470
+ this.logger.info('All components compiled and registered');
471
+ }
472
+ if (transportType === 'dual') {
473
+ // DUAL transport: STDIO + HTTP SSE
474
+ // STDIO: For direct MCP connections (dev tools, Claude Desktop)
475
+ // HTTP SSE: For web-based clients and multiple concurrent connections
476
+ // 1. Start HTTP SSE transport (reuse if already created by start())
477
+ let httpTransport = this._httpTransport;
478
+ if (!httpTransport) {
479
+ const { StreamableHttpTransport } = await import('./transports/streamable-http.js');
480
+ httpTransport = new StreamableHttpTransport({
481
+ port: transportOptions?.port || 3000,
482
+ host: transportOptions?.host || 'localhost',
483
+ endpoint: transportOptions?.endpoint || '/mcp',
484
+ enableSessions: false, // Disable sessions for simpler backward compat
485
+ enableCors: transportOptions?.enableCors !== false, // Enable CORS by default for web clients
486
+ });
487
+ await httpTransport.start();
488
+ this._httpTransport = httpTransport;
489
+ }
490
+ // Wire up HTTP transport to handle MCP messages
491
+ // Since we can't connect to two transports, manually forward HTTP messages
492
+ const transport = httpTransport;
493
+ transport.onmessage = async (message) => {
494
+ // Handle the message through the MCP server's internal handler
495
+ try {
496
+ // Access internal handlers - this is necessary for dual mode
497
+ const mcpServerInternal = this.mcpServer;
498
+ const handlers = mcpServerInternal._requestHandlers;
499
+ if (handlers && message && message.method && message.id !== undefined) {
500
+ const handler = handlers.get(message.method);
501
+ if (handler) {
502
+ const result = await handler(message);
503
+ // Send response back through HTTP transport
504
+ await transport.send({
505
+ jsonrpc: '2.0',
506
+ id: message.id,
507
+ result,
508
+ });
509
+ }
510
+ }
511
+ }
512
+ catch (error) {
513
+ const err = error;
514
+ // Send error response
515
+ await transport.send({
516
+ jsonrpc: '2.0',
517
+ id: message.id ?? null,
518
+ error: {
519
+ code: -32603,
520
+ message: err.message || 'Internal error',
521
+ },
522
+ });
523
+ }
524
+ };
525
+ // 2. Connect MCP server via STDIO for direct connections
526
+ const stdioTransport = new StdioServerTransport();
527
+ await this.mcpServer.connect(stdioTransport);
528
+ this.logger.info(`${this.config.name} started successfully (DUAL MODE)`);
529
+ this.logger.info(`📡 STDIO: Ready for direct MCP connections`);
530
+ this.logger.info(`🌐 HTTP SSE: http://${transportOptions?.host || 'localhost'}:${transportOptions?.port || 3000}${transportOptions?.endpoint || '/mcp'}`);
531
+ }
532
+ else if (transportType === 'http') {
533
+ // HTTP-only transport (Streamable HTTP with SSE)
534
+ // Reuse if already created by start()
535
+ let httpTransport = this._httpTransport;
536
+ if (!httpTransport) {
537
+ const { StreamableHttpTransport } = await import('./transports/streamable-http.js');
538
+ const transport = new StreamableHttpTransport({
539
+ port: transportOptions?.port || 3000,
540
+ host: transportOptions?.host || 'localhost',
541
+ endpoint: transportOptions?.endpoint || '/mcp',
542
+ enableSessions: true,
543
+ enableCors: transportOptions?.enableCors || false,
544
+ });
545
+ // Set up tools callback and server config for documentation page
546
+ transport.setToolsCallback(async () => {
547
+ const tools = await Promise.all(Array.from(this.tools.values()).map((tool) => tool.toMcpTool()));
548
+ return tools;
549
+ });
550
+ transport.setServerConfig({
551
+ name: this.config.name,
552
+ version: this.config.version,
553
+ description: this.config.description,
554
+ });
555
+ // Start HTTP server first
556
+ await transport.start();
557
+ httpTransport = transport;
558
+ this._httpTransport = httpTransport;
559
+ }
560
+ // Then connect MCP server
561
+ await this.mcpServer.connect(httpTransport);
562
+ this.logger.info(`${this.config.name} started successfully (HTTP SSE transport)`);
563
+ }
564
+ else {
565
+ // STDIO-only transport (default)
566
+ const transport = new StdioServerTransport();
567
+ await this.mcpServer.connect(transport);
568
+ this.logger.info(`${this.config.name} started successfully (STDIO transport)`);
569
+ }
570
+ }
571
+ catch (error) {
572
+ const errorMessage = error instanceof Error ? error.message : String(error);
573
+ this.logger.error('Failed to start server', { error: errorMessage });
574
+ throw error;
575
+ }
576
+ }
577
+ /**
578
+ * Stop the server
579
+ */
580
+ async stop() {
581
+ try {
582
+ // Call stop for all modules
583
+ for (const moduleClass of this.modules) {
584
+ const moduleInstance = DIContainer.getInstance().resolve(moduleClass);
585
+ if (moduleInstance.stop) {
586
+ await moduleInstance.stop();
587
+ }
588
+ }
589
+ // Close HTTP transport if running in dual mode
590
+ if (this._httpTransport) {
591
+ await this._httpTransport.close();
592
+ this._httpTransport = undefined;
593
+ }
594
+ // Close MCP server
595
+ await this.mcpServer.close();
596
+ this.logger.info('Server stopped');
597
+ }
598
+ catch (error) {
599
+ const errorMessage = error instanceof Error ? error.message : String(error);
600
+ this.logger.error('Error stopping server', { error: errorMessage });
601
+ throw error;
602
+ }
603
+ }
604
+ /**
605
+ * Get the HTTP transport (for modules that need to register endpoints)
606
+ */
607
+ getHttpTransport() {
608
+ return this._httpTransport;
609
+ }
610
+ }
611
+ /**
612
+ * Helper function to create a server
613
+ */
614
+ export function createServer(config) {
615
+ return new NitroStackServer(config);
616
+ }
617
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAY,cAAc,EAAE,MAAM,eAAe,CAAC;AAWzD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsDhD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,SAAS,CAAY;IACrB,KAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;IACrC,SAAS,GAA0B,IAAI,GAAG,EAAE,CAAC;IAC7C,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IACzC,OAAO,GAAuB,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