mcp4openapi 0.2.8 → 0.3.1
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/README.md +143 -63
- package/dist/scripts/validate-profile.js +3 -3
- package/dist/scripts/validate-profile.js.map +1 -1
- package/dist/src/argument-normalizer.d.ts +5 -0
- package/dist/src/argument-normalizer.d.ts.map +1 -0
- package/dist/src/argument-normalizer.js +61 -0
- package/dist/src/argument-normalizer.js.map +1 -0
- package/dist/src/auth/oauth-provider.d.ts +131 -0
- package/dist/src/auth/oauth-provider.d.ts.map +1 -0
- package/dist/src/auth/oauth-provider.js +839 -0
- package/dist/src/auth/oauth-provider.js.map +1 -0
- package/dist/src/cli-config.d.ts +9 -0
- package/dist/src/cli-config.d.ts.map +1 -0
- package/dist/src/cli-config.js +111 -0
- package/dist/src/cli-config.js.map +1 -0
- package/dist/src/core/cli-config.d.ts +9 -0
- package/dist/src/core/cli-config.d.ts.map +1 -0
- package/dist/src/core/cli-config.js +125 -0
- package/dist/src/core/cli-config.js.map +1 -0
- package/dist/src/core/constants.d.ts +86 -0
- package/dist/src/core/constants.d.ts.map +1 -0
- package/dist/src/core/constants.js +86 -0
- package/dist/src/core/constants.js.map +1 -0
- package/dist/src/core/errors.d.ts +59 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +119 -0
- package/dist/src/core/errors.js.map +1 -0
- package/dist/src/core/filtering.d.ts +19 -0
- package/dist/src/core/filtering.d.ts.map +1 -0
- package/dist/src/core/filtering.js +292 -0
- package/dist/src/core/filtering.js.map +1 -0
- package/dist/src/core/index.d.ts +26 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +276 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/lib.d.ts +8 -0
- package/dist/src/core/lib.d.ts.map +1 -0
- package/dist/src/core/lib.js +7 -0
- package/dist/src/core/lib.js.map +1 -0
- package/dist/src/core/logger.d.ts +59 -0
- package/dist/src/core/logger.d.ts.map +1 -0
- package/dist/src/core/logger.js +197 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/metrics.d.ts +97 -0
- package/dist/src/core/metrics.d.ts.map +1 -0
- package/dist/src/core/metrics.js +273 -0
- package/dist/src/core/metrics.js.map +1 -0
- package/dist/src/core/naming-warnings.d.ts +23 -0
- package/dist/src/core/naming-warnings.d.ts.map +1 -0
- package/dist/src/core/naming-warnings.js +83 -0
- package/dist/src/core/naming-warnings.js.map +1 -0
- package/dist/src/core/naming.d.ts +58 -0
- package/dist/src/core/naming.d.ts.map +1 -0
- package/dist/src/core/naming.js +510 -0
- package/dist/src/core/naming.js.map +1 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +15 -6
- package/dist/src/errors.js.map +1 -1
- package/dist/src/filtering.d.ts +19 -0
- package/dist/src/filtering.d.ts.map +1 -0
- package/dist/src/filtering.js +292 -0
- package/dist/src/filtering.js.map +1 -0
- package/dist/src/generated-schemas.d.ts +290 -79
- package/dist/src/generated-schemas.d.ts.map +1 -1
- package/dist/src/generated-schemas.js +17 -2
- package/dist/src/generated-schemas.js.map +1 -1
- package/dist/src/http-transport-config.d.ts +6 -0
- package/dist/src/http-transport-config.d.ts.map +1 -0
- package/dist/src/http-transport-config.js +47 -0
- package/dist/src/http-transport-config.js.map +1 -0
- package/dist/src/http-transport.d.ts +63 -13
- package/dist/src/http-transport.d.ts.map +1 -1
- package/dist/src/http-transport.js +1045 -482
- package/dist/src/http-transport.js.map +1 -1
- package/dist/src/index.d.ts +1 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -170
- package/dist/src/index.js.map +1 -1
- package/dist/src/interceptors.d.ts +1 -0
- package/dist/src/interceptors.d.ts.map +1 -1
- package/dist/src/interceptors.js +73 -63
- package/dist/src/interceptors.js.map +1 -1
- package/dist/src/lib.d.ts +1 -7
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +1 -6
- package/dist/src/lib.js.map +1 -1
- package/dist/src/logger.d.ts +5 -0
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/logger.js +9 -1
- package/dist/src/logger.js.map +1 -1
- package/dist/src/mcp/mcp-server-manager.d.ts +20 -0
- package/dist/src/mcp/mcp-server-manager.d.ts.map +1 -0
- package/dist/src/mcp/mcp-server-manager.js +38 -0
- package/dist/src/mcp/mcp-server-manager.js.map +1 -0
- package/dist/src/mcp/mcp-server.d.ts +205 -0
- package/dist/src/mcp/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp/mcp-server.js +1473 -0
- package/dist/src/mcp/mcp-server.js.map +1 -0
- package/dist/src/mcp-server-manager.d.ts +20 -0
- package/dist/src/mcp-server-manager.d.ts.map +1 -0
- package/dist/src/mcp-server-manager.js +38 -0
- package/dist/src/mcp-server-manager.js.map +1 -0
- package/dist/src/mcp-server.d.ts +28 -0
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +406 -109
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/metrics.d.ts +11 -0
- package/dist/src/metrics.d.ts.map +1 -1
- package/dist/src/metrics.js +61 -0
- package/dist/src/metrics.js.map +1 -1
- package/dist/src/oauth-provider.d.ts +5 -0
- package/dist/src/oauth-provider.d.ts.map +1 -1
- package/dist/src/oauth-provider.js +29 -1
- package/dist/src/oauth-provider.js.map +1 -1
- package/dist/src/openapi/openapi-parser.d.ts +70 -0
- package/dist/src/openapi/openapi-parser.d.ts.map +1 -0
- package/dist/src/openapi/openapi-parser.js +458 -0
- package/dist/src/openapi/openapi-parser.js.map +1 -0
- package/dist/src/profile/profile-loader.d.ts +78 -0
- package/dist/src/profile/profile-loader.d.ts.map +1 -0
- package/dist/src/profile/profile-loader.js +490 -0
- package/dist/src/profile/profile-loader.js.map +1 -0
- package/dist/src/profile/profile-registry.d.ts +19 -0
- package/dist/src/profile/profile-registry.d.ts.map +1 -0
- package/dist/src/profile/profile-registry.js +43 -0
- package/dist/src/profile/profile-registry.js.map +1 -0
- package/dist/src/profile/profile-resolver.d.ts +41 -0
- package/dist/src/profile/profile-resolver.d.ts.map +1 -0
- package/dist/src/profile/profile-resolver.js +324 -0
- package/dist/src/profile/profile-resolver.js.map +1 -0
- package/dist/src/profile/startup-profile.d.ts +17 -0
- package/dist/src/profile/startup-profile.d.ts.map +1 -0
- package/dist/src/profile/startup-profile.js +30 -0
- package/dist/src/profile/startup-profile.js.map +1 -0
- package/dist/src/profile/startup-validation.d.ts +11 -0
- package/dist/src/profile/startup-validation.d.ts.map +1 -0
- package/dist/src/profile/startup-validation.js +21 -0
- package/dist/src/profile/startup-validation.js.map +1 -0
- package/dist/src/profile-loader.d.ts +1 -0
- package/dist/src/profile-loader.d.ts.map +1 -1
- package/dist/src/profile-loader.js +14 -3
- package/dist/src/profile-loader.js.map +1 -1
- package/dist/src/profile-registry.d.ts +18 -0
- package/dist/src/profile-registry.d.ts.map +1 -0
- package/dist/src/profile-registry.js +26 -0
- package/dist/src/profile-registry.js.map +1 -0
- package/dist/src/profile-resolver.d.ts +19 -0
- package/dist/src/profile-resolver.d.ts.map +1 -0
- package/dist/src/profile-resolver.js +167 -0
- package/dist/src/profile-resolver.js.map +1 -0
- package/dist/src/proxy-executor.d.ts.map +1 -1
- package/dist/src/proxy-executor.js +7 -0
- package/dist/src/proxy-executor.js.map +1 -1
- package/dist/src/startup-profile.d.ts +17 -0
- package/dist/src/startup-profile.d.ts.map +1 -0
- package/dist/src/startup-profile.js +30 -0
- package/dist/src/startup-profile.js.map +1 -0
- package/dist/src/startup-validation.d.ts +11 -0
- package/dist/src/startup-validation.d.ts.map +1 -0
- package/dist/src/startup-validation.js +21 -0
- package/dist/src/startup-validation.js.map +1 -0
- package/dist/src/testing/dynamic-mock-server.d.ts +24 -0
- package/dist/src/testing/dynamic-mock-server.d.ts.map +1 -0
- package/dist/src/testing/dynamic-mock-server.js +138 -0
- package/dist/src/testing/dynamic-mock-server.js.map +1 -0
- package/dist/src/testing/request-assertions.d.ts +5 -0
- package/dist/src/testing/request-assertions.d.ts.map +1 -0
- package/dist/src/testing/request-assertions.js +165 -0
- package/dist/src/testing/request-assertions.js.map +1 -0
- package/dist/src/testing/template-utils.d.ts +10 -0
- package/dist/src/testing/template-utils.d.ts.map +1 -0
- package/dist/src/testing/template-utils.js +72 -0
- package/dist/src/testing/template-utils.js.map +1 -0
- package/dist/src/testing/test-http-utils.d.ts +1 -1
- package/dist/src/testing/test-http-utils.d.ts.map +1 -1
- package/dist/src/testing/test-http-utils.js +1 -1
- package/dist/src/testing/test-http-utils.js.map +1 -1
- package/dist/src/testing/test-loader.d.ts +6 -0
- package/dist/src/testing/test-loader.d.ts.map +1 -0
- package/dist/src/testing/test-loader.js +212 -0
- package/dist/src/testing/test-loader.js.map +1 -0
- package/dist/src/testing/test-schema.d.ts +1270 -0
- package/dist/src/testing/test-schema.d.ts.map +1 -0
- package/dist/src/testing/test-schema.js +76 -0
- package/dist/src/testing/test-schema.js.map +1 -0
- package/dist/src/tool-filter/compat.d.ts +49 -0
- package/dist/src/tool-filter/compat.d.ts.map +1 -0
- package/dist/src/tool-filter/compat.js +72 -0
- package/dist/src/tool-filter/compat.js.map +1 -0
- package/dist/src/tool-filter/config/env-config-parser.d.ts +38 -0
- package/dist/src/tool-filter/config/env-config-parser.d.ts.map +1 -0
- package/dist/src/tool-filter/config/env-config-parser.js +103 -0
- package/dist/src/tool-filter/config/env-config-parser.js.map +1 -0
- package/dist/src/tool-filter/config/header-config-parser.d.ts +37 -0
- package/dist/src/tool-filter/config/header-config-parser.d.ts.map +1 -0
- package/dist/src/tool-filter/config/header-config-parser.js +118 -0
- package/dist/src/tool-filter/config/header-config-parser.js.map +1 -0
- package/dist/src/tool-filter/errors.d.ts +18 -0
- package/dist/src/tool-filter/errors.d.ts.map +1 -0
- package/dist/src/tool-filter/errors.js +21 -0
- package/dist/src/tool-filter/errors.js.map +1 -0
- package/dist/src/tool-filter/filter/filter-engine.d.ts +45 -0
- package/dist/src/tool-filter/filter/filter-engine.d.ts.map +1 -0
- package/dist/src/tool-filter/filter/filter-engine.js +94 -0
- package/dist/src/tool-filter/filter/filter-engine.js.map +1 -0
- package/dist/src/tool-filter/filter/filter-rules.d.ts +44 -0
- package/dist/src/tool-filter/filter/filter-rules.d.ts.map +1 -0
- package/dist/src/tool-filter/filter/filter-rules.js +72 -0
- package/dist/src/tool-filter/filter/filter-rules.js.map +1 -0
- package/dist/src/tool-filter/filter/global-tool-filter.d.ts +40 -0
- package/dist/src/tool-filter/filter/global-tool-filter.d.ts.map +1 -0
- package/dist/src/tool-filter/filter/global-tool-filter.js +92 -0
- package/dist/src/tool-filter/filter/global-tool-filter.js.map +1 -0
- package/dist/src/tool-filter/filter/session-tool-filter.d.ts +29 -0
- package/dist/src/tool-filter/filter/session-tool-filter.d.ts.map +1 -0
- package/dist/src/tool-filter/filter/session-tool-filter.js +69 -0
- package/dist/src/tool-filter/filter/session-tool-filter.js.map +1 -0
- package/dist/src/tool-filter/index.d.ts +25 -0
- package/dist/src/tool-filter/index.d.ts.map +1 -0
- package/dist/src/tool-filter/index.js +30 -0
- package/dist/src/tool-filter/index.js.map +1 -0
- package/dist/src/tool-filter/integration/tool-filter-service.d.ts +44 -0
- package/dist/src/tool-filter/integration/tool-filter-service.d.ts.map +1 -0
- package/dist/src/tool-filter/integration/tool-filter-service.js +68 -0
- package/dist/src/tool-filter/integration/tool-filter-service.js.map +1 -0
- package/dist/src/tool-filter/operation/operation-classifier.d.ts +20 -0
- package/dist/src/tool-filter/operation/operation-classifier.d.ts.map +1 -0
- package/dist/src/tool-filter/operation/operation-classifier.js +26 -0
- package/dist/src/tool-filter/operation/operation-classifier.js.map +1 -0
- package/dist/src/tool-filter/operation/operation-detector.d.ts +30 -0
- package/dist/src/tool-filter/operation/operation-detector.d.ts.map +1 -0
- package/dist/src/tool-filter/operation/operation-detector.js +96 -0
- package/dist/src/tool-filter/operation/operation-detector.js.map +1 -0
- package/dist/src/tool-filter/operation/operation-resolver.d.ts +22 -0
- package/dist/src/tool-filter/operation/operation-resolver.d.ts.map +1 -0
- package/dist/src/tool-filter/operation/operation-resolver.js +32 -0
- package/dist/src/tool-filter/operation/operation-resolver.js.map +1 -0
- package/dist/src/tool-filter/regex/regex-compiler.d.ts +22 -0
- package/dist/src/tool-filter/regex/regex-compiler.d.ts.map +1 -0
- package/dist/src/tool-filter/regex/regex-compiler.js +56 -0
- package/dist/src/tool-filter/regex/regex-compiler.js.map +1 -0
- package/dist/src/tool-filter/regex/regex-validator.d.ts +24 -0
- package/dist/src/tool-filter/regex/regex-validator.d.ts.map +1 -0
- package/dist/src/tool-filter/regex/regex-validator.js +58 -0
- package/dist/src/tool-filter/regex/regex-validator.js.map +1 -0
- package/dist/src/tool-filter/types.d.ts +92 -0
- package/dist/src/tool-filter/types.d.ts.map +1 -0
- package/dist/src/tool-filter/types.js +5 -0
- package/dist/src/tool-filter/types.js.map +1 -0
- package/dist/src/tool-filter/utils.d.ts +11 -0
- package/dist/src/tool-filter/utils.d.ts.map +1 -0
- package/dist/src/tool-filter/utils.js +13 -0
- package/dist/src/tool-filter/utils.js.map +1 -0
- package/dist/src/tool-filter.d.ts +65 -0
- package/dist/src/tool-filter.d.ts.map +1 -0
- package/dist/src/tool-filter.js +471 -0
- package/dist/src/tool-filter.js.map +1 -0
- package/dist/src/tool-generator.d.ts +1 -0
- package/dist/src/tool-generator.d.ts.map +1 -1
- package/dist/src/tool-generator.js +15 -6
- package/dist/src/tool-generator.js.map +1 -1
- package/dist/src/tooling/composite-executor.d.ts +77 -0
- package/dist/src/tooling/composite-executor.d.ts.map +1 -0
- package/dist/src/tooling/composite-executor.js +198 -0
- package/dist/src/tooling/composite-executor.js.map +1 -0
- package/dist/src/tooling/dag-executor.d.ts +49 -0
- package/dist/src/tooling/dag-executor.d.ts.map +1 -0
- package/dist/src/tooling/dag-executor.js +138 -0
- package/dist/src/tooling/dag-executor.js.map +1 -0
- package/dist/src/tooling/proxy-executor.d.ts +86 -0
- package/dist/src/tooling/proxy-executor.d.ts.map +1 -0
- package/dist/src/tooling/proxy-executor.js +501 -0
- package/dist/src/tooling/proxy-executor.js.map +1 -0
- package/dist/src/tooling/tool-generator.d.ts +67 -0
- package/dist/src/tooling/tool-generator.d.ts.map +1 -0
- package/dist/src/tooling/tool-generator.js +222 -0
- package/dist/src/tooling/tool-generator.js.map +1 -0
- package/dist/src/transport/http-client-factory.d.ts +65 -0
- package/dist/src/transport/http-client-factory.d.ts.map +1 -0
- package/dist/src/transport/http-client-factory.js +143 -0
- package/dist/src/transport/http-client-factory.js.map +1 -0
- package/dist/src/transport/http-transport-config.d.ts +6 -0
- package/dist/src/transport/http-transport-config.d.ts.map +1 -0
- package/dist/src/transport/http-transport-config.js +63 -0
- package/dist/src/transport/http-transport-config.js.map +1 -0
- package/dist/src/transport/http-transport.d.ts +329 -0
- package/dist/src/transport/http-transport.d.ts.map +1 -0
- package/dist/src/transport/http-transport.js +2584 -0
- package/dist/src/transport/http-transport.js.map +1 -0
- package/dist/src/transport/interceptors.d.ts +119 -0
- package/dist/src/transport/interceptors.d.ts.map +1 -0
- package/dist/src/transport/interceptors.js +413 -0
- package/dist/src/transport/interceptors.js.map +1 -0
- package/dist/src/transport/profile-index.d.ts +84 -0
- package/dist/src/transport/profile-index.d.ts.map +1 -0
- package/dist/src/transport/profile-index.js +405 -0
- package/dist/src/transport/profile-index.js.map +1 -0
- package/dist/src/types/http-transport.d.ts +26 -0
- package/dist/src/types/http-transport.d.ts.map +1 -1
- package/dist/src/types/openapi.d.ts +3 -0
- package/dist/src/types/openapi.d.ts.map +1 -1
- package/dist/src/types/profile.d.ts +16 -1
- package/dist/src/types/profile.d.ts.map +1 -1
- package/dist/src/validation/argument-normalizer.d.ts +6 -0
- package/dist/src/validation/argument-normalizer.d.ts.map +1 -0
- package/dist/src/validation/argument-normalizer.js +70 -0
- package/dist/src/validation/argument-normalizer.js.map +1 -0
- package/dist/src/validation/jsonrpc-validator.d.ts +27 -0
- package/dist/src/validation/jsonrpc-validator.d.ts.map +1 -0
- package/dist/src/validation/jsonrpc-validator.js +58 -0
- package/dist/src/validation/jsonrpc-validator.js.map +1 -0
- package/dist/src/validation/schema-validator.d.ts +30 -0
- package/dist/src/validation/schema-validator.d.ts.map +1 -0
- package/dist/src/validation/schema-validator.js +128 -0
- package/dist/src/validation/schema-validator.js.map +1 -0
- package/dist/src/validation/validation-utils.d.ts +49 -0
- package/dist/src/validation/validation-utils.d.ts.map +1 -0
- package/dist/src/validation/validation-utils.js +139 -0
- package/dist/src/validation/validation-utils.js.map +1 -0
- package/html/profile-index.html +386 -0
- package/package.json +10 -3
- package/profile-schema.json +77 -3
- package/profiles/gitlab/developer-profile-oauth.json +1520 -0
- package/profiles/gitlab/developer-profile-oauth.test.json +3432 -0
- package/profiles/gitlab/developer-profile.json +1508 -0
- package/profiles/gitlab/developer-profile.test.json +3432 -0
- package/profiles/gitlab/openapi.yaml +6891 -0
- package/profiles/n8n/openapi.yaml +2441 -0
- package/profiles/n8n/profile-optimized.json +965 -0
- package/profiles/n8n/profile-optimized.test.json +1078 -0
- package/profiles/n8n/profile.json +1033 -0
- package/profiles/n8n/profile.test.json +983 -0
- package/profiles/n8n-nodes/openapi.yaml +24 -0
- package/profiles/n8n-nodes/profile-nodes.json +44 -0
- package/profiles/n8n-nodes/profile-nodes.test.json +91 -0
- package/profiles/semgrep/openapi.yaml +4706 -0
- package/profiles/semgrep/profile.json +692 -0
- package/profiles/semgrep/profile.test.json +471 -0
- package/profiles/youtrack/openapi.json +16976 -0
- package/profiles/youtrack/profile.json +608 -0
- package/profiles/youtrack/profile.test.json +1926 -0
- package/dist/src/testing/fixtures.d.ts +0 -684
- package/dist/src/testing/fixtures.d.ts.map +0 -1
- package/dist/src/testing/fixtures.js +0 -528
- package/dist/src/testing/fixtures.js.map +0 -1
- package/dist/src/testing/mock-gitlab-server.d.ts +0 -43
- package/dist/src/testing/mock-gitlab-server.d.ts.map +0 -1
- package/dist/src/testing/mock-gitlab-server.js +0 -1026
- package/dist/src/testing/mock-gitlab-server.js.map +0 -1
- package/dist/src/testing/mock-semgrep-server.d.ts +0 -32
- package/dist/src/testing/mock-semgrep-server.d.ts.map +0 -1
- package/dist/src/testing/mock-semgrep-server.js +0 -213
- package/dist/src/testing/mock-semgrep-server.js.map +0 -1
- package/dist/src/testing/mock-youtrack-server.d.ts +0 -11
- package/dist/src/testing/mock-youtrack-server.d.ts.map +0 -1
- package/dist/src/testing/mock-youtrack-server.js +0 -152
- package/dist/src/testing/mock-youtrack-server.js.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter engine - orchestrates filter rules
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Filter result
|
|
6
|
+
*/
|
|
7
|
+
export class FilterResult {
|
|
8
|
+
constructor(allowed, reason) {
|
|
9
|
+
this.allowed = allowed;
|
|
10
|
+
this.reason = reason;
|
|
11
|
+
}
|
|
12
|
+
static allowed(reason) {
|
|
13
|
+
return new FilterResult(true, reason);
|
|
14
|
+
}
|
|
15
|
+
static denied(reason) {
|
|
16
|
+
return new FilterResult(false, reason);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Filter engine that evaluates tools against rules
|
|
21
|
+
*/
|
|
22
|
+
export class FilterEngine {
|
|
23
|
+
constructor(allowRules, denyRules) {
|
|
24
|
+
this.allowRules = allowRules;
|
|
25
|
+
this.denyRules = denyRules;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Evaluate tool name against rules
|
|
29
|
+
*
|
|
30
|
+
* Rule precedence:
|
|
31
|
+
* 1. Deny rules (if any match, deny immediately)
|
|
32
|
+
* 2. If no allow rules, allow by default
|
|
33
|
+
* 3. Allow rules (must match at least one)
|
|
34
|
+
*/
|
|
35
|
+
evaluate(toolName) {
|
|
36
|
+
// Normalize tool name (Unicode NFC)
|
|
37
|
+
const normalized = toolName.normalize('NFC');
|
|
38
|
+
// Check deny rules first (precedence)
|
|
39
|
+
for (const rule of this.denyRules) {
|
|
40
|
+
if (rule.matches(normalized)) {
|
|
41
|
+
return FilterResult.denied(rule.getReason());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// If no allow rules, allow by default
|
|
45
|
+
if (this.allowRules.length === 0) {
|
|
46
|
+
return FilterResult.allowed();
|
|
47
|
+
}
|
|
48
|
+
// Check allow rules
|
|
49
|
+
for (const rule of this.allowRules) {
|
|
50
|
+
if (rule.matches(normalized)) {
|
|
51
|
+
return FilterResult.allowed(rule.getReason());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// No allow rule matched
|
|
55
|
+
return FilterResult.denied('no_allow_match');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Evaluate tool definition against rules
|
|
59
|
+
*
|
|
60
|
+
* Used when rules need full tool definition (e.g., CategoryMatchRule).
|
|
61
|
+
* Tool name is normalized (NFC) before passing to name-based rules.
|
|
62
|
+
*
|
|
63
|
+
* Rule precedence:
|
|
64
|
+
* 1. Deny rules (if any match, deny immediately)
|
|
65
|
+
* 2. If no allow rules, allow by default
|
|
66
|
+
* 3. Allow rules (must match at least one)
|
|
67
|
+
*/
|
|
68
|
+
evaluateTool(tool) {
|
|
69
|
+
// Normalize tool name for consistency (NFC)
|
|
70
|
+
const normalizedTool = {
|
|
71
|
+
...tool,
|
|
72
|
+
name: tool.name.normalize('NFC')
|
|
73
|
+
};
|
|
74
|
+
// Check deny rules first (precedence)
|
|
75
|
+
for (const rule of this.denyRules) {
|
|
76
|
+
if (rule.matches(normalizedTool)) {
|
|
77
|
+
return FilterResult.denied(rule.getReason());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// If no allow rules, allow by default
|
|
81
|
+
if (this.allowRules.length === 0) {
|
|
82
|
+
return FilterResult.allowed();
|
|
83
|
+
}
|
|
84
|
+
// Check allow rules
|
|
85
|
+
for (const rule of this.allowRules) {
|
|
86
|
+
if (rule.matches(normalizedTool)) {
|
|
87
|
+
return FilterResult.allowed(rule.getReason());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// No allow rule matched
|
|
91
|
+
return FilterResult.denied('no_allow_match');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=filter-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-engine.js","sourceRoot":"","sources":["../../../../src/tool-filter/filter/filter-engine.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,YACkB,OAAgB,EAChB,MAAe;QADf,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAS;IAC9B,CAAC;IAEJ,MAAM,CAAC,OAAO,CAAC,MAAe;QAC5B,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,MAAc;QAC1B,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,YACU,UAAwB,EACxB,SAAuB;QADvB,eAAU,GAAV,UAAU,CAAc;QACxB,cAAS,GAAT,SAAS,CAAc;IAC9B,CAAC;IAEJ;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAgB;QACvB,oCAAoC;QACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE7C,sCAAsC;QACtC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7B,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,sCAAsC;QACtC,IAAI,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AAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter rules - Strategy pattern for tool filtering
|
|
3
|
+
*/
|
|
4
|
+
import type { CompiledRegex } from '../types.js';
|
|
5
|
+
import type { ToolDefinition } from '../../types/profile.js';
|
|
6
|
+
import type { OperationDetector } from '../operation/operation-detector.js';
|
|
7
|
+
/**
|
|
8
|
+
* Filter rule interface
|
|
9
|
+
*/
|
|
10
|
+
export interface FilterRule {
|
|
11
|
+
matches(toolNameOrTool: string | ToolDefinition): boolean;
|
|
12
|
+
getReason(): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Exact name match rule
|
|
16
|
+
*/
|
|
17
|
+
export declare class ExactMatchRule implements FilterRule {
|
|
18
|
+
private names;
|
|
19
|
+
private type;
|
|
20
|
+
constructor(names: Set<string>, type: 'allow' | 'deny');
|
|
21
|
+
matches(toolNameOrTool: string | ToolDefinition): boolean;
|
|
22
|
+
getReason(): string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Regex pattern match rule
|
|
26
|
+
*/
|
|
27
|
+
export declare class RegexMatchRule implements FilterRule {
|
|
28
|
+
private patterns;
|
|
29
|
+
private type;
|
|
30
|
+
constructor(patterns: CompiledRegex[], type: 'allow' | 'deny');
|
|
31
|
+
matches(toolNameOrTool: string | ToolDefinition): boolean;
|
|
32
|
+
getReason(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Category match rule - matches based on operation categories
|
|
36
|
+
*/
|
|
37
|
+
export declare class CategoryMatchRule implements FilterRule {
|
|
38
|
+
private allowedCategories;
|
|
39
|
+
private detector;
|
|
40
|
+
constructor(allowedCategories: Set<'list' | 'read'>, detector: OperationDetector);
|
|
41
|
+
matches(toolNameOrTool: string | ToolDefinition): boolean;
|
|
42
|
+
getReason(): string;
|
|
43
|
+
}
|
|
44
|
+
//# source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8BzD,SAAS,IAAI,MAAM;CAIpB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter rules - Strategy pattern for tool filtering
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Exact name match rule
|
|
6
|
+
*/
|
|
7
|
+
export class ExactMatchRule {
|
|
8
|
+
constructor(names, type) {
|
|
9
|
+
this.names = names;
|
|
10
|
+
this.type = type;
|
|
11
|
+
}
|
|
12
|
+
matches(toolNameOrTool) {
|
|
13
|
+
const toolName = typeof toolNameOrTool === 'string' ? toolNameOrTool : toolNameOrTool.name;
|
|
14
|
+
return this.names.has(toolName);
|
|
15
|
+
}
|
|
16
|
+
getReason() {
|
|
17
|
+
return `${this.type}_list`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Regex pattern match rule
|
|
22
|
+
*/
|
|
23
|
+
export class RegexMatchRule {
|
|
24
|
+
constructor(patterns, type) {
|
|
25
|
+
this.patterns = patterns;
|
|
26
|
+
this.type = type;
|
|
27
|
+
}
|
|
28
|
+
matches(toolNameOrTool) {
|
|
29
|
+
const toolName = typeof toolNameOrTool === 'string' ? toolNameOrTool : toolNameOrTool.name;
|
|
30
|
+
return this.patterns.some(pattern => pattern.test(toolName));
|
|
31
|
+
}
|
|
32
|
+
getReason() {
|
|
33
|
+
return `${this.type}_regex`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Category match rule - matches based on operation categories
|
|
38
|
+
*/
|
|
39
|
+
export class CategoryMatchRule {
|
|
40
|
+
constructor(allowedCategories, detector) {
|
|
41
|
+
this.allowedCategories = allowedCategories;
|
|
42
|
+
this.detector = detector;
|
|
43
|
+
}
|
|
44
|
+
matches(toolNameOrTool) {
|
|
45
|
+
// This rule only works with ToolDefinition objects
|
|
46
|
+
if (typeof toolNameOrTool === 'string') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const tool = toolNameOrTool;
|
|
50
|
+
const categories = this.detector.detectCategories(tool);
|
|
51
|
+
// Check if tool matches allowed categories
|
|
52
|
+
const hasListAndRead = this.allowedCategories.has('list') && this.allowedCategories.has('read');
|
|
53
|
+
if (hasListAndRead) {
|
|
54
|
+
// If both list and read are allowed, accept tools that are list-only, read-only, or both
|
|
55
|
+
// But NOT tools that have modify operations
|
|
56
|
+
return categories.isList || categories.isRead;
|
|
57
|
+
}
|
|
58
|
+
// Single category - must match exactly (no mixing)
|
|
59
|
+
if (this.allowedCategories.has('list')) {
|
|
60
|
+
return categories.isList && !categories.isRead;
|
|
61
|
+
}
|
|
62
|
+
if (this.allowedCategories.has('read')) {
|
|
63
|
+
return categories.isRead && !categories.isList;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
getReason() {
|
|
68
|
+
const cats = Array.from(this.allowedCategories).sort();
|
|
69
|
+
return `allow_categories:${cats.join(',')}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=filter-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-rules.js","sourceRoot":"","sources":["../../../../src/tool-filter/filter/filter-rules.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB,YACU,KAAkB,EAClB,IAAsB;QADtB,UAAK,GAAL,KAAK,CAAa;QAClB,SAAI,GAAJ,IAAI,CAAkB;IAC7B,CAAC;IAEJ,OAAO,CAAC,cAAuC;QAC7C,MAAM,QAAQ,GAAG,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC;QAC3F,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,SAAS;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,OAAO,CAAC;IAC7B,CAAC;CACF;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iB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,OAAO,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QACjD,CAAC;QAED,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,OAAO,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QACjD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,SAAS;QACP,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,oBAAoB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global tool filter - applies environment-based filtering
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from '../../types/profile.js';
|
|
5
|
+
import type { ToolFilterConfig } from '../types.js';
|
|
6
|
+
import type { Logger } from '../../core/logger.js';
|
|
7
|
+
import type { OperationDetector } from '../operation/operation-detector.js';
|
|
8
|
+
export interface GlobalToolFilterResult {
|
|
9
|
+
allowed: ToolDefinition[];
|
|
10
|
+
removed: ToolDefinition[];
|
|
11
|
+
reasons: Map<string, string[]>;
|
|
12
|
+
summary: {
|
|
13
|
+
originalCount: number;
|
|
14
|
+
allowedCount: number;
|
|
15
|
+
removedCount: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Applies global tool filtering based on environment configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare class GlobalToolFilter {
|
|
22
|
+
private config;
|
|
23
|
+
private logger;
|
|
24
|
+
private detector?;
|
|
25
|
+
private engine;
|
|
26
|
+
constructor(config: ToolFilterConfig, logger: Logger, detector?: OperationDetector | undefined);
|
|
27
|
+
/**
|
|
28
|
+
* Apply filter to tools
|
|
29
|
+
*/
|
|
30
|
+
apply(tools: ToolDefinition[]): GlobalToolFilterResult;
|
|
31
|
+
/**
|
|
32
|
+
* Build filter engine from config
|
|
33
|
+
*/
|
|
34
|
+
private buildEngine;
|
|
35
|
+
/**
|
|
36
|
+
* Log filtered tool
|
|
37
|
+
*/
|
|
38
|
+
private logFiltered;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=global-tool-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-tool-filter.d.ts","sourceRoot":"","sources":["../../../../src/tool-filter/filter/global-tool-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAI5E,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/B,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC;IALnB,OAAO,CAAC,MAAM,CAAe;gBAGnB,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,iBAAiB,YAAA;IAKtC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,sBAAsB;IA+BtD;;OAEG;IACH,OAAO,CAAC,WAAW;IAsCnB;;OAEG;IACH,OAAO,CAAC,WAAW;CAQpB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global tool filter - applies environment-based filtering
|
|
3
|
+
*/
|
|
4
|
+
import { FilterEngine } from './filter-engine.js';
|
|
5
|
+
import { ExactMatchRule, RegexMatchRule, CategoryMatchRule } from './filter-rules.js';
|
|
6
|
+
/**
|
|
7
|
+
* Applies global tool filtering based on environment configuration
|
|
8
|
+
*/
|
|
9
|
+
export class GlobalToolFilter {
|
|
10
|
+
constructor(config, logger, detector) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.detector = detector;
|
|
14
|
+
this.engine = this.buildEngine(config);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Apply filter to tools
|
|
18
|
+
*/
|
|
19
|
+
apply(tools) {
|
|
20
|
+
const allowed = [];
|
|
21
|
+
const removed = [];
|
|
22
|
+
const reasons = new Map();
|
|
23
|
+
for (const tool of tools) {
|
|
24
|
+
const result = this.engine.evaluateTool(tool);
|
|
25
|
+
if (result.allowed) {
|
|
26
|
+
allowed.push(tool);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
removed.push(tool);
|
|
30
|
+
if (result.reason) {
|
|
31
|
+
reasons.set(tool.name, [result.reason]);
|
|
32
|
+
}
|
|
33
|
+
this.logFiltered(tool, result.reason);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
allowed,
|
|
38
|
+
removed,
|
|
39
|
+
reasons,
|
|
40
|
+
summary: {
|
|
41
|
+
originalCount: tools.length,
|
|
42
|
+
allowedCount: allowed.length,
|
|
43
|
+
removedCount: removed.length
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build filter engine from config
|
|
49
|
+
*/
|
|
50
|
+
buildEngine(config) {
|
|
51
|
+
const allowRules = [];
|
|
52
|
+
const denyRules = [];
|
|
53
|
+
// Build allow rules
|
|
54
|
+
if (config.allowList.size > 0) {
|
|
55
|
+
allowRules.push(new ExactMatchRule(config.allowList, 'allow'));
|
|
56
|
+
}
|
|
57
|
+
if (config.allowRegex.length > 0) {
|
|
58
|
+
allowRules.push(new RegexMatchRule(config.allowRegex, 'allow'));
|
|
59
|
+
}
|
|
60
|
+
// Add CategoryMatchRule if categories configured and detector available
|
|
61
|
+
if (config.allowCategories.size > 0) {
|
|
62
|
+
if (this.detector) {
|
|
63
|
+
allowRules.push(new CategoryMatchRule(config.allowCategories, this.detector));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Fail-safe: if allowCategories is set but detector is not available, throw error
|
|
67
|
+
throw new Error('MCP4_TOOL_FILTER_ALLOW_CATEGORIES is set but OperationDetector is not available. ' +
|
|
68
|
+
'This is a configuration error - category filtering requires OpenAPI parser.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Build deny rules
|
|
72
|
+
if (config.denyList.size > 0) {
|
|
73
|
+
denyRules.push(new ExactMatchRule(config.denyList, 'deny'));
|
|
74
|
+
}
|
|
75
|
+
if (config.denyRegex.length > 0) {
|
|
76
|
+
denyRules.push(new RegexMatchRule(config.denyRegex, 'deny'));
|
|
77
|
+
}
|
|
78
|
+
return new FilterEngine(allowRules, denyRules);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Log filtered tool
|
|
82
|
+
*/
|
|
83
|
+
logFiltered(tool, reason) {
|
|
84
|
+
this.logger.info('Tool filtered', {
|
|
85
|
+
filter_source: 'env',
|
|
86
|
+
tool: tool.name,
|
|
87
|
+
action: 'removed',
|
|
88
|
+
reason: reason || 'unknown'
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=global-tool-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-tool-filter.js","sourceRoot":"","sources":["../../../../src/tool-filter/filter/global-tool-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAatF;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAG3B,YACU,MAAwB,EACxB,MAAc,EACd,QAA4B;QAF5B,WAAM,GAAN,MAAM,CAAkB;QACxB,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAoB;QAEpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAuB;QAC3B,MAAM,OAAO,GAAqB,EAAE,CAAC;QACrC,MAAM,OAAO,GAAqB,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;QAE5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAE9C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnB,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;oBAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1C,CAAC;gBACD,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO;YACP,OAAO;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AAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,SAAS,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,IAAI,YAAY,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,IAAoB,EAAE,MAAe;QACvD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE;YAChC,aAAa,EAAE,KAAK;YACpB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,MAAM,IAAI,SAAS;SAC5B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session tool filter - applies per-session filtering
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from '../../types/profile.js';
|
|
5
|
+
import type { SessionToolFilterRequest } from '../types.js';
|
|
6
|
+
import type { OperationDetector } from '../operation/operation-detector.js';
|
|
7
|
+
export interface SessionToolFilterResult {
|
|
8
|
+
allowedToolNames: Set<string>;
|
|
9
|
+
reasons: Map<string, string[]>;
|
|
10
|
+
normalizedHeader: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Applies session-based tool filtering from X-Mcp4-Tools header
|
|
14
|
+
*/
|
|
15
|
+
export declare class SessionToolFilter {
|
|
16
|
+
private request;
|
|
17
|
+
private detector?;
|
|
18
|
+
private engine;
|
|
19
|
+
constructor(request: SessionToolFilterRequest, detector?: OperationDetector | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Apply filter to tools
|
|
22
|
+
*/
|
|
23
|
+
apply(tools: ToolDefinition[]): SessionToolFilterResult;
|
|
24
|
+
/**
|
|
25
|
+
* Build filter engine from request
|
|
26
|
+
*/
|
|
27
|
+
private buildEngine;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=session-tool-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-tool-filter.d.ts","sourceRoot":"","sources":["../../../../src/tool-filter/filter/session-tool-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAI5E,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ,CAAC;IAJnB,OAAO,CAAC,MAAM,CAAe;gBAGnB,OAAO,EAAE,wBAAwB,EACjC,QAAQ,CAAC,EAAE,iBAAiB,YAAA;IAKtC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,uBAAuB;IAkCvD;;OAEG;IACH,OAAO,CAAC,WAAW;CAuBpB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session tool filter - applies per-session filtering
|
|
3
|
+
*/
|
|
4
|
+
import { FilterEngine } from './filter-engine.js';
|
|
5
|
+
import { ExactMatchRule, RegexMatchRule, CategoryMatchRule } from './filter-rules.js';
|
|
6
|
+
/**
|
|
7
|
+
* Applies session-based tool filtering from X-Mcp4-Tools header
|
|
8
|
+
*/
|
|
9
|
+
export class SessionToolFilter {
|
|
10
|
+
constructor(request, detector) {
|
|
11
|
+
this.request = request;
|
|
12
|
+
this.detector = detector;
|
|
13
|
+
this.engine = this.buildEngine(request);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Apply filter to tools
|
|
17
|
+
*/
|
|
18
|
+
apply(tools) {
|
|
19
|
+
const allowedToolNames = new Set();
|
|
20
|
+
const reasons = new Map();
|
|
21
|
+
// If no rules, allow all
|
|
22
|
+
if (!this.request.hasRules) {
|
|
23
|
+
for (const tool of tools) {
|
|
24
|
+
allowedToolNames.add(tool.name);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
allowedToolNames,
|
|
28
|
+
reasons,
|
|
29
|
+
normalizedHeader: this.request.normalizedHeader
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Apply rules
|
|
33
|
+
for (const tool of tools) {
|
|
34
|
+
const result = this.engine.evaluateTool(tool);
|
|
35
|
+
if (result.allowed) {
|
|
36
|
+
allowedToolNames.add(tool.name);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
reasons.set(tool.name, ['session_filter']);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
allowedToolNames,
|
|
44
|
+
reasons,
|
|
45
|
+
normalizedHeader: this.request.normalizedHeader
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build filter engine from request
|
|
50
|
+
*/
|
|
51
|
+
buildEngine(request) {
|
|
52
|
+
const allowRules = [];
|
|
53
|
+
if (request.exactNames.size > 0) {
|
|
54
|
+
allowRules.push(new ExactMatchRule(request.exactNames, 'allow'));
|
|
55
|
+
}
|
|
56
|
+
if (request.regexPatterns.length > 0) {
|
|
57
|
+
allowRules.push(new RegexMatchRule(request.regexPatterns, 'allow'));
|
|
58
|
+
}
|
|
59
|
+
if (request.allowCategories.size > 0) {
|
|
60
|
+
if (!this.detector) {
|
|
61
|
+
throw new Error('X-Mcp4-Tools includes _allow_list/_allow_read but OperationDetector is not available. ' +
|
|
62
|
+
'Category-based session tool filtering requires OpenAPI parser.');
|
|
63
|
+
}
|
|
64
|
+
allowRules.push(new CategoryMatchRule(request.allowCategories, this.detector));
|
|
65
|
+
}
|
|
66
|
+
return new FilterEngine(allowRules, []);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=session-tool-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-tool-filter.js","sourceRoot":"","sources":["../../../../src/tool-filter/filter/session-tool-filter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQtF;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAG5B,YACU,OAAiC,EACjC,QAA4B;QAD5B,YAAO,GAAP,OAAO,CAA0B;QACjC,aAAQ,GAAR,QAAQ,CAAoB;QAEpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAuB;QAC3B,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;QAE5C,yBAAyB;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;YACD,OAAO;gBACL,gBAAgB;gBAChB,OAAO;gBACP,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;aAChD,CAAC;QACJ,CAAC;QAED,cAAc;QACd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAE9C,I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
|
|
3
|
+
*
|
|
4
|
+
* This module provides tool filtering functionality for MCP servers.
|
|
5
|
+
*/
|
|
6
|
+
export { RegexValidator } from './regex/regex-validator.js';
|
|
7
|
+
export { RegexCompiler } from './regex/regex-compiler.js';
|
|
8
|
+
export { OperationClassifier } from './operation/operation-classifier.js';
|
|
9
|
+
export { OpenAPIOperationResolver } from './operation/operation-resolver.js';
|
|
10
|
+
export { OperationDetector } from './operation/operation-detector.js';
|
|
11
|
+
export { FilterEngine, FilterResult } from './filter/filter-engine.js';
|
|
12
|
+
export { ExactMatchRule, RegexMatchRule, CategoryMatchRule } from './filter/filter-rules.js';
|
|
13
|
+
export type { FilterRule } from './filter/filter-rules.js';
|
|
14
|
+
export { GlobalToolFilter } from './filter/global-tool-filter.js';
|
|
15
|
+
export type { GlobalToolFilterResult } from './filter/global-tool-filter.js';
|
|
16
|
+
export { SessionToolFilter } from './filter/session-tool-filter.js';
|
|
17
|
+
export type { SessionToolFilterResult } from './filter/session-tool-filter.js';
|
|
18
|
+
export { EnvConfigParser } from './config/env-config-parser.js';
|
|
19
|
+
export { HeaderConfigParser } from './config/header-config-parser.js';
|
|
20
|
+
export { ToolFilterService } from './integration/tool-filter-service.js';
|
|
21
|
+
export { normalizeToolName } from './utils.js';
|
|
22
|
+
export { normalizeToolFilterHeaderValue, parseSessionToolFilterHeader, applySessionToolFilter, type SessionToolFilter as SessionToolFilterCompat } from './compat.js';
|
|
23
|
+
export type { ValidationResult, CompiledRegex, ToolFilterConfig, ToolFilterResult, SessionToolFilterRequest, SessionToolFilter as SessionToolFilterLegacy, OperationResolver, OperationCategory, ToolFilterCategory, ToolCategories } from './types.js';
|
|
24
|
+
export { InvalidRegexError, ConfigurationError, ValidationError } from './errors.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tool-filter/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG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AAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Filter Module - Public API
|
|
3
|
+
*
|
|
4
|
+
* This module provides tool filtering functionality for MCP servers.
|
|
5
|
+
*/
|
|
6
|
+
// Regex validation and compilation
|
|
7
|
+
export { RegexValidator } from './regex/regex-validator.js';
|
|
8
|
+
export { RegexCompiler } from './regex/regex-compiler.js';
|
|
9
|
+
// Operation classification
|
|
10
|
+
export { OperationClassifier } from './operation/operation-classifier.js';
|
|
11
|
+
export { OpenAPIOperationResolver } from './operation/operation-resolver.js';
|
|
12
|
+
export { OperationDetector } from './operation/operation-detector.js';
|
|
13
|
+
// Filter engine and rules
|
|
14
|
+
export { FilterEngine, FilterResult } from './filter/filter-engine.js';
|
|
15
|
+
export { ExactMatchRule, RegexMatchRule, CategoryMatchRule } from './filter/filter-rules.js';
|
|
16
|
+
// Filter implementations
|
|
17
|
+
export { GlobalToolFilter } from './filter/global-tool-filter.js';
|
|
18
|
+
export { SessionToolFilter } from './filter/session-tool-filter.js';
|
|
19
|
+
// Config parsers
|
|
20
|
+
export { EnvConfigParser } from './config/env-config-parser.js';
|
|
21
|
+
export { HeaderConfigParser } from './config/header-config-parser.js';
|
|
22
|
+
// Integration service
|
|
23
|
+
export { ToolFilterService } from './integration/tool-filter-service.js';
|
|
24
|
+
// Utilities
|
|
25
|
+
export { normalizeToolName } from './utils.js';
|
|
26
|
+
// Compatibility functions (for legacy code)
|
|
27
|
+
export { normalizeToolFilterHeaderValue, parseSessionToolFilterHeader, applySessionToolFilter } from './compat.js';
|
|
28
|
+
// Errors
|
|
29
|
+
export { InvalidRegexError, ConfigurationError, ValidationError } from './errors.js';
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tool-filter/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mCAAmC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,2BAA2B;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,0BAA0B;AAC1B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,yBAAyB;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,iBAAiB;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,sBAAsB;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,YAAY;AACZ,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,4CAA4C;AAC5C,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,sBAAsB,EAEvB,MAAM,aAAa,CAAC;AAgBrB,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Filter Service - orchestrates all filtering components
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from '../../types/profile.js';
|
|
5
|
+
import type { Logger } from '../../core/logger.js';
|
|
6
|
+
import type { EnvConfigParser } from '../config/env-config-parser.js';
|
|
7
|
+
import type { HeaderConfigParser } from '../config/header-config-parser.js';
|
|
8
|
+
import type { OperationDetector } from '../operation/operation-detector.js';
|
|
9
|
+
import type { SessionToolFilterResult } from '../filter/session-tool-filter.js';
|
|
10
|
+
/**
|
|
11
|
+
* Service that orchestrates tool filtering from environment and headers
|
|
12
|
+
*/
|
|
13
|
+
export declare class ToolFilterService {
|
|
14
|
+
private envParser;
|
|
15
|
+
private headerParser;
|
|
16
|
+
private logger;
|
|
17
|
+
private detector?;
|
|
18
|
+
constructor(envParser: EnvConfigParser, headerParser: HeaderConfigParser, logger: Logger, detector?: OperationDetector | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Apply global filtering based on environment variables
|
|
21
|
+
*
|
|
22
|
+
* @param tools - Tools to filter
|
|
23
|
+
* @param env - Environment variables (process.env)
|
|
24
|
+
* @returns Filtered tools (or original if no config)
|
|
25
|
+
*/
|
|
26
|
+
applyGlobalFilter(tools: ToolDefinition[], env: NodeJS.ProcessEnv): ToolDefinition[];
|
|
27
|
+
/**
|
|
28
|
+
* Apply session filtering based on X-Mcp4-Tools header
|
|
29
|
+
*
|
|
30
|
+
* @param tools - Tools to filter (typically after global filtering)
|
|
31
|
+
* @param headerValue - X-Mcp4-Tools header value
|
|
32
|
+
* @returns Session filter result with allowed tool names
|
|
33
|
+
*/
|
|
34
|
+
applySessionFilter(tools: ToolDefinition[], headerValue: string): SessionToolFilterResult;
|
|
35
|
+
/**
|
|
36
|
+
* Check if tool is allowed in session
|
|
37
|
+
*
|
|
38
|
+
* @param toolName - Tool name to check
|
|
39
|
+
* @param sessionResult - Session filter result
|
|
40
|
+
* @returns true if tool is allowed
|
|
41
|
+
*/
|
|
42
|
+
isToolAllowed(toolName: string, sessionResult: SessionToolFilterResult): boolean;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=tool-filter-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-filter-service.d.ts","sourceRoot":"","sources":["../../../../src/tool-filter/integration/tool-filter-service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAIhF;;GAEG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC;gBAHT,SAAS,EAAE,eAAe,EAC1B,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,iBAAiB,YAAA;IAGtC;;;;;;OAMG;IACH,iBAAiB,CACf,KAAK,EAAE,cAAc,EAAE,EACvB,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,cAAc,EAAE;IAmBnB;;;;;;OAMG;IACH,kBAAkB,CAChB,KAAK,EAAE,cAAc,EAAE,EACvB,WAAW,EAAE,MAAM,GAClB,uBAAuB;IAgB1B;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,uBAAuB,GAAG,OAAO;CAGjF"}
|