ExecuteMCPPrompt executes an MCP prompt with provided arguments and returns the content.
(ctx context.Context, promptName string, arguments map[string]string)
| 1195 | |
| 1196 | // ExecuteMCPPrompt executes an MCP prompt with provided arguments and returns the content. |
| 1197 | func (r *LocalRuntime) ExecuteMCPPrompt(ctx context.Context, promptName string, arguments map[string]string) (string, error) { |
| 1198 | currentAgent := r.CurrentAgent() |
| 1199 | if currentAgent == nil { |
| 1200 | return "", errors.New("no current agent available") |
| 1201 | } |
| 1202 | |
| 1203 | for _, toolset := range currentAgent.ToolSets() { |
| 1204 | mcpToolset, ok := tools.As[*mcptools.Toolset](toolset) |
| 1205 | if !ok { |
| 1206 | continue |
| 1207 | } |
| 1208 | |
| 1209 | result, err := mcpToolset.GetPrompt(ctx, promptName, arguments) |
| 1210 | if err != nil { |
| 1211 | // If error is "prompt not found", continue to next toolset |
| 1212 | if err.Error() == "prompt not found" { |
| 1213 | continue |
| 1214 | } |
| 1215 | return "", fmt.Errorf("error executing prompt '%s': %w", promptName, err) |
| 1216 | } |
| 1217 | |
| 1218 | // Convert the MCP result to a string format |
| 1219 | if len(result.Messages) == 0 { |
| 1220 | return "No content returned from MCP prompt", nil |
| 1221 | } |
| 1222 | |
| 1223 | var content strings.Builder |
| 1224 | for i, message := range result.Messages { |
| 1225 | if i > 0 { |
| 1226 | content.WriteString("\n\n") |
| 1227 | } |
| 1228 | if textContent, ok := message.Content.(*mcp.TextContent); ok { |
| 1229 | content.WriteString(textContent.Text) |
| 1230 | } else { |
| 1231 | fmt.Fprintf(&content, "[Non-text content: %T]", message.Content) |
| 1232 | } |
| 1233 | } |
| 1234 | return content.String(), nil |
| 1235 | } |
| 1236 | |
| 1237 | return "", fmt.Errorf("MCP prompt '%s' not found in any active toolset", promptName) |
| 1238 | } |
| 1239 | |
| 1240 | // TitleGenerator returns a title generator for automatic session title generation. |
| 1241 | func (r *LocalRuntime) TitleGenerator(ctx context.Context) *sessiontitle.Generator { |