Elffuss BraidHub

kikocis/continue public

fix: mcp now working
Changesetfc89067dc2f197c70068671a5236feb29fba9860fbfdc67eafe60e2672b005dc
AuthorNate <sestinj@gmail.com> · 2025-08-24 15:39 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-24 15:39 -07:00
Parents675e3d10e9f3

Browse the files at this changeset

5 files changed

modified extensions/cli/src/configEnhancer.test.ts +52 −0
@@ -127,4 +127,56 @@
127127 expect(config.rules?.[0]).toBe("./rules/my-rule.md");
128128 expect(config.rules?.[1]).toBe("/absolute/path/rule.txt");
129129 });
130+
131+ it("should prepend models from --model flag to make them default", async () => {
132+ // Mock loadPackagesFromHub to return test models
133+ const { loadPackagesFromHub } = await import("./hubLoader.js");
134+ (loadPackagesFromHub as any).mockResolvedValueOnce([
135+ { name: "GPT-5", provider: "openai", model: "gpt-5" },
136+ { name: "Claude-3", provider: "anthropic", model: "claude-3" },
137+ ]);
138+
139+ // Set up existing models in config
140+ mockConfig.models = [
141+ { name: "GPT-4", provider: "openai", model: "gpt-4" },
142+ { name: "Claude-2", provider: "anthropic", model: "claude-2" },
143+ ];
144+
145+ const options: BaseCommandOptions = {
146+ model: ["openai/gpt-5", "anthropic/claude-3"],
147+ };
148+
149+ const config = await enhancer.enhanceConfig(mockConfig, options);
150+
151+ // Models from --model flag should be prepended (at the start)
152+ expect(config.models).toHaveLength(4);
153+ expect(config.models?.[0]).toEqual({ name: "GPT-5", provider: "openai", model: "gpt-5" });
154+ expect(config.models?.[1]).toEqual({ name: "Claude-3", provider: "anthropic", model: "claude-3" });
155+ expect(config.models?.[2]).toEqual({ name: "GPT-4", provider: "openai", model: "gpt-4" });
156+ expect(config.models?.[3]).toEqual({ name: "Claude-2", provider: "anthropic", model: "claude-2" });
157+ });
158+
159+ it("should prepend MCPs from --mcp flag", async () => {
160+ // Mock loadPackagesFromHub to return test MCPs
161+ const { loadPackagesFromHub } = await import("./hubLoader.js");
162+ (loadPackagesFromHub as any).mockResolvedValueOnce([
163+ { name: "New-MCP", command: "new-mcp" },
164+ ]);
165+
166+ // Set up existing MCPs in config
167+ mockConfig.mcpServers = [
168+ { name: "Existing-MCP", command: "existing-mcp" },
169+ ];
170+
171+ const options: BaseCommandOptions = {
172+ mcp: ["test/new-mcp"],
173+ };
174+
175+ const config = await enhancer.enhanceConfig(mockConfig, options);
176+
177+ // MCPs from --mcp flag should be prepended (at the start)
178+ expect(config.mcpServers).toHaveLength(2);
179+ expect(config.mcpServers?.[0]).toEqual({ name: "New-MCP", command: "new-mcp" });
180+ expect(config.mcpServers?.[1]).toEqual({ name: "Existing-MCP", command: "existing-mcp" });
181+ });
130182 });
No newline at the end of the file
modified extensions/cli/src/configEnhancer.ts +4 −4
@@ -103,11 +103,11 @@
103103 // Clone the config to avoid mutating the original
104104 const modifiedConfig = { ...config };
105105
106- // Add processed MCPs to existing mcpServers array
106+ // Prepend processed MCPs to existing mcpServers array for consistency
107107 const existingMcpServers = (modifiedConfig as any).mcpServers || [];
108108 (modifiedConfig as any).mcpServers = [
109- ...existingMcpServers,
110109 ...processedMcps,
110+ ...existingMcpServers,
111111 ];
112112
113113 return modifiedConfig;
@@ -125,9 +125,9 @@
125125 // Clone the config to avoid mutating the original
126126 const modifiedConfig = { ...config };
127127
128- // Add processed models to existing models array
128+ // Prepend processed models to existing models array so they become the default
129129 const existingModels = (modifiedConfig as any).models || [];
130- (modifiedConfig as any).models = [...existingModels, ...processedModels];
130+ (modifiedConfig as any).models = [...processedModels, ...existingModels];
131131
132132 return modifiedConfig;
133133 }
modified extensions/cli/src/hubLoader.test.ts +19 −12
@@ -93,7 +93,11 @@
9393 });
9494
9595 const result = await loadPackageFromHub("owner/mcp", mcpProcessor);
96- expect(result).toEqual(mcpConfig);
96+ // Should parse the YAML content, not return the wrapper
97+ expect(result).toEqual({
98+ name: "test-mcp",
99+ version: "1.0.0"
100+ });
97101 });
98102
99103 it("should handle missing files", async () => {
@@ -186,11 +190,12 @@
186190
187191 expect(result).toBeDefined();
188192 expect(typeof result).toBe("object");
189- // The registry returns an object with a content field containing the YAML/JSON
190- expect(result).toHaveProperty("content");
191- expect(typeof result.content).toBe("string");
192- // The content should contain MCP configuration
193- expect(result.content).toContain("mcp");
193+ // Should now return the parsed MCP configuration
194+ expect(result).toHaveProperty("name");
195+ expect(typeof result.name).toBe("string");
196+ // The MCP should have type and url properties
197+ expect(result).toHaveProperty("type");
198+ expect(result).toHaveProperty("url");
194199 }, 30000);
195200
196201 it("should load model from real hub: openai/gpt-5", async () => {
@@ -203,12 +208,14 @@
203208
204209 expect(result).toBeDefined();
205210 expect(typeof result).toBe("object");
206- // The registry returns an object with a content field containing the model configuration
207- expect(result).toHaveProperty("content");
208- expect(typeof result.content).toBe("string");
209- // The content should contain model configuration
210- expect(result.content).toContain("model");
211- expect(result.content).toContain("gpt-5");
211+ // Should now return the extracted model from the models array
212+ expect(result).toHaveProperty("name");
213+ expect(result).toHaveProperty("provider");
214+ expect(result).toHaveProperty("model");
215+ // Check that the model properties are correct
216+ expect(result.provider).toBe("openai");
217+ expect(result.model).toBe("gpt-5");
218+ expect(result.name).toBe("GPT-5");
212219 }, 30000);
213220
214221 it("should load prompt from real hub: launchdarkly/using-flags", async () => {
modified extensions/cli/src/hubLoader.ts +37 −7
@@ -34,12 +34,21 @@
3434 type: "mcp",
3535 expectedFileExtensions: [".json", ".yaml", ".yml"],
3636 parseContent: async (content: string, filename: string) => {
37+ let parsed;
3738 if (filename.endsWith(".json")) {
38- return JSON.parse(content);
39+ parsed = JSON.parse(content);
3940 } else {
4041 const yaml = await import("yaml");
41- return yaml.parse(content);
42+ parsed = yaml.parse(content);
4243 }
44+
45+ // If the parsed content has an 'mcpServers' array, extract the first MCP server
46+ // This handles hub packages that return a full config block
47+ if (parsed.mcpServers && Array.isArray(parsed.mcpServers) && parsed.mcpServers.length > 0) {
48+ return parsed.mcpServers[0];
49+ }
50+
51+ return parsed;
4352 },
4453 };
4554
@@ -50,12 +59,21 @@
5059 type: "model",
5160 expectedFileExtensions: [".json", ".yaml", ".yml"],
5261 parseContent: async (content: string, filename: string) => {
62+ let parsed;
5363 if (filename.endsWith(".json")) {
54- return JSON.parse(content);
64+ parsed = JSON.parse(content);
5565 } else {
5666 const yaml = await import("yaml");
57- return yaml.parse(content);
67+ parsed = yaml.parse(content);
68+ }
69+
70+ // If the parsed content has a 'models' array, extract the first model
71+ // This handles hub packages that return a full config block
72+ if (parsed.models && Array.isArray(parsed.models) && parsed.models.length > 0) {
73+ return parsed.models[0];
5874 }
75+
76+ return parsed;
5977 },
6078 };
6179
@@ -109,9 +127,21 @@
109127
110128 // Check if this is a registry endpoint (returns JSON directly) or a zip file
111129 if (processor.type === "mcp" || processor.type === "model") {
112- // Registry endpoints return JSON directly
113- const jsonContent = await response.json();
114- return jsonContent;
130+ // Registry endpoints return JSON with a 'content' field containing YAML/JSON
131+ const jsonResponse = await response.json();
132+
133+ // Extract and parse the content field
134+ if (jsonResponse.content) {
135+ // Parse the YAML/JSON content
136+ const parsedContent = await processor.parseContent(
137+ jsonResponse.content,
138+ `${slug}.yaml`,
139+ );
140+ return parsedContent;
141+ } else {
142+ // If there's no content field, return the response as-is (backward compatibility)
143+ return jsonResponse;
144+ }
115145 } else {
116146 // v0 endpoints return zip files
117147 const arrayBuffer = await response.arrayBuffer();
modified extensions/cli/src/loadMcpFromHub.test.ts +6 −1
@@ -62,7 +62,12 @@
6262 });
6363
6464 const result = await loadMcpFromHub("continuedev/test-mcp");
65- expect(result).toEqual(mockConfig);
65+ // Should now parse the YAML content and return the parsed object
66+ expect(result).toEqual({
67+ name: "test-mcp",
68+ command: "npx test-mcp",
69+ args: ["--port", 3000]
70+ });
6671 });
6772
6873 it("should handle missing configuration files", async () => {