2025-10-11 18:25:59 +08:00

45 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ModelContextProtocol.Server;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XiaoZhiSharp_ConsoleApp.McpTools
{
[McpServerToolType]
public sealed class Chrome_Tool
{
[McpServerTool, Description("打开网站")]
public static string OpenUrl(string url)
{
return OpenUrlInChrome(url);
}
public static string OpenUrlInChrome(string url)
{
try
{
// 如果URL为空使用默认主页
if (string.IsNullOrEmpty(url))
url = "https://www.google.com";
// 在Windows上使用Process.Start()直接打开URL
// 系统会自动选择默认浏览器
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
return "网站打开成功";
}
catch (Exception ex)
{
Console.WriteLine($"打开浏览器时出错: {ex.Message}");
// 如果上述方法失败尝试直接启动Chrome
//TryOpenChromeDirectly(url);
return "网站打开失败";
}
}
}
}