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
20 changes: 6 additions & 14 deletions pkg/awmg/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/githubnext/gh-aw/pkg/console"
"github.com/githubnext/gh-aw/pkg/logger"
"github.com/githubnext/gh-aw/pkg/parser"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/spf13/cobra"
)
Expand All @@ -35,17 +36,8 @@ func GetVersion() string {

// MCPGatewayConfig represents the configuration for the MCP gateway.
type MCPGatewayConfig struct {
MCPServers map[string]MCPServerConfig `json:"mcpServers"`
Gateway GatewaySettings `json:"gateway,omitempty"`
}

// MCPServerConfig represents configuration for a single MCP server.
type MCPServerConfig struct {
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
URL string `json:"url,omitempty"`
Container string `json:"container,omitempty"`
MCPServers map[string]parser.MCPServerConfig `json:"mcpServers"`
Gateway GatewaySettings `json:"gateway,omitempty"`
}

// GatewaySettings represents gateway-specific settings.
Expand Down Expand Up @@ -310,7 +302,7 @@ func parseGatewayConfig(data []byte) (*MCPGatewayConfig, error) {

// Filter out internal workflow MCP servers (safeinputs and safeoutputs)
// These are used internally by the workflow and should not be proxied by the gateway
filteredServers := make(map[string]MCPServerConfig)
filteredServers := make(map[string]parser.MCPServerConfig)
for name, serverConfig := range config.MCPServers {
if name == "safeinputs" || name == "safeoutputs" {
gatewayLog.Printf("Filtering out internal workflow server: %s", name)
Expand All @@ -327,7 +319,7 @@ func parseGatewayConfig(data []byte) (*MCPGatewayConfig, error) {
// mergeConfigs merges two gateway configurations, with the second overriding the first
func mergeConfigs(base, override *MCPGatewayConfig) *MCPGatewayConfig {
result := &MCPGatewayConfig{
MCPServers: make(map[string]MCPServerConfig),
MCPServers: make(map[string]parser.MCPServerConfig),
Gateway: base.Gateway,
}

Expand Down Expand Up @@ -500,7 +492,7 @@ func (g *MCPGatewayServer) initializeSessions() error {
}

// createMCPSession creates an MCP session for a single server configuration
func (g *MCPGatewayServer) createMCPSession(serverName string, config MCPServerConfig) (*mcp.ClientSession, error) {
func (g *MCPGatewayServer) createMCPSession(serverName string, config parser.MCPServerConfig) (*mcp.ClientSession, error) {
// Create log file for this server (flat directory structure)
logFile := filepath.Join(g.logDir, fmt.Sprintf("%s.log", serverName))
gatewayLog.Printf("Creating log file for %s: %s", serverName, logFile)
Expand Down
4 changes: 3 additions & 1 deletion pkg/awmg/gateway_inspect_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"testing"
"time"

"github.com/githubnext/gh-aw/pkg/parser"
)

// TestMCPGateway_InspectWithPlaywright tests the MCP gateway by:
Expand Down Expand Up @@ -66,7 +68,7 @@ This workflow tests the MCP gateway configuration and tool list.
// Create MCP gateway configuration with gh-aw MCP server
configFile := filepath.Join(tmpDir, "gateway-config.json")
config := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"gh-aw": {
Command: binaryPath,
Args: []string{"mcp-server"},
Expand Down
4 changes: 3 additions & 1 deletion pkg/awmg/gateway_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path/filepath"
"testing"
"time"

"github.com/githubnext/gh-aw/pkg/parser"
)

func TestMCPGateway_BasicStartup(t *testing.T) {
Expand All @@ -24,7 +26,7 @@ func TestMCPGateway_BasicStartup(t *testing.T) {
configFile := filepath.Join(tmpDir, "gateway-config.json")

config := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"gh-aw": {
Command: binaryPath,
Args: []string{"mcp-server"},
Expand Down
6 changes: 4 additions & 2 deletions pkg/awmg/gateway_rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"testing"

"github.com/githubnext/gh-aw/pkg/parser"
)

// TestRewriteMCPConfigForGateway_PreservesNonProxiedServers tests that
Expand Down Expand Up @@ -42,7 +44,7 @@ func TestRewriteMCPConfigForGateway_PreservesNonProxiedServers(t *testing.T) {

// Gateway config only includes external server (github), not internal servers
gatewayConfig := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"github": {
Command: "docker",
Args: []string{"run", "-i", "--rm", "ghcr.io/github-mcp-server"},
Expand Down Expand Up @@ -184,7 +186,7 @@ func TestRewriteMCPConfigForGateway_NoGatewaySection(t *testing.T) {
}

gatewayConfig := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"github": {
Command: "gh",
Args: []string{"aw", "mcp-server"},
Expand Down
6 changes: 4 additions & 2 deletions pkg/awmg/gateway_streamable_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"testing"
"time"

"github.com/githubnext/gh-aw/pkg/parser"

"github.com/modelcontextprotocol/go-sdk/mcp"
)

Expand All @@ -38,7 +40,7 @@ func TestStreamableHTTPTransport_GatewayConnection(t *testing.T) {

// Create gateway config with the gh-aw MCP server
config := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"gh-aw": {
Command: binaryPath,
Args: []string{"mcp-server"},
Expand Down Expand Up @@ -350,7 +352,7 @@ func TestStreamableHTTPTransport_URLConfigured(t *testing.T) {
}

// Create a session with URL configuration
serverConfig := MCPServerConfig{
serverConfig := parser.MCPServerConfig{
URL: mockServer.URL,
}

Expand Down
30 changes: 16 additions & 14 deletions pkg/awmg/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"testing"

"github.com/githubnext/gh-aw/pkg/parser"
)

func TestReadGatewayConfig_FromFile(t *testing.T) {
Expand All @@ -13,7 +15,7 @@ func TestReadGatewayConfig_FromFile(t *testing.T) {
configFile := filepath.Join(tmpDir, "gateway-config.json")

config := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"test-server": {
Command: "test-command",
Args: []string{"arg1", "arg2"},
Expand Down Expand Up @@ -83,7 +85,7 @@ func TestReadGatewayConfig_InvalidJSON(t *testing.T) {

func TestMCPGatewayConfig_EmptyServers(t *testing.T) {
config := &MCPGatewayConfig{
MCPServers: make(map[string]MCPServerConfig),
MCPServers: make(map[string]parser.MCPServerConfig),
Gateway: GatewaySettings{
Port: 8080,
},
Expand All @@ -95,7 +97,7 @@ func TestMCPGatewayConfig_EmptyServers(t *testing.T) {
}

func TestMCPServerConfig_CommandType(t *testing.T) {
config := MCPServerConfig{
config := parser.MCPServerConfig{
Command: "gh",
Args: []string{"aw", "mcp-server"},
Env: map[string]string{
Expand All @@ -117,7 +119,7 @@ func TestMCPServerConfig_CommandType(t *testing.T) {
}

func TestMCPServerConfig_URLType(t *testing.T) {
config := MCPServerConfig{
config := parser.MCPServerConfig{
URL: "http://localhost:3000",
}

Expand All @@ -131,7 +133,7 @@ func TestMCPServerConfig_URLType(t *testing.T) {
}

func TestMCPServerConfig_ContainerType(t *testing.T) {
config := MCPServerConfig{
config := parser.MCPServerConfig{
Container: "mcp-server:latest",
Args: []string{"--verbose"},
Env: map[string]string{
Expand Down Expand Up @@ -188,7 +190,7 @@ func TestReadGatewayConfig_EmptyServers(t *testing.T) {
configFile := filepath.Join(tmpDir, "empty-servers.json")

config := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{},
MCPServers: map[string]parser.MCPServerConfig{},
Gateway: GatewaySettings{
Port: 8080,
},
Expand Down Expand Up @@ -237,7 +239,7 @@ func TestReadGatewayConfig_MultipleFiles(t *testing.T) {
tmpDir := t.TempDir()
baseConfig := filepath.Join(tmpDir, "base-config.json")
baseConfigData := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"server1": {
Command: "command1",
Args: []string{"arg1"},
Expand All @@ -263,7 +265,7 @@ func TestReadGatewayConfig_MultipleFiles(t *testing.T) {
// Create override config file
overrideConfig := filepath.Join(tmpDir, "override-config.json")
overrideConfigData := MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"server2": {
Command: "override-command2",
Args: []string{"override-arg2"},
Expand Down Expand Up @@ -336,7 +338,7 @@ func TestReadGatewayConfig_MultipleFiles(t *testing.T) {

func TestMergeConfigs(t *testing.T) {
base := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"server1": {
Command: "cmd1",
},
Expand All @@ -351,7 +353,7 @@ func TestMergeConfigs(t *testing.T) {
}

override := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"server2": {
Command: "override-cmd2",
},
Expand Down Expand Up @@ -396,7 +398,7 @@ func TestMergeConfigs(t *testing.T) {

func TestMergeConfigs_EmptyOverride(t *testing.T) {
base := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"server1": {
Command: "cmd1",
},
Expand All @@ -407,7 +409,7 @@ func TestMergeConfigs_EmptyOverride(t *testing.T) {
}

override := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{},
MCPServers: map[string]parser.MCPServerConfig{},
Gateway: GatewaySettings{},
}

Expand Down Expand Up @@ -533,7 +535,7 @@ func TestRewriteMCPConfigForGateway(t *testing.T) {

// Create a gateway config (after filtering)
gatewayConfig := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"github": {
Command: "gh",
Args: []string{"aw", "mcp-server"},
Expand Down Expand Up @@ -634,7 +636,7 @@ func TestRewriteMCPConfigForGateway_WithAPIKey(t *testing.T) {

// Create a gateway config with API key
gatewayConfig := &MCPGatewayConfig{
MCPServers: map[string]MCPServerConfig{
MCPServers: map[string]parser.MCPServerConfig{
"github": {
Command: "gh",
Args: []string{"aw", "mcp-server"},
Expand Down
Loading