Skip to content

Commit 7c4696a

Browse files
committed
feature:tool result add command type
1 parent 99a21bb commit 7c4696a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

mcp/utils.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func AsBlobResourceContents(content any) (*BlobResourceContents, bool) {
9898
return asType[BlobResourceContents](content)
9999
}
100100

101+
// AsCommandContent attempts to cast the given interface to CommandContent
102+
func AsCommandContent(content any) (*CommandContent, bool) {
103+
return asType[CommandContent](content)
104+
}
105+
101106
// Helper function for JSON-RPC
102107

103108
// NewJSONRPCResponse creates a new JSONRPCResponse with the given id and result
@@ -354,7 +359,7 @@ func NewToolResultErrorf(format string, a ...any) *CallToolResult {
354359
}
355360

356361
// NewToolResultCommand creates a CallToolResult with a command content.
357-
func NewToolResultCommand(command string, params map[string]interface{}) *CallToolResult {
362+
func NewToolResultCommand(command string, params map[string]any) *CallToolResult {
358363
return &CallToolResult{
359364
Content: []Content{
360365
CommandContent{
@@ -522,6 +527,18 @@ func ParseContent(contentMap map[string]any) (Content, error) {
522527
}
523528

524529
return NewEmbeddedResource(resourceContents), nil
530+
531+
case "command":
532+
command := ExtractString(contentMap, "command")
533+
if command == "" {
534+
return nil, fmt.Errorf("command name is missing")
535+
}
536+
params := ExtractMap(contentMap, "params")
537+
return CommandContent{
538+
Type: "command",
539+
Command: command,
540+
Params: params,
541+
}, nil
525542
}
526543

527544
return nil, fmt.Errorf("unsupported content type: %s", contentType)

0 commit comments

Comments
 (0)