@nimrobo/mcporter-remote 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/.gitattributes +2 -0
- package/.github/workflows/ci.yml +26 -0
- package/AGENTS.md +109 -0
- package/CHANGELOG.md +361 -0
- package/LICENSE +21 -0
- package/README.md +449 -0
- package/bin/git +180 -0
- package/biome.json +43 -0
- package/config/mcporter.json +134 -0
- package/dist/cli/adhoc-server.d.ts +21 -0
- package/dist/cli/adhoc-server.d.ts.map +1 -0
- package/dist/cli/adhoc-server.js +228 -0
- package/dist/cli/adhoc-server.js.map +1 -0
- package/dist/cli/auth-command.d.ts +6 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +257 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/call-argument-expression.d.ts +5 -0
- package/dist/cli/call-argument-expression.d.ts.map +1 -0
- package/dist/cli/call-argument-expression.js +57 -0
- package/dist/cli/call-argument-expression.js.map +1 -0
- package/dist/cli/call-argument-values.d.ts +10 -0
- package/dist/cli/call-argument-values.d.ts.map +1 -0
- package/dist/cli/call-argument-values.js +83 -0
- package/dist/cli/call-argument-values.js.map +1 -0
- package/dist/cli/call-arguments.d.ts +17 -0
- package/dist/cli/call-arguments.d.ts.map +1 -0
- package/dist/cli/call-arguments.js +183 -0
- package/dist/cli/call-arguments.js.map +1 -0
- package/dist/cli/call-command.d.ts +5 -0
- package/dist/cli/call-command.d.ts.map +1 -0
- package/dist/cli/call-command.js +371 -0
- package/dist/cli/call-command.js.map +1 -0
- package/dist/cli/call-expression-parser.d.ts +9 -0
- package/dist/cli/call-expression-parser.d.ts.map +1 -0
- package/dist/cli/call-expression-parser.js +177 -0
- package/dist/cli/call-expression-parser.js.map +1 -0
- package/dist/cli/cli-factory.d.ts +16 -0
- package/dist/cli/cli-factory.d.ts.map +1 -0
- package/dist/cli/cli-factory.js +37 -0
- package/dist/cli/cli-factory.js.map +1 -0
- package/dist/cli/command-inference.d.ts +12 -0
- package/dist/cli/command-inference.d.ts.map +1 -0
- package/dist/cli/command-inference.js +75 -0
- package/dist/cli/command-inference.js.map +1 -0
- package/dist/cli/config/add.d.ts +23 -0
- package/dist/cli/config/add.d.ts.map +1 -0
- package/dist/cli/config/add.js +267 -0
- package/dist/cli/config/add.js.map +1 -0
- package/dist/cli/config/auth.d.ts +4 -0
- package/dist/cli/config/auth.d.ts.map +1 -0
- package/dist/cli/config/auth.js +21 -0
- package/dist/cli/config/auth.js.map +1 -0
- package/dist/cli/config/doctor.d.ts +3 -0
- package/dist/cli/config/doctor.d.ts.map +1 -0
- package/dist/cli/config/doctor.js +26 -0
- package/dist/cli/config/doctor.js.map +1 -0
- package/dist/cli/config/get.d.ts +3 -0
- package/dist/cli/config/get.d.ts.map +1 -0
- package/dist/cli/config/get.js +45 -0
- package/dist/cli/config/get.js.map +1 -0
- package/dist/cli/config/help.d.ts +18 -0
- package/dist/cli/config/help.d.ts.map +1 -0
- package/dist/cli/config/help.js +193 -0
- package/dist/cli/config/help.js.map +1 -0
- package/dist/cli/config/import.d.ts +9 -0
- package/dist/cli/config/import.d.ts.map +1 -0
- package/dist/cli/config/import.js +88 -0
- package/dist/cli/config/import.js.map +1 -0
- package/dist/cli/config/index.d.ts +2 -0
- package/dist/cli/config/index.d.ts.map +1 -0
- package/dist/cli/config/index.js +2 -0
- package/dist/cli/config/index.js.map +1 -0
- package/dist/cli/config/list.d.ts +7 -0
- package/dist/cli/config/list.d.ts.map +1 -0
- package/dist/cli/config/list.js +71 -0
- package/dist/cli/config/list.js.map +1 -0
- package/dist/cli/config/remove.d.ts +3 -0
- package/dist/cli/config/remove.d.ts.map +1 -0
- package/dist/cli/config/remove.js +19 -0
- package/dist/cli/config/remove.js.map +1 -0
- package/dist/cli/config/render.d.ts +26 -0
- package/dist/cli/config/render.d.ts.map +1 -0
- package/dist/cli/config/render.js +99 -0
- package/dist/cli/config/render.js.map +1 -0
- package/dist/cli/config/shared.d.ts +21 -0
- package/dist/cli/config/shared.d.ts.map +1 -0
- package/dist/cli/config/shared.js +130 -0
- package/dist/cli/config/shared.js.map +1 -0
- package/dist/cli/config/types.d.ts +7 -0
- package/dist/cli/config/types.d.ts.map +1 -0
- package/dist/cli/config/types.js +2 -0
- package/dist/cli/config/types.js.map +1 -0
- package/dist/cli/config-command.d.ts +7 -0
- package/dist/cli/config-command.d.ts.map +1 -0
- package/dist/cli/config-command.js +67 -0
- package/dist/cli/config-command.js.map +1 -0
- package/dist/cli/daemon-command.d.ts +8 -0
- package/dist/cli/daemon-command.d.ts.map +1 -0
- package/dist/cli/daemon-command.js +219 -0
- package/dist/cli/daemon-command.js.map +1 -0
- package/dist/cli/emit-ts-command.d.ts +31 -0
- package/dist/cli/emit-ts-command.d.ts.map +1 -0
- package/dist/cli/emit-ts-command.js +217 -0
- package/dist/cli/emit-ts-command.js.map +1 -0
- package/dist/cli/emit-ts-templates.d.ts +23 -0
- package/dist/cli/emit-ts-templates.d.ts.map +1 -0
- package/dist/cli/emit-ts-templates.js +130 -0
- package/dist/cli/emit-ts-templates.js.map +1 -0
- package/dist/cli/ephemeral-flags.d.ts +7 -0
- package/dist/cli/ephemeral-flags.d.ts.map +1 -0
- package/dist/cli/ephemeral-flags.js +108 -0
- package/dist/cli/ephemeral-flags.js.map +1 -0
- package/dist/cli/ephemeral-target.d.ts +16 -0
- package/dist/cli/ephemeral-target.d.ts.map +1 -0
- package/dist/cli/ephemeral-target.js +105 -0
- package/dist/cli/ephemeral-target.js.map +1 -0
- package/dist/cli/errors.d.ts +4 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +7 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/flag-utils.d.ts +4 -0
- package/dist/cli/flag-utils.d.ts.map +1 -0
- package/dist/cli/flag-utils.js +27 -0
- package/dist/cli/flag-utils.js.map +1 -0
- package/dist/cli/generate/artifacts.d.ts +15 -0
- package/dist/cli/generate/artifacts.d.ts.map +1 -0
- package/dist/cli/generate/artifacts.js +247 -0
- package/dist/cli/generate/artifacts.js.map +1 -0
- package/dist/cli/generate/definition.d.ts +22 -0
- package/dist/cli/generate/definition.d.ts.map +1 -0
- package/dist/cli/generate/definition.js +265 -0
- package/dist/cli/generate/definition.js.map +1 -0
- package/dist/cli/generate/flag-parser.d.ts +11 -0
- package/dist/cli/generate/flag-parser.d.ts.map +1 -0
- package/dist/cli/generate/flag-parser.js +41 -0
- package/dist/cli/generate/flag-parser.js.map +1 -0
- package/dist/cli/generate/flags.d.ts +20 -0
- package/dist/cli/generate/flags.d.ts.map +1 -0
- package/dist/cli/generate/flags.js +220 -0
- package/dist/cli/generate/flags.js.map +1 -0
- package/dist/cli/generate/fs-helpers.d.ts +3 -0
- package/dist/cli/generate/fs-helpers.d.ts.map +1 -0
- package/dist/cli/generate/fs-helpers.js +34 -0
- package/dist/cli/generate/fs-helpers.js.map +1 -0
- package/dist/cli/generate/name-utils.d.ts +5 -0
- package/dist/cli/generate/name-utils.d.ts.map +1 -0
- package/dist/cli/generate/name-utils.js +170 -0
- package/dist/cli/generate/name-utils.js.map +1 -0
- package/dist/cli/generate/output.d.ts +5 -0
- package/dist/cli/generate/output.d.ts.map +1 -0
- package/dist/cli/generate/output.js +24 -0
- package/dist/cli/generate/output.js.map +1 -0
- package/dist/cli/generate/runtime.d.ts +3 -0
- package/dist/cli/generate/runtime.d.ts.map +1 -0
- package/dist/cli/generate/runtime.js +34 -0
- package/dist/cli/generate/runtime.js.map +1 -0
- package/dist/cli/generate/server-utils.d.ts +3 -0
- package/dist/cli/generate/server-utils.d.ts.map +1 -0
- package/dist/cli/generate/server-utils.js +33 -0
- package/dist/cli/generate/server-utils.js.map +1 -0
- package/dist/cli/generate/template-data.d.ts +25 -0
- package/dist/cli/generate/template-data.d.ts.map +1 -0
- package/dist/cli/generate/template-data.js +90 -0
- package/dist/cli/generate/template-data.js.map +1 -0
- package/dist/cli/generate/template-help.d.ts +2 -0
- package/dist/cli/generate/template-help.d.ts.map +1 -0
- package/dist/cli/generate/template-help.js +113 -0
- package/dist/cli/generate/template-help.js.map +1 -0
- package/dist/cli/generate/template.d.ts +30 -0
- package/dist/cli/generate/template.d.ts.map +1 -0
- package/dist/cli/generate/template.js +366 -0
- package/dist/cli/generate/template.js.map +1 -0
- package/dist/cli/generate/tools.d.ts +46 -0
- package/dist/cli/generate/tools.d.ts.map +1 -0
- package/dist/cli/generate/tools.js +304 -0
- package/dist/cli/generate/tools.js.map +1 -0
- package/dist/cli/generate/types.d.ts +5 -0
- package/dist/cli/generate/types.d.ts.map +1 -0
- package/dist/cli/generate/types.js +2 -0
- package/dist/cli/generate/types.js.map +1 -0
- package/dist/cli/generate-cli-runner.d.ts +3 -0
- package/dist/cli/generate-cli-runner.d.ts.map +1 -0
- package/dist/cli/generate-cli-runner.js +72 -0
- package/dist/cli/generate-cli-runner.js.map +1 -0
- package/dist/cli/help-output.d.ts +6 -0
- package/dist/cli/help-output.d.ts.map +1 -0
- package/dist/cli/help-output.js +186 -0
- package/dist/cli/help-output.js.map +1 -0
- package/dist/cli/http-utils.d.ts +9 -0
- package/dist/cli/http-utils.d.ts.map +1 -0
- package/dist/cli/http-utils.js +88 -0
- package/dist/cli/http-utils.js.map +1 -0
- package/dist/cli/identifier-helpers.d.ts +20 -0
- package/dist/cli/identifier-helpers.d.ts.map +1 -0
- package/dist/cli/identifier-helpers.js +84 -0
- package/dist/cli/identifier-helpers.js.map +1 -0
- package/dist/cli/image-output.d.ts +3 -0
- package/dist/cli/image-output.d.ts.map +1 -0
- package/dist/cli/image-output.js +57 -0
- package/dist/cli/image-output.js.map +1 -0
- package/dist/cli/inspect-cli-command.d.ts +11 -0
- package/dist/cli/inspect-cli-command.d.ts.map +1 -0
- package/dist/cli/inspect-cli-command.js +78 -0
- package/dist/cli/inspect-cli-command.js.map +1 -0
- package/dist/cli/json-output.d.ts +23 -0
- package/dist/cli/json-output.d.ts.map +1 -0
- package/dist/cli/json-output.js +38 -0
- package/dist/cli/json-output.js.map +1 -0
- package/dist/cli/list-command.d.ts +15 -0
- package/dist/cli/list-command.d.ts.map +1 -0
- package/dist/cli/list-command.js +372 -0
- package/dist/cli/list-command.js.map +1 -0
- package/dist/cli/list-detail-helpers.d.ts +41 -0
- package/dist/cli/list-detail-helpers.d.ts.map +1 -0
- package/dist/cli/list-detail-helpers.js +99 -0
- package/dist/cli/list-detail-helpers.js.map +1 -0
- package/dist/cli/list-doc-comments.d.ts +6 -0
- package/dist/cli/list-doc-comments.d.ts.map +1 -0
- package/dist/cli/list-doc-comments.js +114 -0
- package/dist/cli/list-doc-comments.js.map +1 -0
- package/dist/cli/list-format.d.ts +38 -0
- package/dist/cli/list-format.d.ts.map +1 -0
- package/dist/cli/list-format.js +98 -0
- package/dist/cli/list-format.js.map +1 -0
- package/dist/cli/list-output.d.ts +39 -0
- package/dist/cli/list-output.d.ts.map +1 -0
- package/dist/cli/list-output.js +159 -0
- package/dist/cli/list-output.js.map +1 -0
- package/dist/cli/list-signature.d.ts +26 -0
- package/dist/cli/list-signature.d.ts.map +1 -0
- package/dist/cli/list-signature.js +176 -0
- package/dist/cli/list-signature.js.map +1 -0
- package/dist/cli/logger-context.d.ts +9 -0
- package/dist/cli/logger-context.d.ts.map +1 -0
- package/dist/cli/logger-context.js +29 -0
- package/dist/cli/logger-context.js.map +1 -0
- package/dist/cli/output-format.d.ts +11 -0
- package/dist/cli/output-format.d.ts.map +1 -0
- package/dist/cli/output-format.js +51 -0
- package/dist/cli/output-format.js.map +1 -0
- package/dist/cli/output-utils.d.ts +5 -0
- package/dist/cli/output-utils.d.ts.map +1 -0
- package/dist/cli/output-utils.js +143 -0
- package/dist/cli/output-utils.js.map +1 -0
- package/dist/cli/path-utils.d.ts +2 -0
- package/dist/cli/path-utils.d.ts.map +1 -0
- package/dist/cli/path-utils.js +12 -0
- package/dist/cli/path-utils.js.map +1 -0
- package/dist/cli/runtime-debug.d.ts +4 -0
- package/dist/cli/runtime-debug.d.ts.map +1 -0
- package/dist/cli/runtime-debug.js +134 -0
- package/dist/cli/runtime-debug.js.map +1 -0
- package/dist/cli/server-lookup.d.ts +3 -0
- package/dist/cli/server-lookup.d.ts.map +1 -0
- package/dist/cli/server-lookup.js +21 -0
- package/dist/cli/server-lookup.js.map +1 -0
- package/dist/cli/terminal.d.ts +10 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +33 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/cli/timeouts.d.ts +9 -0
- package/dist/cli/timeouts.d.ts.map +1 -0
- package/dist/cli/timeouts.js +55 -0
- package/dist/cli/timeouts.js.map +1 -0
- package/dist/cli/tool-cache.d.ts +9 -0
- package/dist/cli/tool-cache.d.ts.map +1 -0
- package/dist/cli/tool-cache.js +31 -0
- package/dist/cli/tool-cache.js.map +1 -0
- package/dist/cli/transport-utils.d.ts +3 -0
- package/dist/cli/transport-utils.d.ts.map +1 -0
- package/dist/cli/transport-utils.js +9 -0
- package/dist/cli/transport-utils.js.map +1 -0
- package/dist/cli-metadata.d.ts +57 -0
- package/dist/cli-metadata.d.ts.map +1 -0
- package/dist/cli-metadata.js +92 -0
- package/dist/cli-metadata.js.map +1 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +217 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/imports/external.d.ts +8 -0
- package/dist/config/imports/external.d.ts.map +1 -0
- package/dist/config/imports/external.js +231 -0
- package/dist/config/imports/external.js.map +1 -0
- package/dist/config/imports/paths-utils.d.ts +3 -0
- package/dist/config/imports/paths-utils.d.ts.map +1 -0
- package/dist/config/imports/paths-utils.js +27 -0
- package/dist/config/imports/paths-utils.js.map +1 -0
- package/dist/config/imports/paths.d.ts +3 -0
- package/dist/config/imports/paths.d.ts.map +1 -0
- package/dist/config/imports/paths.js +135 -0
- package/dist/config/imports/paths.js.map +1 -0
- package/dist/config/imports/shared.d.ts +4 -0
- package/dist/config/imports/shared.d.ts.map +1 -0
- package/dist/config/imports/shared.js +25 -0
- package/dist/config/imports/shared.js.map +1 -0
- package/dist/config/path-discovery.d.ts +11 -0
- package/dist/config/path-discovery.d.ts.map +1 -0
- package/dist/config/path-discovery.js +65 -0
- package/dist/config/path-discovery.js.map +1 -0
- package/dist/config/read-config.d.ts +9 -0
- package/dist/config/read-config.d.ts.map +1 -0
- package/dist/config/read-config.js +74 -0
- package/dist/config/read-config.js.map +1 -0
- package/dist/config-imports.d.ts +7 -0
- package/dist/config-imports.d.ts.map +1 -0
- package/dist/config-imports.js +8 -0
- package/dist/config-imports.js.map +1 -0
- package/dist/config-normalize.d.ts +8 -0
- package/dist/config-normalize.d.ts.map +1 -0
- package/dist/config-normalize.js +184 -0
- package/dist/config-normalize.js.map +1 -0
- package/dist/config-schema.d.ts +164 -0
- package/dist/config-schema.d.ts.map +1 -0
- package/dist/config-schema.js +103 -0
- package/dist/config-schema.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon/client.d.ts +34 -0
- package/dist/daemon/client.d.ts.map +1 -0
- package/dist/daemon/client.js +291 -0
- package/dist/daemon/client.js.map +1 -0
- package/dist/daemon/config-layers.d.ts +7 -0
- package/dist/daemon/config-layers.d.ts.map +1 -0
- package/dist/daemon/config-layers.js +20 -0
- package/dist/daemon/config-layers.js.map +1 -0
- package/dist/daemon/host.d.ts +32 -0
- package/dist/daemon/host.d.ts.map +1 -0
- package/dist/daemon/host.js +345 -0
- package/dist/daemon/host.js.map +1 -0
- package/dist/daemon/launch.d.ts +10 -0
- package/dist/daemon/launch.d.ts.map +1 -0
- package/dist/daemon/launch.js +35 -0
- package/dist/daemon/launch.js.map +1 -0
- package/dist/daemon/log-context.d.ts +18 -0
- package/dist/daemon/log-context.d.ts.map +1 -0
- package/dist/daemon/log-context.js +64 -0
- package/dist/daemon/log-context.js.map +1 -0
- package/dist/daemon/paths.d.ts +5 -0
- package/dist/daemon/paths.d.ts.map +1 -0
- package/dist/daemon/paths.js +30 -0
- package/dist/daemon/paths.js.map +1 -0
- package/dist/daemon/protocol.d.ts +51 -0
- package/dist/daemon/protocol.d.ts.map +1 -0
- package/dist/daemon/protocol.js +2 -0
- package/dist/daemon/protocol.js.map +1 -0
- package/dist/daemon/request-utils.d.ts +12 -0
- package/dist/daemon/request-utils.d.ts.map +1 -0
- package/dist/daemon/request-utils.js +52 -0
- package/dist/daemon/request-utils.js.map +1 -0
- package/dist/daemon/runtime-wrapper.d.ts +9 -0
- package/dist/daemon/runtime-wrapper.d.ts.map +1 -0
- package/dist/daemon/runtime-wrapper.js +110 -0
- package/dist/daemon/runtime-wrapper.js.map +1 -0
- package/dist/env.d.ts +5 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +93 -0
- package/dist/env.js.map +1 -0
- package/dist/error-classifier.d.ts +11 -0
- package/dist/error-classifier.d.ts.map +1 -0
- package/dist/error-classifier.js +141 -0
- package/dist/error-classifier.js.map +1 -0
- package/dist/fs-json.d.ts +3 -0
- package/dist/fs-json.d.ts.map +1 -0
- package/dist/fs-json.js +21 -0
- package/dist/fs-json.js.map +1 -0
- package/dist/generate-cli.d.ts +32 -0
- package/dist/generate-cli.d.ts.map +1 -0
- package/dist/generate-cli.js +155 -0
- package/dist/generate-cli.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +8 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +106 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/logging.d.ts +19 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +76 -0
- package/dist/logging.js.map +1 -0
- package/dist/oauth-manual.d.ts +9 -0
- package/dist/oauth-manual.d.ts.map +1 -0
- package/dist/oauth-manual.js +84 -0
- package/dist/oauth-manual.js.map +1 -0
- package/dist/oauth-persistence.d.ts +20 -0
- package/dist/oauth-persistence.d.ts.map +1 -0
- package/dist/oauth-persistence.js +254 -0
- package/dist/oauth-persistence.js.map +1 -0
- package/dist/oauth-vault.d.ts +19 -0
- package/dist/oauth-vault.d.ts.map +1 -0
- package/dist/oauth-vault.js +100 -0
- package/dist/oauth-vault.js.map +1 -0
- package/dist/oauth.d.ts +31 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +414 -0
- package/dist/oauth.js.map +1 -0
- package/dist/result-utils.d.ts +22 -0
- package/dist/result-utils.d.ts.map +1 -0
- package/dist/result-utils.js +229 -0
- package/dist/result-utils.js.map +1 -0
- package/dist/runtime/errors.d.ts +2 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +16 -0
- package/dist/runtime/errors.js.map +1 -0
- package/dist/runtime/http-transport.d.ts +15 -0
- package/dist/runtime/http-transport.d.ts.map +1 -0
- package/dist/runtime/http-transport.js +91 -0
- package/dist/runtime/http-transport.js.map +1 -0
- package/dist/runtime/manual-oauth.d.ts +8 -0
- package/dist/runtime/manual-oauth.d.ts.map +1 -0
- package/dist/runtime/manual-oauth.js +81 -0
- package/dist/runtime/manual-oauth.js.map +1 -0
- package/dist/runtime/oauth.d.ts +22 -0
- package/dist/runtime/oauth.d.ts.map +1 -0
- package/dist/runtime/oauth.js +83 -0
- package/dist/runtime/oauth.js.map +1 -0
- package/dist/runtime/transport.d.ts +24 -0
- package/dist/runtime/transport.d.ts.map +1 -0
- package/dist/runtime/transport.js +165 -0
- package/dist/runtime/transport.js.map +1 -0
- package/dist/runtime/utils.d.ts +5 -0
- package/dist/runtime/utils.d.ts.map +1 -0
- package/dist/runtime/utils.js +47 -0
- package/dist/runtime/utils.js.map +1 -0
- package/dist/runtime-header-utils.d.ts +2 -0
- package/dist/runtime-header-utils.d.ts.map +1 -0
- package/dist/runtime-header-utils.js +19 -0
- package/dist/runtime-header-utils.js.map +1 -0
- package/dist/runtime-oauth-support.d.ts +5 -0
- package/dist/runtime-oauth-support.d.ts.map +1 -0
- package/dist/runtime-oauth-support.js +21 -0
- package/dist/runtime-oauth-support.js.map +1 -0
- package/dist/runtime-process-utils.d.ts +11 -0
- package/dist/runtime-process-utils.d.ts.map +1 -0
- package/dist/runtime-process-utils.js +299 -0
- package/dist/runtime-process-utils.js.map +1 -0
- package/dist/runtime.d.ts +55 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +245 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema-cache.d.ts +10 -0
- package/dist/schema-cache.d.ts.map +1 -0
- package/dist/schema-cache.js +40 -0
- package/dist/schema-cache.js.map +1 -0
- package/dist/sdk-patches.d.ts +5 -0
- package/dist/sdk-patches.d.ts.map +1 -0
- package/dist/sdk-patches.js +399 -0
- package/dist/sdk-patches.js.map +1 -0
- package/dist/server-proxy.d.ts +17 -0
- package/dist/server-proxy.d.ts.map +1 -0
- package/dist/server-proxy.js +342 -0
- package/dist/server-proxy.js.map +1 -0
- package/docs/RELEASE.md +96 -0
- package/docs/adhoc.md +76 -0
- package/docs/call-heuristic.md +31 -0
- package/docs/call-syntax.md +75 -0
- package/docs/cli-generator.md +116 -0
- package/docs/cli-reference.md +76 -0
- package/docs/config.md +208 -0
- package/docs/daemon.md +95 -0
- package/docs/emit-ts.md +98 -0
- package/docs/hang-debug.md +88 -0
- package/docs/import.md +59 -0
- package/docs/known-issues.md +33 -0
- package/docs/livetests.md +31 -0
- package/docs/local.md +73 -0
- package/docs/logging.md +67 -0
- package/docs/manual-testing.md +78 -0
- package/docs/mcp.md +44 -0
- package/docs/migration.md +77 -0
- package/docs/pnpm-mcp-migration.md +15 -0
- package/docs/refactor.md +76 -0
- package/docs/shortcuts.md +31 -0
- package/docs/spec.md +86 -0
- package/docs/subagent.md +39 -0
- package/docs/supabase-auth-issue.md +53 -0
- package/docs/tmux.md +30 -0
- package/docs/tool-calling.md +73 -0
- package/docs/windows.md +25 -0
- package/examples/context7-headlines.ts +72 -0
- package/git +3 -0
- package/mcporter.png +0 -0
- package/mcporter.schema.json +263 -0
- package/package.json +105 -0
- package/pnpm-workspace.yaml +2 -0
- package/runner +13 -0
- package/scripts/agent-send.ts +179 -0
- package/scripts/build-bun.ts +125 -0
- package/scripts/committer +53 -0
- package/scripts/docs-list.ts +132 -0
- package/scripts/generate-json-schema.ts +50 -0
- package/scripts/git-policy.ts +165 -0
- package/scripts/mcp_signoz_retry_patch.cjs +9 -0
- package/scripts/release.sh +86 -0
- package/scripts/runner.ts +1556 -0
- package/scripts/test-runner.js +39 -0
- package/src/cli/adhoc-server.ts +263 -0
- package/src/cli/auth-command.ts +290 -0
- package/src/cli/call-argument-expression.ts +61 -0
- package/src/cli/call-argument-values.ts +95 -0
- package/src/cli/call-arguments.ts +246 -0
- package/src/cli/call-command.ts +478 -0
- package/src/cli/call-expression-parser.ts +210 -0
- package/src/cli/cli-factory.ts +51 -0
- package/src/cli/command-inference.ts +99 -0
- package/src/cli/config/add.ts +308 -0
- package/src/cli/config/auth.ts +23 -0
- package/src/cli/config/doctor.ts +27 -0
- package/src/cli/config/get.ts +47 -0
- package/src/cli/config/help.ts +213 -0
- package/src/cli/config/import.ts +97 -0
- package/src/cli/config/index.ts +1 -0
- package/src/cli/config/list.ts +81 -0
- package/src/cli/config/remove.ts +20 -0
- package/src/cli/config/render.ts +119 -0
- package/src/cli/config/shared.ts +159 -0
- package/src/cli/config/types.ts +8 -0
- package/src/cli/config-command.ts +72 -0
- package/src/cli/daemon-command.ts +260 -0
- package/src/cli/emit-ts-command.ts +260 -0
- package/src/cli/emit-ts-templates.ts +161 -0
- package/src/cli/ephemeral-flags.ts +128 -0
- package/src/cli/ephemeral-target.ts +134 -0
- package/src/cli/errors.ts +6 -0
- package/src/cli/flag-utils.ts +29 -0
- package/src/cli/generate/artifacts.ts +308 -0
- package/src/cli/generate/definition.ts +325 -0
- package/src/cli/generate/flag-parser.ts +50 -0
- package/src/cli/generate/flags.ts +248 -0
- package/src/cli/generate/fs-helpers.ts +34 -0
- package/src/cli/generate/name-utils.ts +176 -0
- package/src/cli/generate/output.ts +27 -0
- package/src/cli/generate/runtime.ts +38 -0
- package/src/cli/generate/server-utils.ts +38 -0
- package/src/cli/generate/template-data.ts +126 -0
- package/src/cli/generate/template-help.ts +112 -0
- package/src/cli/generate/template.ts +407 -0
- package/src/cli/generate/tools.ts +354 -0
- package/src/cli/generate/types.ts +1 -0
- package/src/cli/generate-cli-runner.ts +82 -0
- package/src/cli/help-output.ts +207 -0
- package/src/cli/http-utils.ts +89 -0
- package/src/cli/identifier-helpers.ts +107 -0
- package/src/cli/image-output.ts +62 -0
- package/src/cli/inspect-cli-command.ts +89 -0
- package/src/cli/json-output.ts +60 -0
- package/src/cli/list-command.ts +432 -0
- package/src/cli/list-detail-helpers.ts +179 -0
- package/src/cli/list-doc-comments.ts +129 -0
- package/src/cli/list-format.ts +150 -0
- package/src/cli/list-output.ts +224 -0
- package/src/cli/list-signature.ts +217 -0
- package/src/cli/logger-context.ts +36 -0
- package/src/cli/output-format.ts +63 -0
- package/src/cli/output-utils.ts +161 -0
- package/src/cli/path-utils.ts +13 -0
- package/src/cli/runtime-debug.ts +141 -0
- package/src/cli/server-lookup.ts +22 -0
- package/src/cli/terminal.ts +41 -0
- package/src/cli/timeouts.ts +67 -0
- package/src/cli/tool-cache.ts +43 -0
- package/src/cli/transport-utils.ts +10 -0
- package/src/cli-metadata.ts +164 -0
- package/src/cli.ts +234 -0
- package/src/config/imports/external.ts +284 -0
- package/src/config/imports/paths-utils.ts +29 -0
- package/src/config/imports/paths.ts +145 -0
- package/src/config/imports/shared.ts +27 -0
- package/src/config/path-discovery.ts +79 -0
- package/src/config/read-config.ts +91 -0
- package/src/config-imports.ts +12 -0
- package/src/config-normalize.ts +220 -0
- package/src/config-schema.ts +175 -0
- package/src/config.ts +136 -0
- package/src/daemon/client.ts +350 -0
- package/src/daemon/config-layers.ts +23 -0
- package/src/daemon/host.ts +455 -0
- package/src/daemon/launch.ts +45 -0
- package/src/daemon/log-context.ts +78 -0
- package/src/daemon/paths.ts +35 -0
- package/src/daemon/protocol.ts +57 -0
- package/src/daemon/request-utils.ts +67 -0
- package/src/daemon/runtime-wrapper.ts +135 -0
- package/src/env.ts +107 -0
- package/src/error-classifier.ts +158 -0
- package/src/fs-json.ts +21 -0
- package/src/generate-cli.ts +211 -0
- package/src/index.ts +14 -0
- package/src/lifecycle.ts +138 -0
- package/src/logging.ts +93 -0
- package/src/oauth-manual.ts +103 -0
- package/src/oauth-persistence.ts +316 -0
- package/src/oauth-vault.ts +128 -0
- package/src/oauth.ts +494 -0
- package/src/result-utils.ts +278 -0
- package/src/runtime/errors.ts +17 -0
- package/src/runtime/oauth.ts +112 -0
- package/src/runtime/transport.ts +198 -0
- package/src/runtime/utils.ts +54 -0
- package/src/runtime-header-utils.ts +23 -0
- package/src/runtime-oauth-support.ts +24 -0
- package/src/runtime-process-utils.ts +324 -0
- package/src/runtime.ts +321 -0
- package/src/schema-cache.ts +49 -0
- package/src/sdk-patches.ts +498 -0
- package/src/server-proxy.ts +407 -0
- package/tests/adhoc-server.test.ts +49 -0
- package/tests/call-arguments.test.ts +111 -0
- package/tests/cli-auth-help.test.ts +43 -0
- package/tests/cli-auth-retry.test.ts +41 -0
- package/tests/cli-auth.test.ts +96 -0
- package/tests/cli-call-args.test.ts +69 -0
- package/tests/cli-call-errors.test.ts +27 -0
- package/tests/cli-call-execution.test.ts +279 -0
- package/tests/cli-call-help.test.ts +43 -0
- package/tests/cli-command-inference.test.ts +73 -0
- package/tests/cli-config-command.test.ts +371 -0
- package/tests/cli-config-fallback.test.ts +259 -0
- package/tests/cli-config-routing.test.ts +20 -0
- package/tests/cli-ephemeral-flags.test.ts +54 -0
- package/tests/cli-flag-utils.test.ts +17 -0
- package/tests/cli-generate-artifacts.test.ts +52 -0
- package/tests/cli-generate-cli.integration.test.ts +675 -0
- package/tests/cli-generate-runner.test.ts +156 -0
- package/tests/cli-global-flags.test.ts +61 -0
- package/tests/cli-help-shortcuts.test.ts +42 -0
- package/tests/cli-image-output.test.ts +65 -0
- package/tests/cli-inspect-command.test.ts +15 -0
- package/tests/cli-list-classification.test.ts +291 -0
- package/tests/cli-list-flags.test.ts +83 -0
- package/tests/cli-list-formatting.test.ts +358 -0
- package/tests/cli-list-help.test.ts +43 -0
- package/tests/cli-list-json.test.ts +55 -0
- package/tests/cli-list-stdio-logs.test.ts +108 -0
- package/tests/cli-list-verbose-e2e.test.ts +83 -0
- package/tests/cli-oauth-timeout-flag.test.ts +94 -0
- package/tests/cli-output-utils.test.ts +129 -0
- package/tests/cli-regenerate.test.ts +261 -0
- package/tests/cli-version.test.ts +24 -0
- package/tests/config-add-dry-run.test.ts +45 -0
- package/tests/config-add-flags.test.ts +61 -0
- package/tests/config-add-imports.test.ts +28 -0
- package/tests/config-add-persist.test.ts +27 -0
- package/tests/config-add-scope-behavior.test.ts +46 -0
- package/tests/config-add-scope.test.ts +101 -0
- package/tests/config-add-sse.test.ts +23 -0
- package/tests/config-command-string.test.ts +96 -0
- package/tests/config-doctor.test.ts +45 -0
- package/tests/config-get-json.test.ts +24 -0
- package/tests/config-import-dedupe.test.ts +27 -0
- package/tests/config-import-paths.test.ts +49 -0
- package/tests/config-import.test.ts +64 -0
- package/tests/config-imports-unit.test.ts +337 -0
- package/tests/config-imports.test.ts +417 -0
- package/tests/config-layered.test.ts +178 -0
- package/tests/config-list-text-footer.test.ts +33 -0
- package/tests/config-list.test.ts +62 -0
- package/tests/config-missing.test.ts +140 -0
- package/tests/config-normalize.test.ts +71 -0
- package/tests/config-remove.test.ts +44 -0
- package/tests/config-render.test.ts +61 -0
- package/tests/config-resolution.test.ts +94 -0
- package/tests/config-schema-file.test.ts +29 -0
- package/tests/config-shared.test.ts +41 -0
- package/tests/config-sources.test.ts +58 -0
- package/tests/daemon-cli-command.test.ts +112 -0
- package/tests/daemon-client-config-stale.test.ts +222 -0
- package/tests/daemon-client-timeout.test.ts +114 -0
- package/tests/daemon-client.test.ts +61 -0
- package/tests/daemon-host.test.ts +33 -0
- package/tests/daemon.integration.test.ts +175 -0
- package/tests/emit-ts.test.ts +125 -0
- package/tests/ephemeral-target.test.ts +26 -0
- package/tests/error-classifier.test.ts +46 -0
- package/tests/fixtures/ansi.ts +18 -0
- package/tests/fixtures/cli-list-fixtures.ts +43 -0
- package/tests/fixtures/config-fixture.ts +29 -0
- package/tests/fixtures/imports/.claude/mcp.json +8 -0
- package/tests/fixtures/imports/.claude/settings.json +10 -0
- package/tests/fixtures/imports/.claude/settings.local.json +10 -0
- package/tests/fixtures/imports/.codeium/windsurf/mcp_config.json +14 -0
- package/tests/fixtures/imports/.codex/config.toml +7 -0
- package/tests/fixtures/imports/.config/opencode/opencode.jsonc +10 -0
- package/tests/fixtures/imports/.cursor/mcp.json +14 -0
- package/tests/fixtures/imports/Library/Application Support/Code/User/mcp.json +11 -0
- package/tests/fixtures/imports/config/mcporter.json +11 -0
- package/tests/fixtures/imports/home/.claude/settings.json +7 -0
- package/tests/fixtures/imports/home/.codeium/windsurf/mcp_config.json +14 -0
- package/tests/fixtures/imports/home/.codex/config.toml +7 -0
- package/tests/fixtures/imports/home/Library/Application Support/Code/User/mcp.json +11 -0
- package/tests/fixtures/imports/opencode.jsonc +11 -0
- package/tests/fixtures/mcporter.json +64 -0
- package/tests/fixtures/stdio-filesystem-server.mjs +63 -0
- package/tests/fixtures/stdio-memory-server.mjs +58 -0
- package/tests/fixtures/test-helpers.ts +24 -0
- package/tests/fixtures/tool-fixtures.ts +35 -0
- package/tests/fs-json.test.ts +35 -0
- package/tests/generate-cli-helpers.test.ts +162 -0
- package/tests/generate-cli.test.ts +595 -0
- package/tests/generate-definition.test.ts +25 -0
- package/tests/generator-flag-parser.test.ts +19 -0
- package/tests/index-api.test.ts +136 -0
- package/tests/keep-alive-runtime.test.ts +152 -0
- package/tests/lifecycle.test.ts +29 -0
- package/tests/list-detail-helpers.test.ts +204 -0
- package/tests/list-format.test.ts +40 -0
- package/tests/list-inline-stdio.test.ts +71 -0
- package/tests/list-output.test.ts +138 -0
- package/tests/live/deepwiki-live.test.ts +53 -0
- package/tests/oauth-callback.test.ts +108 -0
- package/tests/oauth-open-external.test.ts +29 -0
- package/tests/oauth-persistence.test.ts +146 -0
- package/tests/oauth-session.test.ts +216 -0
- package/tests/result-utils.test.ts +254 -0
- package/tests/runtime-call-timeout.test.ts +75 -0
- package/tests/runtime-compose.test.ts +298 -0
- package/tests/runtime-error-reset.test.ts +65 -0
- package/tests/runtime-header-utils.test.ts +36 -0
- package/tests/runtime-integration.test.ts +113 -0
- package/tests/runtime-oauth-connect.test.ts +72 -0
- package/tests/runtime-oauth-detection.test.ts +72 -0
- package/tests/runtime-oauth-timeout.test.ts +60 -0
- package/tests/runtime-oauth-utils.test.ts +14 -0
- package/tests/runtime-process-utils.test.ts +53 -0
- package/tests/runtime-transport.test.ts +69 -0
- package/tests/runtime-utils.test.ts +31 -0
- package/tests/runtime.test.ts +94 -0
- package/tests/sdk-patches.test.ts +24 -0
- package/tests/server-proxy.test.ts +336 -0
- package/tests/stdio-servers.integration.test.ts +139 -0
- package/tests/tool-cache.test.ts +42 -0
- package/tests/version-consistency.test.ts +11 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ServerDefinition } from './config.js';
|
|
2
|
+
import { analyzeConnectionError } from './error-classifier.js';
|
|
3
|
+
import type { Logger } from './logging.js';
|
|
4
|
+
|
|
5
|
+
export function maybeEnableOAuth(definition: ServerDefinition, logger: Logger): ServerDefinition | undefined {
|
|
6
|
+
if (definition.auth === 'oauth') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
if (definition.command.kind !== 'http') {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
// Allow OAuth promotion for any HTTP server that returns 401,
|
|
13
|
+
// not just ad-hoc servers (fixes issue #38)
|
|
14
|
+
logger.info(`Detected OAuth requirement for '${definition.name}'. Launching browser flow...`);
|
|
15
|
+
return {
|
|
16
|
+
...definition,
|
|
17
|
+
auth: 'oauth',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isUnauthorizedError(error: unknown): boolean {
|
|
22
|
+
const issue = analyzeConnectionError(error);
|
|
23
|
+
return issue.kind === 'auth';
|
|
24
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
4
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
+
import type { Logger } from './logging.js';
|
|
6
|
+
|
|
7
|
+
// closeTransportAndWait closes transports and ensures backing processes exit cleanly.
|
|
8
|
+
export async function closeTransportAndWait(
|
|
9
|
+
logger: Logger,
|
|
10
|
+
transport: Transport & { close(): Promise<void> }
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
const pidBeforeClose = getTransportPid(transport);
|
|
13
|
+
const childProcess =
|
|
14
|
+
transport instanceof StdioClientTransport
|
|
15
|
+
? ((transport as unknown as { _process?: ChildProcess | null })._process ?? null)
|
|
16
|
+
: null;
|
|
17
|
+
try {
|
|
18
|
+
await transport.close();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logger.warn(`Failed to close transport cleanly: ${(error as Error).message}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (childProcess) {
|
|
24
|
+
await waitForChildClose(childProcess, 1_000).catch(() => {});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!pidBeforeClose) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await ensureProcessTerminated(logger, pidBeforeClose);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getTransportPid(transport: Transport & { pid?: number | null }): number | null {
|
|
35
|
+
if (transport instanceof StdioClientTransport) {
|
|
36
|
+
const pid = transport.pid;
|
|
37
|
+
return typeof pid === 'number' && pid > 0 ? pid : null;
|
|
38
|
+
}
|
|
39
|
+
if ('pid' in transport) {
|
|
40
|
+
const candidate = transport.pid;
|
|
41
|
+
if (typeof candidate === 'number' && candidate > 0) {
|
|
42
|
+
return candidate;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const rawPid = (transport as unknown as { _process?: { pid?: number } | null | undefined })._process?.pid;
|
|
46
|
+
return typeof rawPid === 'number' && rawPid > 0 ? rawPid : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function ensureProcessTerminated(logger: Logger, pid: number): Promise<void> {
|
|
50
|
+
await ensureProcessTreeTerminated(logger, pid);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function waitForChildClose(child: ChildProcess, timeoutMs: number): Promise<void> {
|
|
54
|
+
if (
|
|
55
|
+
(child as { exitCode?: number | null }).exitCode !== null &&
|
|
56
|
+
(child as { exitCode?: number | null }).exitCode !== undefined
|
|
57
|
+
) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
await new Promise<void>((resolve) => {
|
|
61
|
+
let settled = false;
|
|
62
|
+
const finish = () => {
|
|
63
|
+
if (settled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
settled = true;
|
|
67
|
+
cleanup();
|
|
68
|
+
resolve();
|
|
69
|
+
};
|
|
70
|
+
const cleanup = () => {
|
|
71
|
+
child.removeListener('close', finish);
|
|
72
|
+
child.removeListener('exit', finish);
|
|
73
|
+
child.removeListener('error', finish);
|
|
74
|
+
if (timer) {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
child.once('close', finish);
|
|
79
|
+
child.once('exit', finish);
|
|
80
|
+
child.once('error', finish);
|
|
81
|
+
let timer: NodeJS.Timeout | undefined;
|
|
82
|
+
if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
|
|
83
|
+
timer = setTimeout(finish, timeoutMs);
|
|
84
|
+
timer.unref?.();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
child.stdin?.end?.();
|
|
90
|
+
} catch {
|
|
91
|
+
// ignore
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
child.stdout?.destroy?.();
|
|
95
|
+
child.stdout?.removeAllListeners?.();
|
|
96
|
+
(child.stdout as unknown as { unref?: () => void })?.unref?.();
|
|
97
|
+
} catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
child.stderr?.destroy?.();
|
|
102
|
+
child.stderr?.removeAllListeners?.();
|
|
103
|
+
(child.stderr as unknown as { unref?: () => void })?.unref?.();
|
|
104
|
+
} catch {
|
|
105
|
+
// ignore
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const stdio = (child as { stdio?: unknown[] }).stdio;
|
|
109
|
+
if (Array.isArray(stdio)) {
|
|
110
|
+
for (const stream of stdio) {
|
|
111
|
+
if (!stream || typeof stream !== 'object') {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
(stream as { removeAllListeners?: () => void }).removeAllListeners?.();
|
|
116
|
+
(stream as { destroy?: () => void }).destroy?.();
|
|
117
|
+
(stream as { end?: () => void }).end?.();
|
|
118
|
+
} catch {
|
|
119
|
+
// ignore
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// ignore
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
child.removeAllListeners();
|
|
128
|
+
} catch {
|
|
129
|
+
// ignore
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
child.unref?.();
|
|
133
|
+
} catch {
|
|
134
|
+
// ignore
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isProcessAlive(pid: number): boolean {
|
|
139
|
+
try {
|
|
140
|
+
process.kill(pid, 0);
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function ensureProcessTreeTerminated(logger: Logger, rootPid: number): Promise<void> {
|
|
148
|
+
if (!isProcessAlive(rootPid)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let targets = await collectProcessTreePids(rootPid);
|
|
153
|
+
if (await waitForTreeExit(targets, 300)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
await sendSignalToTargets(targets, 'SIGTERM');
|
|
158
|
+
targets = await collectProcessTreePids(rootPid);
|
|
159
|
+
if (await waitForTreeExit(targets, 700)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
targets = await collectProcessTreePids(rootPid);
|
|
164
|
+
await sendSignalToTargets(targets, 'SIGKILL');
|
|
165
|
+
if (await waitForTreeExit(targets, 500)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
logger.warn(`Process tree rooted at pid=${rootPid} did not exit after SIGKILL.`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function sendSignalToTargets(pids: number[], signal: NodeJS.Signals): Promise<void> {
|
|
173
|
+
const seen = new Set<number>();
|
|
174
|
+
for (const pid of pids) {
|
|
175
|
+
if (seen.has(pid)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
seen.add(pid);
|
|
179
|
+
sendSignal(pid, signal);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function sendSignal(pid: number, signal: NodeJS.Signals): void {
|
|
184
|
+
try {
|
|
185
|
+
process.kill(pid, signal);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (typeof error === 'object' && error && 'code' in error && (error as { code?: string }).code === 'ESRCH') {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function listDescendantPids(rootPid: number): Promise<number[]> {
|
|
195
|
+
if (!isProcessAlive(rootPid)) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
if (process.platform === 'win32') {
|
|
199
|
+
return listDescendantPidsWindows(rootPid);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const { stdout } = await execFileAsync('ps', ['-eo', 'pid=,ppid=']);
|
|
204
|
+
const children = new Map<number, number[]>();
|
|
205
|
+
for (const line of stdout.split('\n')) {
|
|
206
|
+
const trimmed = line.trim();
|
|
207
|
+
if (!trimmed) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const [pidText, ppidText] = trimmed.split(/\s+/, 2);
|
|
211
|
+
const pid = Number.parseInt(pidText ?? '', 10);
|
|
212
|
+
const ppid = Number.parseInt(ppidText ?? '', 10);
|
|
213
|
+
if (!Number.isFinite(pid) || !Number.isFinite(ppid)) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const bucket = children.get(ppid) ?? [];
|
|
217
|
+
bucket.push(pid);
|
|
218
|
+
children.set(ppid, bucket);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return collectDescendantsFromChildren(rootPid, children);
|
|
222
|
+
} catch {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function listDescendantPidsWindows(rootPid: number): Promise<number[]> {
|
|
228
|
+
try {
|
|
229
|
+
const powershellScript =
|
|
230
|
+
'Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId | ConvertTo-Json -Compress';
|
|
231
|
+
const { stdout } = await execFileAsync('powershell.exe', ['-NoProfile', '-Command', powershellScript]);
|
|
232
|
+
const trimmed = stdout.trim();
|
|
233
|
+
if (!trimmed) {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
const parsed = JSON.parse(trimmed) as
|
|
237
|
+
| { ProcessId?: number; ParentProcessId?: number }
|
|
238
|
+
| Array<{ ProcessId?: number; ParentProcessId?: number }>;
|
|
239
|
+
const entries = Array.isArray(parsed) ? parsed : [parsed];
|
|
240
|
+
const children = new Map<number, number[]>();
|
|
241
|
+
for (const entry of entries) {
|
|
242
|
+
const pidCandidate = entry?.ProcessId;
|
|
243
|
+
const ppidCandidate = entry?.ParentProcessId;
|
|
244
|
+
if (typeof pidCandidate !== 'number' || typeof ppidCandidate !== 'number') {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const pid = Number.isFinite(pidCandidate) ? pidCandidate : undefined;
|
|
248
|
+
const ppid = Number.isFinite(ppidCandidate) ? ppidCandidate : undefined;
|
|
249
|
+
if (pid === undefined || ppid === undefined) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const bucket = children.get(ppid) ?? [];
|
|
253
|
+
bucket.push(pid);
|
|
254
|
+
children.set(ppid, bucket);
|
|
255
|
+
}
|
|
256
|
+
return collectDescendantsFromChildren(rootPid, children);
|
|
257
|
+
} catch {
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function execFileAsync(command: string, args: readonly string[]): Promise<{ stdout: string; stderr: string }> {
|
|
263
|
+
return new Promise((resolve, reject) => {
|
|
264
|
+
execFile(command, args, { encoding: 'utf8' }, (error, stdout, stderr) => {
|
|
265
|
+
if (error) {
|
|
266
|
+
reject(error);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
resolve({ stdout, stderr });
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function collectProcessTreePids(rootPid: number): Promise<number[]> {
|
|
275
|
+
const descendants = await listDescendantPids(rootPid);
|
|
276
|
+
return [...descendants, rootPid];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function collectDescendantsFromChildren(rootPid: number, children: Map<number, number[]>): number[] {
|
|
280
|
+
const result: number[] = [];
|
|
281
|
+
const queue = [...(children.get(rootPid) ?? [])];
|
|
282
|
+
const seen = new Set<number>(queue);
|
|
283
|
+
while (queue.length > 0) {
|
|
284
|
+
const current = queue.shift();
|
|
285
|
+
if (current === undefined) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
result.push(current);
|
|
289
|
+
for (const child of children.get(current) ?? []) {
|
|
290
|
+
if (!seen.has(child)) {
|
|
291
|
+
seen.add(child);
|
|
292
|
+
queue.push(child);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export const __testHooks = {
|
|
300
|
+
listDescendantPids,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
async function waitForTreeExit(pids: number[], durationMs: number): Promise<boolean> {
|
|
304
|
+
const deadline = Date.now() + durationMs;
|
|
305
|
+
while (true) {
|
|
306
|
+
if (pids.every((pid) => !isProcessAlive(pid))) {
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
if (Date.now() >= deadline) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
const remaining = Math.max(10, Math.min(100, deadline - Date.now()));
|
|
313
|
+
await delay(remaining);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function delay(ms: number): Promise<void> {
|
|
318
|
+
return new Promise((resolve) => {
|
|
319
|
+
const timer = setTimeout(resolve, ms);
|
|
320
|
+
if (typeof (timer as { unref?: () => void }).unref === 'function') {
|
|
321
|
+
(timer as { unref?: () => void }).unref?.();
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
3
|
+
import type { CallToolRequest, ListResourcesRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { loadServerDefinitions, type ServerDefinition } from './config.js';
|
|
5
|
+
import { createPrefixedConsoleLogger, type Logger, type LogLevel, resolveLogLevelFromEnv } from './logging.js';
|
|
6
|
+
import { closeTransportAndWait } from './runtime-process-utils.js';
|
|
7
|
+
import './sdk-patches.js';
|
|
8
|
+
import { shouldResetConnection } from './runtime/errors.js';
|
|
9
|
+
import { resolveOAuthTimeoutFromEnv } from './runtime/oauth.js';
|
|
10
|
+
import { type ClientContext, createClientContext } from './runtime/transport.js';
|
|
11
|
+
import { normalizeTimeout, raceWithTimeout } from './runtime/utils.js';
|
|
12
|
+
|
|
13
|
+
const PACKAGE_NAME = 'mcporter';
|
|
14
|
+
// Keep version in one place by reading package.json; fall back gracefully when bundled without it (e.g., bun bundle).
|
|
15
|
+
const CLIENT_VERSION = (() => {
|
|
16
|
+
try {
|
|
17
|
+
return createRequire(import.meta.url)('../package.json').version as string;
|
|
18
|
+
} catch {
|
|
19
|
+
return process.env.MCPORTER_VERSION ?? '0.0.0-dev';
|
|
20
|
+
}
|
|
21
|
+
})();
|
|
22
|
+
export const MCPORTER_VERSION = CLIENT_VERSION;
|
|
23
|
+
const OAUTH_CODE_TIMEOUT_MS = resolveOAuthTimeoutFromEnv();
|
|
24
|
+
|
|
25
|
+
export interface RuntimeOptions {
|
|
26
|
+
readonly configPath?: string;
|
|
27
|
+
readonly servers?: ServerDefinition[];
|
|
28
|
+
readonly rootDir?: string;
|
|
29
|
+
readonly clientInfo?: {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
};
|
|
33
|
+
readonly logger?: RuntimeLogger;
|
|
34
|
+
readonly oauthTimeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type RuntimeLogger = Logger;
|
|
38
|
+
|
|
39
|
+
export interface CallOptions {
|
|
40
|
+
readonly args?: CallToolRequest['params']['arguments'];
|
|
41
|
+
readonly timeoutMs?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ListToolsOptions {
|
|
45
|
+
readonly includeSchema?: boolean;
|
|
46
|
+
readonly autoAuthorize?: boolean;
|
|
47
|
+
readonly allowCachedAuth?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ConnectOptions {
|
|
51
|
+
readonly maxOAuthAttempts?: number;
|
|
52
|
+
readonly skipCache?: boolean;
|
|
53
|
+
readonly allowCachedAuth?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Runtime {
|
|
57
|
+
listServers(): string[];
|
|
58
|
+
getDefinitions(): ServerDefinition[];
|
|
59
|
+
getDefinition(server: string): ServerDefinition;
|
|
60
|
+
registerDefinition(definition: ServerDefinition, options?: { overwrite?: boolean }): void;
|
|
61
|
+
listTools(server: string, options?: ListToolsOptions): Promise<ServerToolInfo[]>;
|
|
62
|
+
callTool(server: string, toolName: string, options?: CallOptions): Promise<unknown>;
|
|
63
|
+
listResources(server: string, options?: Partial<ListResourcesRequest['params']>): Promise<unknown>;
|
|
64
|
+
connect(server: string): Promise<ClientContext>;
|
|
65
|
+
close(server?: string): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ServerToolInfo {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly description?: string;
|
|
71
|
+
readonly inputSchema?: unknown;
|
|
72
|
+
readonly outputSchema?: unknown;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// createRuntime spins up a pooled MCP runtime from config JSON or provided definitions.
|
|
76
|
+
export async function createRuntime(options: RuntimeOptions = {}): Promise<Runtime> {
|
|
77
|
+
// Build the runtime with either the provided server list or the config file contents.
|
|
78
|
+
const servers =
|
|
79
|
+
options.servers ??
|
|
80
|
+
(await loadServerDefinitions({
|
|
81
|
+
configPath: options.configPath,
|
|
82
|
+
rootDir: options.rootDir,
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
const runtime = new McpRuntime(servers, options);
|
|
86
|
+
return runtime;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// callOnce connects to a server, invokes a single tool, and disposes the connection immediately.
|
|
90
|
+
export async function callOnce(params: {
|
|
91
|
+
server: string;
|
|
92
|
+
toolName: string;
|
|
93
|
+
args?: Record<string, unknown>;
|
|
94
|
+
configPath?: string;
|
|
95
|
+
}): Promise<unknown> {
|
|
96
|
+
const runtime = await createRuntime({ configPath: params.configPath });
|
|
97
|
+
try {
|
|
98
|
+
return await runtime.callTool(params.server, params.toolName, {
|
|
99
|
+
args: params.args,
|
|
100
|
+
});
|
|
101
|
+
} finally {
|
|
102
|
+
await runtime.close(params.server);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class McpRuntime implements Runtime {
|
|
107
|
+
private readonly definitions: Map<string, ServerDefinition>;
|
|
108
|
+
private readonly clients = new Map<string, Promise<ClientContext>>();
|
|
109
|
+
private readonly logger: RuntimeLogger;
|
|
110
|
+
private readonly clientInfo: { name: string; version: string };
|
|
111
|
+
private readonly oauthTimeoutMs?: number;
|
|
112
|
+
|
|
113
|
+
constructor(servers: ServerDefinition[], options: RuntimeOptions = {}) {
|
|
114
|
+
this.definitions = new Map(servers.map((entry) => [entry.name, entry]));
|
|
115
|
+
this.logger = options.logger ?? createConsoleLogger();
|
|
116
|
+
this.clientInfo = options.clientInfo ?? {
|
|
117
|
+
name: PACKAGE_NAME,
|
|
118
|
+
version: CLIENT_VERSION,
|
|
119
|
+
};
|
|
120
|
+
this.oauthTimeoutMs = options.oauthTimeoutMs;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// listServers returns configured names sorted alphabetically for stable CLI output.
|
|
124
|
+
listServers(): string[] {
|
|
125
|
+
return [...this.definitions.keys()].sort((a, b) => a.localeCompare(b));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// getDefinitions exposes raw server metadata to consumers such as the CLI.
|
|
129
|
+
getDefinitions(): ServerDefinition[] {
|
|
130
|
+
return [...this.definitions.values()];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// getDefinition throws when the caller requests an unknown server name.
|
|
134
|
+
getDefinition(server: string): ServerDefinition {
|
|
135
|
+
const definition = this.definitions.get(server);
|
|
136
|
+
if (!definition) {
|
|
137
|
+
throw new Error(`Unknown MCP server '${server}'.`);
|
|
138
|
+
}
|
|
139
|
+
return definition;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
registerDefinition(definition: ServerDefinition, options: { overwrite?: boolean } = {}): void {
|
|
143
|
+
if (!options.overwrite && this.definitions.has(definition.name)) {
|
|
144
|
+
throw new Error(`MCP server '${definition.name}' already exists.`);
|
|
145
|
+
}
|
|
146
|
+
this.definitions.set(definition.name, definition);
|
|
147
|
+
this.clients.delete(definition.name);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// listTools queries tool metadata and optionally includes schemas when requested.
|
|
151
|
+
async listTools(server: string, options: ListToolsOptions = {}): Promise<ServerToolInfo[]> {
|
|
152
|
+
// Toggle auto authorization so list can run without forcing OAuth flows.
|
|
153
|
+
const autoAuthorize = options.autoAuthorize !== false;
|
|
154
|
+
const context = await this.connect(server, {
|
|
155
|
+
maxOAuthAttempts: autoAuthorize ? undefined : 0,
|
|
156
|
+
skipCache: !autoAuthorize,
|
|
157
|
+
allowCachedAuth: options.allowCachedAuth,
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
const tools: ServerToolInfo[] = [];
|
|
161
|
+
let cursor: string | undefined;
|
|
162
|
+
do {
|
|
163
|
+
const response = await context.client.listTools(cursor ? { cursor } : undefined);
|
|
164
|
+
tools.push(
|
|
165
|
+
...(response.tools ?? []).map((tool) => ({
|
|
166
|
+
name: tool.name,
|
|
167
|
+
description: tool.description ?? undefined,
|
|
168
|
+
inputSchema: options.includeSchema ? tool.inputSchema : undefined,
|
|
169
|
+
outputSchema: options.includeSchema ? tool.outputSchema : undefined,
|
|
170
|
+
}))
|
|
171
|
+
);
|
|
172
|
+
cursor = response.nextCursor ?? undefined;
|
|
173
|
+
} while (cursor);
|
|
174
|
+
|
|
175
|
+
return tools;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
// Keep-alive STDIO transports often die when Chrome closes; drop the cached client
|
|
178
|
+
// so the next call spins up a fresh process instead of reusing the broken handle.
|
|
179
|
+
await this.resetConnectionOnError(server, error);
|
|
180
|
+
throw error;
|
|
181
|
+
} finally {
|
|
182
|
+
if (!autoAuthorize) {
|
|
183
|
+
await context.client.close().catch(() => {});
|
|
184
|
+
await closeTransportAndWait(this.logger, context.transport).catch(() => {});
|
|
185
|
+
await context.oauthSession?.close().catch(() => {});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// callTool executes a tool using the args provided by the caller.
|
|
191
|
+
async callTool(server: string, toolName: string, options: CallOptions = {}): Promise<unknown> {
|
|
192
|
+
try {
|
|
193
|
+
const { client } = await this.connect(server);
|
|
194
|
+
const params: CallToolRequest['params'] = {
|
|
195
|
+
name: toolName,
|
|
196
|
+
arguments: options.args ?? {},
|
|
197
|
+
};
|
|
198
|
+
// Forward the requested timeout to the MCP client so server-side requests don't hit the SDK's
|
|
199
|
+
// default 60s cap. Keep our own outer race as a second guard.
|
|
200
|
+
const timeoutMs = normalizeTimeout(options.timeoutMs);
|
|
201
|
+
const resultPromise = client.callTool(params, undefined, {
|
|
202
|
+
timeout: timeoutMs,
|
|
203
|
+
// Long runs (e.g., GPT-5 Pro) emit progress/logging; allow that to refresh the timer.
|
|
204
|
+
resetTimeoutOnProgress: true,
|
|
205
|
+
maxTotalTimeout: timeoutMs,
|
|
206
|
+
});
|
|
207
|
+
if (!timeoutMs) {
|
|
208
|
+
return await resultPromise;
|
|
209
|
+
}
|
|
210
|
+
return await raceWithTimeout(resultPromise, timeoutMs);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
// Runtime timeouts and transport crashes should tear down the cached connection so
|
|
213
|
+
// the daemon (or direct runtime) can relaunch the MCP server on the next attempt.
|
|
214
|
+
await this.resetConnectionOnError(server, error);
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// listResources delegates to the MCP resources/list method with passthrough params.
|
|
220
|
+
async listResources(server: string, options: Partial<ListResourcesRequest['params']> = {}): Promise<unknown> {
|
|
221
|
+
try {
|
|
222
|
+
const { client } = await this.connect(server);
|
|
223
|
+
return await client.listResources(options as ListResourcesRequest['params']);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
// Fatal listResources errors usually mean the underlying transport has gone away.
|
|
226
|
+
await this.resetConnectionOnError(server, error);
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// connect lazily instantiates a client context per server and memoizes it.
|
|
232
|
+
async connect(server: string, options: ConnectOptions = {}): Promise<ClientContext> {
|
|
233
|
+
// Reuse cached connections unless the caller explicitly opted out.
|
|
234
|
+
const normalized = server.trim();
|
|
235
|
+
|
|
236
|
+
const useCache = options.skipCache !== true && options.maxOAuthAttempts === undefined;
|
|
237
|
+
|
|
238
|
+
if (useCache) {
|
|
239
|
+
const existing = this.clients.get(normalized);
|
|
240
|
+
if (existing) {
|
|
241
|
+
return existing;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const definition = this.definitions.get(normalized);
|
|
246
|
+
if (!definition) {
|
|
247
|
+
throw new Error(`Unknown MCP server '${normalized}'.`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const connection = createClientContext(definition, this.logger, this.clientInfo, {
|
|
251
|
+
maxOAuthAttempts: options.maxOAuthAttempts,
|
|
252
|
+
oauthTimeoutMs: this.oauthTimeoutMs ?? OAUTH_CODE_TIMEOUT_MS,
|
|
253
|
+
onDefinitionPromoted: (promoted) => this.definitions.set(promoted.name, promoted),
|
|
254
|
+
allowCachedAuth: options.allowCachedAuth,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (useCache) {
|
|
258
|
+
this.clients.set(normalized, connection);
|
|
259
|
+
try {
|
|
260
|
+
return await connection;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
this.clients.delete(normalized);
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return connection;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// close tears down transports (and OAuth sessions) for a single server or all servers.
|
|
271
|
+
async close(server?: string): Promise<void> {
|
|
272
|
+
if (server) {
|
|
273
|
+
const normalized = server.trim();
|
|
274
|
+
const context = await this.clients.get(normalized);
|
|
275
|
+
if (!context) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
await context.client.close().catch(() => {});
|
|
279
|
+
await closeTransportAndWait(this.logger, context.transport).catch(() => {});
|
|
280
|
+
await context.oauthSession?.close().catch(() => {});
|
|
281
|
+
this.clients.delete(normalized);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
for (const [name, promise] of this.clients.entries()) {
|
|
286
|
+
try {
|
|
287
|
+
const context = await promise;
|
|
288
|
+
await context.client.close().catch(() => {});
|
|
289
|
+
await closeTransportAndWait(this.logger, context.transport).catch(() => {});
|
|
290
|
+
await context.oauthSession?.close().catch(() => {});
|
|
291
|
+
} finally {
|
|
292
|
+
this.clients.delete(name);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private async resetConnectionOnError(server: string, error: unknown): Promise<void> {
|
|
298
|
+
if (!shouldResetConnection(error)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const normalized = server.trim();
|
|
302
|
+
if (!this.clients.has(normalized)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
// Reuse the existing close() helper so transport shutdown stays consistent with
|
|
307
|
+
// normal runtime disposal (wait for STDIO children, close OAuth sessions, etc.).
|
|
308
|
+
await this.close(normalized);
|
|
309
|
+
} catch (closeError) {
|
|
310
|
+
const detail = closeError instanceof Error ? closeError.message : String(closeError);
|
|
311
|
+
this.logger.warn(`Failed to reset '${normalized}' after error: ${detail}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// createConsoleLogger produces the default runtime logger honoring MCPORTER_LOG_LEVEL.
|
|
317
|
+
function createConsoleLogger(level: LogLevel = resolveLogLevelFromEnv()): RuntimeLogger {
|
|
318
|
+
return createPrefixedConsoleLogger('mcporter', level);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export { readJsonFile, writeJsonFile } from './fs-json.js';
|