mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 12:43:16 +00:00
fix: only support http or sse mcp servers (#698)
* fix: only support http or sse mcp servers * cr * cr * cr * cr
This commit is contained in:
parent
0a41c0ac0b
commit
b299baf3e4
3 changed files with 63 additions and 7 deletions
|
|
@ -126,9 +126,9 @@ ${ISSUE_CONTENT_CLOSE_TAG}`,
|
|||
messages: [
|
||||
new AIMessage({
|
||||
id: uuidv4(),
|
||||
content: `Success! I just created a new session for your request. Thread ID: ${newManagerThreadId}
|
||||
|
||||
TODO: Replace with link to new thread.`,
|
||||
content: `Success! I just created a new session for your request. Thread ID: \`${newManagerThreadId}\`
|
||||
|
||||
Click [here](/chat/${newManagerThreadId}) to view the thread.`,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { MultiServerMCPClient } from "@langchain/mcp-adapters";
|
|||
import type { StructuredToolInterface } from "@langchain/core/tools";
|
||||
import { GraphConfig } from "@open-swe/shared/open-swe/types";
|
||||
import {
|
||||
McpServerConfig,
|
||||
McpServerConfigSchema,
|
||||
McpServers,
|
||||
} from "@open-swe/shared/open-swe/mcp";
|
||||
|
|
@ -14,11 +15,52 @@ const logger = createLogger(LogLevel.INFO, "MCP Client");
|
|||
let mcpClientInstance: MultiServerMCPClient | null = null;
|
||||
let lastConfigHash: string | null = null;
|
||||
|
||||
function isLangGraphDocsServer(server: McpServerConfig): boolean {
|
||||
if (!("command" in server) || !("args" in server)) return false;
|
||||
|
||||
const langgraphMcpServer = Object.values(DEFAULT_MCP_SERVERS)[0];
|
||||
|
||||
return (
|
||||
server.command === langgraphMcpServer.command &&
|
||||
server.args.every((arg, index) => arg === langgraphMcpServer.args[index])
|
||||
);
|
||||
}
|
||||
|
||||
function validateMcpServers(mcpServers: McpServers): McpServers {
|
||||
try {
|
||||
const validatedServers: McpServers = {};
|
||||
|
||||
for (const [serverName, config] of Object.entries(mcpServers)) {
|
||||
// Check if the server has http or sse transport/type
|
||||
const transport = config.transport || config.type;
|
||||
|
||||
if (transport === "http" || transport === "sse") {
|
||||
validatedServers[serverName] = config;
|
||||
} else if (
|
||||
serverName === Object.keys(DEFAULT_MCP_SERVERS)[0] &&
|
||||
isLangGraphDocsServer(config)
|
||||
) {
|
||||
// Allow LangGraphDocs server to be specified as a stdio server
|
||||
validatedServers[serverName] = config;
|
||||
} else {
|
||||
logger.info(
|
||||
`Skipping MCP server "${serverName}" - only http and sse transports are supported, got: ${transport || "undefined"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return validatedServers;
|
||||
} catch (error) {
|
||||
logger.error("Failed to validate MCP servers: ", error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shared MCP client instance
|
||||
*/
|
||||
export function mcpClient(mcpServers: McpServers): MultiServerMCPClient {
|
||||
const serversToUse = mcpServers;
|
||||
function mcpClient(mcpServers: McpServers): MultiServerMCPClient {
|
||||
const serversToUse = validateMcpServers(mcpServers);
|
||||
const configHash = JSON.stringify(serversToUse);
|
||||
|
||||
// Recreate client if configuration changed
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@ import {
|
|||
} from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Settings, AlertTriangle } from "lucide-react";
|
||||
import { Settings, AlertTriangle, CircleAlert } from "lucide-react";
|
||||
import { ConfigField } from "@/components/configuration/config-field";
|
||||
import { useConfigStore, DEFAULT_CONFIG_KEY } from "@/hooks/useConfigStore";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { ConfigurableFieldUIMetadata } from "@open-swe/shared/configurable-metadata";
|
||||
import { GraphConfigurationMetadata } from "@open-swe/shared/open-swe/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
|
@ -183,6 +182,21 @@ export function ConfigManager() {
|
|||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
{config.label === "mcpServers" && (
|
||||
<Alert className="border-blue-200 bg-blue-50 text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-400">
|
||||
<CircleAlert className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
<p>
|
||||
<strong>Notice:</strong> Open SWE{" "}
|
||||
<i className="underline underline-offset-2">only</i>{" "}
|
||||
supports MCP servers with <strong>HTTP</strong> or{" "}
|
||||
<strong>SSE</strong> transports (with the exception
|
||||
of the default LangGraph documentation MCP server).
|
||||
Other transports will be <strong>ignored</strong>.
|
||||
</p>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<ConfigField
|
||||
id={config.label}
|
||||
label={config.label}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue