MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / buildTransport

Function buildTransport

src/mcp/client.ts:16–56  ·  view source on GitHub ↗

Build the SDK transport for a server config. For http/sse servers with an * `oauth` block, returns an auth-aware transport whose `authenticate()` runs * the OAuth flow (browser redirect or M2M) before `start()`.

(name: string, config: McpServerConfig, intercept?: AuthIntercept)

Source from the content-addressed store, hash-verified

14 * `oauth` block, returns an auth-aware transport whose `authenticate()` runs
15 * the OAuth flow (browser redirect or M2M) before `start()`. */
16function buildTransport(name: string, config: McpServerConfig, intercept?: AuthIntercept): {
17 transport: AnyTransport
18 authenticate?: () => Promise<void>
19} {
20 if (config.type === "sse") {
21 if (hasOAuth(config)) {
22 const auth = createAuthTransport(name, new URL(config.url), "sse", config.oauth!, {
23 headers: config.headers ?? {},
24 }, intercept)
25 return { transport: auth.transport, authenticate: auth.authenticate }
26 }
27 return {
28 transport: new SSEClientTransport(new URL(config.url), {
29 requestInit: { headers: config.headers ?? {} },
30 }),
31 }
32 }
33 if (config.type === "http") {
34 if (hasOAuth(config)) {
35 const auth = createAuthTransport(name, new URL(config.url), "http", config.oauth!, {
36 headers: config.headers ?? {},
37 }, intercept)
38 return { transport: auth.transport, authenticate: auth.authenticate }
39 }
40 return {
41 transport: new StreamableHTTPClientTransport(new URL(config.url), {
42 requestInit: { headers: config.headers ?? {} },
43 }),
44 }
45 }
46 // stdio (default)
47 return {
48 transport: new StdioClientTransport({
49 command: config.command,
50 args: config.args ?? [],
51 env: config.env,
52 cwd: config.cwd,
53 stderr: "pipe",
54 }),
55 }
56}
57
58/** A live connection to a single MCP server. */
59export interface McpConnection {

Callers 1

connectMcpServerFunction · 0.85

Calls 2

hasOAuthFunction · 0.85
createAuthTransportFunction · 0.85

Tested by

no test coverage detected