Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const LogId = {
streamableHttpTransportCloseFailure: mongoLogId(1_006_006),
streamableHttpTransportKeepAliveFailure: mongoLogId(1_006_007),
streamableHttpTransportKeepAlive: mongoLogId(1_006_008),
streamableHttpTransportHttpHostWarning: mongoLogId(1_006_009),

exportCleanupError: mongoLogId(1_007_001),
exportCreationError: mongoLogId(1_007_002),
Expand Down
15 changes: 15 additions & 0 deletions src/transports/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ export class StreamableHttpRunner extends TransportRunnerBase {
message: `Server started on ${this.serverAddress}`,
noRedaction: true,
});

if (this.shouldWarnAboutHttpHost(this.userConfig.httpHost)) {
this.logger.warning({
id: LogId.streamableHttpTransportHttpHostWarning,
context: "streamableHttpTransport",
message: `Binding to ${this.userConfig.httpHost} can expose the MCP Server to the entire local network, which allows other devices on the same network to potentially access the MCP Server. This is a security risk and could allow unauthorized access to your database context.`,
noRedaction: true,
});
}
}

async closeTransport(): Promise<void> {
Expand Down Expand Up @@ -243,4 +252,10 @@ export class StreamableHttpRunner extends TransportRunnerBase {
});
};
}

private shouldWarnAboutHttpHost(httpHost: string): boolean {
const host = httpHost.trim();
const safeHosts = new Set(["127.0.0.1", "localhost", "::1"]);
return host === "0.0.0.0" || host === "::" || (!safeHosts.has(host) && host !== "");
}
}
Loading