|
7 | 7 | "encoding/json"
|
8 | 8 | "os"
|
9 | 9 | "os/exec"
|
| 10 | + "slices" |
10 | 11 | "sync"
|
11 | 12 | "testing"
|
12 | 13 | "time"
|
@@ -115,6 +116,9 @@ func setupMCPClient(t *testing.T, options ...ClientOption) *mcpClient.Client {
|
115 | 116 | t.Log("Starting Stdio MCP client...")
|
116 | 117 | client, err := mcpClient.NewStdioMCPClient(args[0], []string{}, args[1:]...)
|
117 | 118 | require.NoError(t, err, "expected to create client successfully")
|
| 119 | + t.Cleanup(func() { |
| 120 | + require.NoError(t, client.Close(), "expected to close client successfully") |
| 121 | + }) |
118 | 122 |
|
119 | 123 | // Initialize the client
|
120 | 124 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
@@ -166,5 +170,33 @@ func TestGetMe(t *testing.T) {
|
166 | 170 | require.NoError(t, err, "expected to get user successfully")
|
167 | 171 | require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")
|
168 | 172 |
|
169 |
| - require.NoError(t, mcpClient.Close(), "expected to close client successfully") |
| 173 | +} |
| 174 | + |
| 175 | +func TestToolsets(t *testing.T) { |
| 176 | + mcpClient := setupMCPClient( |
| 177 | + t, |
| 178 | + WithEnvVars(map[string]string{ |
| 179 | + "GITHUB_TOOLSETS": "repos,issues", |
| 180 | + }), |
| 181 | + ) |
| 182 | + |
| 183 | + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 184 | + defer cancel() |
| 185 | + |
| 186 | + request := mcp.ListToolsRequest{} |
| 187 | + response, err := mcpClient.ListTools(ctx, request) |
| 188 | + require.NoError(t, err, "expected to list tools successfully") |
| 189 | + |
| 190 | + // We could enumerate the tools here, but we'll need to expose that information |
| 191 | + // declaratively in the MCP server, so for the moment let's just check the existence |
| 192 | + // of an issue and repo tool, and the non-existence of a pull_request tool. |
| 193 | + var toolsContains = func(expectedName string) bool { |
| 194 | + return slices.ContainsFunc(response.Tools, func(tool mcp.Tool) bool { |
| 195 | + return tool.Name == expectedName |
| 196 | + }) |
| 197 | + } |
| 198 | + |
| 199 | + require.True(t, toolsContains("get_issue"), "expected to find 'get_issue' tool") |
| 200 | + require.True(t, toolsContains("list_branches"), "expected to find 'list_branches' tool") |
| 201 | + require.False(t, toolsContains("get_pull_request"), "expected not to find 'get_pull_request' tool") |
170 | 202 | }
|
0 commit comments