-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathserver_test.go
More file actions
113 lines (104 loc) · 3.17 KB
/
server_test.go
File metadata and controls
113 lines (104 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ghmcp
import (
"testing"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestNewMCPServer_CreatesSuccessfully verifies that the server can be created
// with the deps injection middleware properly configured.
func TestNewMCPServer_CreatesSuccessfully(t *testing.T) {
t.Parallel()
// Create a minimal server configuration
cfg := MCPServerConfig{
Version: "test",
Host: "", // defaults to github.com
Token: "test-token",
EnabledToolsets: []string{"context"},
ReadOnly: false,
Translator: translations.NullTranslationHelper,
ContentWindowSize: 5000,
LockdownMode: false,
InsidersMode: false,
}
// Create the server
server, err := NewMCPServer(cfg)
require.NoError(t, err, "expected server creation to succeed")
require.NotNil(t, server, "expected server to be non-nil")
// The fact that the server was created successfully indicates that:
// 1. The deps injection middleware is properly added
// 2. Tools can be registered without panicking
//
// If the middleware wasn't properly added, tool calls would panic with
// "ToolDependencies not found in context" when executed.
//
// The actual middleware functionality and tool execution with ContextWithDeps
// is already tested in pkg/github/*_test.go.
}
// TestResolveEnabledToolsets verifies the toolset resolution logic.
func TestResolveEnabledToolsets(t *testing.T) {
t.Parallel()
tests := []struct {
name string
cfg MCPServerConfig
expectedResult []string
}{
{
name: "nil toolsets without dynamic mode and no tools - use defaults",
cfg: MCPServerConfig{
EnabledToolsets: nil,
DynamicToolsets: false,
EnabledTools: nil,
},
expectedResult: nil, // nil means "use defaults"
},
{
name: "nil toolsets with dynamic mode - start empty",
cfg: MCPServerConfig{
EnabledToolsets: nil,
DynamicToolsets: true,
EnabledTools: nil,
},
expectedResult: []string{}, // empty slice means no toolsets
},
{
name: "explicit toolsets",
cfg: MCPServerConfig{
EnabledToolsets: []string{"repos", "issues"},
DynamicToolsets: false,
},
expectedResult: []string{"repos", "issues"},
},
{
name: "empty toolsets - disable all",
cfg: MCPServerConfig{
EnabledToolsets: []string{},
DynamicToolsets: false,
},
expectedResult: []string{}, // empty slice means no toolsets
},
{
name: "specific tools without toolsets - no default toolsets",
cfg: MCPServerConfig{
EnabledToolsets: nil,
DynamicToolsets: false,
EnabledTools: []string{"get_me"},
},
expectedResult: []string{}, // empty slice when tools specified but no toolsets
},
{
name: "dynamic mode with explicit toolsets removes all and default",
cfg: MCPServerConfig{
EnabledToolsets: []string{"all", "repos"},
DynamicToolsets: true,
},
expectedResult: []string{"repos"}, // "all" is removed in dynamic mode
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := resolveEnabledToolsets(tc.cfg)
assert.Equal(t, tc.expectedResult, result)
})
}
}