Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support workspace name in get workspace tool#20474

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
code-asher merged 1 commit intomainfromasher/mcp-get-workspace-by-name
Oct 31, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
25 changes: 14 additions & 11 deletionscodersdk/toolsdk/toolsdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,13 +317,14 @@ type GetWorkspaceArgs struct {
var GetWorkspace = Tool[GetWorkspaceArgs, codersdk.Workspace]{
Tool: aisdk.Tool{
Name: ToolNameGetWorkspace,
Description: `Get a workspace by ID.
Description: `Get a workspace byname orID.

This returns more data than list_workspaces to reduce token usage.`,
Schema: aisdk.Schema{
Properties: map[string]any{
"workspace_id": map[string]any{
"type": "string",
"type": "string",
"description": workspaceDescription,
},
},
Required: []string{"workspace_id"},
Expand All@@ -332,7 +333,7 @@ This returns more data than list_workspaces to reduce token usage.`,
Handler: func(ctx context.Context, deps Deps, args GetWorkspaceArgs) (codersdk.Workspace, error) {
wsID, err := uuid.Parse(args.WorkspaceID)
if err != nil {
returncodersdk.Workspace{}, xerrors.New("workspace_id must be a valid UUID")
returnnamedWorkspace(ctx, deps.coderClient, NormalizeWorkspaceInput(args.WorkspaceID))
}
return deps.coderClient.Workspace(ctx, wsID)
},
Expand DownExpand Up@@ -1432,7 +1433,7 @@ var WorkspaceLS = Tool[WorkspaceLSArgs, WorkspaceLSResponse]{
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"path": map[string]any{
"type": "string",
Expand DownExpand Up@@ -1489,7 +1490,7 @@ var WorkspaceReadFile = Tool[WorkspaceReadFileArgs, WorkspaceReadFileResponse]{
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"path": map[string]any{
"type": "string",
Expand DownExpand Up@@ -1566,7 +1567,7 @@ content you are trying to write, then re-encode it properly.
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"path": map[string]any{
"type": "string",
Expand DownExpand Up@@ -1614,7 +1615,7 @@ var WorkspaceEditFile = Tool[WorkspaceEditFileArgs, codersdk.Response]{
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"path": map[string]any{
"type": "string",
Expand DownExpand Up@@ -1681,7 +1682,7 @@ var WorkspaceEditFiles = Tool[WorkspaceEditFilesArgs, codersdk.Response]{
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"files": map[string]any{
"type": "array",
Expand DownExpand Up@@ -1755,7 +1756,7 @@ var WorkspacePortForward = Tool[WorkspacePortForwardArgs, WorkspacePortForwardRe
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
"port": map[string]any{
"type": "number",
Expand DownExpand Up@@ -1812,7 +1813,7 @@ var WorkspaceListApps = Tool[WorkspaceListAppsArgs, WorkspaceListAppsResponse]{
Properties: map[string]any{
"workspace": map[string]any{
"type": "string",
"description":workspaceDescription,
"description":workspaceAgentDescription,
},
},
Required: []string{"workspace"},
Expand DownExpand Up@@ -2199,7 +2200,9 @@ func newAgentConn(ctx context.Context, client *codersdk.Client, workspace string
return conn, nil
}

const workspaceDescription = "The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used."
const workspaceDescription = "The workspace ID or name in the format [owner/]workspace. If an owner is not specified, the authenticated user is used."

const workspaceAgentDescription = "The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used."

func taskIDDescription(action string) string {
return fmt.Sprintf("ID or workspace identifier in the format [owner/]workspace[.agent] for the task to %s. If an owner is not specified, the authenticated user is used.", action)
Expand Down
30 changes: 25 additions & 5 deletionscodersdk/toolsdk/toolsdk_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,12 +126,32 @@ func TestTools(t *testing.T) {
t.Run("GetWorkspace", func(t *testing.T) {
tb, err := toolsdk.NewDeps(memberClient)
require.NoError(t, err)
result, err := testTool(t, toolsdk.GetWorkspace, tb, toolsdk.GetWorkspaceArgs{
WorkspaceID: r.Workspace.ID.String(),
})

require.NoError(t, err)
require.Equal(t, r.Workspace.ID, result.ID, "expected the workspace ID to match")
tests := []struct {
name string
workspace string
}{
{
name: "ByID",
workspace: r.Workspace.ID.String(),
},
{
name: "ByName",
workspace: r.Workspace.Name,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result, err := testTool(t, toolsdk.GetWorkspace, tb, toolsdk.GetWorkspaceArgs{
WorkspaceID: tt.workspace,
})
require.NoError(t, err)
require.Equal(t, r.Workspace.ID, result.ID, "expected the workspace ID to match")
})
}
})

t.Run("ListTemplates", func(t *testing.T) {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp