66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
// pkg/mcp/tools_browser.go
|
|
package mcp
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// --- browser_open_url ---
|
|
|
|
type BrowserOpenURLInput struct {
|
|
URL string `json:"url"`
|
|
}
|
|
type BrowserOpenURLOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) browserOpenURL(_ context.Context, _ *mcp.CallToolRequest, input BrowserOpenURLInput) (*mcp.CallToolResult, BrowserOpenURLOutput, error) {
|
|
r := s.core.Action("browser.openURL").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "url", Value: input.URL},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, BrowserOpenURLOutput{}, e
|
|
}
|
|
return nil, BrowserOpenURLOutput{}, nil
|
|
}
|
|
return nil, BrowserOpenURLOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- browser_open_file ---
|
|
|
|
type BrowserOpenFileInput struct {
|
|
Path string `json:"path"`
|
|
}
|
|
type BrowserOpenFileOutput struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (s *Subsystem) browserOpenFile(_ context.Context, _ *mcp.CallToolRequest, input BrowserOpenFileInput) (*mcp.CallToolResult, BrowserOpenFileOutput, error) {
|
|
r := s.core.Action("browser.openFile").Run(context.Background(), core.NewOptions(
|
|
core.Option{Key: "path", Value: input.Path},
|
|
))
|
|
if !r.OK {
|
|
if e, ok := r.Value.(error); ok {
|
|
return nil, BrowserOpenFileOutput{}, e
|
|
}
|
|
return nil, BrowserOpenFileOutput{}, nil
|
|
}
|
|
return nil, BrowserOpenFileOutput{Success: true}, nil
|
|
}
|
|
|
|
// --- Registration ---
|
|
|
|
func (s *Subsystem) registerBrowserTools(server *mcp.Server) {
|
|
addTool(s, server, &mcp.Tool{
|
|
Name: "browser_open_url",
|
|
Description: `Open a URL in the default system browser. Example: {"url":"https://docs.example.com"}`,
|
|
}, s.browserOpenURL)
|
|
addTool(s, server, &mcp.Tool{
|
|
Name: "browser_open_file",
|
|
Description: `Open a file in the system default application. Example: {"path":"/tmp/readme.md"}`,
|
|
}, s.browserOpenFile)
|
|
}
|