mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 04:11:03 +00:00
fix: address review feedback - fix env JSDoc, warn on dropped headers, await server close
This commit is contained in:
committed by
Peter Steinberger
parent
d89bfed5cc
commit
bf8303370e
@@ -11,7 +11,10 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function toStringRecord(value: unknown): Record<string, string> | undefined {
|
||||
function toStringRecord(
|
||||
value: unknown,
|
||||
warnDropped?: (key: string, entry: unknown) => void,
|
||||
): Record<string, string> | undefined {
|
||||
if (!isRecord(value)) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -23,13 +26,17 @@ function toStringRecord(value: unknown): Record<string, string> | undefined {
|
||||
if (typeof entry === "number" || typeof entry === "boolean") {
|
||||
return [key, String(entry)] as const;
|
||||
}
|
||||
warnDropped?.(key, entry);
|
||||
return null;
|
||||
})
|
||||
.filter((entry): entry is readonly [string, string] => entry !== null);
|
||||
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
||||
}
|
||||
|
||||
export function resolveSseMcpServerLaunchConfig(raw: unknown): SseMcpServerLaunchResult {
|
||||
export function resolveSseMcpServerLaunchConfig(
|
||||
raw: unknown,
|
||||
options?: { onDroppedHeader?: (key: string, value: unknown) => void },
|
||||
): SseMcpServerLaunchResult {
|
||||
if (!isRecord(raw)) {
|
||||
return { ok: false, reason: "server config must be an object" };
|
||||
}
|
||||
@@ -53,7 +60,7 @@ export function resolveSseMcpServerLaunchConfig(raw: unknown): SseMcpServerLaunc
|
||||
ok: true,
|
||||
config: {
|
||||
url,
|
||||
headers: toStringRecord(raw.headers),
|
||||
headers: toStringRecord(raw.headers, options?.onDroppedHeader),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -188,7 +188,9 @@ describe("createBundleMcpToolRuntime", () => {
|
||||
await runtime.dispose();
|
||||
}
|
||||
} finally {
|
||||
httpServer.close();
|
||||
await new Promise<void>((resolve, reject) =>
|
||||
httpServer.close((err) => (err ? reject(err) : resolve())),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,7 +153,13 @@ function resolveTransport(
|
||||
}
|
||||
|
||||
// Try SSE (url-based servers).
|
||||
const sseLaunch = resolveSseMcpServerLaunchConfig(rawServer);
|
||||
const sseLaunch = resolveSseMcpServerLaunchConfig(rawServer, {
|
||||
onDroppedHeader: (key) => {
|
||||
logWarn(
|
||||
`bundle-mcp: server "${serverName}": header "${key}" has an unsupported value type and was ignored.`,
|
||||
);
|
||||
},
|
||||
});
|
||||
if (sseLaunch.ok) {
|
||||
const headers: Record<string, string> = {
|
||||
...sseLaunch.config.headers,
|
||||
|
||||
@@ -3,7 +3,7 @@ export type McpServerConfig = {
|
||||
command?: string;
|
||||
/** Stdio transport: arguments for the command. */
|
||||
args?: string[];
|
||||
/** Environment variables passed to the server process (stdio) or as headers (SSE). */
|
||||
/** Environment variables passed to the server process (stdio only). */
|
||||
env?: Record<string, string | number | boolean>;
|
||||
/** Working directory for stdio server. */
|
||||
cwd?: string;
|
||||
|
||||
Reference in New Issue
Block a user