[McpServerTool,Description("send a HTTP GET request.")]
publicasyncTask<HttpResponse>HttpGet(
[Description("request url")]stringurl,
[Description("request headers(JSON format, like '{\"Content-Type\":\"application/json\"}').")]stringheaders="{\"Content-Type\":\"application/json\"}s",
[Description("timeout(ms)")]inttimeout=15000)
{
if(string.IsNullOrEmpty(url))
{
returnnewHttpResponse("URL is empty");
}
Dictionary<string,string>headerList=[];
try
{
varjson=JsonNode.Parse(headers);
if(jsonisnull)
returnnewHttpResponse($"Parse JSON headers error: JSON is null.");
if(json.GetValueKind()!=JsonValueKind.Object)
returnnewHttpResponse($"Parse JSON headers error: Root JSON type is not Object.");
foreach(varkvinjson.AsObject())
{
if(kv.Valueisnull)
returnnewHttpResponse($"Parse JSON headers error: JSON key {kv.Key} is null.");
if(kv.Value.GetValueKind()!=JsonValueKind.String)
returnnewHttpResponse($"Parse JSON headers error: JSON key {kv.Key} type is not String.");