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

Already on GitHub?Sign in to your account

Merged
johnstcn merged 20 commits intomainfromcj/exp/mcp
Mar 31, 2025
Merged

feat(cli): addcoder exp mcp command#17066

johnstcn merged 20 commits intomainfromcj/exp/mcp
Mar 31, 2025

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedMar 24, 2025
edited
Loading

Adds acoder exp mcp command which will start a local MCP server listening on stdio with the following capabilities:

  • Show logged in user (coder whoami)
  • List workspaces (coder list)
  • List templates (coder templates list)
  • Start a workspace (coder start)
  • Stop a workspace (coder stop)
  • Fetch a single workspace (no direct CLI analogue)
  • Execute a command inside a workspace (coder exp rpty)
  • Report the status of a task (currently a no-op, pending task support)

This can be tested as follows:

# Start a local Coder server../scripts/develop.sh# Start a workspace. Currently, creating workspaces is not supported../scripts/coder-dev.sh create -t docker --yes# Add the MCP to your Claude config.claude mcp add coder ./scripts/coder-dev.sh exp mcp# Tell Claude to do something Coder-related. You may need to nudge it to use the tools.claude 'start a docker workspace and tell me what version of python is installed'

NOTE: Some of this code was generated by AI tooling, but was reviewed by a human before committing.

@johnstcnjohnstcn changed the titleCj/exp/mcpWIP: feat(cli): add experimental MCP serverMar 24, 2025
@johnstcnjohnstcnforce-pushed thecj/exp/mcp branch 2 times, most recently from5223489 to19a504cCompareMarch 28, 2025 11:26
@johnstcnjohnstcn changed the titleWIP: feat(cli): add experimental MCP serverfeat(cli): add experimental MCP serverMar 28, 2025
@johnstcnjohnstcn changed the titlefeat(cli): add experimental MCP serverfeat(cli): addcoder exp mcp commandMar 28, 2025
@johnstcnjohnstcn marked this pull request as ready for reviewMarch 28, 2025 12:31
Copy link
Member

@mtojekmtojek left a comment
edited
Loading

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.

if deps.Client == nil {
return nil, xerrors.New("developer error: client is required")
}
templates, err := deps.Client.Templates(ctx, codersdk.TemplateFilter{})
Copy link
Member

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?

Copy link
MemberAuthor

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 asdeleted,organization_id,exact_name etc.

mtojek reacted with thumbs up emoji
defer conn.Close()

var buf bytes.Buffer
if _, err := io.Copy(&buf, conn); err != nil {
Copy link
Member

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?

Copy link
MemberAuthor

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.

mtojek reacted with thumbs up emoji

// 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))
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

dead code on purpose?

Copy link
MemberAuthor

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.


// 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 {
Copy link
Member

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?

Copy link
MemberAuthor

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.

Copy link
Member

@mtojekmtojekMar 28, 2025
edited
Loading

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 theTracing chart.

Copy link
MemberAuthor

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.

mtojek reacted with thumbs up emoji
}
}

return &mcp.CallToolResult{
Copy link
Member

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...)

Copy link
MemberAuthor

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 ofcommand; echo $?

mtojek reacted with thumbs up emoji
Copy link
Member

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

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM 👍

johnstcn reacted with heart emoji
@johnstcnjohnstcn merged commit057cbd4 intomainMar 31, 2025
30 checks passed
@johnstcnjohnstcn deleted the cj/exp/mcp branchMarch 31, 2025 17:52
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 31, 2025
@stirby
Copy link
Collaborator

/cherry-pick release/2.21

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@kylecarbskylecarbskylecarbs approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@johnstcn@stirby@kylecarbs@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp