MCPcopy Index your code
hub / github.com/coder/coder / createTransport

Function createTransport

coderd/x/chatd/mcpclient/mcpclient.go:284–318  ·  view source on GitHub ↗

createTransport builds the appropriate mcp-go transport based on the server's configured transport type.

(
	cfg database.MCPServerConfig,
	headers map[string]string,
)

Source from the content-addressed store, hash-verified

282// createTransport builds the appropriate mcp-go transport based
283// on the server's configured transport type.
284func createTransport(
285 cfg database.MCPServerConfig,
286 headers map[string]string,
287) (transport.Interface, error) {
288 // Each connection gets its own HTTP client with a dedicated
289 // transport so that httptest.Server.Close() (which calls
290 // CloseIdleConnections on http.DefaultTransport) does not
291 // disrupt unrelated connections during parallel tests.
292 var httpClient *http.Client
293 if dt, ok := http.DefaultTransport.(*http.Transport); ok {
294 httpClient = &http.Client{Transport: dt.Clone()}
295 } else {
296 httpClient = &http.Client{}
297 }
298
299 switch cfg.Transport {
300 case "sse":
301 return transport.NewSSE(
302 cfg.Url,
303 transport.WithHeaders(headers),
304 transport.WithHTTPClient(httpClient),
305 )
306 case "", "streamable_http":
307 // Default to streamable HTTP, the newer transport.
308 return transport.NewStreamableHTTP(
309 cfg.Url,
310 transport.WithHTTPHeaders(headers),
311 transport.WithHTTPBasicClient(httpClient),
312 )
313 default:
314 return nil, xerrors.Errorf(
315 "unsupported transport %q", cfg.Transport,
316 )
317 }
318}
319
320// buildAuthHeaders constructs HTTP headers for authenticating
321// with the MCP server based on the configured auth type.

Callers 1

connectOneFunction · 0.85

Calls 2

CloneMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected