-
Notifications
You must be signed in to change notification settings - Fork 350
feat: Multi-Server MCP Support Infrastructure #321
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
Open
open-swe
wants to merge
28
commits into
main
Choose a base branch
from
open-swe/7cb19a9a-4906-4488-b1e4-c7fb02c0cb8b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3a1e5d0
Apply patch [skip ci]
open-swe b37e9f3
Apply patch [skip ci]
open-swe 2258fd0
Apply patch [skip ci]
open-swe 7443bf0
Apply patch [skip ci]
open-swe 54576bd
Apply patch [skip ci]
open-swe d9c4f58
Apply patch [skip ci]
open-swe 16ea828
Apply patch [skip ci]
open-swe b4c96a7
Apply patch [skip ci]
open-swe 6db3b52
Apply patch [skip ci]
open-swe 8dbdaf4
Apply patch [skip ci]
open-swe 1a7a111
Apply patch [skip ci]
open-swe fee57b6
Apply patch [skip ci]
open-swe c63e1ec
Apply patch [skip ci]
open-swe 564b895
Apply patch [skip ci]
open-swe 1a8bb5e
Apply patch [skip ci]
open-swe 8a39de6
Apply patch [skip ci]
open-swe 4638eb0
Apply patch [skip ci]
open-swe 3707931
Apply patch [skip ci]
open-swe 7dce3fb
Apply patch [skip ci]
open-swe 3d8ec7b
Apply patch [skip ci]
open-swe 18f3986
Apply patch [skip ci]
open-swe e39ea74
Apply patch [skip ci]
open-swe 8b6a463
Apply patch [skip ci]
open-swe 99aa4db
Apply patch [skip ci]
open-swe c01e7bf
Empty commit to trigger CI
open-swe 4a8fa78
fix linting
bracesproul c1fd422
cr
bracesproul 6de3b39
Merge branch 'main' into open-swe/7cb19a9a-4906-4488-b1e4-c7fb02c0cb8b
bracesproul 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,99 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Migration script to convert legacy single MCP server configuration to multi-server format | ||
* | ||
* Usage: | ||
* node scripts/migrate-single-to-multi-mcp.ts | ||
* | ||
* This script reads the legacy environment variables: | ||
* - NEXT_PUBLIC_MCP_SERVER_URL | ||
* - NEXT_PUBLIC_MCP_AUTH_REQUIRED | ||
* | ||
* And generates the new NEXT_PUBLIC_MCP_SERVERS JSON configuration. | ||
* | ||
* The output can be copied to your .env file or environment configuration. | ||
* | ||
* Example output: | ||
* NEXT_PUBLIC_MCP_SERVERS='{"default":{"type":"http","url":"http://localhost:3001","authProvider":{"type":"bearer"}}}' | ||
*/ | ||
|
||
import { MCPServersConfig, MCPServerHTTPConfig } from "../src/types/mcp"; | ||
|
||
function migrateSingleToMultiMCP(): void { | ||
const legacyUrl = process.env.NEXT_PUBLIC_MCP_SERVER_URL; | ||
const authRequired = process.env.NEXT_PUBLIC_MCP_AUTH_REQUIRED === "true"; | ||
|
||
if (!legacyUrl) { | ||
console.error("❌ No legacy MCP server configuration found."); | ||
console.error(" NEXT_PUBLIC_MCP_SERVER_URL is not set."); | ||
process.exit(1); | ||
} | ||
|
||
console.log("🔍 Found legacy MCP configuration:"); | ||
console.log(` URL: ${legacyUrl}`); | ||
console.log(` Auth Required: ${authRequired}`); | ||
console.log(""); | ||
|
||
// Create the new multi-server configuration | ||
const serverConfig: MCPServerHTTPConfig = { | ||
type: "http", | ||
transport: "http", | ||
url: legacyUrl, | ||
}; | ||
|
||
// Add auth provider if authentication was required | ||
if (authRequired) { | ||
serverConfig.authProvider = { | ||
type: "bearer", | ||
}; | ||
} | ||
|
||
const multiServerConfig: MCPServersConfig = { | ||
default: serverConfig, | ||
}; | ||
|
||
// Generate the JSON string | ||
const jsonConfig = JSON.stringify(multiServerConfig); | ||
|
||
console.log("✅ Generated multi-server configuration:"); | ||
console.log(""); | ||
console.log("Add the following to your .env file:"); | ||
console.log("====================================="); | ||
console.log(`NEXT_PUBLIC_MCP_SERVERS='${jsonConfig}'`); | ||
console.log("====================================="); | ||
console.log(""); | ||
console.log("📝 Notes:"); | ||
console.log(" - The legacy server is now named 'default'"); | ||
console.log(" - You can add more servers by editing the JSON"); | ||
console.log(" - The legacy variables can be removed after migration"); | ||
console.log(""); | ||
console.log("Example with multiple servers:"); | ||
console.log("=============================="); | ||
const exampleConfig: MCPServersConfig = { | ||
default: serverConfig, | ||
"github-tools": { | ||
type: "http", | ||
transport: "http", | ||
url: "https://api.github.com/mcp", | ||
authProvider: { | ||
type: "api-key", | ||
apiKey: "your-api-key-here", | ||
}, | ||
}, | ||
"local-stdio": { | ||
type: "stdio", | ||
transport: "stdio", | ||
command: "node", | ||
args: ["./local-mcp-server.js"], | ||
}, | ||
}; | ||
console.log( | ||
`NEXT_PUBLIC_MCP_SERVERS='${JSON.stringify(exampleConfig, null, 2)}'`, | ||
); | ||
} | ||
|
||
// Run the migration | ||
if (require.main === module) { | ||
migrateSingleToMultiMCP(); | ||
} |
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,47 @@ | ||
import { NextRequest } from "next/server"; | ||
import { proxyMultiServerRequest } from "../../proxy-request"; | ||
|
||
export const runtime = "edge"; | ||
|
||
function extractParamsFromUrl(req: NextRequest) { | ||
const pathname = req.nextUrl?.pathname ?? new URL(req.url).pathname; | ||
const afterBase = pathname.replace(/^\/api\/oap_mcp\//, ""); | ||
const segments = afterBase.split("/").filter(Boolean); | ||
const [server, ...path] = segments; | ||
return { server, path } as const; | ||
} | ||
|
||
export async function GET(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function PUT(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function PATCH(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function DELETE(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function HEAD(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} | ||
|
||
export async function OPTIONS(req: NextRequest) { | ||
const { server, path } = extractParamsFromUrl(req); | ||
return proxyMultiServerRequest(req, { params: { server, path } }); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The script migrate-single-to-multi-mcp.ts claims you can run it with node, but it’s a TypeScript file (.ts)! Of course, Node.js will just throw an error, because it can’t execute TypeScript out-of-the-box.