JebProvider throws when REA_JEB_MCP_URL fails endpoint validation, and the composition built it eagerly for the CLI and every MCP connection. A malformed value, or http://localhost:8425/mcp, therefore crashed every CLI command with a stack trace and failed every MCP connection with an internal server error. The composition now parses the endpoint first and, when it is unusable, returns a JEB port that reports not_configured availability and a ConfigurationError naming REA_JEB_MCP_URL. Fixes #2143 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import type { JebAnalysisPort } from "../application/jeb/JebAnalysisPort.js";
|
|
import { ConfigurationError } from "../domain/configurationErrors.js";
|
|
import { err } from "../domain/result.js";
|
|
import type { JebMcpConnectionFactory } from "../jeb/JebMcpConnection.js";
|
|
import { parseJebMcpEndpoint } from "../jeb/JebMcpEndpoint.js";
|
|
import { JebProvider } from "../jeb/JebProvider.js";
|
|
|
|
/**
|
|
* Construct one JEB provider bound to the caller-selected MCP endpoint. An
|
|
* unusable endpoint makes only JEB unavailable; every other CLI command and
|
|
* MCP tool is composed alongside it.
|
|
*/
|
|
export const createJebAnalysisProvider = (
|
|
environment: Readonly<Record<string, string | undefined>> = process.env,
|
|
connectionFactory?: JebMcpConnectionFactory,
|
|
): JebAnalysisPort => {
|
|
const endpoint = parseJebMcpEndpoint(environment.REA_JEB_MCP_URL);
|
|
if (!endpoint.ok) {
|
|
const constraint =
|
|
typeof endpoint.error.cause === "string"
|
|
? endpoint.error.cause
|
|
: endpoint.error.message;
|
|
return unconfiguredJebProvider(
|
|
new ConfigurationError("Invalid REA environment configuration", {
|
|
cause: endpoint.error,
|
|
settings: [{ setting: "REA_JEB_MCP_URL", constraint }],
|
|
}),
|
|
);
|
|
}
|
|
return new JebProvider({
|
|
environment,
|
|
...(connectionFactory === undefined ? {} : { connectionFactory }),
|
|
});
|
|
};
|
|
|
|
const unconfiguredJebProvider = (
|
|
error: ConfigurationError,
|
|
): JebAnalysisPort => ({
|
|
inspectAvailability: () =>
|
|
Promise.resolve({
|
|
status: "unavailable",
|
|
code: "not_configured",
|
|
reason: `REA_JEB_MCP_URL is invalid: ${error.settings[0]?.constraint ?? error.message}`,
|
|
diagnostics: { setting: "REA_JEB_MCP_URL" },
|
|
}),
|
|
close: () => Promise.resolve(),
|
|
execute: () => Promise.resolve(err(error)),
|
|
});
|