parent
9a244f5770
commit
7ccdeb20eb
7 changed files with 46 additions and 21 deletions
|
|
@ -10,14 +10,14 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Diagnostics;
|
|||
using System.Text.Json;
|
||||
using McpDotNet.Utils.Json;
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
internal class McpClient : IMcpClient
|
||||
{
|
||||
private readonly IMcpTransport _transport;
|
||||
|
|
@ -21,13 +21,13 @@ internal class McpClient : IMcpClient
|
|||
private CancellationTokenSource? _cts;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions().ConfigureForMcp();
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public bool IsInitialized => _isInitialized;
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public ServerCapabilities? ServerCapabilities { get; private set; }
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public Implementation? ServerInfo { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -44,7 +44,7 @@ internal class McpClient : IMcpClient
|
|||
_nextRequestId = 1;
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public async Task ConnectAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_isInitialized)
|
||||
|
|
@ -122,7 +122,7 @@ internal class McpClient : IMcpClient
|
|||
}
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public async Task PingAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await SendRequestAsync<dynamic>(
|
||||
|
|
@ -134,7 +134,7 @@ internal class McpClient : IMcpClient
|
|||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public async Task<ListToolsResponse> ListToolsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await SendRequestAsync<ListToolsResponse>(
|
||||
|
|
@ -147,7 +147,7 @@ internal class McpClient : IMcpClient
|
|||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public async Task<CallToolResponse> CallToolAsync(string toolName, Dictionary<string, object>? arguments = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
|
@ -215,7 +215,7 @@ internal class McpClient : IMcpClient
|
|||
}
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public async Task<T> SendRequestAsync<T>(JsonRpcRequest request, CancellationToken cancellationToken) where T : class
|
||||
{
|
||||
if (!_transport.IsConnected)
|
||||
|
|
@ -273,7 +273,7 @@ internal class McpClient : IMcpClient
|
|||
await _transport.SendMessageAsync(notification, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public void OnNotification(string method, Func<JsonRpcNotification,Task> handler)
|
||||
{
|
||||
var handlers = _notificationHandlers.GetOrAdd(method, _ => new());
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public readonly struct RequestId : IEquatable<RequestId>
|
|||
}
|
||||
|
||||
public static RequestId FromString(string value) => new(value);
|
||||
|
||||
public static RequestId FromNumber(long value) => new(value);
|
||||
|
||||
public bool IsString => _value is string;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace McpDotNet.Utils.Json;
|
|||
/// </summary>
|
||||
public class ContentJsonConverter : JsonConverter<IContent>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override IContent? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -34,7 +34,7 @@ public class ContentJsonConverter : JsonConverter<IContent>
|
|||
};
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override void Write(Utf8JsonWriter writer, IContent value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace McpDotNet.Utils.Json;
|
|||
/// </summary>
|
||||
public class JsonRpcMessageConverter : JsonConverter<IJsonRpcMessage>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override IJsonRpcMessage? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -63,7 +63,7 @@ public class JsonRpcMessageConverter : JsonConverter<IJsonRpcMessage>
|
|||
throw new JsonException("Invalid JSON-RPC message format");
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override void Write(Utf8JsonWriter writer, IJsonRpcMessage value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace McpDotNet.Utils.Json;
|
|||
/// </summary>
|
||||
public class ResourceContentsJsonConverter : JsonConverter<IResourceContents>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override IResourceContents? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -33,7 +33,7 @@ public class ResourceContentsJsonConverter : JsonConverter<IResourceContents>
|
|||
throw new JsonException("Resource contents must have either 'text' or 'blob' property");
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
/// <inheritdoc/>
|
||||
public override void Write(Utf8JsonWriter writer, IResourceContents value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,31 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- license and package properties -->
|
||||
<PackageId>mcpdotnet</PackageId>
|
||||
<Version>0.1.0-alpha1</Version>
|
||||
<Authors>PederHP</Authors>
|
||||
<Description>.NET client library for the Model Context Protocol (MCP)</Description>
|
||||
<PackageProjectUrl>https://github.com/PederHP/mcpdotnet</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/PederHP/mcpdotnet</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>mcp;ai;llm;client</PackageTags>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<!-- Assembly properties -->
|
||||
<AssemblyName>mcpdotnet</AssemblyName>
|
||||
<RootNamespace>mcpdotnet</RootNamespace>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\README.md" Pack="true" PackagePath="/" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in a new issue