Completion support (#15)

This commit is contained in:
Peder Holdgaard Pedersen 2025-01-19 12:59:21 +01:00 • committed by GitHub
commit 107c7acc8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 270 additions and 1 deletions

View file

@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace McpDotNet.Protocol.Types;
/// <summary>
/// Used for completion requests to provide additional context for the completion options.
/// </summary>
public class Argument
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("value")]
public string Value { get; set; } = string.Empty;
}

View file

@ -0,0 +1,27 @@
using System.Text.Json.Serialization;
namespace McpDotNet.Protocol.Types;
/// <summary>
/// Represents a completion object in the server's response.
/// </summary>
public class Completion
{
/// <summary>
/// An array of completion values. Must not exceed 100 items.
/// </summary>
[JsonPropertyName("values")]
public string[] Values { get; set; } = new string[0];
/// <summary>
/// The total number of completion options available. This can exceed the number of values actually sent in the response.
/// </summary>
[JsonPropertyName("total")]
public int? Total { get; set; }
/// <summary>
/// Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
/// </summary>
[JsonPropertyName("hasMore")]
public bool? HasMore { get; set; }
}

View file

@ -0,0 +1,69 @@
using System.Text.Json.Serialization;
namespace McpDotNet.Protocol.Types;
/// <summary>
/// Represents a reference to a resource or prompt. Umbrella type for both ResourceReference and PromptReference from the spec schema.
/// </summary>
public class Reference
{
/// <summary>
/// The type of content. Can be ref/resource or ref/prompt.
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
[JsonPropertyName("uri")]
public string? Uri { get; set; }
[JsonPropertyName("name")]
public string? Name { get; set; }
/// <summary>
/// Returns a string representation of the reference.
/// </summary>
public override string ToString()
{
return $"\"{Type}\": \"{Uri ?? Name}\"";
}
/// <summary>
/// Validates the reference object.
/// </summary>
public bool Validate(out string validationMessage)
{
if (Type == "ref/resource")
{
if (string.IsNullOrEmpty(Uri))
{
validationMessage = "Uri is required for ref/resource";
return false;
}
}
else if (Type == "ref/prompt")
{
if (string.IsNullOrEmpty(Name))
{
validationMessage = "Name is required for ref/prompt";
return false;
}
}
else
{
validationMessage = $"Unknown reference type: {Type}";
return false;
}
validationMessage = string.Empty;
return true;
}
}
/// <summary>
/// The server's response to a completion/complete request
/// </summary>
public class CompleteResult
{
[JsonPropertyName("completion")]
public Completion Completion { get; set; } = new Completion();
}