feat: 2025-11-25 review fixes (#201)
* fix: review fixes of the latest changes * fix: updated unit tests * chore: more conformance compliance improvements * chore: reverted protocol changes * chore: more compliance improvements * chore: more conformance compliance improvements * chore: improvements to the backcompat and updated to Tool unit tests * chore: ci update
This commit is contained in:
parent
6112a3995a
commit
973b46b8f7
1 changed files with 692 additions and 507 deletions
|
|
@ -48,8 +48,8 @@ public struct Prompt: Hashable, Codable, Sendable {
|
|||
try container.encodeIfPresent(title, forKey: .title)
|
||||
try container.encodeIfPresent(description, forKey: .description)
|
||||
try container.encodeIfPresent(arguments, forKey: .arguments)
|
||||
try container.encodeIfPresent(icons, forKey: . icons)
|
||||
try container.encodeIfPresent(_meta, forKey: . _meta)
|
||||
try container.encodeIfPresent(icons, forKey: .icons)
|
||||
try container.encodeIfPresent(_meta, forKey: ._meta)
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
|
|
@ -58,8 +58,8 @@ public struct Prompt: Hashable, Codable, Sendable {
|
|||
title = try container.decodeIfPresent(String.self, forKey: .title)
|
||||
description = try container.decodeIfPresent(String.self, forKey: .description)
|
||||
arguments = try container.decodeIfPresent([Argument].self, forKey: .arguments)
|
||||
icons = try container.decodeIfPresent([Icon].self, forKey: . icons)
|
||||
_meta = try container.decodeIfPresent(Metadata.self, forKey: . _meta)
|
||||
icons = try container.decodeIfPresent([Icon].self, forKey: .icons)
|
||||
_meta = try container.decodeIfPresent(Metadata.self, forKey: ._meta)
|
||||
}
|
||||
|
||||
/// An argument for a prompt
|
||||
|
|
@ -136,6 +136,8 @@ public struct Prompt: Hashable, Codable, Sendable {
|
|||
case audio(data: String, mimeType: String)
|
||||
/// Embedded resource content (EmbeddedResource from spec)
|
||||
case resource(resource: Resource.Content, annotations: Resource.Annotations? = nil, _meta: Metadata? = nil)
|
||||
/// Resource link
|
||||
case resourceLink(uri: String, name: String, title: String? = nil, description: String? = nil, mimeType: String? = nil, annotations: Resource.Annotations? = nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +178,7 @@ public struct Prompt: Hashable, Codable, Sendable {
|
|||
extension Prompt.Message.Content: Codable {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case type, text, data, mimeType, resource, annotations, _meta
|
||||
case uri, name, title, description
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
|
@ -198,6 +201,14 @@ extension Prompt.Message.Content: Codable {
|
|||
try container.encode(resourceContent, forKey: .resource)
|
||||
try container.encodeIfPresent(annotations, forKey: .annotations)
|
||||
try container.encodeIfPresent(_meta, forKey: ._meta)
|
||||
case .resourceLink(let uri, let name, let title, let description, let mimeType, let annotations):
|
||||
try container.encode("resource_link", forKey: .type)
|
||||
try container.encode(uri, forKey: .uri)
|
||||
try container.encode(name, forKey: .name)
|
||||
try container.encodeIfPresent(title, forKey: .title)
|
||||
try container.encodeIfPresent(description, forKey: .description)
|
||||
try container.encodeIfPresent(mimeType, forKey: .mimeType)
|
||||
try container.encodeIfPresent(annotations, forKey: .annotations)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -222,6 +233,14 @@ extension Prompt.Message.Content: Codable {
|
|||
let annotations = try container.decodeIfPresent(Resource.Annotations.self, forKey: .annotations)
|
||||
let _meta = try container.decodeIfPresent(Metadata.self, forKey: ._meta)
|
||||
self = .resource(resource: resourceContent, annotations: annotations, _meta: _meta)
|
||||
case "resource_link":
|
||||
let uri = try container.decode(String.self, forKey: .uri)
|
||||
let name = try container.decode(String.self, forKey: .name)
|
||||
let title = try container.decodeIfPresent(String.self, forKey: .title)
|
||||
let description = try container.decodeIfPresent(String.self, forKey: .description)
|
||||
let mimeType = try container.decodeIfPresent(String.self, forKey: .mimeType)
|
||||
let annotations = try container.decodeIfPresent(Resource.Annotations.self, forKey: .annotations)
|
||||
self = .resourceLink(uri: uri, name: name, title: title, description: description, mimeType: mimeType, annotations: annotations)
|
||||
default:
|
||||
throw DecodingError.dataCorruptedError(
|
||||
forKey: .type,
|
||||
|
|
@ -250,7 +269,7 @@ extension Prompt.Message.Content: ExpressibleByStringInterpolation {
|
|||
// MARK: -
|
||||
|
||||
/// To retrieve available prompts, clients send a `prompts/list` request.
|
||||
/// - SeeAlso: https://modelcontextprotocol.io/specification/2024-11-05/server/prompts/#listing-prompts
|
||||
/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/server/prompts/#listing-prompts
|
||||
public enum ListPrompts: Method {
|
||||
public static let name: String = "prompts/list"
|
||||
|
||||
|
|
@ -267,9 +286,9 @@ public enum ListPrompts: Method {
|
|||
}
|
||||
|
||||
public struct Result: Hashable, Codable, Sendable {
|
||||
let prompts: [Prompt]
|
||||
let nextCursor: String?
|
||||
var _meta: Metadata?
|
||||
public let prompts: [Prompt]
|
||||
public let nextCursor: String?
|
||||
public var _meta: Metadata?
|
||||
|
||||
public init(
|
||||
prompts: [Prompt],
|
||||
|
|
@ -303,15 +322,15 @@ public enum ListPrompts: Method {
|
|||
|
||||
/// To retrieve a specific prompt, clients send a `prompts/get` request.
|
||||
/// Arguments may be auto-completed through the completion API.
|
||||
/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/server/prompts/#getting-a-prompt
|
||||
/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/server/prompts/#getting-a-prompt
|
||||
public enum GetPrompt: Method {
|
||||
public static let name: String = "prompts/get"
|
||||
|
||||
public struct Parameters: Hashable, Codable, Sendable {
|
||||
public let name: String
|
||||
public let arguments: [String: Value]?
|
||||
public let arguments: [String: String]?
|
||||
|
||||
public init(name: String, arguments: [String: Value]? = nil) {
|
||||
public init(name: String, arguments: [String: String]? = nil) {
|
||||
self.name = name
|
||||
self.arguments = arguments
|
||||
}
|
||||
|
|
@ -354,7 +373,7 @@ public enum GetPrompt: Method {
|
|||
}
|
||||
|
||||
/// When the list of available prompts changes, servers that declared the listChanged capability SHOULD send a notification.
|
||||
/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/server/prompts/#list-changed-notification
|
||||
/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/server/prompts/#list-changed-notification
|
||||
public struct PromptListChangedNotification: Notification {
|
||||
public static let name: String = "notifications/prompts/list_changed"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue