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

fix(codersdk/toolsdk): fix tool schemata#17365

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 2 commits intomainfromcj/mcp/fix-schema
Apr 11, 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
12 changes: 12 additions & 0 deletionscli/exp_mcp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -402,7 +402,9 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct
// Create a new context for the tools with all relevant information.
clientCtx := toolsdk.WithClient(ctx, client)
// Get the workspace agent token from the environment.
var hasAgentClient bool
if agentToken, err := getAgentToken(fs); err == nil && agentToken != "" {
hasAgentClient = true
agentClient := agentsdk.New(client.URL)
agentClient.SetSessionToken(agentToken)
clientCtx = toolsdk.WithAgentClient(clientCtx, agentClient)
Expand All@@ -417,6 +419,11 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct

// Register tools based on the allowlist (if specified)
for _, tool := range toolsdk.All {
// Skip adding the coder_report_task tool if there is no agent client
if !hasAgentClient && tool.Tool.Name == "coder_report_task" {
cliui.Warnf(inv.Stderr, "Task reporting not available")
continue
}
if len(allowedTools) == 0 || slices.ContainsFunc(allowedTools, func(t string) bool {
return t == tool.Tool.Name
}) {
Expand DownExpand Up@@ -689,6 +696,11 @@ func getAgentToken(fs afero.Fs) (string, error) {
// mcpFromSDK adapts a toolsdk.Tool to go-mcp's server.ServerTool.
// It assumes that the tool responds with a valid JSON object.
func mcpFromSDK(sdkTool toolsdk.Tool[any]) server.ServerTool {
// NOTE: some clients will silently refuse to use tools if there is an issue
// with the tool's schema or configuration.
if sdkTool.Schema.Properties == nil {
panic("developer error: schema properties cannot be nil")
}
return server.ServerTool{
Tool: mcp.Tool{
Name: sdkTool.Tool.Name,
Expand Down
8 changes: 8 additions & 0 deletionscodersdk/toolsdk/toolsdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -259,6 +259,10 @@ is provisioned correctly and the agent can connect to the control plane.
Tool: aisdk.Tool{
Name: "coder_list_templates",
Description: "Lists templates for the authenticated user.",
Schema: aisdk.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

ANewSchema function or a builder in aisdk might be a good idea.

Properties: map[string]any{},
Required: []string{},
},
},
Handler: func(ctx context.Context, _ map[string]any) ([]MinimalTemplate, error) {
client, err := clientFromContext(ctx)
Expand DownExpand Up@@ -318,6 +322,10 @@ is provisioned correctly and the agent can connect to the control plane.
Tool: aisdk.Tool{
Name: "coder_get_authenticated_user",
Description: "Get the currently authenticated user, similar to the `whoami` command.",
Schema: aisdk.Schema{
Properties: map[string]any{},
Required: []string{},
},
},
Handler: func(ctx context.Context, _ map[string]any) (codersdk.User, error) {
client, err := clientFromContext(ctx)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp