Add new helper properties to request and notification types (#388)
Add properties for types of new schema ## Motivation and Context Added getters to simplify access to properties in request and notification types. ## How Has This Been Tested? All tests pass ## Breaking Changes None ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [x] I have added appropriate error handling - [x] I have added or updated documentation as needed
This commit is contained in:
parent
0e6a41dcd5
commit
13f858d5d2
11 changed files with 320 additions and 51 deletions
|
|
@ -11,4 +11,7 @@ public data class PingRequest(override val params: BaseRequestParams? = null) :
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.Ping
|
||||
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,27 @@ public data class CompleteRequest(override val params: CompleteRequestParams) :
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
public override val method: Method = Method.Defined.CompletionComplete
|
||||
|
||||
/**
|
||||
* The argument's information for which completion options are requested.
|
||||
*/
|
||||
public val argument: CompleteRequestParams.Argument
|
||||
get() = params.argument
|
||||
|
||||
/**
|
||||
* A reference to either a prompt or resource template to complete within.
|
||||
*/
|
||||
public val ref: Reference
|
||||
get() = params.ref
|
||||
|
||||
/**
|
||||
* Additional, context for generating completions.
|
||||
*/
|
||||
public val context: CompleteRequestParams.Context?
|
||||
get() = params.context
|
||||
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,6 +20,24 @@ public data class ElicitRequest(override val params: ElicitRequestParams) : Serv
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
public override val method: Method = Method.Defined.ElicitationCreate
|
||||
|
||||
/**
|
||||
* The message to present to the user. This should clearly explain what information is being requested and why.
|
||||
*/
|
||||
public val message: String
|
||||
get() = params.message
|
||||
|
||||
/**
|
||||
* A restricted subset of JSON Schema defining the structure of the requested data.
|
||||
*/
|
||||
public val requestedSchema: ElicitRequestParams.RequestedSchema
|
||||
get() = params.requestedSchema
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,6 +21,30 @@ public data class InitializeRequest(override val params: InitializeRequestParams
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.Initialize
|
||||
|
||||
/**
|
||||
* The latest version of the Model Context Protocol that the client supports.
|
||||
*/
|
||||
public val protocolVersion: String
|
||||
get() = params.protocolVersion
|
||||
|
||||
/**
|
||||
* The capabilities that this client supports. Describes which optional features the client has implemented.
|
||||
*/
|
||||
public val capabilities: ClientCapabilities
|
||||
get() = params.capabilities
|
||||
|
||||
/**
|
||||
* Information about the client implementation, including name, version, and branding.
|
||||
*/
|
||||
public val clientInfo: Implementation
|
||||
get() = params.clientInfo
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,6 +63,18 @@ public data class SetLevelRequest(override val params: SetLevelRequestParams) :
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.LoggingSetLevel
|
||||
|
||||
/**
|
||||
* The minimum severity level of logging that the client wants to receive from the server.
|
||||
*/
|
||||
public val level: LoggingLevel
|
||||
get() = params.level
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -77,7 +77,11 @@ public class Progress(
|
|||
@Serializable
|
||||
public data class CustomNotification(override val method: Method, override val params: BaseNotificationParams? = null) :
|
||||
ClientNotification,
|
||||
ServerNotification
|
||||
ServerNotification {
|
||||
|
||||
public val meta: JsonObject?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Cancelled Notification
|
||||
|
|
@ -101,6 +105,24 @@ public data class CancelledNotification(override val params: CancelledNotificati
|
|||
ServerNotification {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.NotificationsCancelled
|
||||
|
||||
/**
|
||||
* The ID of the request to cancel.
|
||||
*/
|
||||
public val requestId: RequestId
|
||||
get() = params.requestId
|
||||
|
||||
/**
|
||||
* A string describing the reason for the cancellation.
|
||||
*/
|
||||
public val reason: String?
|
||||
get() = params.reason
|
||||
|
||||
/**
|
||||
* Metadata for this notification.
|
||||
*/
|
||||
public val meta: JsonObject?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -187,6 +187,18 @@ public data class ListPromptsRequest(override val params: PaginatedRequestParams
|
|||
PaginatedRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.PromptsList
|
||||
|
||||
/**
|
||||
* An opaque token representing the current pagination position.
|
||||
*/
|
||||
public val cursor: String?
|
||||
get() = params?.cursor
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -190,6 +190,18 @@ public data class ListResourcesRequest(override val params: PaginatedRequestPara
|
|||
PaginatedRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesList
|
||||
|
||||
/**
|
||||
* An opaque token representing the current pagination position.
|
||||
*/
|
||||
public val cursor: String?
|
||||
get() = params?.cursor
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -217,22 +229,6 @@ public data class ListResourcesResult(
|
|||
// resources/read
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Parameters for a resources/read request.
|
||||
*
|
||||
* @property uri The URI of the resource to read. The URI can use any protocol;
|
||||
* it is up to the server how to interpret it. Common schemes include
|
||||
* file://, http://, https://, or custom application-specific schemes.
|
||||
* @property meta Optional metadata for this request. May include a progressToken for
|
||||
* out-of-band progress notifications.
|
||||
*/
|
||||
@Serializable
|
||||
public data class ReadResourceRequestParams(
|
||||
val uri: String,
|
||||
@SerialName("_meta")
|
||||
override val meta: RequestMeta? = null,
|
||||
) : RequestParams
|
||||
|
||||
/**
|
||||
* Sent from the client to the server to read a specific resource URI.
|
||||
*
|
||||
|
|
@ -258,6 +254,22 @@ public data class ReadResourceRequest(override val params: ReadResourceRequestPa
|
|||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for a resources/read request.
|
||||
*
|
||||
* @property uri The URI of the resource to read. The URI can use any protocol;
|
||||
* it is up to the server how to interpret it. Common schemes include
|
||||
* file://, http://, https://, or custom application-specific schemes.
|
||||
* @property meta Optional metadata for this request. May include a progressToken for
|
||||
* out-of-band progress notifications.
|
||||
*/
|
||||
@Serializable
|
||||
public data class ReadResourceRequestParams(
|
||||
val uri: String,
|
||||
@SerialName("_meta")
|
||||
override val meta: RequestMeta? = null,
|
||||
) : RequestParams
|
||||
|
||||
/**
|
||||
* The server's response to a [ReadResourceRequest] from the client.
|
||||
*
|
||||
|
|
@ -280,6 +292,34 @@ public data class ReadResourceResult(
|
|||
// resources/subscribe
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Sent from the client to request resources/updated notifications from the server
|
||||
* whenever a particular resource changes.
|
||||
*
|
||||
* After subscribing, the server will send [ResourceUpdatedNotification] messages
|
||||
* whenever the subscribed resource is modified. This requires the server to support
|
||||
* the `subscribe` capability in [ServerCapabilities.resources].
|
||||
*
|
||||
* @property params The parameters specifying which resource URI to subscribe to.
|
||||
*/
|
||||
@Serializable
|
||||
public data class SubscribeRequest(override val params: SubscribeRequestParams) : ClientRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesSubscribe
|
||||
|
||||
/**
|
||||
* The URI of the resource to subscribe to.
|
||||
*/
|
||||
public val uri: String
|
||||
get() = params.uri
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for a resources/subscribe request.
|
||||
*
|
||||
|
|
@ -295,26 +335,36 @@ public data class SubscribeRequestParams(
|
|||
override val meta: RequestMeta? = null,
|
||||
) : RequestParams
|
||||
|
||||
/**
|
||||
* Sent from the client to request resources/updated notifications from the server
|
||||
* whenever a particular resource changes.
|
||||
*
|
||||
* After subscribing, the server will send [ResourceUpdatedNotification] messages
|
||||
* whenever the subscribed resource is modified. This requires the server to support
|
||||
* the `subscribe` capability in [ServerCapabilities.resources].
|
||||
*
|
||||
* @property params The parameters specifying which resource URI to subscribe to.
|
||||
*/
|
||||
@Serializable
|
||||
public data class SubscribeRequest(override val params: SubscribeRequestParams) : ClientRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesSubscribe
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// resources/unsubscribe
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Sent from the client to request cancellation of resources/updated notifications from the server.
|
||||
*
|
||||
* This should follow a previous [SubscribeRequest]. After unsubscribing, the server will
|
||||
* stop sending [ResourceUpdatedNotification] messages for this resource.
|
||||
*
|
||||
* @property params The parameters specifying which resource URI to unsubscribe from.
|
||||
*/
|
||||
@Serializable
|
||||
public data class UnsubscribeRequest(override val params: UnsubscribeRequestParams) : ClientRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesUnsubscribe
|
||||
|
||||
/**
|
||||
* The URI of the resource to unsubscribe from.
|
||||
*/
|
||||
public val uri: String
|
||||
get() = params.uri
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for a resources/unsubscribe request.
|
||||
*
|
||||
|
|
@ -330,20 +380,6 @@ public data class UnsubscribeRequestParams(
|
|||
override val meta: RequestMeta? = null,
|
||||
) : RequestParams
|
||||
|
||||
/**
|
||||
* Sent from the client to request cancellation of resources/updated notifications from the server.
|
||||
*
|
||||
* This should follow a previous [SubscribeRequest]. After unsubscribing, the server will
|
||||
* stop sending [ResourceUpdatedNotification] messages for this resource.
|
||||
*
|
||||
* @property params The parameters specifying which resource URI to unsubscribe from.
|
||||
*/
|
||||
@Serializable
|
||||
public data class UnsubscribeRequest(override val params: UnsubscribeRequestParams) : ClientRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesUnsubscribe
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// resources/templates/list
|
||||
// ============================================================================
|
||||
|
|
@ -363,6 +399,18 @@ public data class ListResourceTemplatesRequest(override val params: PaginatedReq
|
|||
PaginatedRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ResourcesTemplatesList
|
||||
|
||||
/**
|
||||
* An opaque token representing the current pagination position.
|
||||
*/
|
||||
public val cursor: String?
|
||||
get() = params?.cursor
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ public data class ListRootsRequest(override val params: BaseRequestParams? = nul
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.RootsList
|
||||
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -107,31 +107,85 @@ public data class CreateMessageRequest(override val params: CreateMessageRequest
|
|||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.SamplingCreateMessage
|
||||
|
||||
/**
|
||||
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
||||
*/
|
||||
public val maxTokens: Int
|
||||
get() = params.maxTokens
|
||||
|
||||
/**
|
||||
* The messages to use as context for sampling.
|
||||
*/
|
||||
public val messages: List<SamplingMessage>
|
||||
get() = params.messages
|
||||
|
||||
/**
|
||||
* The server's preferences for which model to select.
|
||||
*/
|
||||
public val modelPreferences: ModelPreferences?
|
||||
get() = params.modelPreferences
|
||||
|
||||
/**
|
||||
* An optional system prompt the server wants to use for sampling.
|
||||
*/
|
||||
public val systemPrompt: String?
|
||||
get() = params.systemPrompt
|
||||
|
||||
/**
|
||||
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
||||
*/
|
||||
public val includeContext: IncludeContext?
|
||||
get() = params.includeContext
|
||||
|
||||
/**
|
||||
* Temperature parameter for sampling (typically 0.0-2.0).
|
||||
*/
|
||||
public val temperature: Double?
|
||||
get() = params.temperature
|
||||
|
||||
/**
|
||||
* List of sequences that will stop generation if encountered.
|
||||
*/
|
||||
public val stopSequences: List<String>?
|
||||
get() = params.stopSequences
|
||||
|
||||
/**
|
||||
* Metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
||||
*/
|
||||
public val metadata: JsonObject?
|
||||
get() = params.metadata
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params.meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for a sampling/createMessage request.
|
||||
*
|
||||
* @property maxTokens The requested maximum number of tokens to sample (to prevent runaway completions).
|
||||
* The client MAY choose to sample fewer tokens than the requested maximum.
|
||||
* The client MAY choose to sample fewer tokens than the requested maximum.
|
||||
* @property messages The messages to use as context for sampling. Typically includes conversation history
|
||||
* and the current user message.
|
||||
* and the current user message.
|
||||
* @property modelPreferences The server's preferences for which model to select.
|
||||
* The client MAY ignore these preferences and choose any model.
|
||||
* The client MAY ignore these preferences and choose any model.
|
||||
* @property systemPrompt An optional system prompt the server wants to use for sampling.
|
||||
* The client MAY modify or omit this prompt.
|
||||
* The client MAY modify or omit this prompt.
|
||||
* @property includeContext A request to include context from one or more MCP servers (including the caller),
|
||||
* to be attached to the prompt. The client MAY ignore this request.
|
||||
* - "none": Don't include any server context
|
||||
* - "thisServer": Include context only from the requesting server
|
||||
* - "allServers": Include context from all connected MCP servers
|
||||
* to be attached to the prompt. The client MAY ignore this request.
|
||||
* - `none`: Don't include any server context
|
||||
* - `thisServer`: Include context only from the requesting server
|
||||
* - `allServers`: Include context from all connected MCP servers
|
||||
* @property temperature Optional temperature parameter for sampling (typically 0.0-2.0).
|
||||
* Higher values make output more random, lower values make it more deterministic.
|
||||
* Higher values make output more random, lower values make it more deterministic.
|
||||
* @property stopSequences Optional list of sequences that will stop generation if encountered.
|
||||
* @property metadata Optional metadata to pass through to the LLM provider.
|
||||
* The format of this metadata is provider-specific.
|
||||
* The format of this metadata is provider-specific.
|
||||
* @property meta Optional metadata for this request. May include a progressToken for
|
||||
* out-of-band progress notifications.
|
||||
* out-of-band progress notifications.
|
||||
*/
|
||||
@Serializable
|
||||
public data class CreateMessageRequestParams(
|
||||
|
|
|
|||
|
|
@ -226,6 +226,18 @@ public data class ListToolsRequest(override val params: PaginatedRequestParams?
|
|||
PaginatedRequest {
|
||||
@EncodeDefault
|
||||
override val method: Method = Method.Defined.ToolsList
|
||||
|
||||
/**
|
||||
* An opaque token representing the current pagination position.
|
||||
*/
|
||||
public val cursor: String?
|
||||
get() = params?.cursor
|
||||
|
||||
/**
|
||||
* Metadata for this request. May include a progressToken for out-of-band progress notifications.
|
||||
*/
|
||||
public val meta: RequestMeta?
|
||||
get() = params?.meta
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue