Skip to content

Commit 21fe6bc

Browse files
committed
feat(mcp): Robust remote server handling & DI
- Health monitoring (30s) & auto-recovery with exp backoff - Smart tool management based on server state - Continues operation during remote failures - Moved to config.go with fx integration - Consolidated to NewMCPComponents Breaking: NewMCPServer/SSEServer -> NewMCPComponents
1 parent fd34d8e commit 21fe6bc

File tree

3 files changed

+572
-144
lines changed

3 files changed

+572
-144
lines changed

internal/app/app.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var DatabaseModule = fx.Module("database",
6565
// ConfigModule provides configuration loading services.
6666
var ConfigModule = fx.Module("config",
6767
fx.Provide(
68-
config.NewExporter,
68+
mcp.NewMCPConfig,
6969
),
7070
)
7171

@@ -86,8 +86,7 @@ var BackendModule = fx.Module("backend",
8686
// MCPClientModule provides the MCP client (distinct from server frontend).
8787
var MCPClientModule = fx.Module("mcp_client",
8888
fx.Provide(
89-
mcp.NewMCPServer,
90-
mcp.NewSSEServer,
89+
mcp.NewMCPComponents,
9190
),
9291
fx.Invoke(mcp.RegisterMCPServerHooks),
9392
)

internal/mcp/config.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Package mcp implements the MCP server logic.
2+
package mcp
3+
4+
import (
5+
"github.com/co-browser/agent-browser/internal/log"
6+
"go.uber.org/fx"
7+
)
8+
9+
// RemoteMCPServer defines a remote MCP server to connect to
10+
type RemoteMCPServer struct {
11+
URL string `json:"url"`
12+
Name string `json:"name"`
13+
Description string `json:"description"`
14+
}
15+
16+
// MCPServerConfig holds the configuration for the MCP server
17+
type MCPServerConfig struct {
18+
RemoteServers []RemoteMCPServer `json:"remote_servers"`
19+
Port int `json:"port" default:"8087"`
20+
}
21+
22+
// ConfigParams contains the parameters needed for configuration
23+
type ConfigParams struct {
24+
fx.In
25+
26+
Logger log.Logger
27+
}
28+
29+
// ConfigResult contains the configuration output
30+
type ConfigResult struct {
31+
fx.Out
32+
33+
Config MCPServerConfig
34+
}
35+
36+
// NewMCPConfig creates a new MCP configuration
37+
func NewMCPConfig(p ConfigParams) (ConfigResult, error) {
38+
// TODO: Load from environment or config file
39+
config := MCPServerConfig{
40+
Port: 8087,
41+
RemoteServers: []RemoteMCPServer{
42+
{
43+
URL: "http://0.0.0.0:8001/sse",
44+
Name: "Local Test Server",
45+
Description: "Local MCP test server",
46+
},
47+
{
48+
URL: "https://api-gateway.cobrowser.xyz/mcp/api/sse?api_key=REDACTED_API_KEY",
49+
Name: "API Gateway",
50+
Description: "API Gateway MCP server",
51+
},
52+
},
53+
}
54+
55+
p.Logger.Info().
56+
Int("port", config.Port).
57+
Int("remote_servers", len(config.RemoteServers)).
58+
Msg("MCP configuration loaded")
59+
60+
return ConfigResult{Config: config}, nil
61+
}

0 commit comments

Comments
 (0)