nitrostack 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 (290) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/CONTRIBUTING.md +182 -0
  3. package/LICENSE +201 -0
  4. package/LICENSE_URLS_UPDATE_COMPLETE.md +388 -0
  5. package/NOTICE +153 -0
  6. package/README.md +571 -0
  7. package/dist/auth/api-key.d.ts +118 -0
  8. package/dist/auth/api-key.d.ts.map +1 -0
  9. package/dist/auth/api-key.js +168 -0
  10. package/dist/auth/api-key.js.map +1 -0
  11. package/dist/auth/client.d.ts +151 -0
  12. package/dist/auth/client.d.ts.map +1 -0
  13. package/dist/auth/client.js +330 -0
  14. package/dist/auth/client.js.map +1 -0
  15. package/dist/auth/index.d.ts +30 -0
  16. package/dist/auth/index.d.ts.map +1 -0
  17. package/dist/auth/index.js +43 -0
  18. package/dist/auth/index.js.map +1 -0
  19. package/dist/auth/middleware.d.ts +95 -0
  20. package/dist/auth/middleware.d.ts.map +1 -0
  21. package/dist/auth/middleware.js +260 -0
  22. package/dist/auth/middleware.js.map +1 -0
  23. package/dist/auth/pkce.d.ts +53 -0
  24. package/dist/auth/pkce.d.ts.map +1 -0
  25. package/dist/auth/pkce.js +105 -0
  26. package/dist/auth/pkce.js.map +1 -0
  27. package/dist/auth/quick-setup.d.ts +94 -0
  28. package/dist/auth/quick-setup.d.ts.map +1 -0
  29. package/dist/auth/quick-setup.js +210 -0
  30. package/dist/auth/quick-setup.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 +88 -0
  40. package/dist/auth/simple-jwt.d.ts.map +1 -0
  41. package/dist/auth/simple-jwt.js +152 -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 +47 -0
  48. package/dist/auth/token-validation.d.ts.map +1 -0
  49. package/dist/auth/token-validation.js +237 -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/cli/commands/build.d.ts +6 -0
  56. package/dist/cli/commands/build.d.ts.map +1 -0
  57. package/dist/cli/commands/build.js +104 -0
  58. package/dist/cli/commands/build.js.map +1 -0
  59. package/dist/cli/commands/dev.d.ts +7 -0
  60. package/dist/cli/commands/dev.d.ts.map +1 -0
  61. package/dist/cli/commands/dev.js +312 -0
  62. package/dist/cli/commands/dev.js.map +1 -0
  63. package/dist/cli/commands/generate-types.d.ts +8 -0
  64. package/dist/cli/commands/generate-types.d.ts.map +1 -0
  65. package/dist/cli/commands/generate-types.js +220 -0
  66. package/dist/cli/commands/generate-types.js.map +1 -0
  67. package/dist/cli/commands/generate.d.ts +5 -0
  68. package/dist/cli/commands/generate.d.ts.map +1 -0
  69. package/dist/cli/commands/generate.js +365 -0
  70. package/dist/cli/commands/generate.js.map +1 -0
  71. package/dist/cli/commands/init.d.ts +7 -0
  72. package/dist/cli/commands/init.d.ts.map +1 -0
  73. package/dist/cli/commands/init.js +365 -0
  74. package/dist/cli/commands/init.js.map +1 -0
  75. package/dist/cli/commands/start.d.ts +6 -0
  76. package/dist/cli/commands/start.d.ts.map +1 -0
  77. package/dist/cli/commands/start.js +61 -0
  78. package/dist/cli/commands/start.js.map +1 -0
  79. package/dist/cli/index.d.ts +3 -0
  80. package/dist/cli/index.d.ts.map +1 -0
  81. package/dist/cli/index.js +47 -0
  82. package/dist/cli/index.js.map +1 -0
  83. package/dist/cli/mcp-dev-wrapper.d.ts +3 -0
  84. package/dist/cli/mcp-dev-wrapper.d.ts.map +1 -0
  85. package/dist/cli/mcp-dev-wrapper.js +116 -0
  86. package/dist/cli/mcp-dev-wrapper.js.map +1 -0
  87. package/dist/core/apikey-module.d.ts +69 -0
  88. package/dist/core/apikey-module.d.ts.map +1 -0
  89. package/dist/core/apikey-module.js +114 -0
  90. package/dist/core/apikey-module.js.map +1 -0
  91. package/dist/core/app-decorator.d.ts +58 -0
  92. package/dist/core/app-decorator.d.ts.map +1 -0
  93. package/dist/core/app-decorator.js +261 -0
  94. package/dist/core/app-decorator.js.map +1 -0
  95. package/dist/core/builders.d.ts +38 -0
  96. package/dist/core/builders.d.ts.map +1 -0
  97. package/dist/core/builders.js +129 -0
  98. package/dist/core/builders.js.map +1 -0
  99. package/dist/core/component.d.ts +105 -0
  100. package/dist/core/component.d.ts.map +1 -0
  101. package/dist/core/component.js +182 -0
  102. package/dist/core/component.js.map +1 -0
  103. package/dist/core/config-module.d.ts +55 -0
  104. package/dist/core/config-module.d.ts.map +1 -0
  105. package/dist/core/config-module.js +94 -0
  106. package/dist/core/config-module.js.map +1 -0
  107. package/dist/core/decorators/cache.decorator.d.ts +61 -0
  108. package/dist/core/decorators/cache.decorator.d.ts.map +1 -0
  109. package/dist/core/decorators/cache.decorator.js +115 -0
  110. package/dist/core/decorators/cache.decorator.js.map +1 -0
  111. package/dist/core/decorators/health-check.decorator.d.ts +80 -0
  112. package/dist/core/decorators/health-check.decorator.d.ts.map +1 -0
  113. package/dist/core/decorators/health-check.decorator.js +153 -0
  114. package/dist/core/decorators/health-check.decorator.js.map +1 -0
  115. package/dist/core/decorators/rate-limit.decorator.d.ts +62 -0
  116. package/dist/core/decorators/rate-limit.decorator.d.ts.map +1 -0
  117. package/dist/core/decorators/rate-limit.decorator.js +129 -0
  118. package/dist/core/decorators/rate-limit.decorator.js.map +1 -0
  119. package/dist/core/decorators.d.ts +151 -0
  120. package/dist/core/decorators.d.ts.map +1 -0
  121. package/dist/core/decorators.js +142 -0
  122. package/dist/core/decorators.js.map +1 -0
  123. package/dist/core/di/container.d.ts +42 -0
  124. package/dist/core/di/container.d.ts.map +1 -0
  125. package/dist/core/di/container.js +76 -0
  126. package/dist/core/di/container.js.map +1 -0
  127. package/dist/core/di/injectable.decorator.d.ts +35 -0
  128. package/dist/core/di/injectable.decorator.d.ts.map +1 -0
  129. package/dist/core/di/injectable.decorator.js +57 -0
  130. package/dist/core/di/injectable.decorator.js.map +1 -0
  131. package/dist/core/errors.d.ts +54 -0
  132. package/dist/core/errors.d.ts.map +1 -0
  133. package/dist/core/errors.js +87 -0
  134. package/dist/core/errors.js.map +1 -0
  135. package/dist/core/events/event-emitter.d.ts +50 -0
  136. package/dist/core/events/event-emitter.d.ts.map +1 -0
  137. package/dist/core/events/event-emitter.js +94 -0
  138. package/dist/core/events/event-emitter.js.map +1 -0
  139. package/dist/core/events/event.decorator.d.ts +48 -0
  140. package/dist/core/events/event.decorator.d.ts.map +1 -0
  141. package/dist/core/events/event.decorator.js +68 -0
  142. package/dist/core/events/event.decorator.js.map +1 -0
  143. package/dist/core/filters/exception-filter.decorator.d.ts +40 -0
  144. package/dist/core/filters/exception-filter.decorator.d.ts.map +1 -0
  145. package/dist/core/filters/exception-filter.decorator.js +54 -0
  146. package/dist/core/filters/exception-filter.decorator.js.map +1 -0
  147. package/dist/core/filters/exception-filter.interface.d.ts +30 -0
  148. package/dist/core/filters/exception-filter.interface.d.ts.map +1 -0
  149. package/dist/core/filters/exception-filter.interface.js +2 -0
  150. package/dist/core/filters/exception-filter.interface.js.map +1 -0
  151. package/dist/core/guards/apikey.guard.d.ts +22 -0
  152. package/dist/core/guards/apikey.guard.d.ts.map +1 -0
  153. package/dist/core/guards/apikey.guard.js +11 -0
  154. package/dist/core/guards/apikey.guard.js.map +1 -0
  155. package/dist/core/guards/guard.interface.d.ts +18 -0
  156. package/dist/core/guards/guard.interface.d.ts.map +1 -0
  157. package/dist/core/guards/guard.interface.js +2 -0
  158. package/dist/core/guards/guard.interface.js.map +1 -0
  159. package/dist/core/guards/jwt.guard.d.ts +18 -0
  160. package/dist/core/guards/jwt.guard.d.ts.map +1 -0
  161. package/dist/core/guards/jwt.guard.js +2 -0
  162. package/dist/core/guards/jwt.guard.js.map +1 -0
  163. package/dist/core/guards/oauth.guard.d.ts +35 -0
  164. package/dist/core/guards/oauth.guard.d.ts.map +1 -0
  165. package/dist/core/guards/oauth.guard.js +2 -0
  166. package/dist/core/guards/oauth.guard.js.map +1 -0
  167. package/dist/core/guards/use-guards.decorator.d.ts +25 -0
  168. package/dist/core/guards/use-guards.decorator.d.ts.map +1 -0
  169. package/dist/core/guards/use-guards.decorator.js +32 -0
  170. package/dist/core/guards/use-guards.decorator.js.map +1 -0
  171. package/dist/core/health/health-checks.resource.d.ts +14 -0
  172. package/dist/core/health/health-checks.resource.d.ts.map +1 -0
  173. package/dist/core/health/health-checks.resource.js +29 -0
  174. package/dist/core/health/health-checks.resource.js.map +1 -0
  175. package/dist/core/index.d.ts +55 -0
  176. package/dist/core/index.d.ts.map +1 -0
  177. package/dist/core/index.js +57 -0
  178. package/dist/core/index.js.map +1 -0
  179. package/dist/core/interceptors/interceptor.decorator.d.ts +37 -0
  180. package/dist/core/interceptors/interceptor.decorator.d.ts.map +1 -0
  181. package/dist/core/interceptors/interceptor.decorator.js +51 -0
  182. package/dist/core/interceptors/interceptor.decorator.js.map +1 -0
  183. package/dist/core/interceptors/interceptor.interface.d.ts +31 -0
  184. package/dist/core/interceptors/interceptor.interface.d.ts.map +1 -0
  185. package/dist/core/interceptors/interceptor.interface.js +2 -0
  186. package/dist/core/interceptors/interceptor.interface.js.map +1 -0
  187. package/dist/core/jwt-module.d.ts +51 -0
  188. package/dist/core/jwt-module.d.ts.map +1 -0
  189. package/dist/core/jwt-module.js +52 -0
  190. package/dist/core/jwt-module.js.map +1 -0
  191. package/dist/core/logger.d.ts +18 -0
  192. package/dist/core/logger.d.ts.map +1 -0
  193. package/dist/core/logger.js +51 -0
  194. package/dist/core/logger.js.map +1 -0
  195. package/dist/core/middleware/middleware.decorator.d.ts +39 -0
  196. package/dist/core/middleware/middleware.decorator.d.ts.map +1 -0
  197. package/dist/core/middleware/middleware.decorator.js +53 -0
  198. package/dist/core/middleware/middleware.decorator.js.map +1 -0
  199. package/dist/core/middleware/middleware.interface.d.ts +29 -0
  200. package/dist/core/middleware/middleware.interface.d.ts.map +1 -0
  201. package/dist/core/middleware/middleware.interface.js +2 -0
  202. package/dist/core/middleware/middleware.interface.js.map +1 -0
  203. package/dist/core/module.d.ts +74 -0
  204. package/dist/core/module.d.ts.map +1 -0
  205. package/dist/core/module.js +82 -0
  206. package/dist/core/module.js.map +1 -0
  207. package/dist/core/oauth-module.d.ts +144 -0
  208. package/dist/core/oauth-module.d.ts.map +1 -0
  209. package/dist/core/oauth-module.js +190 -0
  210. package/dist/core/oauth-module.js.map +1 -0
  211. package/dist/core/pipes/pipe.decorator.d.ts +55 -0
  212. package/dist/core/pipes/pipe.decorator.d.ts.map +1 -0
  213. package/dist/core/pipes/pipe.decorator.js +85 -0
  214. package/dist/core/pipes/pipe.decorator.js.map +1 -0
  215. package/dist/core/pipes/pipe.interface.d.ts +36 -0
  216. package/dist/core/pipes/pipe.interface.d.ts.map +1 -0
  217. package/dist/core/pipes/pipe.interface.js +2 -0
  218. package/dist/core/pipes/pipe.interface.js.map +1 -0
  219. package/dist/core/prompt.d.ts +37 -0
  220. package/dist/core/prompt.d.ts.map +1 -0
  221. package/dist/core/prompt.js +76 -0
  222. package/dist/core/prompt.js.map +1 -0
  223. package/dist/core/resource.d.ts +42 -0
  224. package/dist/core/resource.d.ts.map +1 -0
  225. package/dist/core/resource.js +90 -0
  226. package/dist/core/resource.js.map +1 -0
  227. package/dist/core/server.d.ts +72 -0
  228. package/dist/core/server.d.ts.map +1 -0
  229. package/dist/core/server.js +406 -0
  230. package/dist/core/server.js.map +1 -0
  231. package/dist/core/tool.d.ts +78 -0
  232. package/dist/core/tool.d.ts.map +1 -0
  233. package/dist/core/tool.js +190 -0
  234. package/dist/core/tool.js.map +1 -0
  235. package/dist/core/transports/http-server.d.ts +102 -0
  236. package/dist/core/transports/http-server.d.ts.map +1 -0
  237. package/dist/core/transports/http-server.js +265 -0
  238. package/dist/core/transports/http-server.js.map +1 -0
  239. package/dist/core/types.d.ts +123 -0
  240. package/dist/core/types.d.ts.map +1 -0
  241. package/dist/core/types.js +2 -0
  242. package/dist/core/types.js.map +1 -0
  243. package/dist/core/widgets/widget-examples.resource.d.ts +17 -0
  244. package/dist/core/widgets/widget-examples.resource.d.ts.map +1 -0
  245. package/dist/core/widgets/widget-examples.resource.js +28 -0
  246. package/dist/core/widgets/widget-examples.resource.js.map +1 -0
  247. package/dist/core/widgets/widget-registry.d.ts +56 -0
  248. package/dist/core/widgets/widget-registry.d.ts.map +1 -0
  249. package/dist/core/widgets/widget-registry.js +75 -0
  250. package/dist/core/widgets/widget-registry.js.map +1 -0
  251. package/dist/testing/index.d.ts +82 -0
  252. package/dist/testing/index.d.ts.map +1 -0
  253. package/dist/testing/index.js +164 -0
  254. package/dist/testing/index.js.map +1 -0
  255. package/dist/ui-next/index.d.ts +31 -0
  256. package/dist/ui-next/index.d.ts.map +1 -0
  257. package/dist/ui-next/index.js +687 -0
  258. package/dist/ui-next/index.js.map +1 -0
  259. package/dist/widgets/index.d.ts +9 -0
  260. package/dist/widgets/index.d.ts.map +1 -0
  261. package/dist/widgets/index.js +9 -0
  262. package/dist/widgets/index.js.map +1 -0
  263. package/dist/widgets/metadata.d.ts +53 -0
  264. package/dist/widgets/metadata.d.ts.map +1 -0
  265. package/dist/widgets/metadata.js +29 -0
  266. package/dist/widgets/metadata.js.map +1 -0
  267. package/dist/widgets/withToolData.d.ts +19 -0
  268. package/dist/widgets/withToolData.d.ts.map +1 -0
  269. package/dist/widgets/withToolData.js +240 -0
  270. package/dist/widgets/withToolData.js.map +1 -0
  271. package/jest.config.js +21 -0
  272. package/package.json +108 -0
  273. package/templates/typescript-auth/AI_AGENT_CLI_REFERENCE.md +702 -0
  274. package/templates/typescript-auth/AI_AGENT_SDK_REFERENCE.md +1260 -0
  275. package/templates/typescript-auth/README.md +400 -0
  276. package/templates/typescript-auth/package.json +44 -0
  277. package/templates/typescript-auth-api-key/AI_AGENT_CLI_REFERENCE.md +701 -0
  278. package/templates/typescript-auth-api-key/AI_AGENT_SDK_REFERENCE.md +1260 -0
  279. package/templates/typescript-auth-api-key/README.md +483 -0
  280. package/templates/typescript-auth-api-key/package-lock.json +124 -0
  281. package/templates/typescript-auth-api-key/package.json +29 -0
  282. package/templates/typescript-oauth/AI_AGENT_CLI_REFERENCE.md +701 -0
  283. package/templates/typescript-oauth/AI_AGENT_SDK_REFERENCE.md +1260 -0
  284. package/templates/typescript-oauth/OAUTH_SETUP.md +406 -0
  285. package/templates/typescript-oauth/README.md +350 -0
  286. package/templates/typescript-oauth/package.json +30 -0
  287. package/templates/typescript-starter/AI_AGENT_CLI_REFERENCE.md +701 -0
  288. package/templates/typescript-starter/AI_AGENT_SDK_REFERENCE.md +1260 -0
  289. package/templates/typescript-starter/README.md +312 -0
  290. package/templates/typescript-starter/package.json +32 -0
