@@ -166,8 +166,11 @@ func TestLoadFromStdin_UnsupportedType(t *testing.T) {
166166 // Should fail validation for unsupported type
167167 require .Error (t , err )
168168
169- // Error should mention configuration error
170- assert .Contains (t , err .Error (), "Configuration error" , "Expected configuration error" )
169+ // Error should mention configuration error or validation error
170+ errorMsg := err .Error ()
171+ assert .True (t ,
172+ strings .Contains (errorMsg , "Configuration error" ) || strings .Contains (errorMsg , "Configuration validation error" ),
173+ "Expected configuration error or validation error, got: %s" , errorMsg )
171174
172175 // Config should be nil on validation error
173176 assert .Nil (t , cfg , "Config should be nil when validation fails" )
@@ -1531,3 +1534,108 @@ registry = "https://api.mcp.github.com/v0/servers/github/github-mcp-server"
15311534
15321535 assert .Equal (t , "https://api.mcp.github.com/v0/servers/github/github-mcp-server" , server .Registry , "Registry field not preserved in TOML config" )
15331536}
1537+
1538+ // TestLoadFromStdin_WithGuardPolicies tests that guard-policies field is correctly parsed from JSON stdin
1539+ func TestLoadFromStdin_WithGuardPolicies (t * testing.T ) {
1540+ jsonConfig := `{
1541+ "mcpServers": {
1542+ "github": {
1543+ "type": "stdio",
1544+ "container": "ghcr.io/github/github-mcp-server:latest",
1545+ "guard-policies": {
1546+ "github": {
1547+ "owner": "github",
1548+ "repos": ["gh-aw-mcpg", "gh-aw"]
1549+ }
1550+ }
1551+ },
1552+ "http-server": {
1553+ "type": "http",
1554+ "url": "https://example.com/mcp",
1555+ "guard-policies": {
1556+ "network": {
1557+ "allow": ["api.example.com"]
1558+ }
1559+ }
1560+ }
1561+ },
1562+ "gateway": {
1563+ "port": 8080,
1564+ "domain": "localhost",
1565+ "apiKey": "test-key"
1566+ }
1567+ }`
1568+
1569+ // Mock stdin
1570+ r , w , _ := os .Pipe ()
1571+ oldStdin := os .Stdin
1572+ os .Stdin = r
1573+ go func () {
1574+ w .Write ([]byte (jsonConfig ))
1575+ w .Close ()
1576+ }()
1577+
1578+ cfg , err := LoadFromStdin ()
1579+ os .Stdin = oldStdin
1580+
1581+ require .NoError (t , err , "LoadFromStdin() failed" )
1582+ require .NotNil (t , cfg , "Config should not be nil" )
1583+
1584+ // Test stdio server with guard policies
1585+ githubServer , ok := cfg .Servers ["github" ]
1586+ require .True (t , ok , "Server 'github' not found" )
1587+ require .NotNil (t , githubServer .GuardPolicies , "GuardPolicies should not be nil" )
1588+
1589+ githubPolicy , ok := githubServer .GuardPolicies ["github" ]
1590+ require .True (t , ok , "GitHub policy not found in guard-policies" )
1591+ githubPolicyMap , ok := githubPolicy .(map [string ]interface {})
1592+ require .True (t , ok , "GitHub policy should be a map" )
1593+ assert .Equal (t , "github" , githubPolicyMap ["owner" ], "Owner field mismatch" )
1594+
1595+ // Test HTTP server with guard policies
1596+ httpServer , ok := cfg .Servers ["http-server" ]
1597+ require .True (t , ok , "Server 'http-server' not found" )
1598+ require .NotNil (t , httpServer .GuardPolicies , "GuardPolicies should not be nil for HTTP server" )
1599+
1600+ networkPolicy , ok := httpServer .GuardPolicies ["network" ]
1601+ require .True (t , ok , "Network policy not found in guard-policies" )
1602+ require .NotNil (t , networkPolicy , "Network policy should not be nil" )
1603+ }
1604+
1605+ // TestLoadFromFile_WithGuardPolicies tests that guard_policies field is correctly parsed from TOML
1606+ func TestLoadFromFile_WithGuardPolicies (t * testing.T ) {
1607+ tmpDir := t .TempDir ()
1608+ tmpFile := filepath .Join (tmpDir , "config.toml" )
1609+
1610+ tomlContent := `
1611+ [gateway]
1612+ port = 8080
1613+ api_key = "test-key"
1614+
1615+ [servers.github]
1616+ command = "docker"
1617+ args = ["run", "--rm", "-i", "ghcr.io/github/github-mcp-server:latest"]
1618+
1619+ [servers.github.guard_policies]
1620+ [servers.github.guard_policies.github]
1621+ owner = "github"
1622+ repos = ["gh-aw-mcpg", "gh-aw"]
1623+ `
1624+
1625+ err := os .WriteFile (tmpFile , []byte (tomlContent ), 0644 )
1626+ require .NoError (t , err , "Failed to write temp TOML file" )
1627+
1628+ cfg , err := LoadFromFile (tmpFile )
1629+ require .NoError (t , err , "LoadFromFile() failed" )
1630+ require .NotNil (t , cfg , "Config should not be nil" )
1631+
1632+ server , ok := cfg .Servers ["github" ]
1633+ require .True (t , ok , "Server 'github' not found" )
1634+ require .NotNil (t , server .GuardPolicies , "GuardPolicies should not be nil" )
1635+
1636+ githubPolicy , ok := server .GuardPolicies ["github" ]
1637+ require .True (t , ok , "GitHub policy not found in guard_policies" )
1638+ githubPolicyMap , ok := githubPolicy .(map [string ]interface {})
1639+ require .True (t , ok , "GitHub policy should be a map" )
1640+ assert .Equal (t , "github" , githubPolicyMap ["owner" ], "Owner field mismatch in TOML config" )
1641+ }
0 commit comments