MCPcopy Create free account
hub / github.com/coder/coder / Run

Method Run

coderd/x/chatd/chattool/mcpworkspace.go:60–100  ·  view source on GitHub ↗
(
	ctx context.Context,
	params fantasy.ToolCall,
)

Source from the content-addressed store, hash-verified

58}
59
60func (t *WorkspaceMCPTool) Run(
61 ctx context.Context,
62 params fantasy.ToolCall,
63) (fantasy.ToolResponse, error) {
64 conn, err := t.getConn(ctx)
65 if err != nil {
66 return fantasy.NewTextErrorResponse(
67 "workspace connection failed: " + err.Error(),
68 ), nil
69 }
70
71 var args map[string]any
72 if params.Input != "" {
73 if err := json.Unmarshal(
74 []byte(params.Input), &args,
75 ); err != nil {
76 return fantasy.NewTextErrorResponse(
77 "invalid JSON input: " + err.Error(),
78 ), nil
79 }
80 }
81
82 resp, err := conn.CallMCPTool(ctx, workspacesdk.CallMCPToolRequest{
83 ToolName: t.info.Name,
84 Arguments: args,
85 })
86 if err != nil {
87 // If the agent returns a 404 (ErrUnknownServer), the
88 // server was removed or renamed. Invalidate the chat's
89 // cached tool list so the next turn refetches.
90 var coderErr *codersdk.Error
91 if errors.As(err, &coderErr) && coderErr.StatusCode() == http.StatusNotFound {
92 if t.invalidateCache != nil {
93 t.invalidateCache()
94 }
95 }
96 return fantasy.NewTextErrorResponse(err.Error()), nil
97 }
98
99 return convertMCPToolResponse(resp), nil
100}
101
102func (t *WorkspaceMCPTool) ProviderOptions() fantasy.ProviderOptions {
103 return t.providerOpts

Callers 1

Calls 6

StatusCodeMethod · 0.95
convertMCPToolResponseFunction · 0.85
AsMethod · 0.80
CallMCPToolMethod · 0.65
ErrorMethod · 0.45
UnmarshalMethod · 0.45

Tested by 1