GeezerVison is showing github.com — better mcp support - should fix hanging when streamable http server i… · pecastro/opencode@e8eaa77
File treeExpand file treeCollapse file tree Open diff view settings packages/opencode/src/mcp
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: opencode.json +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | } | 21 | 21 | }, | 22 | 22 | "mcp": { | | 23 | + "context7": { | | 24 | + "type": "remote", | | 25 | + "url": "https://mcp.context7.com/sse" | | 26 | + }, | 23 | 27 | "weather": { | 24 | 28 | "type": "local", | 25 | 29 | "command": ["opencode", "x", "@h1deya/mcp-server-weather"] | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/mcp/index.ts +26-14Lines changed: 26 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { experimental_createMCPClient, type Tool } from "ai" | 2 | | -import { Experimental_StdioMCPTransport } from "ai/mcp-stdio" | | 2 | +import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" | | 3 | +import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js" | | 4 | +import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js" | 3 | 5 | import { App } from "../app/app" | 4 | 6 | import { Config } from "../config/config" | 5 | 7 | import { Log } from "../util/log" | @@ -32,15 +34,28 @@ export namespace MCP { | 32 | 34 | } | 33 | 35 | log.info("found", { key, type: mcp.type }) | 34 | 36 | if (mcp.type === "remote") { | 35 | | - const client = await experimental_createMCPClient({ | 36 | | - name: key, | 37 | | - transport: { | 38 | | - type: "sse", | 39 | | - url: mcp.url, | 40 | | - headers: mcp.headers, | 41 | | - }, | 42 | | - }).catch(() => {}) | 43 | | - if (!client) { | | 37 | + const transports = [ | | 38 | + new StreamableHTTPClientTransport(new URL(mcp.url), { | | 39 | + requestInit: { | | 40 | + headers: mcp.headers, | | 41 | + }, | | 42 | + }), | | 43 | + new SSEClientTransport(new URL(mcp.url), { | | 44 | + requestInit: { | | 45 | + headers: mcp.headers, | | 46 | + }, | | 47 | + }), | | 48 | + ] | | 49 | + for (const transport of transports) { | | 50 | + const client = await experimental_createMCPClient({ | | 51 | + name: key, | | 52 | + transport, | | 53 | + }).catch(() => {}) | | 54 | + if (!client) continue | | 55 | + clients[key] = client | | 56 | + break | | 57 | + } | | 58 | + if (!clients[key]) | 44 | 59 | Bus.publish(Session.Event.Error, { | 45 | 60 | error: { | 46 | 61 | name: "UnknownError", | @@ -49,16 +64,13 @@ export namespace MCP { | 49 | 64 | }, | 50 | 65 | }, | 51 | 66 | }) | 52 | | - continue | 53 | | - } | 54 | | - clients[key] = client | 55 | 67 | } | 56 | 68 |
| 57 | 69 | if (mcp.type === "local") { | 58 | 70 | const [cmd, ...args] = mcp.command | 59 | 71 | const client = await experimental_createMCPClient({ | 60 | 72 | name: key, | 61 | | - transport: new Experimental_StdioMCPTransport({ | | 73 | + transport: new StdioClientTransport({ | 62 | 74 | stderr: "ignore", | 63 | 75 | command: cmd, | 64 | 76 | args, | |
|