Skip to content

feat(codersdk): add toolsdk and replace existing mcp server tool impl #17343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix toolsdk testmain
  • Loading branch information
johnstcn committed Apr 11, 2025
commit ae06274c95cdece8452a3a0b1e6333a9915c67a9
21 changes: 12 additions & 9 deletions codersdk/toolsdk/toolsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,25 @@ func (t Tool[T]) Generic() Tool[any] {
}

var (
// All is a list of all tools that can be used in the Coder CLI.
// When you add a new tool, be sure to include it here!
All = []Tool[any]{
ReportTask.Generic(),
CreateTemplateVersion.Generic(),
CreateTemplate.Generic(),
CreateWorkspace.Generic(),
CreateWorkspaceBuild.Generic(),
DeleteTemplate.Generic(),
GetAuthenticatedUser.Generic(),
GetTemplateVersionLogs.Generic(),
GetWorkspace.Generic(),
GetWorkspaceAgentLogs.Generic(),
GetWorkspaceBuildLogs.Generic(),
ListWorkspaces.Generic(),
ListTemplates.Generic(),
ListTemplateVersionParameters.Generic(),
GetAuthenticatedUser.Generic(),
CreateWorkspaceBuild.Generic(),
ReportTask.Generic(),
UploadTarFile.Generic(),
CreateTemplateVersion.Generic(),
CreateTemplate.Generic(),
GetTemplateVersionLogs.Generic(),
UpdateTemplateActiveVersion.Generic(),
DeleteTemplate.Generic(),
GetWorkspaceAgentLogs.Generic(),
GetWorkspaceBuildLogs.Generic(),
}

ReportTask = Tool[string]{
Expand Down
11 changes: 9 additions & 2 deletions codersdk/toolsdk/toolsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,25 @@ var testedTools sync.Map
// testTool is a helper function to test a tool and mark it as tested.
func testTool[T any](ctx context.Context, t *testing.T, tool toolsdk.Tool[T], args map[string]any) (T, error) {
t.Helper()
testedTools.Store(tool.Tool.Name, struct{}{})
testedTools.Store(tool.Tool.Name, true)
result, err := tool.Handler(ctx, args)
return result, err
}

// TestMain runs after all tests to ensure that all tools in this package have
// been tested once.
func TestMain(m *testing.M) {
// Initialize testedTools
for _, tool := range toolsdk.All {
testedTools.Store(tool.Tool.Name, false)
}

code := m.Run()

// Ensure all tools have been tested
var untested []string
for _, tool := range toolsdk.All {
if _, ok := testedTools.Load(tool.Tool.Name); !ok {
if tested, ok := testedTools.Load(tool.Tool.Name); !ok || !tested.(bool) {
untested = append(untested, tool.Tool.Name)
}
}
Expand Down
Loading