@@ -0,0 +1,406 @@
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
+ /**
11
+ * NitroStackServer - Main server class
12
+ */
13
+ export class NitroStackServer {
14
+ mcpServer;
15
+ tools = new Map();
16
+ resources = new Map();
17
+ prompts = new Map();
18
+ config;
19
+ logger;
20
+ stats = {
21
+ toolCalls: 0,
22
+ resourceReads: 0,
23
+ promptExecutions: 0,
24
+ errors: 0,
25
+ };
26
+ pendingComponentRegistrations = [];
27
+ constructor(config) {
28
+ this.config = config;
29
+ this.logger = createLogger({
30
+ level: config.logging?.level || 'info',
31
+ file: config.logging?.file,
32
+ serviceName: config.name,
33
+ enableConsole: false, // CRITICAL: Console disabled for MCP compatibility
34
+ });
35
+ this.mcpServer = new McpServer({
36
+ name: config.name,
37
+ version: config.version,
38
+ }, {
39
+ capabilities: {
40
+ tools: {},
41
+ resources: {},
42
+ prompts: {},
43
+ },
44
+ });
45
+ this.setupHandlers();
46
+ }
47
+ /**
48
+ * Add a tool to the server
49
+ */
50
+ tool(tool) {
51
+ this.tools.set(tool.name, tool);
52
+ this.logger.info(`Tool registered: ${tool.name}`);
53
+ // Auto-register component if attached
54
+ if (tool.hasComponent()) {
55
+ const component = tool.getComponent();
56
+ // Track async component registration
57
+ const registration = this.registerComponentResource(component).catch(err => {
58
+ this.logger.error(`Failed to register component for tool ${tool.name}: ${err.message}`);
59
+ });
60
+ this.pendingComponentRegistrations.push(registration);
61
+ this.logger.info(`Component auto-registered for tool: ${tool.name} -> ${component.getResourceUri()}`);
62
+ }
63
+ return this;
64
+ }
65
+ /**
66
+ * Register a component as an MCP resource
67
+ */
68
+ async registerComponentResource(component) {
69
+ // Compile component
70
+ await component.compile();
71
+ // Create resource for component
72
+ const resource = createResource({
73
+ uri: component.getResourceUri(),
74
+ name: component.name,
75
+ description: component.description || `UI component for ${component.name}`,
76
+ mimeType: 'text/html',
77
+ handler: async (context) => {
78
+ context.logger.info(`Serving component: ${component.getResourceUri()}`);
79
+ return {
80
+ type: 'text',
81
+ data: component.getBundle(),
82
+ };
83
+ },
84
+ });
85
+ // Add resource metadata
86
+ const metadata = component.getResourceMetadata();
87
+ if (metadata && Object.keys(metadata).length > 0) {
88
+ resource.metadata = metadata;
89
+ }
90
+ // Register resource
91
+ this.resource(resource);
92
+ }
93
+ /**
94
+ * Add a resource to the server
95
+ */
96
+ resource(resource) {
97
+ this.resources.set(resource.uri, resource);
98
+ this.logger.info(`Resource registered: ${resource.uri}`);
99
+ return this;
100
+ }
101
+ /**
102
+ * Add a prompt to the server
103
+ */
104
+ prompt(prompt) {
105
+ this.prompts.set(prompt.name, prompt);
106
+ this.logger.info(`Prompt registered: ${prompt.name}`);
107
+ return this;
108
+ }
109
+ /**
110
+ * Register a module with all its controllers
111
+ * Automatically extracts and registers all tools, resources, and prompts
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * server.module(AuthModule);
116
+ * server.module(ProductsModule);
117
+ * ```
118
+ */
119
+ module(moduleClass) {
120
+ // Check if it's a module
121
+ if (!isModule(moduleClass)) {
122
+ throw new Error(`Class ${moduleClass.name} is not decorated with @Module. Use @Module decorator.`);
123
+ }
124
+ // Get module metadata
125
+ const metadata = getModuleMetadata(moduleClass);
126
+ if (!metadata) {
127
+ throw new Error(`Failed to get metadata for module ${moduleClass.name}`);
128
+ }
129
+ this.logger.info(`Registering module: ${metadata.name}`);
130
+ // Process all controllers in the module
131
+ const controllers = metadata.controllers || [];
132
+ for (const controller of controllers) {
133
+ this.logger.info(` Processing controller: ${controller.name}`);
134
+ // Build all tools, resources, and prompts from controller
135
+ const { tools, resources, prompts } = buildController(controller);
136
+ // Register tools
137
+ tools.forEach(tool => {
138
+ this.tool(tool);
139
+ this.logger.info(` ✓ Tool: ${tool.name}`);
140
+ });
141
+ // Register resources
142
+ resources.forEach(resource => {
143
+ this.resource(resource);
144
+ this.logger.info(` ✓ Resource: ${resource.uri}`);
145
+ });
146
+ // Register prompts
147
+ prompts.forEach(prompt => {
148
+ this.prompt(prompt);
149
+ this.logger.info(` ✓ Prompt: ${prompt.name}`);
150
+ });
151
+ }
152
+ this.logger.info(`Module registered: ${metadata.name} (${controllers.length} controller(s))`);
153
+ return this;
154
+ }
155
+ /**
156
+ * Get server statistics
157
+ */
158
+ getStats() {
159
+ return { ...this.stats };
160
+ }
161
+ /**
162
+ * Create execution context
163
+ */
164
+ createContext(metadata) {
165
+ return {
166
+ logger: this.logger,
167
+ requestId: uuidv4(),
168
+ metadata: metadata || {},
169
+ };
170
+ }
171
+ /**
172
+ * Setup MCP protocol handlers
173
+ */
174
+ setupHandlers() {
175
+ // List tools
176
+ this.mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
177
+ this.logger.debug('Listing tools');
178
+ const tools = await Promise.all(Array.from(this.tools.values()).map((tool) => tool.toMcpTool()));
179
+ return {
180
+ tools,
181
+ };
182
+ });
183
+ // Call tool
184
+ this.mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
185
+ const { name, arguments: args } = request.params;
186
+ const tool = this.tools.get(name);
187
+ if (!tool) {
188
+ throw new ToolExecutionError(name, new Error('Tool not found'));
189
+ }
190
+ // Extract _meta from args if present and add to context metadata
191
+ const { _meta, ...toolArgs } = args || {};
192
+ const context = this.createContext(_meta);
193
+ try {
194
+ // Pass original args (including _meta) to tool
195
+ const result = await tool.execute(args, context);
196
+ this.stats.toolCalls++;
197
+ // Check if tool has a UI component
198
+ const response = {
199
+ content: [
200
+ {
201
+ type: 'text',
202
+ text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
203
+ },
204
+ ],
205
+ };
206
+ // Add structured content if component is attached
207
+ if (tool.hasComponent()) {
208
+ const component = tool.getComponent();
209
+ const transformedData = await component.transformData(result, context);
210
+ response.structuredContent = transformedData;
211
+ context.logger.info(`Tool response includes structured content for component: ${component.id}`);
212
+ }
213
+ return response;
214
+ }
215
+ catch (error) {
216
+ this.stats.errors++;
217
+ context.logger.error(`Tool execution failed: ${name}`, error);
218
+ const formattedError = error instanceof ValidationError || error instanceof ToolExecutionError
219
+ ? error
220
+ : new ToolExecutionError(name, error);
221
+ return {
222
+ content: [
223
+ {
224
+ type: 'text',
225
+ text: `Error: ${formattedError.message}`,
226
+ },
227
+ ],
228
+ isError: true,
229
+ };
230
+ }
231
+ });
232
+ // List resources
233
+ this.mcpServer.setRequestHandler(ListResourcesRequestSchema, async () => {
234
+ this.logger.debug('Listing resources');
235
+ return {
236
+ resources: Array.from(this.resources.values()).map((resource) => resource.toMcpResource()),
237
+ };
238
+ });
239
+ // Read resource
240
+ this.mcpServer.setRequestHandler(ReadResourceRequestSchema, async (request) => {
241
+ const { uri } = request.params;
242
+ const resource = this.resources.get(uri);
243
+ if (!resource) {
244
+ throw new ResourceNotFoundError(uri);
245
+ }
246
+ const context = this.createContext();
247
+ try {
248
+ const content = await resource.fetch(context);
249
+ let responseContent;
250
+ switch (content.type) {
251
+ case 'text':
252
+ responseContent = {
253
+ uri: uri,
254
+ mimeType: resource.mimeType || 'text/plain',
255
+ text: content.data,
256
+ };
257
+ break;
258
+ case 'binary':
259
+ responseContent = {
260
+ uri: uri,
261
+ mimeType: resource.mimeType || 'application/octet-stream',
262
+ blob: content.data.toString('base64'),
263
+ };
264
+ break;
265
+ case 'json':
266
+ responseContent = {
267
+ uri: uri,
268
+ mimeType: resource.mimeType || 'application/json',
269
+ text: JSON.stringify(content.data, null, 2),
270
+ };
271
+ break;
272
+ }
273
+ this.stats.resourceReads++;
274
+ return {
275
+ contents: [responseContent],
276
+ };
277
+ }
278
+ catch (error) {
279
+ context.logger.error(`Resource fetch failed: ${uri}`, error);
280
+ throw error;
281
+ }
282
+ });
283
+ // List prompts
284
+ this.mcpServer.setRequestHandler(ListPromptsRequestSchema, async () => {
285
+ this.logger.debug('Listing prompts');
286
+ return {
287
+ prompts: Array.from(this.prompts.values()).map((prompt) => prompt.toMcpPrompt()),
288
+ };
289
+ });
290
+ // Get prompt
291
+ this.mcpServer.setRequestHandler(GetPromptRequestSchema, async (request) => {
292
+ const { name, arguments: args } = request.params;
293
+ const prompt = this.prompts.get(name);
294
+ if (!prompt) {
295
+ throw new Error(`Prompt not found: ${name}`);
296
+ }
297
+ const context = this.createContext();
298
+ try {
299
+ const result = await prompt.execute(args || {}, context);
300
+ this.stats.promptExecutions++;
301
+ // Transform messages to MCP protocol format
302
+ // MCP expects content to be an object with type and text, not a plain string
303
+ const messages = result.map((msg) => ({
304
+ role: msg.role,
305
+ content: {
306
+ type: 'text',
307
+ text: msg.content,
308
+ },
309
+ }));
310
+ return {
311
+ description: prompt.description,
312
+ messages,
313
+ };
314
+ }
315
+ catch (error) {
316
+ this.stats.errors++;
317
+ context.logger.error(`Prompt execution failed: ${name}`, error);
318
+ throw error;
319
+ }
320
+ });
321
+ // Error handler
322
+ this.mcpServer.onerror = (error) => {
323
+ this.logger.error('MCP Server error', error);
324
+ this.stats.errors++;
325
+ };
326
+ }
327
+ /**
328
+ * Start the server with specified transport
329
+ * @param transportType - 'stdio', 'http', or 'dual' (default: 'stdio')
330
+ * @param transportOptions - Transport-specific options
331
+ */
332
+ async start(transportType = 'stdio', transportOptions) {
333
+ try {
334
+ // Wait for all component registrations to complete
335
+ if (this.pendingComponentRegistrations.length > 0) {
336
+ this.logger.info(`Waiting for ${this.pendingComponentRegistrations.length} component(s) to compile...`);
337
+ await Promise.all(this.pendingComponentRegistrations);
338
+ this.pendingComponentRegistrations = []; // Clear after completion
339
+ this.logger.info('All components compiled and registered');
340
+ }
341
+ if (transportType === 'dual') {
342
+ // DUAL transport: STDIO for MCP + HTTP for OAuth metadata
343
+ // This is the recommended mode for OAuth 2.1 servers
344
+ // 1. Start HTTP server for OAuth metadata (non-blocking)
345
+ const { HttpServerTransport } = await import('./transports/http-server.js');
346
+ const httpTransport = new HttpServerTransport(transportOptions);
347
+ await httpTransport.start();
348
+ // Store HTTP transport reference for later cleanup
349
+ this._httpTransport = httpTransport;
350
+ // 2. Connect MCP server via STDIO for protocol communication
351
+ const stdioTransport = new StdioServerTransport();
352
+ await this.mcpServer.connect(stdioTransport);
353
+ this.logger.info(`${this.config.name} started successfully (DUAL: STDIO + HTTP)`);
354
+ this.logger.info(`📡 MCP Protocol: STDIO (for Studio/Claude)`);
355
+ this.logger.info(`🌐 OAuth Metadata: HTTP (port ${transportOptions?.port || 3000})`);
356
+ }
357
+ else if (transportType === 'http') {
358
+ // HTTP-only transport (for pure HTTP MCP servers)
359
+ const { HttpServerTransport } = await import('./transports/http-server.js');
360
+ const transport = new HttpServerTransport(transportOptions);
361
+ // Start HTTP server first
362
+ await transport.start();
363
+ // Then connect MCP server
364
+ await this.mcpServer.connect(transport);
365
+ this.logger.info(`${this.config.name} started successfully (HTTP transport)`);
366
+ }
367
+ else {
368
+ // STDIO-only transport (default, no OAuth)
369
+ const transport = new StdioServerTransport();
370
+ await this.mcpServer.connect(transport);
371
+ this.logger.info(`${this.config.name} started successfully (STDIO transport)`);
372
+ }
373
+ }
374
+ catch (error) {
375
+ this.logger.error('Failed to start server', error);
376
+ throw error;
377
+ }
378
+ }
379
+ /**
380
+ * Stop the server
381
+ */
382
+ async stop() {
383
+ try {
384
+ // Close HTTP transport if running in dual mode
385
+ const httpTransport = this._httpTransport;
386
+ if (httpTransport) {
387
+ await httpTransport.close();
388
+ this._httpTransport = null;
389
+ }
390
+ // Close MCP server
391
+ await this.mcpServer.close();
392
+ this.logger.info('Server stopped');
393
+ }
394
+ catch (error) {
395
+ this.logger.error('Error stopping server', error);
396
+ throw error;
397
+ }
398
+ }
399
+ }
400
+ /**
401
+ * Helper function to create a server
402
+ */
403
+ export function createServer(config) {
404
+ return new NitroStackServer(config);
405
+ }
406
+ //# 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,wBAA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AK,CAAC,CAAC;YACnD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,+CAA+C;YAC/C,MAAM,aAAa,GAAI,IAAY,CAAC,cAAc,CAAC;YACnD,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,IAAY,CAAC,cAAc,GAAG,IAAI,CAAC;YACtC,CAAC;YAED,mBAAmB;YACnB,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB;IAClD,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { Tool as McpTool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { Component } from './component.js';
3
+ import { ExecutionContext } from './types.js';
4
+ import { GuardConstructor } from './guards/guard.interface.js';
5
+ import { MiddlewareConstructor } from './middleware/middleware.interface.js';
6
+ import { InterceptorConstructor } from './interceptors/interceptor.interface.js';
7
+ import { PipeConstructor } from './pipes/pipe.interface.js';
8
+ import { ExceptionFilterConstructor } from './filters/exception-filter.interface.js';
9
+ export interface ToolOptions {
10
+ name: string;
11
+ description: string;
12
+ inputSchema: any;
13
+ handler: (input: any, context: ExecutionContext) => Promise<any>;
14
+ guards?: GuardConstructor[];
15
+ middlewares?: MiddlewareConstructor[];
16
+ interceptors?: InterceptorConstructor[];
17
+ pipes?: PipeConstructor[];
18
+ filters?: ExceptionFilterConstructor[];
19
+ examples?: {
20
+ request?: any;
21
+ response?: any;
22
+ };
23
+ widget?: {
24
+ route: string;
25
+ };
26
+ outputTemplate?: string;
27
+ }
28
+ export declare class Tool {
29
+ name: string;
30
+ description: string;
31
+ inputSchema: any;
32
+ examples?: {
33
+ request?: any;
34
+ response?: any;
35
+ };
36
+ widget?: {
37
+ route: string;
38
+ };
39
+ outputTemplate?: string;
40
+ private handler;
41
+ private guards;
42
+ private middlewares;
43
+ private interceptors;
44
+ private pipes;
45
+ private filters;
46
+ private component?;
47
+ constructor(options: ToolOptions);
48
+ /**
49
+ * Execute the tool with full pipeline:
50
+ * Exception Filters -> Guards -> Middleware -> Interceptors -> Pipes -> Handler
51
+ */
52
+ execute(input: any, context: ExecutionContext): Promise<any>;
53
+ /**
54
+ * Execute with interceptor chain
55
+ */
56
+ private executeWithInterceptors;
57
+ /**
58
+ * Execute pipes and then the handler
59
+ */
60
+ private executeWithPipes;
61
+ /**
62
+ * Attach a UI component to this tool
63
+ */
64
+ setComponent(component: Component): void;
65
+ /**
66
+ * Check if tool has a component
67
+ */
68
+ hasComponent(): boolean;
69
+ /**
70
+ * Get the attached component
71
+ */
72
+ getComponent(): Component | undefined;
73
+ /**
74
+ * Convert to MCP tool format
75
+ */
76
+ toMcpTool(): Promise<McpTool>;
77
+ }
78
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/core/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAS,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAuB,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAClG,OAAO,EAAwB,sBAAsB,EA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