MCPcopy Create free account
hub / github.com/coder/coder / createTransport

Method createTransport

agent/x/agentmcp/manager.go:963–990  ·  view source on GitHub ↗

createTransport builds the mcp-go transport for a server config.

(ctx context.Context, cfg ServerConfig)

Source from the content-addressed store, hash-verified

961
962// createTransport builds the mcp-go transport for a server config.
963func (m *Manager) createTransport(ctx context.Context, cfg ServerConfig) (transport.Interface, error) {
964 switch cfg.Transport {
965 case "stdio":
966 env := m.buildEnv(ctx, cfg.Env)
967 return transport.NewStdioWithOptions(
968 cfg.Command,
969 env,
970 cfg.Args,
971 transport.WithCommandFunc(func(ctx context.Context, command string, cmdEnv []string, args []string) (*exec.Cmd, error) {
972 cmd := m.execer.CommandContext(ctx, command, args...)
973 cmd.Env = cmdEnv
974 return cmd, nil
975 }),
976 ), nil
977 case "http", "":
978 return transport.NewStreamableHTTP(
979 cfg.URL,
980 transport.WithHTTPHeaders(cfg.Headers),
981 )
982 case "sse":
983 return transport.NewSSE(
984 cfg.URL,
985 transport.WithHeaders(cfg.Headers),
986 )
987 default:
988 return nil, xerrors.Errorf("unsupported transport %q", cfg.Transport)
989 }
990}
991
992// buildEnv enriches the process environment via the agent's
993// updateEnv callback, then merges explicit overrides from the

Callers 1

connectServerMethod · 0.95

Calls 3

buildEnvMethod · 0.95
CommandContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected