createTransport builds the mcp-go transport for a server config.
(ctx context.Context, cfg ServerConfig)
| 961 | |
| 962 | // createTransport builds the mcp-go transport for a server config. |
| 963 | func (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 |
no test coverage detected