swift-sdk/Sources/MCP/Base/Icon.swift
Maksym Mova 6112a3995a
V0.11.x (#199)
* Support 2025-06-18 Spec (#167)

* Support OpenAI _meta for Tool

* Update init

* Add title and outputSchema

* Concurreny issue

* General fields

* Add Generate Fields to Server elements

* 4 tab spacing

* Update Version

* Elicitation

* Format

* More tests and inits

* Elicitation in README

* Fix orphaned test

* Add title to more structs

* Public init

* Fix meta validation and make tests more generic

* Format and make Result properties public again

* Revert more visibility changes

* feat: 2025-11-25 phase 1, includes Version, Icon, Progress (#181)

* chore: fixed unit tests

* feat: added icon and progess base structs

* feat: added progress notification and meta to callTool

* feat: added tests

* feat: simplified RequestMeta encoding/decoding

* tests: added unit test to track progress

* chore: rebased v0.11.x

* feat: implemented cancellation

* feat: added overloaded callTool method

* fix: encoding Response _meta fix

* chore: added old version to the versions list

* feat: 2025-11-25 phase 2; added Logging and Completions (#196)

* feat: added Logging and Completions

* feat: updated EmbeddedResource for the latest spec

* chore: changed encoding of meta in Prompts to encodeIfPresent

* feat: compliance tests + http server transport (#197)

* feat: http server transport

* feat: added http server transport

* feat: removed unused files

* feat: added conformance tests

* feat: improved conformace testing

* chore: removed redundant files

* feat/2025-11-25: sampling, elicitation, roots (#198)

* feat: Roots implementation

* feat: added unit testing

* feat: improved unit tests and fixed NetworkTransport crash

* feat: implemented sampling and elicitation

* feat: improved sampling tests

* feat: improved elicitation tests

* feat: improved confirmance tests

* feat: improved Prompts unit tests

* feat: removed test code

* feat: updated conformance tests

* chore: removed redundant commas

* chore: removed 6.0.3 swift version from ci

* chore: improved unit tests a little bit

* chore: update README.md

* chore: add server progress tracking example to README.md

* chore: updated README.md

* chore: updated transports table formatting

* chore: updated MockNetworkConnection

---------

Co-authored-by: Austin Evans <austinjevans@me.com>
Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
2026-02-19 13:09:31 +02:00

67 lines
2.5 KiB
Swift

import Foundation
/// An optionally-sized icon that can be displayed in a user interface.
///
/// Icons can be used to provide visual representation of tools, resources, prompts,
/// and other MCP entities.
///
/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/schema#icon
public struct Icon: Hashable, Codable, Sendable {
/// The theme this icon is designed for.
public enum Theme: String, Hashable, Codable, Sendable {
/// Icon is designed for light backgrounds
case light
/// Icon is designed for dark backgrounds
case dark
}
/// A standard URI pointing to an icon resource.
///
/// May be an HTTP/HTTPS URL or a `data:` URI with Base64-encoded image data.
///
/// - Note: Consumers SHOULD take steps to ensure URLs serving icons are from
/// the same domain as the client/server or a trusted domain.
/// - Note: Consumers SHOULD take appropriate precautions when consuming SVGs
/// as they can contain executable JavaScript.
public let src: String
/// Optional MIME type override if the source MIME type is missing or generic.
///
/// For example: `"image/png"`, `"image/jpeg"`, or `"image/svg+xml"`.
public let mimeType: String?
/// Optional array of strings that specify sizes at which the icon can be used.
///
/// Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"`
/// for scalable formats like SVG.
///
/// If not provided, the client should assume that the icon can be used at any size.
public let sizes: [String]?
/// Optional specifier for the theme this icon is designed for.
///
/// - `light`: Icon is designed to be used with a light background
/// - `dark`: Icon is designed to be used with a dark background
///
/// If not provided, the client should assume the icon can be used with any theme.
public let theme: Theme?
/// Creates a new icon.
///
/// - Parameters:
/// - src: A standard URI pointing to an icon resource (HTTP/HTTPS URL or data: URI)
/// - mimeType: Optional MIME type override
/// - sizes: Optional array of size strings (e.g., ["48x48", "96x96"])
/// - theme: Optional theme specifier
public init(
src: String,
mimeType: String? = nil,
sizes: [String]? = nil,
theme: Theme? = nil
) {
self.src = src
self.mimeType = mimeType
self.sizes = sizes
self.theme = theme
}
}