feat(tools): add MCP tool registry with web_fetch and web_search builtins

This commit is contained in:
2026-06-10 00:49:20 +03:30
parent 1c1b7ffe7e
commit 2d22523795
2 changed files with 110 additions and 0 deletions

48
internal/tools/builtin.go Normal file
View 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
}