37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using ModelContextProtocol.Client;
|
|
using ModelContextProtocol.Protocol.Transport;
|
|
using ModelContextProtocol.Protocol.Types;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace LinkToolAddin.client;
|
|
|
|
public class SseMcpClient : McpClient
|
|
{
|
|
private SseClientTransportOptions options;
|
|
private IClientTransport transport;
|
|
public SseMcpClient(string url)
|
|
{
|
|
options = new SseClientTransportOptions
|
|
{
|
|
Endpoint = new Uri(url),
|
|
};
|
|
transport = new SseClientTransport(options);
|
|
}
|
|
public async Task<IList<McpClientTool>> GetToolListAsync()
|
|
{
|
|
// 创建 MCP Client
|
|
IMcpClient client = await McpClientFactory.CreateAsync(transport);
|
|
var tools = await client.ListToolsAsync();
|
|
return tools;
|
|
}
|
|
|
|
public async Task<CallToolResponse> CallToolAsync(string toolName,Dictionary<string, object> parameters = null)
|
|
{
|
|
IMcpClient client = await McpClientFactory.CreateAsync(transport);
|
|
CallToolResponse result = await client.CallToolAsync(toolName,parameters);
|
|
return result;
|
|
}
|
|
} |