Commit f635690
Changed files (1)
pkg
fetch
pkg/fetch/server.go
@@ -44,8 +44,9 @@ func New() *Server {
htmlProcessor: htmlprocessor.NewContentExtractor(),
}
- // Register all fetch tools
+ // Register all fetch tools and prompts
fetchServer.registerTools()
+ fetchServer.registerPrompts()
return fetchServer
}
@@ -55,6 +56,28 @@ func (fs *Server) registerTools() {
fs.RegisterTool("fetch", fs.HandleFetch)
}
+// registerPrompts registers all Fetch prompts with the server
+func (fs *Server) registerPrompts() {
+ fetchPrompt := mcp.Prompt{
+ Name: "fetch",
+ Description: "Prompt for manually entering a URL to fetch content from",
+ Arguments: []mcp.PromptArgument{
+ {
+ Name: "url",
+ Description: "The URL to fetch content from",
+ Required: true,
+ },
+ {
+ Name: "reason",
+ Description: "Why you want to fetch this URL (optional context)",
+ Required: false,
+ },
+ },
+ }
+
+ fs.RegisterPrompt(fetchPrompt, fs.HandleFetchPrompt)
+}
+
// ListTools returns all available Fetch tools
func (fs *Server) ListTools() []mcp.Tool {
return []mcp.Tool{
@@ -161,6 +184,51 @@ func (fs *Server) HandleFetch(req mcp.CallToolRequest) (mcp.CallToolResult, erro
return mcp.NewToolResult(mcp.NewTextContent(string(jsonResult))), nil
}
+// Prompt handlers
+
+func (fs *Server) HandleFetchPrompt(req mcp.GetPromptRequest) (mcp.GetPromptResult, error) {
+ url, hasURL := req.Arguments["url"].(string)
+ reason, hasReason := req.Arguments["reason"].(string)
+
+ if !hasURL || url == "" {
+ return mcp.GetPromptResult{}, fmt.Errorf("url argument is required")
+ }
+
+ // Create the prompt messages
+ var messages []mcp.PromptMessage
+
+ // User message with the URL and optional reason
+ userContent := fmt.Sprintf("Please fetch the content from this URL: %s", url)
+ if hasReason && reason != "" {
+ userContent += fmt.Sprintf("\n\nReason: %s", reason)
+ }
+
+ messages = append(messages, mcp.PromptMessage{
+ Role: "user",
+ Content: mcp.NewTextContent(userContent),
+ })
+
+ // Assistant message suggesting the fetch tool usage
+ assistantContent := fmt.Sprintf(`I'll fetch the content from %s for you.
+
+Let me use the fetch tool to retrieve and process the content:`, url)
+
+ messages = append(messages, mcp.PromptMessage{
+ Role: "assistant",
+ Content: mcp.NewTextContent(assistantContent),
+ })
+
+ description := "Manual URL fetch prompt"
+ if hasReason && reason != "" {
+ description = fmt.Sprintf("Manual URL fetch: %s", reason)
+ }
+
+ return mcp.GetPromptResult{
+ Description: description,
+ Messages: messages,
+ }, nil
+}
+
// Helper methods
func (fs *Server) fetchContent(urlStr string, maxLength, startIndex int, raw bool) (*FetchResult, error) {