mcp-ts-template 1.9.2 → 1.9.3

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 (234) hide show
  1. package/README.md +16 -16
  2. package/dist/index.js +41 -27
  3. package/dist/index.js.map +1 -1
  4. package/dist/mcp-server/core/managedMcpServer.d.ts +48 -0
  5. package/dist/mcp-server/core/managedMcpServer.d.ts.map +1 -0
  6. package/dist/mcp-server/core/managedMcpServer.js +58 -0
  7. package/dist/mcp-server/core/managedMcpServer.js.map +1 -0
  8. package/dist/mcp-server/resources/echoResource/logic.d.ts +2 -1
  9. package/dist/mcp-server/resources/echoResource/logic.d.ts.map +1 -1
  10. package/dist/mcp-server/resources/echoResource/logic.js +6 -5
  11. package/dist/mcp-server/resources/echoResource/logic.js.map +1 -1
  12. package/dist/mcp-server/resources/echoResource/registration.d.ts +7 -1
  13. package/dist/mcp-server/resources/echoResource/registration.d.ts.map +1 -1
  14. package/dist/mcp-server/resources/echoResource/registration.js +60 -31
  15. package/dist/mcp-server/resources/echoResource/registration.js.map +1 -1
  16. package/dist/mcp-server/server.d.ts +2 -2
  17. package/dist/mcp-server/server.d.ts.map +1 -1
  18. package/dist/mcp-server/server.js +38 -25
  19. package/dist/mcp-server/server.js.map +1 -1
  20. package/dist/mcp-server/tools/catFactFetcher/logic.d.ts +5 -2
  21. package/dist/mcp-server/tools/catFactFetcher/logic.d.ts.map +1 -1
  22. package/dist/mcp-server/tools/catFactFetcher/logic.js +17 -12
  23. package/dist/mcp-server/tools/catFactFetcher/logic.js.map +1 -1
  24. package/dist/mcp-server/tools/catFactFetcher/registration.d.ts +7 -1
  25. package/dist/mcp-server/tools/catFactFetcher/registration.d.ts.map +1 -1
  26. package/dist/mcp-server/tools/catFactFetcher/registration.js +60 -15
  27. package/dist/mcp-server/tools/catFactFetcher/registration.js.map +1 -1
  28. package/dist/mcp-server/tools/echoTool/logic.d.ts +5 -3
  29. package/dist/mcp-server/tools/echoTool/logic.d.ts.map +1 -1
  30. package/dist/mcp-server/tools/echoTool/logic.js +11 -9
  31. package/dist/mcp-server/tools/echoTool/logic.js.map +1 -1
  32. package/dist/mcp-server/tools/echoTool/registration.d.ts +7 -1
  33. package/dist/mcp-server/tools/echoTool/registration.d.ts.map +1 -1
  34. package/dist/mcp-server/tools/echoTool/registration.js +73 -20
  35. package/dist/mcp-server/tools/echoTool/registration.js.map +1 -1
  36. package/dist/mcp-server/tools/imageTest/logic.d.ts +6 -4
  37. package/dist/mcp-server/tools/imageTest/logic.d.ts.map +1 -1
  38. package/dist/mcp-server/tools/imageTest/logic.js +7 -18
  39. package/dist/mcp-server/tools/imageTest/logic.js.map +1 -1
  40. package/dist/mcp-server/tools/imageTest/registration.d.ts +6 -1
  41. package/dist/mcp-server/tools/imageTest/registration.d.ts.map +1 -1
  42. package/dist/mcp-server/tools/imageTest/registration.js +62 -20
  43. package/dist/mcp-server/tools/imageTest/registration.js.map +1 -1
  44. package/dist/mcp-server/transports/auth/authFactory.js +5 -5
  45. package/dist/mcp-server/transports/auth/authFactory.js.map +1 -1
  46. package/dist/mcp-server/transports/auth/authMiddleware.d.ts +2 -2
  47. package/dist/mcp-server/transports/auth/authMiddleware.d.ts.map +1 -1
  48. package/dist/mcp-server/transports/auth/authMiddleware.js +14 -13
  49. package/dist/mcp-server/transports/auth/authMiddleware.js.map +1 -1
  50. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +2 -2
  51. package/dist/mcp-server/transports/auth/lib/authUtils.js +7 -7
  52. package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -1
  53. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts +0 -1
  54. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts.map +1 -1
  55. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js +17 -19
  56. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js.map +1 -1
  57. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts +0 -1
  58. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts.map +1 -1
  59. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js +18 -30
  60. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js.map +1 -1
  61. package/dist/mcp-server/transports/core/baseTransportManager.d.ts +3 -2
  62. package/dist/mcp-server/transports/core/baseTransportManager.d.ts.map +1 -1
  63. package/dist/mcp-server/transports/core/baseTransportManager.js +2 -2
  64. package/dist/mcp-server/transports/core/baseTransportManager.js.map +1 -1
  65. package/dist/mcp-server/transports/core/headerUtils.d.ts +1 -8
  66. package/dist/mcp-server/transports/core/headerUtils.d.ts.map +1 -1
  67. package/dist/mcp-server/transports/core/headerUtils.js +0 -15
  68. package/dist/mcp-server/transports/core/headerUtils.js.map +1 -1
  69. package/dist/mcp-server/transports/core/honoNodeBridge.d.ts.map +1 -1
  70. package/dist/mcp-server/transports/core/honoNodeBridge.js +4 -15
  71. package/dist/mcp-server/transports/core/honoNodeBridge.js.map +1 -1
  72. package/dist/mcp-server/transports/core/statefulTransportManager.d.ts +6 -11
  73. package/dist/mcp-server/transports/core/statefulTransportManager.d.ts.map +1 -1
  74. package/dist/mcp-server/transports/core/statefulTransportManager.js +92 -122
  75. package/dist/mcp-server/transports/core/statefulTransportManager.js.map +1 -1
  76. package/dist/mcp-server/transports/core/statelessTransportManager.d.ts +3 -5
  77. package/dist/mcp-server/transports/core/statelessTransportManager.d.ts.map +1 -1
  78. package/dist/mcp-server/transports/core/statelessTransportManager.js +18 -21
  79. package/dist/mcp-server/transports/core/statelessTransportManager.js.map +1 -1
  80. package/dist/mcp-server/transports/core/transportTypes.d.ts +14 -20
  81. package/dist/mcp-server/transports/core/transportTypes.d.ts.map +1 -1
  82. package/dist/mcp-server/transports/core/transportTypes.js +1 -8
  83. package/dist/mcp-server/transports/core/transportTypes.js.map +1 -1
  84. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts +0 -3
  85. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -1
  86. package/dist/mcp-server/transports/http/httpErrorHandler.js +60 -46
  87. package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -1
  88. package/dist/mcp-server/transports/http/httpTransport.d.ts +8 -12
  89. package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -1
  90. package/dist/mcp-server/transports/http/httpTransport.js +48 -103
  91. package/dist/mcp-server/transports/http/httpTransport.js.map +1 -1
  92. package/dist/mcp-server/transports/http/mcpTransportMiddleware.d.ts +11 -5
  93. package/dist/mcp-server/transports/http/mcpTransportMiddleware.d.ts.map +1 -1
  94. package/dist/mcp-server/transports/http/mcpTransportMiddleware.js +50 -37
  95. package/dist/mcp-server/transports/http/mcpTransportMiddleware.js.map +1 -1
  96. package/dist/mcp-server/transports/stdio/stdioTransport.d.ts.map +1 -1
  97. package/dist/mcp-server/transports/stdio/stdioTransport.js +6 -8
  98. package/dist/mcp-server/transports/stdio/stdioTransport.js.map +1 -1
  99. package/dist/services/llm-providers/openRouterProvider.d.ts +0 -2
  100. package/dist/services/llm-providers/openRouterProvider.d.ts.map +1 -1
  101. package/dist/services/llm-providers/openRouterProvider.js +12 -22
  102. package/dist/services/llm-providers/openRouterProvider.js.map +1 -1
  103. package/dist/services/supabase/supabaseClient.js +7 -5
  104. package/dist/services/supabase/supabaseClient.js.map +1 -1
  105. package/dist/types-global/errors.d.ts +12 -11
  106. package/dist/types-global/errors.d.ts.map +1 -1
  107. package/dist/types-global/errors.js +12 -11
  108. package/dist/types-global/errors.js.map +1 -1
  109. package/dist/utils/internal/errorHandler.d.ts +90 -15
  110. package/dist/utils/internal/errorHandler.d.ts.map +1 -1
  111. package/dist/utils/internal/errorHandler.js +226 -82
  112. package/dist/utils/internal/errorHandler.js.map +1 -1
  113. package/dist/utils/internal/index.d.ts +0 -1
  114. package/dist/utils/internal/index.d.ts.map +1 -1
  115. package/dist/utils/internal/index.js +0 -1
  116. package/dist/utils/internal/index.js.map +1 -1
  117. package/dist/utils/internal/logger.d.ts +67 -21
  118. package/dist/utils/internal/logger.d.ts.map +1 -1
  119. package/dist/utils/internal/logger.js +353 -156
  120. package/dist/utils/internal/logger.js.map +1 -1
  121. package/dist/utils/internal/performance.d.ts +5 -2
  122. package/dist/utils/internal/performance.d.ts.map +1 -1
  123. package/dist/utils/internal/performance.js +8 -14
  124. package/dist/utils/internal/performance.js.map +1 -1
  125. package/dist/utils/internal/requestContext.d.ts +85 -20
  126. package/dist/utils/internal/requestContext.d.ts.map +1 -1
  127. package/dist/utils/internal/requestContext.js +88 -36
  128. package/dist/utils/internal/requestContext.js.map +1 -1
  129. package/dist/utils/metrics/tokenCounter.d.ts.map +1 -1
  130. package/dist/utils/metrics/tokenCounter.js +5 -9
  131. package/dist/utils/metrics/tokenCounter.js.map +1 -1
  132. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
  133. package/dist/utils/network/fetchWithTimeout.js +8 -8
  134. package/dist/utils/network/fetchWithTimeout.js.map +1 -1
  135. package/dist/utils/parsing/dateParser.d.ts +43 -0
  136. package/dist/utils/parsing/dateParser.d.ts.map +1 -1
  137. package/dist/utils/parsing/dateParser.js +50 -9
  138. package/dist/utils/parsing/dateParser.js.map +1 -1
  139. package/dist/utils/parsing/jsonParser.d.ts +22 -0
  140. package/dist/utils/parsing/jsonParser.d.ts.map +1 -1
  141. package/dist/utils/parsing/jsonParser.js +28 -6
  142. package/dist/utils/parsing/jsonParser.js.map +1 -1
  143. package/dist/utils/scheduling/scheduler.d.ts +8 -2
  144. package/dist/utils/scheduling/scheduler.d.ts.map +1 -1
  145. package/dist/utils/scheduling/scheduler.js +23 -20
  146. package/dist/utils/scheduling/scheduler.js.map +1 -1
  147. package/dist/utils/security/idGenerator.d.ts +0 -6
  148. package/dist/utils/security/idGenerator.d.ts.map +1 -1
  149. package/dist/utils/security/idGenerator.js +1 -13
  150. package/dist/utils/security/idGenerator.js.map +1 -1
  151. package/dist/utils/security/index.d.ts +1 -4
  152. package/dist/utils/security/index.d.ts.map +1 -1
  153. package/dist/utils/security/index.js +1 -4
  154. package/dist/utils/security/index.js.map +1 -1
  155. package/dist/utils/security/rateLimiter.d.ts +5 -0
  156. package/dist/utils/security/rateLimiter.d.ts.map +1 -1
  157. package/dist/utils/security/rateLimiter.js +15 -5
  158. package/dist/utils/security/rateLimiter.js.map +1 -1
  159. package/dist/utils/security/sanitization.d.ts +185 -0
  160. package/dist/utils/security/sanitization.d.ts.map +1 -0
  161. package/dist/utils/security/sanitization.js +480 -0
  162. package/dist/utils/security/sanitization.js.map +1 -0
  163. package/dist/utils/telemetry/instrumentation.d.ts.map +1 -1
  164. package/dist/utils/telemetry/instrumentation.js +71 -13
  165. package/dist/utils/telemetry/instrumentation.js.map +1 -1
  166. package/package.json +13 -15
  167. package/dist/mcp-server/resources/index.d.ts +0 -10
  168. package/dist/mcp-server/resources/index.d.ts.map +0 -1
  169. package/dist/mcp-server/resources/index.js +0 -19
  170. package/dist/mcp-server/resources/index.js.map +0 -1
  171. package/dist/mcp-server/resources/utils/resource-utils.d.ts +0 -43
  172. package/dist/mcp-server/resources/utils/resource-utils.d.ts.map +0 -1
  173. package/dist/mcp-server/resources/utils/resource-utils.js +0 -45
  174. package/dist/mcp-server/resources/utils/resource-utils.js.map +0 -1
  175. package/dist/mcp-server/tools/index.d.ts +0 -4
  176. package/dist/mcp-server/tools/index.d.ts.map +0 -1
  177. package/dist/mcp-server/tools/index.js +0 -19
  178. package/dist/mcp-server/tools/index.js.map +0 -1
  179. package/dist/mcp-server/tools/utils/tool-utils.d.ts +0 -43
  180. package/dist/mcp-server/tools/utils/tool-utils.d.ts.map +0 -1
  181. package/dist/mcp-server/tools/utils/tool-utils.js +0 -46
  182. package/dist/mcp-server/tools/utils/tool-utils.js.map +0 -1
  183. package/dist/mcp-server/transports/core/autoTransportManager.d.ts +0 -48
  184. package/dist/mcp-server/transports/core/autoTransportManager.d.ts.map +0 -1
  185. package/dist/mcp-server/transports/core/autoTransportManager.js +0 -57
  186. package/dist/mcp-server/transports/core/autoTransportManager.js.map +0 -1
  187. package/dist/mcp-server/transports/core/transportRequest.d.ts +0 -9
  188. package/dist/mcp-server/transports/core/transportRequest.d.ts.map +0 -1
  189. package/dist/mcp-server/transports/core/transportRequest.js +0 -2
  190. package/dist/mcp-server/transports/core/transportRequest.js.map +0 -1
  191. package/dist/services/duck-db/duckDBConnectionManager.d.ts +0 -57
  192. package/dist/services/duck-db/duckDBConnectionManager.d.ts.map +0 -1
  193. package/dist/services/duck-db/duckDBConnectionManager.js +0 -166
  194. package/dist/services/duck-db/duckDBConnectionManager.js.map +0 -1
  195. package/dist/services/duck-db/duckDBQueryExecutor.d.ts +0 -19
  196. package/dist/services/duck-db/duckDBQueryExecutor.d.ts.map +0 -1
  197. package/dist/services/duck-db/duckDBQueryExecutor.js +0 -117
  198. package/dist/services/duck-db/duckDBQueryExecutor.js.map +0 -1
  199. package/dist/services/duck-db/duckDBService.d.ts +0 -28
  200. package/dist/services/duck-db/duckDBService.d.ts.map +0 -1
  201. package/dist/services/duck-db/duckDBService.js +0 -153
  202. package/dist/services/duck-db/duckDBService.js.map +0 -1
  203. package/dist/services/duck-db/types.d.ts +0 -135
  204. package/dist/services/duck-db/types.d.ts.map +0 -1
  205. package/dist/services/duck-db/types.js +0 -6
  206. package/dist/services/duck-db/types.js.map +0 -1
  207. package/dist/storage/duckdbExample.d.ts +0 -8
  208. package/dist/storage/duckdbExample.d.ts.map +0 -1
  209. package/dist/storage/duckdbExample.js +0 -198
  210. package/dist/storage/duckdbExample.js.map +0 -1
  211. package/dist/utils/internal/asyncContext.d.ts +0 -35
  212. package/dist/utils/internal/asyncContext.d.ts.map +0 -1
  213. package/dist/utils/internal/asyncContext.js +0 -38
  214. package/dist/utils/internal/asyncContext.js.map +0 -1
  215. package/dist/utils/internal/logging-helpers.d.ts +0 -49
  216. package/dist/utils/internal/logging-helpers.d.ts.map +0 -1
  217. package/dist/utils/internal/logging-helpers.js +0 -60
  218. package/dist/utils/internal/logging-helpers.js.map +0 -1
  219. package/dist/utils/security/htmlSanitizer.d.ts +0 -29
  220. package/dist/utils/security/htmlSanitizer.d.ts.map +0 -1
  221. package/dist/utils/security/htmlSanitizer.js +0 -74
  222. package/dist/utils/security/htmlSanitizer.js.map +0 -1
  223. package/dist/utils/security/inputValidator.d.ts +0 -50
  224. package/dist/utils/security/inputValidator.d.ts.map +0 -1
  225. package/dist/utils/security/inputValidator.js +0 -166
  226. package/dist/utils/security/inputValidator.js.map +0 -1
  227. package/dist/utils/security/logRedactor.d.ts +0 -48
  228. package/dist/utils/security/logRedactor.d.ts.map +0 -1
  229. package/dist/utils/security/logRedactor.js +0 -135
  230. package/dist/utils/security/logRedactor.js.map +0 -1
  231. package/dist/utils/security/pathSanitizer.d.ts +0 -35
  232. package/dist/utils/security/pathSanitizer.d.ts.map +0 -1
  233. package/dist/utils/security/pathSanitizer.js +0 -88
  234. package/dist/utils/security/pathSanitizer.js.map +0 -1
