-
Notifications
You must be signed in to change notification settings - Fork 355
Refactor MCP gateway converters to shared pipeline and thin engine adapters #26858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelikhan
merged 3 commits into
main
from
copilot/refactor-mcp-gateway-converter-pipeline
Apr 17, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // @ts-check | ||
| import { describe, it, expect } from "vitest"; | ||
| import fs from "fs"; | ||
| import os from "os"; | ||
| import path from "path"; | ||
|
|
||
| import { rewriteUrl, filterAndTransformServers, writeSecureOutput } from "./convert_gateway_config_shared.cjs"; | ||
| import { transformClaudeEntry } from "./convert_gateway_config_claude.cjs"; | ||
| import { transformCopilotEntry } from "./convert_gateway_config_copilot.cjs"; | ||
| import { transformGeminiEntry } from "./convert_gateway_config_gemini.cjs"; | ||
| import { toCodexTomlSection } from "./convert_gateway_config_codex.cjs"; | ||
|
|
||
| describe("convert gateway config shared pipeline", () => { | ||
| it("rewrites gateway urls to the provided domain/port", () => { | ||
| const rewritten = rewriteUrl("http://old.example:81/mcp/github", "http://host.docker.internal:80"); | ||
| expect(rewritten).toBe("http://host.docker.internal:80/mcp/github"); | ||
| }); | ||
|
|
||
| it("filters CLI-mounted servers before applying engine transforms", () => { | ||
| const servers = { | ||
| github: { url: "http://old/mcp/github" }, | ||
| playwright: { url: "http://old/mcp/playwright" }, | ||
| }; | ||
| const filtered = filterAndTransformServers(servers, new Set(["playwright"]), (_name, entry) => entry); | ||
| expect(filtered).toEqual({ | ||
| github: { url: "http://old/mcp/github" }, | ||
| }); | ||
| }); | ||
|
|
||
| it("enforces output file permission mode to 0o600 even when file already exists", () => { | ||
| const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), "gateway-config-")); | ||
| const outputPath = path.join(outputDir, "mcp-servers.json"); | ||
| fs.writeFileSync(outputPath, "old"); | ||
| fs.chmodSync(outputPath, 0o644); | ||
|
|
||
| writeSecureOutput(outputPath, "{}"); | ||
|
|
||
| const mode = fs.statSync(outputPath).mode & 0o777; | ||
| expect(mode).toBe(0o600); | ||
| expect(fs.readFileSync(outputPath, "utf8")).toBe("{}"); | ||
|
|
||
| fs.rmSync(outputDir, { recursive: true, force: true }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("convert gateway config adapters", () => { | ||
| const urlPrefix = "http://host.docker.internal:80"; | ||
|
|
||
| it("claude adapter enforces type=http and rewrites url", () => { | ||
| const converted = transformClaudeEntry({ type: "ignored", url: "http://old/mcp/github", headers: { Authorization: "token" } }, urlPrefix); | ||
| expect(converted).toEqual({ | ||
| type: "http", | ||
| url: "http://host.docker.internal:80/mcp/github", | ||
| headers: { Authorization: "token" }, | ||
| }); | ||
| }); | ||
|
|
||
| it("copilot adapter adds tools wildcard only when missing", () => { | ||
| const withoutTools = transformCopilotEntry({ url: "http://old/mcp/github" }, urlPrefix); | ||
| expect(withoutTools.tools).toEqual(["*"]); | ||
| expect(withoutTools.url).toBe("http://host.docker.internal:80/mcp/github"); | ||
|
|
||
| const withTools = transformCopilotEntry({ tools: ["repo.read"], url: "http://old/mcp/github" }, urlPrefix); | ||
| expect(withTools.tools).toEqual(["repo.read"]); | ||
| }); | ||
|
|
||
| it("gemini adapter removes type while keeping other fields", () => { | ||
| const converted = transformGeminiEntry({ type: "http", url: "http://old/mcp/github", headers: { Authorization: "token" } }, urlPrefix); | ||
| expect(converted).toEqual({ | ||
| url: "http://host.docker.internal:80/mcp/github", | ||
| headers: { Authorization: "token" }, | ||
| }); | ||
| }); | ||
|
|
||
| it("codex adapter emits toml section with rewritten URL and auth header", () => { | ||
| const toml = toCodexTomlSection("github", { headers: { Authorization: "Bearer abc" } }, "http://172.30.0.1:80"); | ||
| expect(toml).toContain("[mcp_servers.github]"); | ||
| expect(toml).toContain('url = "http://172.30.0.1:80/mcp/github"'); | ||
| expect(toml).toContain('http_headers = { Authorization = "Bearer abc" }'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file uses ESM
importsyntax but has a.cjsextension. CommonJS files typically userequire(). Confirm vitest is configured to handle ESM syntax in.cjsfiles (e.g., viatransformModeor an explicit ESM config), otherwise this may fail at runtime.