Logging Capability (#53)
* Logging Capability * Readability * Redundant using --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
parent
4d61007c11
commit
10c712a12f
5 changed files with 253 additions and 0 deletions
|
|
@ -29,4 +29,9 @@ public static class NotificationMethods
|
|||
/// Sent by the client when roots have been updated.
|
||||
/// </summary>
|
||||
public const string RootsUpdatedNotification = "notifications/roots/list_changed";
|
||||
|
||||
/// <summary>
|
||||
/// Sent by the server when a log message is generated.
|
||||
/// </summary>
|
||||
public const string LoggingMessageNotification = "notifications/message";
|
||||
}
|
||||
|
|
@ -65,6 +65,13 @@ public record SamplingCapability
|
|||
public record LoggingCapability
|
||||
{
|
||||
// Currently empty in the spec, but may be extended in the future
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the handler for set logging level requests.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Func<RequestContext<SetLevelRequestParams>, CancellationToken, Task<EmptyResult>>? SetLoggingLevelHandler { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
43
src/ModelContextProtocol/Protocol/Types/LoggingLevel.cs
Normal file
43
src/ModelContextProtocol/Protocol/Types/LoggingLevel.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// The severity of a log message.
|
||||
/// These map to syslog message severities, as specified in RFC-5424:
|
||||
/// https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
||||
/// </summary>
|
||||
public enum LoggingLevel
|
||||
{
|
||||
/// <summary>Detailed debug information, typically only valuable to developers.</summary>
|
||||
[JsonPropertyName("debug")]
|
||||
Debug,
|
||||
|
||||
/// <summary>Normal operational messages that require no action.</summary>
|
||||
[JsonPropertyName("info")]
|
||||
Info,
|
||||
|
||||
/// <summary>Normal but significant events that might deserve attention.</summary>
|
||||
[JsonPropertyName("notice")]
|
||||
Notice,
|
||||
|
||||
/// <summary>Warning conditions that don't represent an error but indicate potential issues.</summary>
|
||||
[JsonPropertyName("warning")]
|
||||
Warning,
|
||||
|
||||
/// <summary>Error conditions that should be addressed but don't require immediate action.</summary>
|
||||
[JsonPropertyName("error")]
|
||||
Error,
|
||||
|
||||
/// <summary>Critical conditions that require immediate attention.</summary>
|
||||
[JsonPropertyName("critical")]
|
||||
Critical,
|
||||
|
||||
/// <summary>Action must be taken immediately to address the condition.</summary>
|
||||
[JsonPropertyName("alert")]
|
||||
Alert,
|
||||
|
||||
/// <summary>System is unusable and requires immediate attention.</summary>
|
||||
[JsonPropertyName("emergency")]
|
||||
Emergency
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Sent from the server as the payload of "notifications/message" notifications whenever a log message is generated.
|
||||
///
|
||||
/// If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class LoggingMessageNotificationParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The severity of this log message.
|
||||
/// </summary>
|
||||
[JsonPropertyName("level")]
|
||||
public LoggingLevel Level { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// An optional name of the logger issuing this message.
|
||||
/// </summary>
|
||||
[JsonPropertyName("logger")]
|
||||
public string? Logger { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
||||
/// </summary>
|
||||
[JsonPropertyName("data")]
|
||||
public JsonElement? Data { get; init; }
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// A request from the client to the server, to enable or adjust logging.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class SetLevelRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The level of logging that the client wants to receive from the server.
|
||||
/// The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.
|
||||
/// </summary>
|
||||
[JsonPropertyName("level")]
|
||||
public required LoggingLevel Level { get; init; }
|
||||
}
|
||||
Loading…
Reference in a new issue