@@ -3,25 +3,25 @@ package mcp
33import (
44 "context"
55 "fmt"
6+ "os"
67 "sync/atomic"
78
89 "github.com/mark3labs/mcp-go/client"
10+ mcptransport "github.com/mark3labs/mcp-go/client/transport"
911 "github.com/mark3labs/mcp-go/mcp"
1012
1113 "github.com/docker/mcp-gateway/cmd/docker-mcp/internal/catalog"
1214)
1315
1416type remoteMCPClient struct {
15- name string
16- config catalog.Remote
17+ config catalog.ServerConfig
1718
1819 initialized atomic.Bool
1920 * client.Client
2021}
2122
22- func NewRemoteMCPClient (name string , config catalog.Remote ) Client {
23+ func NewRemoteMCPClient (config catalog.ServerConfig ) Client {
2324 return & remoteMCPClient {
24- name : name ,
2525 config : config ,
2626 }
2727}
@@ -36,19 +36,45 @@ func (c *remoteMCPClient) Initialize(ctx context.Context, request mcp.Initialize
3636 err error
3737 )
3838
39- switch c .config .Transport {
39+ // Read configuration.
40+ var (
41+ url string
42+ transport string
43+ )
44+ if c .config .Spec .SSEEndpoint != "" {
45+ // Deprecated
46+ url = c .config .Spec .SSEEndpoint
47+ transport = "sse"
48+ } else {
49+ url = c .config .Spec .Remote .URL
50+ transport = c .config .Spec .Remote .Transport
51+ }
52+
53+ // Secrets to env
54+ env := map [string ]string {}
55+ for _ , secret := range c .config .Spec .Secrets {
56+ env [secret .Env ] = c .config .Secrets [secret .Name ]
57+ }
58+
59+ // Headers
60+ headers := map [string ]string {}
61+ for k , v := range c .config .Spec .Remote .Headers {
62+ headers [k ] = expandEnv (v , env )
63+ }
64+
65+ switch transport {
4066 case "sse" :
41- remoteClient , err = client .NewSSEMCPClient (c . config . URL )
67+ remoteClient , err = client .NewSSEMCPClient (url , client . WithHeaders ( headers ) )
4268 if err != nil {
4369 return nil , err
4470 }
4571 case "http" :
46- remoteClient , err = client .NewStreamableHttpClient (c . config . URL )
72+ remoteClient , err = client .NewStreamableHttpClient (url , mcptransport . WithHTTPHeaders ( headers ) )
4773 if err != nil {
4874 return nil , err
4975 }
5076 default :
51- return nil , fmt .Errorf ("unsupported remote transport: %s" , c . config . Transport )
77+ return nil , fmt .Errorf ("unsupported remote transport: %s" , transport )
5278 }
5379
5480 if err := remoteClient .Start (context .WithoutCancel (ctx )); err != nil {
@@ -64,3 +90,9 @@ func (c *remoteMCPClient) Initialize(ctx context.Context, request mcp.Initialize
6490 c .initialized .Store (true )
6591 return result , nil
6692}
93+
94+ func expandEnv (value string , secrets map [string ]string ) string {
95+ return os .Expand (value , func (name string ) string {
96+ return secrets [name ]
97+ })
98+ }
0 commit comments