Allow --mcp flag to accept URLs for streamable-http servers (#8119)

* Allow --mcp flag to accept URLs for streamable-http servers

When a URL starting with http:// or https:// is passed to the --mcp flag,
it will now automatically be configured as a streamable-http MCP server
connection instead of trying to load it from the hub.

This allows users to run:
  cn --mcp https://docs.continue.dev/mcp

The URL will be parsed and configured with:
- type: streamable-http
- url: the provided URL
- name: hostname from the URL

Fixes CON-4285

Generated with [Continue](https://continue.dev)

Co-authored-by: Username <nate@continue.dev>

* fix: tests

---------

Co-authored-by: Continue Agent <agent@continue.dev>
Co-authored-by: Username <nate@continue.dev>
Co-authored-by: Nate <sestinj@gmail.com>
This commit is contained in:
continue[bot] 2025-10-08 09:49:36 -07:00 • committed by GitHub
parent 9164448c73
commit 7b17637763
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 122 additions and 17 deletions

View file

@ -196,11 +196,12 @@ describe("ConfigEnhancer", () => {
});
it("should prepend MCPs from --mcp flag", async () => {
// Mock loadPackagesFromHub to return test MCPs
const { loadPackagesFromHub } = await import("./hubLoader.js");
(loadPackagesFromHub as any).mockResolvedValueOnce([
{ name: "New-MCP", command: "new-mcp" },
]);
// Mock loadPackageFromHub to return test MCP (singular call for each MCP)
const { loadPackageFromHub } = await import("./hubLoader.js");
(loadPackageFromHub as any).mockResolvedValueOnce({
name: "New-MCP",
command: "new-mcp",
});
// Set up existing MCPs in config
mockConfig.mcpServers = [{ name: "Existing-MCP", command: "existing-mcp" }];
@ -223,6 +224,70 @@ describe("ConfigEnhancer", () => {
});
});
it("should handle URLs in --mcp flag as streamable-http servers", async () => {
// Set up existing MCPs in config
mockConfig.mcpServers = [{ name: "Existing-MCP", command: "existing-mcp" }];
const options: BaseCommandOptions = {
mcp: ["https://docs.continue.dev/mcp"],
};
const config = await enhancer.enhanceConfig(mockConfig, options);
// URL should be converted to streamable-http MCP configuration
expect(config.mcpServers).toHaveLength(2);
expect(config.mcpServers?.[0]).toEqual({
name: "docs.continue.dev",
type: "streamable-http",
url: "https://docs.continue.dev/mcp",
});
expect(config.mcpServers?.[1]).toEqual({
name: "Existing-MCP",
command: "existing-mcp",
});
});
it("should handle mix of URLs and hub slugs in --mcp flag", async () => {
// Mock loadPackageFromHub to return test MCP for hub slug
const { loadPackageFromHub } = await import("./hubLoader.js");
(loadPackageFromHub as any).mockResolvedValueOnce({
name: "Hub-MCP",
command: "hub-mcp",
});
const options: BaseCommandOptions = {
mcp: ["https://example.com/mcp", "test/hub-mcp"],
};
const config = await enhancer.enhanceConfig(mockConfig, options);
expect(config.mcpServers).toHaveLength(2);
expect(config.mcpServers?.[0]).toEqual({
name: "example.com",
type: "streamable-http",
url: "https://example.com/mcp",
});
expect(config.mcpServers?.[1]).toEqual({
name: "Hub-MCP",
command: "hub-mcp",
});
});
it("should handle http:// URLs in --mcp flag", async () => {
const options: BaseCommandOptions = {
mcp: ["http://localhost:8080/mcp"],
};
const config = await enhancer.enhanceConfig(mockConfig, options);
expect(config.mcpServers).toHaveLength(1);
expect(config.mcpServers?.[0]).toEqual({
name: "localhost",
type: "streamable-http",
url: "http://localhost:8080/mcp",
});
});
it("should handle workflow integration gracefully when no workflow", async () => {
// The mocked service container returns null workflow state
const options: BaseCommandOptions = {

View file

@ -171,7 +171,28 @@ export class ConfigEnhancer {
config: AssistantUnrolled,
mcps: string[],
): Promise<AssistantUnrolled> {
const processedMcps = await loadPackagesFromHub(mcps, mcpProcessor);
const processedMcps: any[] = [];
// Process each MCP spec - check if it's a URL or hub slug
for (const mcpSpec of mcps) {
try {
// Check if it's a URL (starts with http:// or https://)
if (mcpSpec.startsWith("http://") || mcpSpec.startsWith("https://")) {
// Create a streamable-http MCP configuration
processedMcps.push({
name: new URL(mcpSpec).hostname,
type: "streamable-http",
url: mcpSpec,
});
} else {
// Otherwise, treat it as a hub slug
const hubMcp = await loadPackageFromHub(mcpSpec, mcpProcessor);
processedMcps.push(hubMcp);
}
} catch (error: any) {
logger.warn(`Failed to load MCP "${mcpSpec}": ${error.message}`);
}
}
// Clone the config to avoid mutating the original
const modifiedConfig = { ...config };

View file

@ -554,11 +554,19 @@ describe("Workflow Integration Tests", () => {
tools: "owner/mcp1, another/mcp2:specific_tool",
};
mockLoadPackageFromHub.mockResolvedValue(workflowWithTools);
mockLoadPackagesFromHub.mockResolvedValue([
{ name: "mcp1" },
{ name: "mcp2" },
]);
// Clear the default mock and setup specific mocks
mockLoadPackageFromHub.mockReset();
// First call loads the workflow file
mockLoadPackageFromHub.mockResolvedValueOnce(workflowWithTools);
// Second call loads the workflow model
mockLoadPackageFromHub.mockResolvedValueOnce({
name: "gpt-4-workflow",
provider: "openai",
});
// Third call loads mcp1
mockLoadPackageFromHub.mockResolvedValueOnce({ name: "mcp1" });
// Fourth call loads mcp2
mockLoadPackageFromHub.mockResolvedValueOnce({ name: "mcp2" });
await workflowService.initialize("owner/workflow");
@ -573,6 +581,7 @@ describe("Workflow Integration Tests", () => {
);
expect(enhancedConfig.mcpServers).toHaveLength(3);
// MCPs are prepended in the order they are loaded
expect(enhancedConfig.mcpServers?.[0]).toEqual({ name: "mcp1" });
expect(enhancedConfig.mcpServers?.[1]).toEqual({ name: "mcp2" });
expect(enhancedConfig.mcpServers?.[2]).toEqual({ name: "existing-mcp" });
@ -584,7 +593,8 @@ describe("Workflow Integration Tests", () => {
tools: undefined,
};
mockLoadPackageFromHub.mockResolvedValue(workflowWithoutTools);
mockLoadPackageFromHub.mockReset();
mockLoadPackageFromHub.mockResolvedValueOnce(workflowWithoutTools);
await workflowService.initialize("owner/workflow");
const baseConfig = {
@ -607,13 +617,22 @@ describe("Workflow Integration Tests", () => {
tools: "owner/mcp1, owner/mcp1:tool1, owner/mcp1:tool2",
};
mockLoadPackageFromHub.mockResolvedValue(workflowWithDuplicateTools);
mockLoadPackagesFromHub.mockResolvedValue([{ name: "mcp1" }]);
// Clear the default mock and setup specific mocks
mockLoadPackageFromHub.mockReset();
// First call loads the workflow file
mockLoadPackageFromHub.mockResolvedValueOnce(workflowWithDuplicateTools);
// Second call loads the workflow model
mockLoadPackageFromHub.mockResolvedValueOnce({
name: "gpt-4-workflow",
provider: "openai",
});
// Third call: The parseWorkflowTools will extract only unique MCP servers, so only one loadPackageFromHub call
mockLoadPackageFromHub.mockResolvedValueOnce({ name: "mcp1" });
await workflowService.initialize("owner/workflow");
const baseConfig = {
mcpServers: [{ name: "mcp1" }], // Already exists
mcpServers: [{ name: "existing-mcp" }], // Changed to avoid confusion
};
const enhancedConfig = await configEnhancer.enhanceConfig(
@ -622,10 +641,10 @@ describe("Workflow Integration Tests", () => {
workflowService.getState(),
);
// Should not deduplicate since we simplified the logic
// parseWorkflowTools deduplicates, so we only get mcp1 once
expect(enhancedConfig.mcpServers).toHaveLength(2);
expect(enhancedConfig.mcpServers?.[0]).toEqual({ name: "mcp1" });
expect(enhancedConfig.mcpServers?.[1]).toEqual({ name: "mcp1" });
expect(enhancedConfig.mcpServers?.[1]).toEqual({ name: "existing-mcp" });
});
});
});