package/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-^5.8.3-blue?style=flat-square)](https://www.typescriptlang.org/)
8
8
  [![Model Context Protocol SDK](https://img.shields.io/badge/MCP%20SDK-^1.17.4-green?style=flat-square)](https://github.com/modelcontextprotocol/typescript-sdk)
9
9
  [![MCP Spec Version](https://img.shields.io/badge/MCP%20Spec-2025--06--18-lightgrey?style=flat-square)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-06-18/changelog.mdx)
10
- [![Version](https://img.shields.io/badge/Version-1.9.1-blue?style=flat-square)](./CHANGELOG.md)
11
- [![Coverage](https://img.shields.io/badge/Coverage-46.52%25-brightgreen?style=flat-square)](./vitest.config.ts)
10
+ [![Version](https://img.shields.io/badge/Version-1.9.3-blue?style=flat-square)](./CHANGELOG.md)
11
+ [![Coverage](https://img.shields.io/badge/Coverage-63.51%25-brightgreen?style=flat-square)](./vitest.config.ts)
12
12
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
13
13
  [![Status](https://img.shields.io/badge/Status-Stable-green?style=flat-square)](https://github.com/cyanheads/mcp-ts-template/issues)
14
14
  [![GitHub](https://img.shields.io/github/stars/cyanheads/mcp-ts-template?style=social)](https://github.com/cyanheads/mcp-ts-template)
@@ -26,7 +26,7 @@ Building a robust server for AI agents is more than just writing code. It requir
26
26
  - **Best Practices by Default**: Enforces a clean, modular architecture that's easy to maintain and extend.
27
27
  - **AI-Ready**: Designed with LLM agents in mind, including detailed schemas and rich LLM developer-friendly resources (e.g. .clinerules).
28
28
 
29
- > **Note on src/mcp-client & src/agent:** The MCP client & Agent components have been enhanced and moved to the (Coming Soon)[**atlas-mcp-agent**](https://github.com/cyanheads/atlas-mcp-agent) repository. This template now focuses exclusively on providing a best-in-class server implementation and framework.
29
+ > **Note on src/mcp-client & src/agent:** The MCP client & Agent components have been enhanced and moved to the [**atlas-mcp-agent**](https://github.com/cyanheads/atlas-mcp-agent) repository. This template now focuses exclusively on providing a best-in-class server implementation and framework.
30
30
 
31
31
  ## ✨ Key Features
32
32
 
@@ -34,14 +34,14 @@ Building a robust server for AI agents is more than just writing code. It requir
34
34
  | :-------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------- |
35
35
  | **🔌 MCP Server** | A functional server with example tools and resources. Supports `stdio` and a **Streamable HTTP** transport built with [**Hono**](https://hono.dev/). | `src/mcp-server/`, `src/mcp-server/transports/` |
36
36
  | **🔭 Observability** | Built-in **OpenTelemetry** for distributed tracing and metrics. Auto-instrumentation for core modules and custom tracing for all tool executions. | `src/utils/telemetry/` |
37
- | **🚀 Production Utilities** | High-performance logging (Pino), Error Handling, ID Generation, Rate Limiting, Async Request Context, Input Sanitization. | `src/utils/` |
37
+ | **🚀 Production Utilities** | Logging, Error Handling, ID Generation, Rate Limiting, Request Context tracking, Input Sanitization. | `src/utils/` |
38
38
  | **🔒 Type Safety/Security** | Strong type checking via TypeScript & Zod validation. Built-in security utilities (sanitization, auth middleware for HTTP). | Throughout, `src/utils/security/`, `src/mcp-server/transports/auth/` |
39
- | **⚙️ Error Handling** | Consistent error categorization (`JsonRpcErrorCode`), detailed logging, centralized handling (`ErrorHandler`). | `src/utils/internal/errorHandler.ts`, `src/types-global/` |
40
- | **📚 Documentation** | Comprehensive `README.md`, structured JSDoc comments, API references, and a detailed [Migration Guide](./docs/migrations/v1.9.0.md). | `README.md`, Codebase, `tsdoc.json`, `docs/` |
39
+ | **⚙️ Error Handling** | Consistent error categorization (`JsonRpcErrorCode`), detailed logging, centralized handling (`ErrorHandler`). | `src/utils/internal/errorHandler.ts`, `src/types-global/` |
40
+ | **📚 Documentation** | Comprehensive `README.md`, structured JSDoc comments, API references. | `README.md`, Codebase, `tsdoc.json`, `docs/api-references/` |
41
41
  | **🕵️ Interaction Logging** | Captures raw requests and responses for all external LLM provider interactions to a dedicated `interactions.log` file for full traceability. | `src/utils/internal/logger.ts` |
42
42
  | **🤖 Agent Ready** | Includes a [.clinerules](./.clinerules/clinerules.md) developer cheatsheet tailored for LLM coding agents. | `.clinerules/` |
43
43
  | **🛠️ Utility Scripts** | Scripts for cleaning builds, setting executable permissions, generating directory trees, and fetching OpenAPI specs. | `scripts/` |
44
- | **🧩 Services** | Reusable modules for LLM (OpenRouter) and data storage (DuckDB) integration, with examples. | `src/services/`, `src/storage/duckdbExample.ts` |
44
+ | **🧩 Services** | Reusable modules for LLM (OpenRouter) integration. | `src/services/` |
45
45
  | **🧪 Integration Testing** | Integrated with Vitest for fast and reliable integration testing. Includes example tests for core logic and a coverage reporter. | `vitest.config.ts`, `tests/` |
46
46
  | **⏱️ Performance Metrics** | Built-in utility to automatically measure and log the execution time and payload size of every tool call. | `src/utils/internal/performance.ts` |
47
47
 
@@ -49,12 +49,12 @@ Building a robust server for AI agents is more than just writing code. It requir
49
49
 
50
50
  This template is built on a set of architectural principles to ensure modularity, testability, and operational clarity.
51
51
 
52
- - **Core Server (`src/mcp-server/server.ts`)**: The central point where tools and resources are registered using the standard `McpServer` from the SDK.
52
+ - **Core Server (`src/mcp-server/server.ts`)**: The central point where tools and resources are registered. It uses a `ManagedMcpServer` wrapper to provide enhanced introspection capabilities. It acts the same way as the native McpServer, but with additional features like introspection and enhanced error handling.
53
53
  - **Transports (`src/mcp-server/transports/`)**: The transport layer connects the core server to the outside world. It supports both `stdio` for direct process communication and a streamable **Hono**-based `http` server.
54
54
  - **"Logic Throws, Handler Catches"**: This is the immutable cornerstone of our error-handling strategy.
55
55
  - **Core Logic (`logic.ts`)**: This layer is responsible for pure, self-contained business logic. It **throws** a structured `McpError` on any failure.
56
- - **Handlers (`registration.ts`)**: This layer interfaces with the server, invokes the core logic, and **catches** any errors using centralized utilities (`createToolHandler`). It is the exclusive location where errors are processed and formatted into a final response.
57
- - **Structured, Traceable Operations**: Every operation is traced from initiation to completion via a `RequestContext` that is implicitly available throughout the entire asynchronous call stack using Node.js's `AsyncLocalStorage`.
56
+ - **Handlers (`registration.ts`)**: This layer interfaces with the server, invokes the core logic, and **catches** any errors. It is the exclusive location where errors are processed and formatted into a final response.
57
+ - **Structured, Traceable Operations**: Every operation is traced from initiation to completion via a `RequestContext` that is passed through the entire call stack, ensuring comprehensive and structured logging.
58
58
 
59
59
  ## Quick Start
60
60
 
@@ -79,11 +79,11 @@ npm run build
79
79
 
80
80
  - **Via Stdio (Default):**
81
81
  ```bash
82
- npm run start:stdio
82
+ npm run start:server
83
83
  ```
84
84
  - **Via Streamable HTTP:**
85
85
  ```bash
86
- npm run start:http
86
+ npm run start:server:http
87
87
  ```
88
88
 
89
89
  ### 4. Running Tests
@@ -127,7 +127,7 @@ Configure the server using these environment variables (or a `.env` file):
127
127
 
128
128
  - **`src/mcp-server/`**: Contains the core MCP server, tools, resources, and transport handlers.
129
129
  - **`src/config/`**: Handles loading and validation of environment variables.
130
- - **`src/services/`**: Reusable modules for integrating with external services (DuckDB, OpenRouter).
130
+ - **`src/services/`**: Reusable modules for integrating with external services (OpenRouter).
131
131
  - **`src/types-global/`**: Defines shared TypeScript interfaces and type definitions.
132
132
  - **`src/utils/`**: Core utilities (logging, error handling, security, etc.).
133
133
  - **`src/index.ts`**: The main entry point that initializes and starts the server.
@@ -150,13 +150,13 @@ This is the cornerstone of the architecture:
150
150
 
151
151
  1. **`logic.ts`**: This file contains the pure business logic.
152
152
  - It defines the Zod schemas for input and output, which serve as the single source of truth for the tool's data contract.
153
- - The core logic function is pure: it takes validated parameters and either returns a result or **throws** a structured `McpError`. It retrieves the request context via `getRequestContext()`.
153
+ - The core logic function is pure: it takes validated parameters and a request context, and either returns a result or **throws** a structured `McpError`.
154
154
  - It **never** contains `try...catch` blocks for formatting a final response.
155
155
 
156
156
  2. **`registration.ts`**: This file is the "handler" that connects the logic to the MCP server.
157
157
  - It imports the schemas and logic function from `logic.ts`.
158
- - It calls `server.registerTool()`, providing the tool's metadata and the runtime handler created by the `createToolHandler` utility.
159
- - The centralized handler **always** wraps the call to the logic function in a `try...catch` block. This is the **only** place where errors are caught, processed by the `ErrorHandler`, and formatted into a standardized error response.
158
+ - It calls `server.registerTool()`, providing the tool's metadata and the runtime handler.
159
+ - The runtime handler **always** wraps the call to the logic function in a `try...catch` block. This is the **only** place where errors are caught, processed by the `ErrorHandler`, and formatted into a standardized error response.
160
160
 
161
161
  This pattern ensures that core logic remains decoupled, pure, and easily testable, while the registration layer handles all transport-level concerns, side effects, and response formatting.
162
162
 
package/dist/index.js CHANGED
@@ -9,12 +9,12 @@
9
9
  // IMPORTANT: This line MUST be the first import to ensure OpenTelemetry is
10
10
  // initialized before any other modules are loaded.
11
11
  import { shutdownOpenTelemetry } from "./utils/telemetry/instrumentation.js";
12
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
13
+ import http from "http";
12
14
  import { config, environment } from "./config/index.js";
13
15
  import { initializeAndStartServer } from "./mcp-server/server.js";
14
16
  import { requestContextService } from "./utils/index.js";
15
- import { logFatal, logOperationError, logOperationStart, logOperationSuccess, } from "./utils/internal/logging-helpers.js";
16
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
17
- import http from "http";
17
+ import { logger } from "./utils/internal/logger.js";
18
18
  let mcpStdioServer;
19
19
  let actualHttpServer;
20
20
  const shutdown = async (signal) => {
@@ -22,38 +22,61 @@ const shutdown = async (signal) => {
22
22
  operation: "ServerShutdown",
23
23
  triggerEvent: signal,
24
24
  });
25
- logOperationStart(shutdownContext, `Received ${signal}. Initiating graceful shutdown...`);
25
+ logger.info(`Received ${signal}. Initiating graceful shutdown...`, shutdownContext);
26
26
  try {
27
+ // Shutdown OpenTelemetry first to ensure buffered telemetry is sent
27
28
  await shutdownOpenTelemetry();
28
29
  let closePromise = Promise.resolve();
29
30
  const transportType = config.mcpTransportType;
30
31
  if (transportType === "stdio" && mcpStdioServer) {
31
- logOperationStart(shutdownContext, "Attempting to close main MCP server (STDIO)...");
32
+ logger.info("Attempting to close main MCP server (STDIO)...", shutdownContext);
32
33
  closePromise = mcpStdioServer.close();
33
34
  }
34
35
  else if (transportType === "http" && actualHttpServer) {
35
- logOperationStart(shutdownContext, "Attempting to close HTTP server...");
36
+ logger.info("Attempting to close HTTP server...", shutdownContext);
36
37
  closePromise = new Promise((resolve, reject) => {
37
38
  actualHttpServer.close((err) => {
38
39
  if (err) {
39
- logOperationError(shutdownContext, "Error closing HTTP server.", err);
40
+ logger.error("Error closing HTTP server.", err, shutdownContext);
40
41
  return reject(err);
41
42
  }
42
- logOperationSuccess(shutdownContext, "HTTP server closed successfully.");
43
+ logger.info("HTTP server closed successfully.", shutdownContext);
43
44
  resolve();
44
45
  });
45
46
  });
46
47
  }
47
48
  await closePromise;
48
- logOperationSuccess(shutdownContext, "Graceful shutdown completed successfully. Exiting.");
49
+ logger.info("Graceful shutdown completed successfully. Exiting.", shutdownContext);
49
50
  process.exit(0);
50
51
  }
51
52
  catch (error) {
52
- logOperationError(shutdownContext, "Critical error during shutdown process.", error);
53
+ logger.error("Critical error during shutdown process.", error, shutdownContext);
53
54
  process.exit(1);
54
55
  }
55
56
  };
56
57
  const start = async () => {
58
+ const validMcpLogLevels = [
59
+ "debug",
60
+ "info",
61
+ "notice",
62
+ "warning",
63
+ "error",
64
+ "crit",
65
+ "alert",
66
+ "emerg",
67
+ ];
68
+ const initialLogLevelConfig = config.logLevel;
69
+ let validatedMcpLogLevel = "info";
70
+ if (validMcpLogLevels.includes(initialLogLevelConfig)) {
71
+ validatedMcpLogLevel = initialLogLevelConfig;
72
+ }
73
+ else {
74
+ if (process.stdout.isTTY) {
75
+ console.warn(`[Startup Warning] Invalid MCP_LOG_LEVEL "${initialLogLevelConfig}". Defaulting to "info".`);
76
+ }
77
+ }
78
+ await logger.initialize(validatedMcpLogLevel);
79
+ logger.info(`Logger initialized. Effective MCP logging level: ${validatedMcpLogLevel}.`, requestContextService.createRequestContext({ operation: "LoggerInit" }));
57
80
  const transportType = config.mcpTransportType;
58
81
  const startupContext = requestContextService.createRequestContext({
59
82
  operation: `ServerStartupSequence_${transportType}`,
@@ -61,7 +84,7 @@ const start = async () => {
61
84
  applicationVersion: config.mcpServerVersion,
62
85
  nodeEnvironment: environment,
63
86
  });
64
- logOperationStart(startupContext, `Starting ${config.mcpServerName} (Version: ${config.mcpServerVersion}, Transport: ${transportType}, Env: ${environment})...`);
87
+ logger.info(`Starting ${config.mcpServerName} (Version: ${config.mcpServerVersion}, Transport: ${transportType}, Env: ${environment})...`, startupContext);
65
88
  try {
66
89
  const serverInstance = await initializeAndStartServer();
67
90
  if (transportType === "stdio" && serverInstance instanceof McpServer) {
@@ -71,28 +94,20 @@ const start = async () => {
71
94
  serverInstance instanceof http.Server) {
72
95
  actualHttpServer = serverInstance;
73
96
  }
74
- logOperationSuccess(startupContext, `${config.mcpServerName} is now running and ready.`);
97
+ logger.info(`${config.mcpServerName} is now running and ready.`, startupContext);
75
98
  process.on("SIGTERM", () => shutdown("SIGTERM"));
76
99
  process.on("SIGINT", () => shutdown("SIGINT"));
77
- // The logger already has a global uncaughtException handler for logging.
78
- // This handler is for initiating a graceful shutdown.
79
100
  process.on("uncaughtException", (error) => {
80
- const context = requestContextService.createRequestContext({
81
- operation: "uncaughtException",
82
- });
83
- logFatal(context, "FATAL: Uncaught exception triggered shutdown.", error);
101
+ logger.fatal("FATAL: Uncaught exception detected.", error, startupContext);
84
102
  shutdown("uncaughtException");
85
103
  });
86
104
  process.on("unhandledRejection", (reason) => {
87
- const context = requestContextService.createRequestContext({
88
- operation: "unhandledRejection",
89
- });
90
- logFatal(context, "FATAL: Unhandled promise rejection triggered shutdown.", reason);
105
+ logger.fatal("FATAL: Unhandled promise rejection detected.", reason, startupContext);
91
106
  shutdown("unhandledRejection");
92
107
  });
93
108
  }
94
109
  catch (error) {
95
- logFatal(startupContext, "CRITICAL ERROR DURING STARTUP.", error);
110
+ logger.fatal("CRITICAL ERROR DURING STARTUP.", error, startupContext);
96
111
  await shutdownOpenTelemetry(); // Attempt to flush any startup-related traces
97
112
  process.exit(1);
98
113
  }
@@ -102,10 +117,9 @@ const start = async () => {
102
117
  await start();
103
118
  }
104
119
  catch (error) {
105
- const context = requestContextService.createRequestContext({
106
- operation: "globalCatch",
107
- });
108
- logFatal(context, "[GLOBAL CATCH] A fatal, unhandled error occurred.", error);
120
+ if (process.stdout.isTTY) {
121
+ console.error("[GLOBAL CATCH] A fatal, unhandled error occurred:", error);
122
+ }
109
123
  process.exit(1);
110
124
  }
111
125
  })();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,2EAA2E;AAC3E,mDAAmD;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,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AAC,SAAS,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/C,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAY,EAAE,EAAE;YAC/C,MAAM,CAAC,KAAK,CACV,qCAAqC,EACrC,KAAK,EACL,cAAc,CACf,CAAC;YACF,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAe,EAAE,EAAE;YACnD,MAAM,CAAC,KAAK,CACV,8CAA8C,EAC9C,MAAe,EACf,cAAc,CACf,CAAC;YACF,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CACV,gCAAgC,EAChC,KAAc,EACd,cAAc,CACf,CAAC;QACF,MAAM,qBAAqB,EAAE,CAAC,CAAC,8CAA8C;QAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAEF,CAAC,KAAK,IAAI,EAAE;IACV,IAAI,CAAC;QACH,MAAM,KAAK,EAAE,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,KAAK,CAAC,mDAAmD,EAAE,KAAK,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @fileoverview Defines a wrapper around the McpServer class to provide
3
+ * extended functionality, such as metadata introspection, without needing
4
+ * to access private properties of the underlying SDK class.
5
+ * @module src/mcp-server/core/managedMcpServer
6
+ */
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ type RegisterToolParameters = Parameters<McpServer["registerTool"]>;
9
+ type ToolSpec = RegisterToolParameters[1];
10
+ type ToolImplementation = RegisterToolParameters[2];
11
+ type RegisteredToolReturn = ReturnType<McpServer["registerTool"]>;
12
+ type ServerIdentity = ConstructorParameters<typeof McpServer>[0];
13
+ type McpServerOptions = NonNullable<ConstructorParameters<typeof McpServer>[1]>;
14
+ /**
15
+ * A wrapper around the McpServer that captures registration metadata
16
+ * to make it available for status endpoints and other diagnostics.
17
+ * It acts as a full pass-through for all McpServer functionality.
18
+ */
19
+ export declare class ManagedMcpServer extends McpServer {
20
+ private readonly storedTools;
21
+ readonly serverIdentity: ServerIdentity;
22
+ readonly serverOptions?: McpServerOptions;
23
+ constructor(identity: ServerIdentity, options?: McpServerOptions);
24
+ registerTool(name: string, spec: ToolSpec, implementation: ToolImplementation): RegisteredToolReturn;
25
+ /**
26
+ * Retrieves the metadata for all registered tools.
27
+ */
28
+ getTools(): {
29
+ name: string;
30
+ description?: string;
31
+ inputSchema: unknown;
32
+ outputSchema?: unknown;
33
+ }[];
34
+ /**
35
+ * Gets the server's name from its identity.
36
+ */
37
+ get name(): string;
38
+ /**
39
+ * Gets the server's version from its identity.
40
+ */
41
+ get version(): string;
42
+ /**
43
+ * Gets the server's capabilities from its options.
44
+ */
45
+ get capabilities(): McpServerOptions["capabilities"] | undefined;
46
+ }
47
+ export {};
48
+ //# sourceMappingURL=managedMcpServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managedMcpServer.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/core/managedMcpServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,KAAK,sBAAsB,GAAG,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;AACpE,KAAK,QAAQ,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAC1C,KAAK,kBAAkB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;AAElE,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,gBAAgB,GAAG,WAAW,CAAC,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAOhF;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEhD,SAAgB,cAAc,EAAE,cAAc,CAAC;IAC/C,SAAgB,aAAa,CAAC,EAAE,gBAAgB,CAAC;gBAErC,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAMvD,YAAY,CACnB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EACd,cAAc,EAAE,kBAAkB,GACjC,oBAAoB;IAKvB;;OAEG;IACI,QAAQ,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,OAAO,CAAC;QACrB,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,EAAE;IASH;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAW,OAAO,IAAI,MAAM,CAE3B;IAED;;OAEG;IACH,IAAW,YAAY,IAAI,gBAAgB,CAAC,cAAc,CAAC,GAAG,SAAS,CAQtE;CACF"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @fileoverview Defines a wrapper around the McpServer class to provide
3
+ * extended functionality, such as metadata introspection, without needing
4
+ * to access private properties of the underlying SDK class.
5
+ * @module src/mcp-server/core/managedMcpServer
6
+ */
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ /**
9
+ * A wrapper around the McpServer that captures registration metadata
10
+ * to make it available for status endpoints and other diagnostics.
11
+ * It acts as a full pass-through for all McpServer functionality.
12
+ */
13
+ export class ManagedMcpServer extends McpServer {
14
+ storedTools = [];
15
+ serverIdentity;
16
+ serverOptions;
17
+ constructor(identity, options) {
18
+ super(identity, options);
19
+ this.serverIdentity = identity;
20
+ this.serverOptions = options;
21
+ }
22
+ registerTool(name, spec, implementation) {
23
+ this.storedTools.push({ name, spec });
24
+ return super.registerTool(name, spec, implementation);
25
+ }
26
+ /**
27
+ * Retrieves the metadata for all registered tools.
28
+ */
29
+ getTools() {
30
+ return this.storedTools.map((t) => ({
31
+ name: t.name,
32
+ description: t.spec.description,
33
+ inputSchema: t.spec.inputSchema,
34
+ outputSchema: t.spec.outputSchema,
35
+ }));
36
+ }
37
+ /**
38
+ * Gets the server's name from its identity.
39
+ */
40
+ get name() {
41
+ return this.serverIdentity.name;
42
+ }
43
+ /**
44
+ * Gets the server's version from its identity.
45
+ */
46
+ get version() {
47
+ return this.serverIdentity.version;
48
+ }
49
+ /**
50
+ * Gets the server's capabilities from its options.
51
+ */
52
+ get capabilities() {
53
+ // The type inference for McpServerOptions is imperfect, so we cast to a
54
+ // known shape as a pragmatic solution, knowing the property exists at runtime.
55
+ return this.serverOptions?.capabilities;
56
+ }
57
+ }
58
+ //# sourceMappingURL=managedMcpServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managedMcpServer.js","sourceRoot":"","sources":["../../../src/mcp-server/core/managedMcpServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkBpE;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC5B,WAAW,GAAiB,EAAE,CAAC;IAEhC,cAAc,CAAiB;IAC/B,aAAa,CAAoB;IAEjD,YAAY,QAAwB,EAAE,OAA0B;QAC9D,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;IAC/B,CAAC;IAEQ,YAAY,CACnB,IAAY,EACZ,IAAc,EACd,cAAkC;QAElC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,OAAO,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,QAAQ;QAMb,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAClC,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;YAC/B,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;YAC/B,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY;SAClC,CAAC,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACrB,wEAAwE;QACxE,+EAA+E;QAC/E,OACE,IAAI,CAAC,aAGN,EAAE,YAAY,CAAC;IAClB,CAAC;CACF"}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @fileoverview Defines the core logic, schemas, and types for the `echo` resource.
3
3
  * @module src/mcp-server/resources/echoResource/logic
4
- **/
4
+ * @see {@link src/mcp-server/resources/echoResource/registration.ts} for the handler and registration logic.
5
+ */
5
6
  import { z } from "zod";
6
7
  import { type RequestContext } from "../../../utils/index.js";
7
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/logic.ts"],"names":[],"mappings":"AAAA;;;IAGI;AAEJ,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;EAOlC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,2BAA2B,CAAC,CAiCtC"}
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/logic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;EAOlC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,2BAA2B,CAAC,CA2BtC"}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @fileoverview Defines the core logic, schemas, and types for the `echo` resource.
3
3
  * @module src/mcp-server/resources/echoResource/logic
4
- **/
4
+ * @see {@link src/mcp-server/resources/echoResource/registration.ts} for the handler and registration logic.
5
+ */
5
6
  import { z } from "zod";
6
7
  import { logger } from "../../../utils/index.js";
7
8
  /**
@@ -25,22 +26,22 @@ export async function echoResourceLogic(uri, params, context) {
25
26
  // For a URI like `echo://my-message?param=1`, `hostname` is `my-message`.
26
27
  const messageFromPath = uri.hostname || uri.pathname.replace(/^\/+/g, "");
27
28
  const messageToEcho = params.message || messageFromPath || "Default echo message";
28
- logger.debug({
29
+ logger.debug("Processing echo resource logic.", {
29
30
  ...context,
30
31
  resourceUri: uri.href,
31
32
  extractedMessage: messageToEcho,
32
- }, "Processing echo resource logic.");
33
+ });
33
34
  const responsePayload = {
34
35
  message: messageToEcho,
35
36
  timestamp: new Date().toISOString(),
36
37
  requestUri: uri.href,
37
38
  };
38
- logger.debug({
39
+ logger.debug("Echo resource processed successfully.", {
39
40
  ...context,
40
41
  responsePayloadSummary: {
41
42
  messageLength: responsePayload.message.length,
42
43
  },
43
- }, "Echo resource processed successfully.");
44
+ });
44
45
  return responsePayload;
45
46
  }
46
47
  //# sourceMappingURL=logic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logic.js","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/logic.ts"],"names":[],"mappings":"AAAA;;;IAGI;AAEJ,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAuB,MAAM,kBAAkB,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,iHAAiH,CAClH;CACJ,CAAC,CAAC;AAgBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAQ,EACR,MAA0B,EAC1B,OAAuB;IAEvB,kEAAkE;IAClE,0EAA0E;IAC1E,MAAM,eAAe,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,aAAa,GACjB,MAAM,CAAC,OAAO,IAAI,eAAe,IAAI,sBAAsB,CAAC;IAE9D,MAAM,CAAC,KAAK,CACV;QACE,GAAG,OAAO;QACV,WAAW,EAAE,GAAG,CAAC,IAAI;QACrB,gBAAgB,EAAE,aAAa;KAChC,EACD,iCAAiC,CAClC,CAAC;IAEF,MAAM,eAAe,GAAgC;QACnD,OAAO,EAAE,aAAa;QACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,UAAU,EAAE,GAAG,CAAC,IAAI;KACrB,CAAC;IAEF,MAAM,CAAC,KAAK,CACV;QACE,GAAG,OAAO;QACV,sBAAsB,EAAE;YACtB,aAAa,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM;SAC9C;KACF,EACD,uCAAuC,CACxC,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"logic.js","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/logic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAuB,MAAM,yBAAyB,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,iHAAiH,CAClH;CACJ,CAAC,CAAC;AAgBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAQ,EACR,MAA0B,EAC1B,OAAuB;IAEvB,kEAAkE;IAClE,0EAA0E;IAC1E,MAAM,eAAe,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,aAAa,GACjB,MAAM,CAAC,OAAO,IAAI,eAAe,IAAI,sBAAsB,CAAC;IAE9D,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE;QAC9C,GAAG,OAAO;QACV,WAAW,EAAE,GAAG,CAAC,IAAI;QACrB,gBAAgB,EAAE,aAAa;KAChC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAgC;QACnD,OAAO,EAAE,aAAa;QACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,UAAU,EAAE,GAAG,CAAC,IAAI;KACrB,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,uCAAuC,EAAE;QACpD,GAAG,OAAO;QACV,sBAAsB,EAAE;YACtB,aAAa,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM;SAC9C;KACF,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * @fileoverview Handles the registration of the `echo` resource with an MCP server instance.
3
3
  * @module src/mcp-server/resources/echoResource/registration.ts
4
- **/
4
+ * @see {@link src/mcp-server/resources/echoResource/logic.ts} for the core business logic and schemas.
5
+ */
5
6
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ /**
8
+ * Registers the 'echo' resource and its handlers with the provided MCP server instance.
9
+ *
10
+ * @param server - The MCP server instance to register the resource with.
11
+ */
6
12
  export declare const registerEchoResource: (server: McpServer) => Promise<void>;
7
13
  //# sourceMappingURL=registration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/registration.ts"],"names":[],"mappings":"AAAA;;;IAGI;AAEJ,OAAO,EACL,SAAS,EAEV,MAAM,yCAAyC,CAAC;AA+BjD,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,SAAS,KAChB,OAAO,CAAC,IAAI,CAsDd,CAAC"}
1
+ {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/registration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,SAAS,EAEV,MAAM,yCAAyC,CAAC;AAcjD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,SAAS,KAChB,OAAO,CAAC,IAAI,CAgGd,CAAC"}
@@ -1,51 +1,80 @@
1
1
  /**
2
2
  * @fileoverview Handles the registration of the `echo` resource with an MCP server instance.
3
3
  * @module src/mcp-server/resources/echoResource/registration.ts
4
- **/
4
+ * @see {@link src/mcp-server/resources/echoResource/logic.ts} for the core business logic and schemas.
5
+ */
5
6
  import { ResourceTemplate, } from "@modelcontextprotocol/sdk/server/mcp.js";
6
7
  import { JsonRpcErrorCode } from "../../../types-global/errors.js";
7
- import { ErrorHandler, requestContextService, } from "../../../utils/index.js";
8
- import { logOperationStart, logOperationSuccess, } from "../../../utils/internal/logging-helpers.js";
9
- import { createResourceHandler, } from "../../resources/utils/resource-utils.js";
8
+ import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
10
9
  import { echoResourceLogic } from "./logic.js";
11
- const RESOURCE_NAME = "echo-resource";
12
- const responseFormatter = (result, uri) => ({
13
- contents: [
14
- {
15
- uri: uri.href,
16
- mimeType: "application/json",
17
- text: JSON.stringify(result),
18
- },
19
- ],
20
- });
10
+ /**
11
+ * Registers the 'echo' resource and its handlers with the provided MCP server instance.
12
+ *
13
+ * @param server - The MCP server instance to register the resource with.
14
+ */
21
15
  export const registerEchoResource = async (server) => {
16
+ const resourceName = "echo-resource";
22
17
  const registrationContext = requestContextService.createRequestContext({
23
18
  operation: "RegisterResource",
24
- resourceName: RESOURCE_NAME,
19
+ additionalContext: { resourceName },
25
20
  });
26
- logOperationStart(registrationContext, `Registering resource: '${RESOURCE_NAME}'`);
27
- const errorHandler = new ErrorHandler();
28
- await errorHandler.tryCatch(async () => {
21
+ logger.info(`Registering resource: '${resourceName}'`, registrationContext);
22
+ await ErrorHandler.tryCatch(async () => {
29
23
  const template = new ResourceTemplate("echo://{message}", {
30
- list: async () => ({
31
- resources: [
32
- {
33
- uri: "echo://hello",
34
- name: "Default Echo Message",
35
- description: "A simple echo resource example.",
36
- },
37
- ],
38
- }),
24
+ list: async () => {
25
+ return {
26
+ resources: [
27
+ {
28
+ uri: "echo://hello",
29
+ name: "Default Echo Message",
30
+ description: "A simple echo resource example.",
31
+ },
32
+ ],
33
+ };
34
+ },
39
35
  });
40
- server.resource(RESOURCE_NAME, template, {
36
+ server.resource(resourceName, template, {
41
37
  name: "Echo Message Resource",
42
38
  description: "A simple echo resource that returns a message.",
43
39
  mimeType: "application/json",
44
40
  examples: [{ name: "Basic echo", uri: "echo://hello" }],
45
- }, createResourceHandler(RESOURCE_NAME, echoResourceLogic, responseFormatter));
46
- logOperationSuccess(registrationContext, `Resource '${RESOURCE_NAME}' registered successfully.`);
41
+ }, async (uri, params, callContext) => {
42
+ const sessionId = typeof callContext?.sessionId === "string"
43
+ ? callContext.sessionId
44
+ : undefined;
45
+ const handlerContext = requestContextService.createRequestContext({
46
+ parentContext: callContext,
47
+ operation: "HandleResourceRead",
48
+ additionalContext: {
49
+ resourceUri: uri.href,
50
+ sessionId,
51
+ inputParams: params,
52
+ },
53
+ });
54
+ try {
55
+ const responseData = await echoResourceLogic(uri, params, handlerContext);
56
+ return {
57
+ contents: [
58
+ {
59
+ uri: uri.href,
60
+ blob: Buffer.from(JSON.stringify(responseData)).toString("base64"),
61
+ mimeType: "application/json",
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ catch (error) {
67
+ // Re-throw to be caught by the SDK's top-level error handler
68
+ throw ErrorHandler.handleError(error, {
69
+ operation: "echoResourceReadHandler",
70
+ context: handlerContext,
71
+ input: { uri: uri.href, params },
72
+ });
73
+ }
74
+ });
75
+ logger.info(`Resource '${resourceName}' registered successfully.`, registrationContext);
47
76
  }, {
48
- operation: `RegisteringResource_${RESOURCE_NAME}`,
77
+ operation: `RegisteringResource_${resourceName}`,
49
78
  context: registrationContext,
50
79
  errorCode: JsonRpcErrorCode.InitializationFailed,
51
80
  critical: true,
@@ -1 +1 @@
1
- {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/registration.ts"],"names":[],"mappings":"AAAA;;;IAGI;AAEJ,OAAO,EAEL,gBAAgB,GACjB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EACL,YAAY,EAEZ,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,GAEtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAA+B,MAAM,YAAY,CAAC;AAE5E,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,MAAM,iBAAiB,GAEnB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACpB,QAAQ,EAAE;QACR;YACE,GAAG,EAAE,GAAG,CAAC,IAAI;YACb,QAAQ,EAAE,kBAAkB;YAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,MAAiB,EACF,EAAE;IACjB,MAAM,mBAAmB,GACvB,qBAAqB,CAAC,oBAAoB,CAAC;QACzC,SAAS,EAAE,kBAAkB;QAC7B,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAC;IAEL,iBAAiB,CACf,mBAAmB,EACnB,0BAA0B,aAAa,GAAG,CAC3C,CAAC;IACF,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IACxC,MAAM,YAAY,CAAC,QAAQ,CACzB,KAAK,IAAI,EAAE;QACT,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YACxD,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;gBACjB,SAAS,EAAE;oBACT;wBACE,GAAG,EAAE,cAAc;wBACnB,IAAI,EAAE,sBAAsB;wBAC5B,WAAW,EAAE,iCAAiC;qBAC/C;iBACF;aACF,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CACb,aAAa,EACb,QAAQ,EACR;YACE,IAAI,EAAE,uBAAuB;YAC7B,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EAAE,kBAAkB;YAC5B,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC;SACxD,EACD,qBAAqB,CACnB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,CAClB,CACF,CAAC;QAEF,mBAAmB,CACjB,mBAAmB,EACnB,aAAa,aAAa,4BAA4B,CACvD,CAAC;IACJ,CAAC,EACD;QACE,SAAS,EAAE,uBAAuB,aAAa,EAAE;QACjD,OAAO,EAAE,mBAAmB;QAC5B,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;QAChD,QAAQ,EAAE,IAAI;KACf,CACF,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../../src/mcp-server/resources/echoResource/registration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,gBAAgB,GACjB,MAAM,yCAAyC,CAAC;AAKjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,E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AAC,oBAAoB,CAAC;gBACzC,aAAa,EAAE,WAAW;gBAC1B,SAAS,EAAE,oBAAoB;gBAC/B,iBAAiB,EAAE;oBACjB,WAAW,EAAE,GAAG,CAAC,IAAI;oBACrB,SAAS;oBACT,WAAW,EAAE,MAAM;iBACpB;aACF,CAAC,CAAC;YAEL,IAAI,CAAC;gBACH,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAC1C,GAAG,EACH,MAAM,EACN,cAAc,CACf,CAAC;gBACF,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,GAAG,EAAE,GAAG,CAAC,IAAI;4BACb,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CACtD,QAAQ,CACT;4BACD,QAAQ,EAAE,kBAAkB;yBAC7B;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,6DAA6D;gBAC7D,MAAM,YAAY,CAAC,WAAW,CAAC,KAAK,EAAE;oBACpC,SAAS,EAAE,yBAAyB;oBACpC,OAAO,EAAE,cAAc;oBACvB,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CACF,CAAC;QAEF,MAAM,CAAC,IAAI,CACT,aAAa,YAAY,4BAA4B,EACrD,mBAAmB,CACpB,CAAC;IACJ,CAAC,EACD;QACE,SAAS,EAAE,uBAAuB,YAAY,EAAE;QAChD,OAAO,EAAE,mBAAmB;QAC5B,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;QAChD,QAAQ,EAAE,IAAI;KACf,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -13,10 +13,10 @@
13
13
  * - Transports: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-03-26/basic/transports.mdx
14
14
  * @module src/mcp-server/server
15
15
  */
16
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
17
16
  import http from "http";
17
+ import { ManagedMcpServer } from "./core/managedMcpServer.js";
18
18
  /**
19
19
  * Main application entry point. Initializes and starts the MCP server.
20
20
  */
21
- export declare function initializeAndStartServer(): Promise<McpServer | http.Server>;
21
+ export declare function initializeAndStartServer(): Promise<ManagedMcpServer | http.Server>;
22
22
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AA4FxB;;GAEG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,SAAS,GAAG,IAAI,CAAC,MAAM,CACxB,CAuBA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp-server/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA+F9D;;GAEG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAC/B,CA6BA"}