Clean up and add more comments (#2)
This commit is contained in:
parent
79af38cf21
commit
9a244f5770
14 changed files with 349 additions and 653 deletions
21
src/mcpdotnet/Protocol/Types/BlobResourceContents.cs
Normal file
21
src/mcpdotnet/Protocol/Types/BlobResourceContents.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Represents binary resource contents.
|
||||
/// </summary>
|
||||
public record BlobResourceContents : IResourceContents
|
||||
{
|
||||
[JsonPropertyName("uri")]
|
||||
public required string Uri { get; init; }
|
||||
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The base64-encoded binary content of the resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("blob")]
|
||||
public required string Blob { get; init; }
|
||||
}
|
||||
18
src/mcpdotnet/Protocol/Types/CallToolResponse.cs
Normal file
18
src/mcpdotnet/Protocol/Types/CallToolResponse.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// A response to a request to call a tool on the server.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class CallToolResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The server's response to a tools/call request from the client.
|
||||
/// </summary>
|
||||
public List<ToolContent> Content { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the tool call was unsuccessful. If true, the call was unsuccessful.
|
||||
/// </summary>
|
||||
public bool IsError { get; set; }
|
||||
}
|
||||
|
|
@ -26,42 +26,6 @@ public record ClientCapabilities
|
|||
public SamplingCapability? Sampling { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the capabilities that a server may support.
|
||||
/// </summary>
|
||||
public record ServerCapabilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Experimental, non-standard capabilities that the server supports.
|
||||
/// </summary>
|
||||
[JsonPropertyName("experimental")]
|
||||
public Dictionary<string, object>? Experimental { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server supports sending log messages to the client.
|
||||
/// </summary>
|
||||
[JsonPropertyName("logging")]
|
||||
public LoggingCapability? Logging { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any prompt templates.
|
||||
/// </summary>
|
||||
[JsonPropertyName("prompts")]
|
||||
public PromptsCapability? Prompts { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any resources to read.
|
||||
/// </summary>
|
||||
[JsonPropertyName("resources")]
|
||||
public ResourcesCapability? Resources { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any tools to call.
|
||||
/// </summary>
|
||||
[JsonPropertyName("tools")]
|
||||
public ToolsCapability? Tools { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the roots capability configuration.
|
||||
/// </summary>
|
||||
|
|
|
|||
10
src/mcpdotnet/Protocol/Types/IResourceContents.cs
Normal file
10
src/mcpdotnet/Protocol/Types/IResourceContents.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for resource contents.
|
||||
/// </summary>
|
||||
public interface IResourceContents
|
||||
{
|
||||
string Uri { get; }
|
||||
string? MimeType { get; }
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
// Protocol/Types/Implementation.cs
|
||||
namespace McpDotNet.Protocol.Types;
|
||||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
|
|
|||
23
src/mcpdotnet/Protocol/Types/JsonSchema.cs
Normal file
23
src/mcpdotnet/Protocol/Types/JsonSchema.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a JSON schema for a tool's input arguments.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class JsonSchema
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the schema, should be "object".
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Map of property names to property definitions.
|
||||
/// </summary>
|
||||
public Dictionary<string, JsonSchemaProperty>? Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of required property names.
|
||||
/// </summary>
|
||||
public List<string>? Required { get; set; }
|
||||
}
|
||||
18
src/mcpdotnet/Protocol/Types/JsonSchemaProperty.cs
Normal file
18
src/mcpdotnet/Protocol/Types/JsonSchemaProperty.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a property in a JSON schema.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class JsonSchemaProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the property. Should be a JSON Schema type and is required.
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// A human-readable description of the property.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
13
src/mcpdotnet/Protocol/Types/ListToolsResponse.cs
Normal file
13
src/mcpdotnet/Protocol/Types/ListToolsResponse.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// A response to a request to list the tools available on the server.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class ListToolsResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The server's response to a tools/list request from the client.
|
||||
/// </summary>
|
||||
public List<Tool> Tools { get; set; } = new();
|
||||
}
|
||||
|
|
@ -37,48 +37,3 @@ public record Resource
|
|||
[JsonPropertyName("annotations")]
|
||||
public Annotations? Annotations { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for resource contents.
|
||||
/// </summary>
|
||||
public interface IResourceContents
|
||||
{
|
||||
string Uri { get; }
|
||||
string? MimeType { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents text-based resource contents.
|
||||
/// </summary>
|
||||
public record TextResourceContents : IResourceContents
|
||||
{
|
||||
[JsonPropertyName("uri")]
|
||||
public required string Uri { get; init; }
|
||||
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The text content of the resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("text")]
|
||||
public required string Text { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents binary resource contents.
|
||||
/// </summary>
|
||||
public record BlobResourceContents : IResourceContents
|
||||
{
|
||||
[JsonPropertyName("uri")]
|
||||
public required string Uri { get; init; }
|
||||
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The base64-encoded binary content of the resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("blob")]
|
||||
public required string Blob { get; init; }
|
||||
}
|
||||
39
src/mcpdotnet/Protocol/Types/ServerCapabilities.cs
Normal file
39
src/mcpdotnet/Protocol/Types/ServerCapabilities.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the capabilities that a server may support.
|
||||
/// </summary>
|
||||
public record ServerCapabilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Experimental, non-standard capabilities that the server supports.
|
||||
/// </summary>
|
||||
[JsonPropertyName("experimental")]
|
||||
public Dictionary<string, object>? Experimental { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server supports sending log messages to the client.
|
||||
/// </summary>
|
||||
[JsonPropertyName("logging")]
|
||||
public LoggingCapability? Logging { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any prompt templates.
|
||||
/// </summary>
|
||||
[JsonPropertyName("prompts")]
|
||||
public PromptsCapability? Prompts { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any resources to read.
|
||||
/// </summary>
|
||||
[JsonPropertyName("resources")]
|
||||
public ResourcesCapability? Resources { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Present if the server offers any tools to call.
|
||||
/// </summary>
|
||||
[JsonPropertyName("tools")]
|
||||
public ToolsCapability? Tools { get; init; }
|
||||
}
|
||||
21
src/mcpdotnet/Protocol/Types/TextResourceContents.cs
Normal file
21
src/mcpdotnet/Protocol/Types/TextResourceContents.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Represents text-based resource contents.
|
||||
/// </summary>
|
||||
public record TextResourceContents : IResourceContents
|
||||
{
|
||||
[JsonPropertyName("uri")]
|
||||
public required string Uri { get; init; }
|
||||
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The text content of the resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("text")]
|
||||
public required string Text { get; init; }
|
||||
}
|
||||
23
src/mcpdotnet/Protocol/Types/Tool.cs
Normal file
23
src/mcpdotnet/Protocol/Types/Tool.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a tool that the server is capable of calling. Part of the ListToolsResponse.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// he name of the tool.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// A human-readable description of the tool.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A JSON Schema object defining the expected parameters for the tool.
|
||||
/// </summary>
|
||||
public JsonSchema? InputSchema { get; set; }
|
||||
}
|
||||
58
src/mcpdotnet/Protocol/Types/ToolContent.cs
Normal file
58
src/mcpdotnet/Protocol/Types/ToolContent.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the content of a tool response.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/schema.json">See the schema for details</see>
|
||||
/// There are multiple subtypes of content, depending on the "type" field, these are represented as separate classes.
|
||||
/// </summary>
|
||||
public class ToolContent
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of content. This determines the structure of the content object. Can be "image", "text", "resource".
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The text content of the message.
|
||||
/// </summary>
|
||||
public string? Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The base64-encoded image data.
|
||||
/// </summary>
|
||||
public string? Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The MIME type of the image.
|
||||
/// </summary>
|
||||
public string? MimeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// One of BlobResourceContents or TextResourceContents.
|
||||
/// </summary>
|
||||
public object? Resource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Validates the content object.
|
||||
/// </summary>
|
||||
/// <returns>Whether the type of tool content has the correct data fields provided.</returns>
|
||||
public bool Validate()
|
||||
{
|
||||
if (Type == "text")
|
||||
{
|
||||
return !string.IsNullOrEmpty(Text);
|
||||
}
|
||||
else if (Type == "image")
|
||||
{
|
||||
return !string.IsNullOrEmpty(Data) && !string.IsNullOrEmpty(MimeType);
|
||||
}
|
||||
else if (Type == "resource")
|
||||
{
|
||||
return Resource is BlobResourceContents || Resource is TextResourceContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Protocol/Types/Tools.cs
|
||||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
using mcpdotnet.Features.Tools;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class ListToolsResponse
|
||||
{
|
||||
public List<Tool> Tools { get; set; } = new();
|
||||
}
|
||||
|
||||
public class Tool
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public JsonSchema? InputSchema { get; set; }
|
||||
}
|
||||
|
||||
public class JsonSchema
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public Dictionary<string, JsonSchemaProperty>? Properties { get; set; }
|
||||
public List<string>? Required { get; set; }
|
||||
}
|
||||
|
||||
public class JsonSchemaProperty
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class CallToolResponse
|
||||
{
|
||||
public List<ToolContent> Content { get; set; } = new();
|
||||
public bool IsError { get; set; }
|
||||
}
|
||||
|
||||
public class ToolContent
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string? Text { get; set; }
|
||||
public string? Data { get; set; }
|
||||
public string? MimeType { get; set; }
|
||||
}
|
||||
Loading…
Reference in a new issue