-
Notifications
You must be signed in to change notification settings - Fork 881
feat(cli): add coder exp mcp
command
#17066
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
Conversation
5223489
to
19a504c
Compare
coder exp mcp
command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed.
I'll admit that command validation is a debatable approach, as it can be relatively easy to bypass.
mcp/tools/tools_coder.go
Outdated
if deps.Client == nil { | ||
return nil, xerrors.New("developer error: client is required") | ||
} | ||
templates, err := deps.Client.Templates(ctx, codersdk.TemplateFilter{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there risk of pagination?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, that endpoint is not paginated. There are some query parameters we could pass in, such as deleted
, organization_id
, exact_name
etc.
mcp/tools/tools_coder.go
Outdated
defer conn.Close() | ||
|
||
var buf bytes.Buffer | ||
if _, err := io.Copy(&buf, conn); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the command is supposed to take more time, should we stream the response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'd like to look into this as a future enhancement.
mcp/tools/tools_coder.go
Outdated
|
||
// TODO: Waiting on support for tasks. | ||
deps.Logger.Info(ctx, "report task tool called", slog.F("summary", summary), slog.F("link", link), slog.F("done", done), slog.F("emoji", emoji)) | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this if you prefer, but I was anticipating this being ready sooner.
mcp/tools/tools_coder.go
Outdated
|
||
// Example payload: | ||
// {"jsonrpc":"2.0","id":1,"method":"tools/call", "params": {"name": "coder_workspace_exec", "arguments": {"workspace": "dev", "command": "ps -ef"}}} | ||
func handleCoderWorkspaceExec(deps ToolDeps) mcpserver.ToolHandlerFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to pass tracing data? for instance, for how long was the command running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For whom is this data intended? For now, I've returned it in the response as JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if the MCP protocol has space for such metadata. If somebody wants to visualize some metrics around calls, it seems to be channel to pass all tracing info.
EDIT:
I thought about data we can display on the Tracing chart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be, from what I can tell.
mcp/tools/tools_coder.go
Outdated
} | ||
} | ||
|
||
return &mcp.CallToolResult{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to return the status code? somebody may use it to build more sophisticated workflows (if commands failed, then...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the agent will have to use the old trick of command; echo $?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's ignore for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
/cherry-pick release/2.21 |
Adds a
coder exp mcp
command which will start a local MCP server listening on stdio with the following capabilities:coder whoami
)coder list
)coder templates list
)coder start
)coder stop
)coder exp rpty
)This can be tested as follows:
NOTE: Some of this code was generated by AI tooling, but was reviewed by a human before committing.