feat(tools): add MCP tool registry with web_fetch and web_search builtins
This commit is contained in:
48
internal/tools/builtin.go
Normal file
48
internal/tools/builtin.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RegisterBuiltins(r *Registry) {
|
||||
r.Register(&Tool{
|
||||
Name: "web_fetch",
|
||||
Description: "Fetch content from a URL",
|
||||
Parameters: []Param{
|
||||
{Name: "url", Type: "string", Required: true, Description: "URL to fetch"},
|
||||
},
|
||||
Execute: webFetch,
|
||||
})
|
||||
|
||||
r.Register(&Tool{
|
||||
Name: "web_search",
|
||||
Description: "Search the web for information",
|
||||
Parameters: []Param{
|
||||
{Name: "query", Type: "string", Required: true, Description: "search query"},
|
||||
},
|
||||
Execute: webSearch,
|
||||
})
|
||||
}
|
||||
|
||||
func webFetch(ctx context.Context, args string) (string, error) {
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
resp, err := client.Get(strings.TrimSpace(args))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func webSearch(ctx context.Context, args string) (string, error) {
|
||||
return "Web search not yet implemented. Query: " + args, nil
|
||||
}
|
||||
Reference in New Issue
Block a user