@cyanheads/mcp-ts-core 0.1.0-beta.12
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.
- package/CLAUDE.md +583 -0
- package/LICENSE +201 -0
- package/README.md +287 -0
- package/biome.json +103 -0
- package/dist/app.d.ts +82 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +222 -0
- package/dist/app.js.map +1 -0
- package/dist/cli/init.d.ts +8 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +161 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/config/index.d.ts +349 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +464 -0
- package/dist/config/index.js.map +1 -0
- package/dist/context.d.ts +119 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +144 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/prompts/prompt-registration.d.ts +33 -0
- package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -0
- package/dist/mcp-server/prompts/prompt-registration.js +91 -0
- package/dist/mcp-server/prompts/prompt-registration.js.map +1 -0
- package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts +49 -0
- package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts.map +1 -0
- package/dist/mcp-server/prompts/utils/newPromptDefinition.js +39 -0
- package/dist/mcp-server/prompts/utils/newPromptDefinition.js.map +1 -0
- package/dist/mcp-server/prompts/utils/promptDefinition.d.ts +37 -0
- package/dist/mcp-server/prompts/utils/promptDefinition.d.ts.map +1 -0
- package/dist/mcp-server/prompts/utils/promptDefinition.js +2 -0
- package/dist/mcp-server/prompts/utils/promptDefinition.js.map +1 -0
- package/dist/mcp-server/resources/resource-registration.d.ts +27 -0
- package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -0
- package/dist/mcp-server/resources/resource-registration.js +85 -0
- package/dist/mcp-server/resources/resource-registration.js.map +1 -0
- package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts +84 -0
- package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts.map +1 -0
- package/dist/mcp-server/resources/utils/newResourceDefinition.js +40 -0
- package/dist/mcp-server/resources/utils/newResourceDefinition.js.map +1 -0
- package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts +32 -0
- package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts.map +1 -0
- package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js +103 -0
- package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js.map +1 -0
- package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +94 -0
- package/dist/mcp-server/resources/utils/resourceDefinition.d.ts.map +1 -0
- package/dist/mcp-server/resources/utils/resourceDefinition.js +2 -0
- package/dist/mcp-server/resources/utils/resourceDefinition.js.map +1 -0
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +14 -0
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -0
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +111 -0
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -0
- package/dist/mcp-server/roots/roots-registration.d.ts +22 -0
- package/dist/mcp-server/roots/roots-registration.d.ts.map +1 -0
- package/dist/mcp-server/roots/roots-registration.js +25 -0
- package/dist/mcp-server/roots/roots-registration.js.map +1 -0
- package/dist/mcp-server/server.d.ts +34 -0
- package/dist/mcp-server/server.d.ts.map +1 -0
- package/dist/mcp-server/server.js +62 -0
- package/dist/mcp-server/server.js.map +1 -0
- package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts +42 -0
- package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts.map +1 -0
- package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js +70 -0
- package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js.map +1 -0
- package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts +109 -0
- package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts.map +1 -0
- package/dist/mcp-server/tasks/core/storageBackedTaskStore.js +209 -0
- package/dist/mcp-server/tasks/core/storageBackedTaskStore.js.map +1 -0
- package/dist/mcp-server/tasks/core/taskManager.d.ts +103 -0
- package/dist/mcp-server/tasks/core/taskManager.d.ts.map +1 -0
- package/dist/mcp-server/tasks/core/taskManager.js +144 -0
- package/dist/mcp-server/tasks/core/taskManager.js.map +1 -0
- package/dist/mcp-server/tasks/core/taskTypes.d.ts +11 -0
- package/dist/mcp-server/tasks/core/taskTypes.d.ts.map +1 -0
- package/dist/mcp-server/tasks/core/taskTypes.js +13 -0
- package/dist/mcp-server/tasks/core/taskTypes.js.map +1 -0
- package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts +108 -0
- package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts.map +1 -0
- package/dist/mcp-server/tasks/utils/taskToolDefinition.js +14 -0
- package/dist/mcp-server/tasks/utils/taskToolDefinition.js.map +1 -0
- package/dist/mcp-server/tools/tool-registration.d.ts +49 -0
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -0
- package/dist/mcp-server/tools/tool-registration.js +269 -0
- package/dist/mcp-server/tools/tool-registration.js.map +1 -0
- package/dist/mcp-server/tools/utils/newToolDefinition.d.ts +73 -0
- package/dist/mcp-server/tools/utils/newToolDefinition.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/newToolDefinition.js +45 -0
- package/dist/mcp-server/tools/utils/newToolDefinition.js.map +1 -0
- package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts +33 -0
- package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/newToolHandlerFactory.js +107 -0
- package/dist/mcp-server/tools/utils/newToolHandlerFactory.js.map +1 -0
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts +118 -0
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/toolDefinition.js +2 -0
- package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -0
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +34 -0
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +68 -0
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -0
- package/dist/mcp-server/transports/ITransport.d.ts +15 -0
- package/dist/mcp-server/transports/ITransport.d.ts.map +1 -0
- package/dist/mcp-server/transports/ITransport.js +2 -0
- package/dist/mcp-server/transports/ITransport.js.map +1 -0
- package/dist/mcp-server/transports/auth/authFactory.d.ts +11 -0
- package/dist/mcp-server/transports/auth/authFactory.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/authFactory.js +43 -0
- package/dist/mcp-server/transports/auth/authFactory.js.map +1 -0
- package/dist/mcp-server/transports/auth/authMiddleware.d.ts +24 -0
- package/dist/mcp-server/transports/auth/authMiddleware.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/authMiddleware.js +69 -0
- package/dist/mcp-server/transports/auth/authMiddleware.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authContext.d.ts +34 -0
- package/dist/mcp-server/transports/auth/lib/authContext.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authContext.js +25 -0
- package/dist/mcp-server/transports/auth/lib/authContext.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authTypes.d.ts +19 -0
- package/dist/mcp-server/transports/auth/lib/authTypes.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authTypes.js +2 -0
- package/dist/mcp-server/transports/auth/lib/authTypes.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.js +64 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts +25 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.js +34 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/claimParser.d.ts +34 -0
- package/dist/mcp-server/transports/auth/lib/claimParser.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/claimParser.js +58 -0
- package/dist/mcp-server/transports/auth/lib/claimParser.js.map +1 -0
- package/dist/mcp-server/transports/auth/lib/withAuth.d.ts +25 -0
- package/dist/mcp-server/transports/auth/lib/withAuth.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/lib/withAuth.js +30 -0
- package/dist/mcp-server/transports/auth/lib/withAuth.js.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts +18 -0
- package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/authStrategy.js +2 -0
- package/dist/mcp-server/transports/auth/strategies/authStrategy.js.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts +14 -0
- package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js +86 -0
- package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts +14 -0
- package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts.map +1 -0
- package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js +113 -0
- package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js.map +1 -0
- package/dist/mcp-server/transports/http/httpErrorHandler.d.ts +25 -0
- package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/httpErrorHandler.js +112 -0
- package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -0
- package/dist/mcp-server/transports/http/httpTransport.d.ts +47 -0
- package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/httpTransport.js +396 -0
- package/dist/mcp-server/transports/http/httpTransport.js.map +1 -0
- package/dist/mcp-server/transports/http/httpTypes.d.ts +17 -0
- package/dist/mcp-server/transports/http/httpTypes.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/httpTypes.js +2 -0
- package/dist/mcp-server/transports/http/httpTypes.js.map +1 -0
- package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts +21 -0
- package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/protectedResourceMetadata.js +44 -0
- package/dist/mcp-server/transports/http/protectedResourceMetadata.js.map +1 -0
- package/dist/mcp-server/transports/http/sessionIdUtils.d.ts +33 -0
- package/dist/mcp-server/transports/http/sessionIdUtils.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/sessionIdUtils.js +54 -0
- package/dist/mcp-server/transports/http/sessionIdUtils.js.map +1 -0
- package/dist/mcp-server/transports/http/sessionStore.d.ts +87 -0
- package/dist/mcp-server/transports/http/sessionStore.d.ts.map +1 -0
- package/dist/mcp-server/transports/http/sessionStore.js +209 -0
- package/dist/mcp-server/transports/http/sessionStore.js.map +1 -0
- package/dist/mcp-server/transports/manager.d.ts +22 -0
- package/dist/mcp-server/transports/manager.d.ts.map +1 -0
- package/dist/mcp-server/transports/manager.js +62 -0
- package/dist/mcp-server/transports/manager.js.map +1 -0
- package/dist/mcp-server/transports/stdio/stdioTransport.d.ts +44 -0
- package/dist/mcp-server/transports/stdio/stdioTransport.d.ts.map +1 -0
- package/dist/mcp-server/transports/stdio/stdioTransport.js +63 -0
- package/dist/mcp-server/transports/stdio/stdioTransport.js.map +1 -0
- package/dist/services/graph/core/GraphService.d.ts +205 -0
- package/dist/services/graph/core/GraphService.d.ts.map +1 -0
- package/dist/services/graph/core/GraphService.js +231 -0
- package/dist/services/graph/core/GraphService.js.map +1 -0
- package/dist/services/graph/core/IGraphProvider.d.ts +295 -0
- package/dist/services/graph/core/IGraphProvider.d.ts.map +1 -0
- package/dist/services/graph/core/IGraphProvider.js +8 -0
- package/dist/services/graph/core/IGraphProvider.js.map +1 -0
- package/dist/services/graph/types.d.ts +107 -0
- package/dist/services/graph/types.d.ts.map +1 -0
- package/dist/services/graph/types.js +8 -0
- package/dist/services/graph/types.js.map +1 -0
- package/dist/services/llm/core/ILlmProvider.d.ts +86 -0
- package/dist/services/llm/core/ILlmProvider.d.ts.map +1 -0
- package/dist/services/llm/core/ILlmProvider.js +2 -0
- package/dist/services/llm/core/ILlmProvider.js.map +1 -0
- package/dist/services/llm/providers/openrouter.provider.d.ts +187 -0
- package/dist/services/llm/providers/openrouter.provider.d.ts.map +1 -0
- package/dist/services/llm/providers/openrouter.provider.js +302 -0
- package/dist/services/llm/providers/openrouter.provider.js.map +1 -0
- package/dist/services/llm/types.d.ts +16 -0
- package/dist/services/llm/types.d.ts.map +1 -0
- package/dist/services/llm/types.js +9 -0
- package/dist/services/llm/types.js.map +1 -0
- package/dist/services/speech/core/ISpeechProvider.d.ts +92 -0
- package/dist/services/speech/core/ISpeechProvider.d.ts.map +1 -0
- package/dist/services/speech/core/ISpeechProvider.js +34 -0
- package/dist/services/speech/core/ISpeechProvider.js.map +1 -0
- package/dist/services/speech/core/SpeechService.d.ts +87 -0
- package/dist/services/speech/core/SpeechService.d.ts.map +1 -0
- package/dist/services/speech/core/SpeechService.js +135 -0
- package/dist/services/speech/core/SpeechService.js.map +1 -0
- package/dist/services/speech/providers/elevenlabs.provider.d.ts +77 -0
- package/dist/services/speech/providers/elevenlabs.provider.d.ts.map +1 -0
- package/dist/services/speech/providers/elevenlabs.provider.js +199 -0
- package/dist/services/speech/providers/elevenlabs.provider.js.map +1 -0
- package/dist/services/speech/providers/whisper.provider.d.ts +94 -0
- package/dist/services/speech/providers/whisper.provider.d.ts.map +1 -0
- package/dist/services/speech/providers/whisper.provider.js +240 -0
- package/dist/services/speech/providers/whisper.provider.js.map +1 -0
- package/dist/services/speech/types.d.ts +173 -0
- package/dist/services/speech/types.d.ts.map +1 -0
- package/dist/services/speech/types.js +8 -0
- package/dist/services/speech/types.js.map +1 -0
- package/dist/storage/core/IStorageProvider.d.ts +159 -0
- package/dist/storage/core/IStorageProvider.d.ts.map +1 -0
- package/dist/storage/core/IStorageProvider.js +2 -0
- package/dist/storage/core/IStorageProvider.js.map +1 -0
- package/dist/storage/core/StorageService.d.ts +22 -0
- package/dist/storage/core/StorageService.d.ts.map +1 -0
- package/dist/storage/core/StorageService.js +151 -0
- package/dist/storage/core/StorageService.js.map +1 -0
- package/dist/storage/core/storageFactory.d.ts +66 -0
- package/dist/storage/core/storageFactory.d.ts.map +1 -0
- package/dist/storage/core/storageFactory.js +122 -0
- package/dist/storage/core/storageFactory.js.map +1 -0
- package/dist/storage/core/storageValidation.d.ts +77 -0
- package/dist/storage/core/storageValidation.d.ts.map +1 -0
- package/dist/storage/core/storageValidation.js +303 -0
- package/dist/storage/core/storageValidation.js.map +1 -0
- package/dist/storage/providers/cloudflare/d1Provider.d.ts +94 -0
- package/dist/storage/providers/cloudflare/d1Provider.d.ts.map +1 -0
- package/dist/storage/providers/cloudflare/d1Provider.js +347 -0
- package/dist/storage/providers/cloudflare/d1Provider.js.map +1 -0
- package/dist/storage/providers/cloudflare/kvProvider.d.ts +21 -0
- package/dist/storage/providers/cloudflare/kvProvider.d.ts.map +1 -0
- package/dist/storage/providers/cloudflare/kvProvider.js +183 -0
- package/dist/storage/providers/cloudflare/kvProvider.js.map +1 -0
- package/dist/storage/providers/cloudflare/r2Provider.d.ts +28 -0
- package/dist/storage/providers/cloudflare/r2Provider.d.ts.map +1 -0
- package/dist/storage/providers/cloudflare/r2Provider.js +222 -0
- package/dist/storage/providers/cloudflare/r2Provider.js.map +1 -0
- package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts +20 -0
- package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts.map +1 -0
- package/dist/storage/providers/fileSystem/fileSystemProvider.js +282 -0
- package/dist/storage/providers/fileSystem/fileSystemProvider.js.map +1 -0
- package/dist/storage/providers/inMemory/inMemoryProvider.d.ts +21 -0
- package/dist/storage/providers/inMemory/inMemoryProvider.d.ts.map +1 -0
- package/dist/storage/providers/inMemory/inMemoryProvider.js +139 -0
- package/dist/storage/providers/inMemory/inMemoryProvider.js.map +1 -0
- package/dist/storage/providers/supabase/supabase.types.d.ts +49 -0
- package/dist/storage/providers/supabase/supabase.types.d.ts.map +1 -0
- package/dist/storage/providers/supabase/supabase.types.js +8 -0
- package/dist/storage/providers/supabase/supabase.types.js.map +1 -0
- package/dist/storage/providers/supabase/supabaseProvider.d.ts +24 -0
- package/dist/storage/providers/supabase/supabaseProvider.d.ts.map +1 -0
- package/dist/storage/providers/supabase/supabaseProvider.js +209 -0
- package/dist/storage/providers/supabase/supabaseProvider.js.map +1 -0
- package/dist/testing/index.d.ts +53 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +132 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-global/errors.d.ts +83 -0
- package/dist/types-global/errors.d.ts.map +1 -0
- package/dist/types-global/errors.js +113 -0
- package/dist/types-global/errors.js.map +1 -0
- package/dist/utils/formatting/diffFormatter.d.ts +227 -0
- package/dist/utils/formatting/diffFormatter.d.ts.map +1 -0
- package/dist/utils/formatting/diffFormatter.js +369 -0
- package/dist/utils/formatting/diffFormatter.js.map +1 -0
- package/dist/utils/formatting/index.d.ts +9 -0
- package/dist/utils/formatting/index.d.ts.map +1 -0
- package/dist/utils/formatting/index.js +9 -0
- package/dist/utils/formatting/index.js.map +1 -0
- package/dist/utils/formatting/markdownBuilder.d.ts +543 -0
- package/dist/utils/formatting/markdownBuilder.d.ts.map +1 -0
- package/dist/utils/formatting/markdownBuilder.js +674 -0
- package/dist/utils/formatting/markdownBuilder.js.map +1 -0
- package/dist/utils/formatting/tableFormatter.d.ts +261 -0
- package/dist/utils/formatting/tableFormatter.d.ts.map +1 -0
- package/dist/utils/formatting/tableFormatter.js +456 -0
- package/dist/utils/formatting/tableFormatter.js.map +1 -0
- package/dist/utils/formatting/treeFormatter.d.ts +344 -0
- package/dist/utils/formatting/treeFormatter.d.ts.map +1 -0
- package/dist/utils/formatting/treeFormatter.js +400 -0
- package/dist/utils/formatting/treeFormatter.js.map +1 -0
- package/dist/utils/internal/encoding.d.ts +42 -0
- package/dist/utils/internal/encoding.d.ts.map +1 -0
- package/dist/utils/internal/encoding.js +87 -0
- package/dist/utils/internal/encoding.js.map +1 -0
- package/dist/utils/internal/error-handler/errorHandler.d.ts +140 -0
- package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -0
- package/dist/utils/internal/error-handler/errorHandler.js +318 -0
- package/dist/utils/internal/error-handler/errorHandler.js.map +1 -0
- package/dist/utils/internal/error-handler/helpers.d.ts +98 -0
- package/dist/utils/internal/error-handler/helpers.d.ts.map +1 -0
- package/dist/utils/internal/error-handler/helpers.js +214 -0
- package/dist/utils/internal/error-handler/helpers.js.map +1 -0
- package/dist/utils/internal/error-handler/mappings.d.ts +85 -0
- package/dist/utils/internal/error-handler/mappings.d.ts.map +1 -0
- package/dist/utils/internal/error-handler/mappings.js +234 -0
- package/dist/utils/internal/error-handler/mappings.js.map +1 -0
- package/dist/utils/internal/error-handler/types.d.ts +160 -0
- package/dist/utils/internal/error-handler/types.d.ts.map +1 -0
- package/dist/utils/internal/error-handler/types.js +6 -0
- package/dist/utils/internal/error-handler/types.js.map +1 -0
- package/dist/utils/internal/health.d.ts +60 -0
- package/dist/utils/internal/health.d.ts.map +1 -0
- package/dist/utils/internal/health.js +46 -0
- package/dist/utils/internal/health.js.map +1 -0
- package/dist/utils/internal/logger.d.ts +300 -0
- package/dist/utils/internal/logger.d.ts.map +1 -0
- package/dist/utils/internal/logger.js +573 -0
- package/dist/utils/internal/logger.js.map +1 -0
- package/dist/utils/internal/performance.d.ts +78 -0
- package/dist/utils/internal/performance.d.ts.map +1 -0
- package/dist/utils/internal/performance.js +227 -0
- package/dist/utils/internal/performance.js.map +1 -0
- package/dist/utils/internal/requestContext.d.ts +200 -0
- package/dist/utils/internal/requestContext.d.ts.map +1 -0
- package/dist/utils/internal/requestContext.js +163 -0
- package/dist/utils/internal/requestContext.js.map +1 -0
- package/dist/utils/internal/runtime.d.ts +49 -0
- package/dist/utils/internal/runtime.d.ts.map +1 -0
- package/dist/utils/internal/runtime.js +90 -0
- package/dist/utils/internal/runtime.js.map +1 -0
- package/dist/utils/internal/startupBanner.d.ts +23 -0
- package/dist/utils/internal/startupBanner.d.ts.map +1 -0
- package/dist/utils/internal/startupBanner.js +34 -0
- package/dist/utils/internal/startupBanner.js.map +1 -0
- package/dist/utils/metrics/tokenCounter.d.ts +97 -0
- package/dist/utils/metrics/tokenCounter.d.ts.map +1 -0
- package/dist/utils/metrics/tokenCounter.js +162 -0
- package/dist/utils/metrics/tokenCounter.js.map +1 -0
- package/dist/utils/network/fetchWithTimeout.d.ts +91 -0
- package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -0
- package/dist/utils/network/fetchWithTimeout.js +305 -0
- package/dist/utils/network/fetchWithTimeout.js.map +1 -0
- package/dist/utils/pagination/pagination.d.ts +157 -0
- package/dist/utils/pagination/pagination.d.ts.map +1 -0
- package/dist/utils/pagination/pagination.js +191 -0
- package/dist/utils/pagination/pagination.js.map +1 -0
- package/dist/utils/parsing/csvParser.d.ts +84 -0
- package/dist/utils/parsing/csvParser.d.ts.map +1 -0
- package/dist/utils/parsing/csvParser.js +132 -0
- package/dist/utils/parsing/csvParser.js.map +1 -0
- package/dist/utils/parsing/dateParser.d.ts +103 -0
- package/dist/utils/parsing/dateParser.d.ts.map +1 -0
- package/dist/utils/parsing/dateParser.js +142 -0
- package/dist/utils/parsing/dateParser.js.map +1 -0
- package/dist/utils/parsing/frontmatterParser.d.ts +91 -0
- package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -0
- package/dist/utils/parsing/frontmatterParser.js +163 -0
- package/dist/utils/parsing/frontmatterParser.js.map +1 -0
- package/dist/utils/parsing/index.d.ts +15 -0
- package/dist/utils/parsing/index.d.ts.map +1 -0
- package/dist/utils/parsing/index.js +15 -0
- package/dist/utils/parsing/index.js.map +1 -0
- package/dist/utils/parsing/jsonParser.d.ts +115 -0
- package/dist/utils/parsing/jsonParser.d.ts.map +1 -0
- package/dist/utils/parsing/jsonParser.js +177 -0
- package/dist/utils/parsing/jsonParser.js.map +1 -0
- package/dist/utils/parsing/pdfParser.d.ts +563 -0
- package/dist/utils/parsing/pdfParser.d.ts.map +1 -0
- package/dist/utils/parsing/pdfParser.js +775 -0
- package/dist/utils/parsing/pdfParser.js.map +1 -0
- package/dist/utils/parsing/thinkBlock.d.ts +31 -0
- package/dist/utils/parsing/thinkBlock.d.ts.map +1 -0
- package/dist/utils/parsing/thinkBlock.js +31 -0
- package/dist/utils/parsing/thinkBlock.js.map +1 -0
- package/dist/utils/parsing/xmlParser.d.ts +69 -0
- package/dist/utils/parsing/xmlParser.d.ts.map +1 -0
- package/dist/utils/parsing/xmlParser.js +140 -0
- package/dist/utils/parsing/xmlParser.js.map +1 -0
- package/dist/utils/parsing/yamlParser.d.ts +64 -0
- package/dist/utils/parsing/yamlParser.d.ts.map +1 -0
- package/dist/utils/parsing/yamlParser.js +129 -0
- package/dist/utils/parsing/yamlParser.js.map +1 -0
- package/dist/utils/scheduling/scheduler.d.ts +174 -0
- package/dist/utils/scheduling/scheduler.d.ts.map +1 -0
- package/dist/utils/scheduling/scheduler.js +248 -0
- package/dist/utils/scheduling/scheduler.js.map +1 -0
- package/dist/utils/security/idGenerator.d.ts +189 -0
- package/dist/utils/security/idGenerator.d.ts.map +1 -0
- package/dist/utils/security/idGenerator.js +301 -0
- package/dist/utils/security/idGenerator.js.map +1 -0
- package/dist/utils/security/index.d.ts +8 -0
- package/dist/utils/security/index.d.ts.map +1 -0
- package/dist/utils/security/index.js +8 -0
- package/dist/utils/security/index.js.map +1 -0
- package/dist/utils/security/rateLimiter.d.ts +171 -0
- package/dist/utils/security/rateLimiter.d.ts.map +1 -0
- package/dist/utils/security/rateLimiter.js +294 -0
- package/dist/utils/security/rateLimiter.js.map +1 -0
- package/dist/utils/security/sanitization.d.ts +430 -0
- package/dist/utils/security/sanitization.d.ts.map +1 -0
- package/dist/utils/security/sanitization.js +759 -0
- package/dist/utils/security/sanitization.js.map +1 -0
- package/dist/utils/telemetry/index.d.ts +12 -0
- package/dist/utils/telemetry/index.d.ts.map +1 -0
- package/dist/utils/telemetry/index.js +12 -0
- package/dist/utils/telemetry/index.js.map +1 -0
- package/dist/utils/telemetry/instrumentation.d.ts +62 -0
- package/dist/utils/telemetry/instrumentation.d.ts.map +1 -0
- package/dist/utils/telemetry/instrumentation.js +223 -0
- package/dist/utils/telemetry/instrumentation.js.map +1 -0
- package/dist/utils/telemetry/metrics.d.ts +170 -0
- package/dist/utils/telemetry/metrics.d.ts.map +1 -0
- package/dist/utils/telemetry/metrics.js +205 -0
- package/dist/utils/telemetry/metrics.js.map +1 -0
- package/dist/utils/telemetry/semconv.d.ts +147 -0
- package/dist/utils/telemetry/semconv.d.ts.map +1 -0
- package/dist/utils/telemetry/semconv.js +159 -0
- package/dist/utils/telemetry/semconv.js.map +1 -0
- package/dist/utils/telemetry/trace.d.ts +141 -0
- package/dist/utils/telemetry/trace.d.ts.map +1 -0
- package/dist/utils/telemetry/trace.js +193 -0
- package/dist/utils/telemetry/trace.js.map +1 -0
- package/dist/utils/types/guards.d.ts +209 -0
- package/dist/utils/types/guards.d.ts.map +1 -0
- package/dist/utils/types/guards.js +229 -0
- package/dist/utils/types/guards.js.map +1 -0
- package/dist/utils/types/index.d.ts +6 -0
- package/dist/utils/types/index.d.ts.map +1 -0
- package/dist/utils/types/index.js +6 -0
- package/dist/utils/types/index.js.map +1 -0
- package/dist/worker.d.ts +59 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +216 -0
- package/dist/worker.js.map +1 -0
- package/package.json +377 -0
- package/skills/README.md +38 -0
- package/skills/add-export/SKILL.md +49 -0
- package/skills/add-prompt/SKILL.md +97 -0
- package/skills/add-provider/SKILL.md +53 -0
- package/skills/add-resource/SKILL.md +107 -0
- package/skills/add-service/SKILL.md +113 -0
- package/skills/add-tool/SKILL.md +110 -0
- package/skills/api-auth/SKILL.md +173 -0
- package/skills/api-config/SKILL.md +68 -0
- package/skills/api-context/SKILL.md +321 -0
- package/skills/api-errors/SKILL.md +146 -0
- package/skills/api-services/SKILL.md +24 -0
- package/skills/api-services/references/graph.md +124 -0
- package/skills/api-services/references/llm.md +46 -0
- package/skills/api-services/references/speech.md +72 -0
- package/skills/api-testing/SKILL.md +263 -0
- package/skills/api-utils/SKILL.md +106 -0
- package/skills/api-utils/references/formatting.md +237 -0
- package/skills/api-utils/references/parsing.md +263 -0
- package/skills/api-utils/references/security.md +226 -0
- package/skills/api-workers/SKILL.md +165 -0
- package/skills/devcheck/SKILL.md +31 -0
- package/skills/maintenance/SKILL.md +52 -0
- package/skills/migrate-mcp-ts-template/SKILL.md +131 -0
- package/skills/release/SKILL.md +67 -0
- package/skills/setup/SKILL.md +89 -0
- package/skills/walkthrough-init/SKILL.md +50 -0
- package/templates/.env.example +17 -0
- package/templates/AGENTS.md +113 -0
- package/templates/CLAUDE.md +113 -0
- package/templates/_tsconfig.json +33 -0
- package/templates/biome.template.json +43 -0
- package/templates/package.json +26 -0
- package/templates/src/index.ts +16 -0
- package/templates/src/mcp-server/prompts/definitions/echo.prompt.ts +19 -0
- package/templates/src/mcp-server/resources/definitions/echo.resource.ts +30 -0
- package/templates/src/mcp-server/tools/definitions/echo.tool.ts +24 -0
- package/templates/vitest.config.ts +12 -0
- package/tsconfig.base.json +44 -0
- package/vitest.config.base.ts +38 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Provides a comprehensive `Sanitization` class for various input cleaning and
|
|
3
|
+
* validation tasks. Includes utilities for sanitizing HTML, strings, URLs, file paths, JSON,
|
|
4
|
+
* and numbers, as well as redacting sensitive fields from data intended for logging.
|
|
5
|
+
*
|
|
6
|
+
* Several methods (`sanitizeHtml`, `sanitizeString`, `sanitizeUrl`, `sanitizeNumber`) are
|
|
7
|
+
* **async** because they lazy-load optional peer dependencies (`sanitize-html`, `validator`)
|
|
8
|
+
* on first use. If a required peer dependency is not installed, these methods throw a
|
|
9
|
+
* `McpError` with `JsonRpcErrorCode.ConfigurationError`.
|
|
10
|
+
*
|
|
11
|
+
* Path sanitization (`sanitizePath`) is synchronous but only available in Node.js environments.
|
|
12
|
+
*
|
|
13
|
+
* @module src/utils/security/sanitization
|
|
14
|
+
*/
|
|
15
|
+
import type sanitizeHtml from 'sanitize-html';
|
|
16
|
+
/**
|
|
17
|
+
* Options controlling how `sanitizePath` processes and validates file paths.
|
|
18
|
+
*/
|
|
19
|
+
export interface PathSanitizeOptions {
|
|
20
|
+
/** If `true`, absolute paths are permitted (subject to `rootDir` containment). Default: `false`. */
|
|
21
|
+
allowAbsolute?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* If provided, all paths are resolved relative to this directory and checked for containment.
|
|
24
|
+
* Any path that escapes the root via traversal (`../`) throws a `McpError`.
|
|
25
|
+
* The value is resolved with `path.resolve` before use.
|
|
26
|
+
*/
|
|
27
|
+
rootDir?: string;
|
|
28
|
+
/** If `true`, normalizes Windows-style backslashes (`\`) to POSIX forward slashes (`/`). */
|
|
29
|
+
toPosix?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result returned by `sanitizePath`, describing the outcome of path sanitization.
|
|
33
|
+
*/
|
|
34
|
+
export interface SanitizedPathInfo {
|
|
35
|
+
/**
|
|
36
|
+
* `true` if the input was absolute but was converted to a relative path because
|
|
37
|
+
* `allowAbsolute` was `false` and a `rootDir` was provided.
|
|
38
|
+
*/
|
|
39
|
+
convertedToRelative: boolean;
|
|
40
|
+
/** The effective options used for sanitization, with defaults applied. */
|
|
41
|
+
optionsUsed: PathSanitizeOptions;
|
|
42
|
+
/** The original path string as passed to `sanitizePath`, before any processing. */
|
|
43
|
+
originalInput: string;
|
|
44
|
+
/** The final sanitized and normalized path string. */
|
|
45
|
+
sanitizedPath: string;
|
|
46
|
+
/** `true` if the input path was absolute after initial `path.normalize`. */
|
|
47
|
+
wasAbsolute: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for context-specific string sanitization passed to `sanitizeString`.
|
|
51
|
+
*/
|
|
52
|
+
export interface SanitizeStringOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Custom allowed HTML attributes, keyed by tag name (e.g., `{ a: ['href'] }`).
|
|
55
|
+
* Only used when `context` is `'html'`.
|
|
56
|
+
*/
|
|
57
|
+
allowedAttributes?: Record<string, string[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Custom list of allowed HTML tag names.
|
|
60
|
+
* Only used when `context` is `'html'`.
|
|
61
|
+
*/
|
|
62
|
+
allowedTags?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* The context in which the sanitized string will be used. Determines how sanitization
|
|
65
|
+
* is performed. `'javascript'` is explicitly disallowed and will throw.
|
|
66
|
+
* Defaults to `'text'`.
|
|
67
|
+
*/
|
|
68
|
+
context?: 'text' | 'html' | 'attribute' | 'url' | 'javascript';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Configuration options for HTML sanitization, mirroring the `sanitize-html` library's options.
|
|
72
|
+
* Passed to `sanitizeHtml` to override the default allowlist.
|
|
73
|
+
*/
|
|
74
|
+
export interface HtmlSanitizeConfig {
|
|
75
|
+
/**
|
|
76
|
+
* Allowed HTML attributes, keyed by tag name or `'*'` for a global allowlist.
|
|
77
|
+
* Mirrors `sanitize-html`'s `IOptions['allowedAttributes']`.
|
|
78
|
+
*/
|
|
79
|
+
allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes'];
|
|
80
|
+
/**
|
|
81
|
+
* Allowed HTML tag names. Any tag not in this list is stripped from the output.
|
|
82
|
+
* Mirrors `sanitize-html`'s `allowedTags`.
|
|
83
|
+
*/
|
|
84
|
+
allowedTags?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* If `true`, HTML comments (`<!-- ... -->`) are preserved in the output.
|
|
87
|
+
* Internally this is implemented by adding `'!--'` to the `allowedTags` list.
|
|
88
|
+
*/
|
|
89
|
+
preserveComments?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Custom tag-transform functions applied during sanitization.
|
|
92
|
+
* If omitted, `<a>` tags are automatically given `rel="noopener noreferrer"`.
|
|
93
|
+
* Mirrors `sanitize-html`'s `IOptions['transformTags']`.
|
|
94
|
+
*/
|
|
95
|
+
transformTags?: sanitizeHtml.IOptions['transformTags'];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Singleton class providing input sanitization across multiple categories:
|
|
99
|
+
* HTML (XSS prevention), URLs, file paths (traversal prevention), JSON, numbers,
|
|
100
|
+
* and log-safe redaction of sensitive fields.
|
|
101
|
+
*
|
|
102
|
+
* Obtain the singleton via `Sanitization.getInstance()` or use the pre-exported
|
|
103
|
+
* `sanitization` constant.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { sanitization } from '../../utils/security/sanitization.js';
|
|
108
|
+
*
|
|
109
|
+
* const clean = await sanitization.sanitizeHtml('<script>alert(1)</script><b>hi</b>');
|
|
110
|
+
* // => '<b>hi</b>'
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare class Sanitization {
|
|
114
|
+
/** @private */
|
|
115
|
+
private static instance;
|
|
116
|
+
private sensitiveFields;
|
|
117
|
+
/**
|
|
118
|
+
* Default configuration for HTML sanitization.
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private defaultHtmlSanitizeConfig;
|
|
122
|
+
/** @private */
|
|
123
|
+
private constructor();
|
|
124
|
+
private normalizedSensitiveSet;
|
|
125
|
+
private wordSensitiveSet;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the singleton instance of `Sanitization`, creating it on first call.
|
|
128
|
+
*
|
|
129
|
+
* @returns The singleton `Sanitization` instance.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const san = Sanitization.getInstance();
|
|
133
|
+
* const safe = await san.sanitizeHtml(userInput);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
static getInstance(): Sanitization;
|
|
137
|
+
/**
|
|
138
|
+
* Extends the list of sensitive field names used by `sanitizeForLogging`.
|
|
139
|
+
* New names are merged with the existing list (deduplication applied, case-insensitive).
|
|
140
|
+
* Changes take effect immediately on subsequent `sanitizeForLogging` calls.
|
|
141
|
+
*
|
|
142
|
+
* @param fields - Field names to add to the sensitive list (e.g., `['myApiKey', 'session_id']`).
|
|
143
|
+
* @returns `void`
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* sanitization.setSensitiveFields(['myApiKey', 'session_id']);
|
|
147
|
+
* sanitization.sanitizeForLogging({ myApiKey: 'abc123' });
|
|
148
|
+
* // => { myApiKey: '[REDACTED]' }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
setSensitiveFields(fields: string[]): void;
|
|
152
|
+
/**
|
|
153
|
+
* Returns a copy of the current sensitive field names list.
|
|
154
|
+
* All names are lowercased. Mutating the returned array has no effect on internal state.
|
|
155
|
+
*
|
|
156
|
+
* @returns Array of lowercase sensitive field name strings.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const fields = sanitization.getSensitiveFields();
|
|
160
|
+
* // => ['password', 'token', 'secret', ...]
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
getSensitiveFields(): string[];
|
|
164
|
+
/**
|
|
165
|
+
* Returns pino-compatible redact path patterns covering sensitive field names at three
|
|
166
|
+
* nesting depths: top-level, one level deep, and two levels deep.
|
|
167
|
+
*
|
|
168
|
+
* For example, the field `'token'` generates:
|
|
169
|
+
* - `'token'` — matches `{ token: '...' }`
|
|
170
|
+
* - `'*.token'` — matches `{ auth: { token: '...' } }`
|
|
171
|
+
* - `'*.*.token'` — matches `{ context: { auth: { token: '...' } } }`
|
|
172
|
+
*
|
|
173
|
+
* Pass the result directly to pino's `redact.paths` option.
|
|
174
|
+
*
|
|
175
|
+
* @returns Array of fast-redact-compatible path strings for use in pino's `redact.paths`.
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* import pino from 'pino';
|
|
179
|
+
* const log = pino({ redact: { paths: sanitization.getSensitivePinoFields(), censor: '[REDACTED]' } });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getSensitivePinoFields(): string[];
|
|
183
|
+
/**
|
|
184
|
+
* Sanitizes an HTML string using `sanitize-html`, stripping disallowed tags and attributes.
|
|
185
|
+
*
|
|
186
|
+
* This method is **async** because it lazy-loads the `sanitize-html` peer dependency on
|
|
187
|
+
* first call. By default, `<a>` tags receive `rel="noopener noreferrer"` automatically.
|
|
188
|
+
* The `style` attribute is intentionally excluded from the default allowlist to prevent
|
|
189
|
+
* CSS injection attacks.
|
|
190
|
+
*
|
|
191
|
+
* @param input - The HTML string to sanitize. Returns `''` immediately if falsy.
|
|
192
|
+
* @param config - Optional config overriding the default tag/attribute allowlists.
|
|
193
|
+
* If omitted, the built-in defaults are used (see `defaultHtmlSanitizeConfig`).
|
|
194
|
+
* @returns Promise resolving to the sanitized HTML string.
|
|
195
|
+
* @throws {McpError} With `ConfigurationError` if `sanitize-html` is not installed.
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* const safe = await sanitization.sanitizeHtml('<script>alert(1)</script><b>Hello</b>');
|
|
199
|
+
* // => '<b>Hello</b>'
|
|
200
|
+
*
|
|
201
|
+
* const custom = await sanitization.sanitizeHtml('<div class="x"><b>ok</b></div>', {
|
|
202
|
+
* allowedTags: ['b'],
|
|
203
|
+
* });
|
|
204
|
+
* // => '<b>ok</b>'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
sanitizeHtml(input: string, config?: HtmlSanitizeConfig): Promise<string>;
|
|
208
|
+
/**
|
|
209
|
+
* Sanitizes a string according to its intended usage context.
|
|
210
|
+
*
|
|
211
|
+
* This method is **async** because it lazy-loads `sanitize-html` and/or `validator`
|
|
212
|
+
* depending on the requested context.
|
|
213
|
+
*
|
|
214
|
+
* | `context` | Behavior |
|
|
215
|
+
* |----------------|----------|
|
|
216
|
+
* | `'text'` | Strips all HTML tags and attributes (default). |
|
|
217
|
+
* | `'html'` | Runs full HTML sanitization via `sanitizeHtml` (respects `allowedTags`/`allowedAttributes`). |
|
|
218
|
+
* | `'attribute'` | Strips all tags and attributes — safe for use inside an HTML attribute value. |
|
|
219
|
+
* | `'url'` | Validates the URL with `validator.isURL` (http/https only); returns `''` if invalid. |
|
|
220
|
+
* | `'javascript'` | **Disallowed.** Always throws `McpError`. |
|
|
221
|
+
*
|
|
222
|
+
* @param input - The string to sanitize. Returns `''` immediately if falsy.
|
|
223
|
+
* @param options - Context and optional allowlist overrides.
|
|
224
|
+
* @returns Promise resolving to the sanitized string, or `''` for invalid URLs.
|
|
225
|
+
* @throws {McpError} With `ValidationError` if `context` is `'javascript'`.
|
|
226
|
+
* @throws {McpError} With `ConfigurationError` if a required peer dep is not installed.
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* await sanitization.sanitizeString('<b>hello</b>', { context: 'text' });
|
|
230
|
+
* // => 'hello'
|
|
231
|
+
*
|
|
232
|
+
* await sanitization.sanitizeString('https://example.com', { context: 'url' });
|
|
233
|
+
* // => 'https://example.com'
|
|
234
|
+
*
|
|
235
|
+
* await sanitization.sanitizeString('javascript:alert(1)', { context: 'url' });
|
|
236
|
+
* // => '' (logged as warning, not thrown)
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
sanitizeString(input: string, options?: SanitizeStringOptions): Promise<string>;
|
|
240
|
+
/**
|
|
241
|
+
* Converts attribute format for `sanitizeHtml`.
|
|
242
|
+
* @param attrs - Attributes in `{ tagName: ['attr1'] }` format.
|
|
243
|
+
* @returns Attributes in `sanitize-html` expected format.
|
|
244
|
+
* @private
|
|
245
|
+
*/
|
|
246
|
+
private convertAttributesFormat;
|
|
247
|
+
/**
|
|
248
|
+
* Validates and sanitizes a URL string.
|
|
249
|
+
*
|
|
250
|
+
* This method is **async** because it lazy-loads the `validator` peer dependency on first call.
|
|
251
|
+
*
|
|
252
|
+
* Validation requires a protocol and host. Even if a protocol appears in `allowedProtocols`,
|
|
253
|
+
* the pseudo-protocols `javascript:`, `data:`, and `vbscript:` are always rejected.
|
|
254
|
+
*
|
|
255
|
+
* @param input - The URL string to sanitize. Leading/trailing whitespace is trimmed.
|
|
256
|
+
* @param allowedProtocols - URL schemes that are permitted. Defaults to `['http', 'https']`.
|
|
257
|
+
* @returns Promise resolving to the trimmed, validated URL string.
|
|
258
|
+
* @throws {McpError} With `ValidationError` if the URL is invalid, uses a disallowed protocol,
|
|
259
|
+
* or uses a blocked pseudo-protocol (`javascript:`, `data:`, `vbscript:`).
|
|
260
|
+
* @throws {McpError} With `ConfigurationError` if `validator` is not installed.
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* await sanitization.sanitizeUrl('https://example.com/path');
|
|
264
|
+
* // => 'https://example.com/path'
|
|
265
|
+
*
|
|
266
|
+
* await sanitization.sanitizeUrl('ftp://files.example.com', ['ftp', 'sftp']);
|
|
267
|
+
* // => 'ftp://files.example.com'
|
|
268
|
+
*
|
|
269
|
+
* await sanitization.sanitizeUrl('javascript:alert(1)');
|
|
270
|
+
* // throws McpError (ValidationError)
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
sanitizeUrl(input: string, allowedProtocols?: string[]): Promise<string>;
|
|
274
|
+
/**
|
|
275
|
+
* Sanitizes a file path, preventing path traversal attacks and normalizing format.
|
|
276
|
+
*
|
|
277
|
+
* This method is **synchronous** and only available in Node.js (uses `node:path`).
|
|
278
|
+
* Calling it in a non-Node.js environment (e.g., Cloudflare Workers) throws immediately.
|
|
279
|
+
*
|
|
280
|
+
* Traversal detection:
|
|
281
|
+
* - With `rootDir`: resolves the full path and asserts it starts within the root.
|
|
282
|
+
* - Without `rootDir`: resolves the relative path against CWD and asserts containment.
|
|
283
|
+
* - Null bytes (`\0`) in paths are always rejected.
|
|
284
|
+
*
|
|
285
|
+
* @param input - The file path string to sanitize.
|
|
286
|
+
* @param options - Options controlling absolute path permission, root directory, and POSIX normalization.
|
|
287
|
+
* @returns A `SanitizedPathInfo` object with the sanitized path and operation metadata.
|
|
288
|
+
* @throws {McpError} With `InternalError` if called outside a Node.js environment.
|
|
289
|
+
* @throws {McpError} With `ValidationError` if the path is empty, contains a null byte,
|
|
290
|
+
* attempts traversal beyond `rootDir` or CWD, or is absolute when `allowAbsolute` is `false`.
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const result = sanitization.sanitizePath('../../etc/passwd', { rootDir: '/app/data' });
|
|
294
|
+
* // throws McpError (path traversal detected)
|
|
295
|
+
*
|
|
296
|
+
* const result = sanitization.sanitizePath('uploads/file.txt', { rootDir: '/app/data' });
|
|
297
|
+
* // => { sanitizedPath: 'uploads/file.txt', wasAbsolute: false, convertedToRelative: false, ... }
|
|
298
|
+
*
|
|
299
|
+
* const result = sanitization.sanitizePath('C:\\Users\\foo\\bar', { toPosix: true, allowAbsolute: true });
|
|
300
|
+
* // => { sanitizedPath: 'C:/Users/foo/bar', wasAbsolute: true, ... }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
sanitizePath(input: string, options?: PathSanitizeOptions): SanitizedPathInfo;
|
|
304
|
+
/**
|
|
305
|
+
* Validates and parses a JSON string, with an optional maximum byte-size guard.
|
|
306
|
+
*
|
|
307
|
+
* This method is **synchronous**. Byte length is computed via `Buffer.byteLength` in
|
|
308
|
+
* Node.js, `TextEncoder` in environments that support it, or falls back to `string.length`.
|
|
309
|
+
*
|
|
310
|
+
* @template T - Expected type of the parsed value. Defaults to `unknown`.
|
|
311
|
+
* @param input - The JSON string to validate and parse. Must be a `string`.
|
|
312
|
+
* @param maxSize - Optional maximum allowed UTF-8 byte length. Throws if exceeded.
|
|
313
|
+
* @returns The parsed JavaScript value cast to `T`.
|
|
314
|
+
* @throws {McpError} With `ValidationError` if:
|
|
315
|
+
* - `input` is not a string
|
|
316
|
+
* - `input` exceeds `maxSize` bytes
|
|
317
|
+
* - `input` is not valid JSON
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* const obj = sanitization.sanitizeJson<{ id: number }>('{"id":1}');
|
|
321
|
+
* // => { id: 1 }
|
|
322
|
+
*
|
|
323
|
+
* sanitization.sanitizeJson('{"big":"value"}', 5);
|
|
324
|
+
* // throws McpError (exceeds maxSize)
|
|
325
|
+
*
|
|
326
|
+
* sanitization.sanitizeJson('{bad json}');
|
|
327
|
+
* // throws McpError (invalid JSON)
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
sanitizeJson<T = unknown>(input: string, maxSize?: number): T;
|
|
331
|
+
/**
|
|
332
|
+
* Validates a numeric input and optionally clamps it to a range.
|
|
333
|
+
*
|
|
334
|
+
* This method is **async** because string inputs are validated using the `validator` peer
|
|
335
|
+
* dependency, which is lazy-loaded on first call. Numeric inputs bypass the lazy load.
|
|
336
|
+
*
|
|
337
|
+
* - String inputs: trimmed and checked with `validator.isNumeric`, then parsed with `parseFloat`.
|
|
338
|
+
* - Number inputs: used directly.
|
|
339
|
+
* - `NaN` and `Infinity` are always rejected.
|
|
340
|
+
* - If `min` or `max` are provided, the value is silently clamped (a debug log is emitted).
|
|
341
|
+
*
|
|
342
|
+
* @param input - The number or numeric string to validate.
|
|
343
|
+
* @param min - Inclusive lower bound. If the value is below this, it is clamped to `min`.
|
|
344
|
+
* @param max - Inclusive upper bound. If the value is above this, it is clamped to `max`.
|
|
345
|
+
* @returns Promise resolving to the validated (and potentially clamped) number.
|
|
346
|
+
* @throws {McpError} With `ValidationError` if the input is not numeric, is `NaN`, or is `Infinity`.
|
|
347
|
+
* @throws {McpError} With `ConfigurationError` if `validator` is not installed (string input only).
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* await sanitization.sanitizeNumber('42.5');
|
|
351
|
+
* // => 42.5
|
|
352
|
+
*
|
|
353
|
+
* await sanitization.sanitizeNumber(150, 0, 100);
|
|
354
|
+
* // => 100 (clamped to max)
|
|
355
|
+
*
|
|
356
|
+
* await sanitization.sanitizeNumber('abc');
|
|
357
|
+
* // throws McpError (ValidationError)
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
sanitizeNumber(input: number | string, min?: number, max?: number): Promise<number>;
|
|
361
|
+
/**
|
|
362
|
+
* Produces a log-safe deep clone of `input` with sensitive field values replaced by `'[REDACTED]'`.
|
|
363
|
+
*
|
|
364
|
+
* This method is **synchronous**. It uses `structuredClone` for deep cloning. Sensitive field
|
|
365
|
+
* detection combines two strategies:
|
|
366
|
+
* - **Exact match**: the normalized key (lowercased, non-alphanumeric stripped) matches a
|
|
367
|
+
* sensitive field name.
|
|
368
|
+
* - **Word match**: splitting the key by camelCase/snake_case/kebab-case tokens and checking
|
|
369
|
+
* each token against the sensitive word set.
|
|
370
|
+
*
|
|
371
|
+
* Non-object/non-array inputs (primitives, `null`) are returned as-is without cloning.
|
|
372
|
+
* If `structuredClone` itself throws (e.g., circular reference, uncloneable type), the method
|
|
373
|
+
* returns the string `'[Log Sanitization Failed]'` and emits an error log rather than throwing.
|
|
374
|
+
*
|
|
375
|
+
* @param input - The value to sanitize. Non-objects are returned unchanged.
|
|
376
|
+
* @returns A sanitized deep clone of `input` (with sensitive values redacted),
|
|
377
|
+
* the original primitive if not an object, or `'[Log Sanitization Failed]'` on clone error.
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* sanitization.sanitizeForLogging({ user: 'alice', password: 'secret', nested: { token: 'abc' } });
|
|
381
|
+
* // => { user: 'alice', password: '[REDACTED]', nested: { token: '[REDACTED]' } }
|
|
382
|
+
*
|
|
383
|
+
* sanitization.sanitizeForLogging('just a string');
|
|
384
|
+
* // => 'just a string' (returned as-is)
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
sanitizeForLogging(input: unknown): unknown;
|
|
388
|
+
/**
|
|
389
|
+
* Recursively redacts sensitive fields in an object or array in place.
|
|
390
|
+
* @param obj - The object or array to redact.
|
|
391
|
+
* @private
|
|
392
|
+
*/
|
|
393
|
+
private redactSensitiveFields;
|
|
394
|
+
/**
|
|
395
|
+
* Normalizes a field name for sensitive-key lookup by lowercasing and stripping
|
|
396
|
+
* all non-alphanumeric characters. Used for exact-match detection in `redactSensitiveFields`.
|
|
397
|
+
* @param str - The raw field name string.
|
|
398
|
+
* @returns Lowercased alphanumeric-only version of `str`.
|
|
399
|
+
* @private
|
|
400
|
+
*/
|
|
401
|
+
private static normalizeName;
|
|
402
|
+
private rebuildSensitiveSets;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Pre-constructed singleton instance of `Sanitization`.
|
|
406
|
+
* Use this for all input sanitization tasks rather than calling `Sanitization.getInstance()` directly.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* import { sanitization } from '../../utils/security/sanitization.js';
|
|
411
|
+
* const safe = await sanitization.sanitizeHtml(userHtml);
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
export declare const sanitization: Sanitization;
|
|
415
|
+
/**
|
|
416
|
+
* Convenience wrapper around `sanitization.sanitizeForLogging`.
|
|
417
|
+
* Produces a log-safe deep clone of `input` with sensitive field values replaced by `'[REDACTED]'`.
|
|
418
|
+
*
|
|
419
|
+
* @param input - The value to sanitize. Non-objects are returned unchanged.
|
|
420
|
+
* @returns A sanitized deep clone of `input`, the original primitive if not an object,
|
|
421
|
+
* or `'[Log Sanitization Failed]'` on clone error.
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* import { sanitizeInputForLogging } from '../../utils/security/sanitization.js';
|
|
425
|
+
* logger.info('Request', sanitizeInputForLogging({ user: 'alice', token: 'secret' }));
|
|
426
|
+
* // logs: { user: 'alice', token: '[REDACTED]' }
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
export declare const sanitizeInputForLogging: (input: unknown) => unknown;
|
|
430
|
+
//# sourceMappingURL=sanitization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitization.d.ts","sourceRoot":"","sources":["../../../src/utils/security/sanitization.ts"],"names":[],"mappings":"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"}
|