Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions internal/server/routed.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ func CreateHTTPServerForRoutedMode(addr string, unifiedServer *UnifiedServer, ap
})
mux.Handle("/mcp/.well-known/oauth-authorization-server", withResponseLogging(oauthHandler))

// Create routes for all backends plus sys
allBackends := append([]string{"sys"}, unifiedServer.GetServerIDs()...)
// Create routes for all backends, plus sys only if DIFC is enabled
allBackends := unifiedServer.GetServerIDs()
if unifiedServer.IsDIFCEnabled() {
allBackends = append([]string{"sys"}, allBackends...)
logRouted.Printf("DIFC enabled: including sys in route registration")
} else {
logRouted.Printf("DIFC disabled: excluding sys from route registration")
}
logRouted.Printf("Registering routes for %d backends: %v", len(allBackends), allBackends)

// Create a proxy for each backend server (including sys)
// Create a proxy for each backend server (sys included only when DIFC is enabled)
for _, serverID := range allBackends {
// Capture serverID for the closure
backendID := serverID
Expand Down
61 changes: 61 additions & 0 deletions internal/server/routed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,64 @@ func TestRoutedMode_SysToolsBackend_DIFCEnabled(t *testing.T) {
}
}
}

func TestRoutedMode_SysRouteNotExposed_DIFCDisabled(t *testing.T) {
// When DIFC is disabled (default), /mcp/sys route should NOT be registered
cfg := &config.Config{
Servers: map[string]*config.ServerConfig{
"github": {Command: "docker", Args: []string{}},
},
// EnableDIFC defaults to false, but explicitly set here for test clarity
EnableDIFC: false,
}

ctx := context.Background()
us, err := NewUnified(ctx, cfg)
require.NoError(t, err, "NewUnified() failed")
defer us.Close()

// Create routed mode server
httpServer := CreateHTTPServerForRoutedMode("127.0.0.1:0", us, "")

// Try to access /mcp/sys route - should get 404
req := httptest.NewRequest(http.MethodGet, "/mcp/sys", nil)
req.Header.Set("Authorization", "test-session")
w := httptest.NewRecorder()

httpServer.Handler.ServeHTTP(w, req)

// Should return 404 because the route is not registered
if w.Code != http.StatusNotFound {
t.Errorf("Expected status 404 for /mcp/sys when DIFC is disabled, got %d", w.Code)
}
}

func TestRoutedMode_SysRouteExposed_DIFCEnabled(t *testing.T) {
// When DIFC is enabled, /mcp/sys route SHOULD be registered
cfg := &config.Config{
Servers: map[string]*config.ServerConfig{
"github": {Command: "docker", Args: []string{}},
},
EnableDIFC: true, // Enable DIFC
}

ctx := context.Background()
us, err := NewUnified(ctx, cfg)
require.NoError(t, err, "NewUnified() failed")
defer us.Close()

// Create routed mode server
httpServer := CreateHTTPServerForRoutedMode("127.0.0.1:0", us, "")

// Try to access /mcp/sys route - should NOT get 404
req := httptest.NewRequest(http.MethodGet, "/mcp/sys", nil)
req.Header.Set("Authorization", "test-session")
w := httptest.NewRecorder()

httpServer.Handler.ServeHTTP(w, req)

// Should NOT return 404 because the route should be registered
if w.Code == http.StatusNotFound {
t.Errorf("Expected /mcp/sys route to be registered when DIFC is enabled, but got 404")
}
}
5 changes: 5 additions & 0 deletions internal/server/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,8 @@ func (us *UnifiedServer) SetTestMode(enabled bool) {
func (us *UnifiedServer) ShouldExit() bool {
return !us.testMode
}

// IsDIFCEnabled returns whether DIFC is enabled
func (us *UnifiedServer) IsDIFCEnabled() bool {
return us.enableDIFC
}