- Notifications
You must be signed in to change notification settings - Fork1k
feat: add coder_workspace_write_file MCP tool#19591
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
d231994
555a946
2503ffd
9dc153e
56f0b12
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -43,6 +43,7 @@ const ( | ||
ToolNameChatGPTSearch = "search" | ||
ToolNameChatGPTFetch = "fetch" | ||
ToolNameWorkspaceReadFile = "coder_workspace_read_file" | ||
ToolNameWorkspaceWriteFile = "coder_workspace_write_file" | ||
) | ||
func NewDeps(client *codersdk.Client, opts ...func(*Deps)) (Deps, error) { | ||
@@ -211,6 +212,7 @@ var All = []GenericTool{ | ||
ChatGPTSearch.Generic(), | ||
ChatGPTFetch.Generic(), | ||
WorkspaceReadFile.Generic(), | ||
WorkspaceWriteFile.Generic(), | ||
} | ||
type ReportTaskArgs struct { | ||
@@ -1441,6 +1443,54 @@ var WorkspaceReadFile = Tool[WorkspaceReadFileArgs, WorkspaceReadFileResponse]{ | ||
}, | ||
} | ||
type WorkspaceWriteFileArgs struct { | ||
Workspace string `json:"workspace"` | ||
Path string `json:"path"` | ||
Content []byte `json:"content"` | ||
} | ||
var WorkspaceWriteFile = Tool[WorkspaceWriteFileArgs, codersdk.Response]{ | ||
Tool: aisdk.Tool{ | ||
Name: ToolNameWorkspaceWriteFile, | ||
Description: `Write a file in a workspace.`, | ||
Schema: aisdk.Schema{ | ||
Properties: map[string]any{ | ||
"workspace": map[string]any{ | ||
"type": "string", | ||
"description": "The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used.", | ||
}, | ||
"path": map[string]any{ | ||
"type": "string", | ||
"description": "The absolute path of the file to write in the workspace.", | ||
}, | ||
"content": map[string]any{ | ||
"type": "string", | ||
"description": "The base64-encoded bytes to write to the file.", | ||
Comment on lines +1466 to +1468 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do we maybe want to limit the amount of file writing? Reads are 1MB, I think, so it might make sense to introduce a restriction here, too. MemberAuthor
| ||
}, | ||
}, | ||
Required: []string{"path", "workspace", "content"}, | ||
}, | ||
}, | ||
UserClientOptional: true, | ||
Handler: func(ctx context.Context, deps Deps, args WorkspaceWriteFileArgs) (codersdk.Response, error) { | ||
conn, err := newAgentConn(ctx, deps.coderClient, args.Workspace) | ||
if err != nil { | ||
return codersdk.Response{}, err | ||
} | ||
defer conn.Close() | ||
reader := bytes.NewReader(args.Content) | ||
ThomasK33 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
err = conn.WriteFile(ctx, args.Path, reader) | ||
if err != nil { | ||
return codersdk.Response{}, err | ||
} | ||
return codersdk.Response{ | ||
Message: "File written successfully.", | ||
}, nil | ||
}, | ||
} | ||
// NormalizeWorkspaceInput converts workspace name input to standard format. | ||
// Handles the following input formats: | ||
// - workspace → workspace | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.