🔁 feat: Allow "http" as Alias for "streamable-http" in MCP Options (#8624)

- Updated StreamableHTTPOptionsSchema to accept "http" alongside "streamable-http".
- Enhanced isStreamableHTTPOptions function to handle both types and validate URLs accordingly.
- Added tests to ensure correct processing of "http" type options and rejection of websocket URLs.
This commit is contained in:
Danny Avila 2025-07-23 10:26:40 -04:00 committed by GitHub
parent a01536ddb7
commit 365e3bca95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 65 additions and 4 deletions

View file

@ -45,9 +45,12 @@ function isSSEOptions(options: t.MCPOptions): options is t.SSEOptions {
* @returns True if options are for a streamable HTTP transport
*/
function isStreamableHTTPOptions(options: t.MCPOptions): options is t.StreamableHTTPOptions {
if ('url' in options && options.type === 'streamable-http') {
const protocol = new URL(options.url).protocol;
return protocol !== 'ws:' && protocol !== 'wss:';
if ('url' in options && 'type' in options) {
const optionType = options.type as string;
if (optionType === 'streamable-http' || optionType === 'http') {
const protocol = new URL(options.url).protocol;
return protocol !== 'ws:' && protocol !== 'wss:';
}
}
return false;
}
@ -142,6 +145,7 @@ export class MCPConnection extends EventEmitter {
} else if (isWebSocketOptions(options)) {
type = 'websocket';
} else if (isStreamableHTTPOptions(options)) {
// Could be either 'streamable-http' or 'http', normalize to 'streamable-http'
type = 'streamable-http';
} else if (isSSEOptions(options)) {
type = 'sse';