{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

{- |
Module      : MCP.Types
Description : Core types for the Model Context Protocol (MCP)
Copyright   : (C) 2025 DPella AB
License     : MPL-2.0
Maintainer  : matti@dpella.io, lobo@dpella.io
Stability   : experimental
Portability : GHC

This module defines the core types used in the Model Context Protocol (MCP),
including JSON-RPC message types, client/server capabilities, resources,
tools, prompts, and various request/response types.
-}
module MCP.Types (
    -- * Basic Types (re-exported from JSONRPC)
    RequestId (..),
    -- * Basic Types
    Role (..),
    Cursor (..),
    ProgressToken (..),
    LoggingLevel (..),

    -- * Content Types
    Annotations (..),
    TextContent (..),
    ImageContent (..),
    AudioContent (..),
    EmbeddedResource (..),
    ResourceLink (..),
    Content (..),
    ContentBlock (..),

    -- * Resource Types
    ResourceContents (..),
    TextResourceContents (..),
    BlobResourceContents (..),
    Resource (..),
    ResourceTemplate (..),
    ResourceReference (..),
    ResourceTemplateReference,

    -- * Tool Types
    ToolAnnotations (..),
    Tool (..),
    InputSchema (..),

    -- * Prompt Types
    PromptArgument (..),
    Prompt (..),
    PromptMessage (..),
    PromptReference (..),

    -- * Model Types
    ModelHint (..),
    ModelPreferences (..),
    IncludeContext (..),
    SamplingMessage (..),

    -- * Capability Types
    ClientCapabilities (..),
    ServerCapabilities (..),
    RootsCapability (..),
    PromptsCapability (..),
    ResourcesCapability (..),
    ToolsCapability (..),
    CompletionsCapability (..),
    LoggingCapability (..),
    SamplingCapability (..),
    ElicitationCapability (..),
    ExperimentalCapability (..),

    -- * Implementation Info
    BaseMetadata (..),
    Implementation (..),

    -- * Roots
    Root (..),

    -- * Result Types
    Result (..),
    Metadata (..),
) where

import Control.Applicative (Alternative ((<|>)))
import Data.Aeson hiding (Error, Result)
import Data.Aeson.TH
import Data.Map (Map)
import Data.Text (Text)
import GHC.Generics
import JSONRPC (RequestId (..))
import MCP.Aeson

{- | The sender or recipient of messages and data in a conversation.

This is used to identify whether content comes from the user or the assistant
in prompt messages and sampling requests.
-}
data Role = User | Assistant
    deriving stock (Int -> Role -> ShowS
[Role] -> ShowS
Role -> String
(Int -> Role -> ShowS)
-> (Role -> String) -> ([Role] -> ShowS) -> Show Role
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Role -> ShowS
showsPrec :: Int -> Role -> ShowS
$cshow :: Role -> String
show :: Role -> String
$cshowList :: [Role] -> ShowS
showList :: [Role] -> ShowS
Show, Role -> Role -> Bool
(Role -> Role -> Bool) -> (Role -> Role -> Bool) -> Eq Role
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Role -> Role -> Bool
== :: Role -> Role -> Bool
$c/= :: Role -> Role -> Bool
/= :: Role -> Role -> Bool
Eq, (forall x. Role -> Rep Role x)
-> (forall x. Rep Role x -> Role) -> Generic Role
forall x. Rep Role x -> Role
forall x. Role -> Rep Role x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Role -> Rep Role x
from :: forall x. Role -> Rep Role x
$cto :: forall x. Rep Role x -> Role
to :: forall x. Rep Role x -> Role
Generic)

instance ToJSON Role where
    toJSON :: Role -> Value
toJSON Role
User = Value
"user"
    toJSON Role
Assistant = Value
"assistant"

instance FromJSON Role where
    parseJSON :: Value -> Parser Role
parseJSON = String -> (Text -> Parser Role) -> Value -> Parser Role
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"Role" ((Text -> Parser Role) -> Value -> Parser Role)
-> (Text -> Parser Role) -> Value -> Parser Role
forall a b. (a -> b) -> a -> b
$ \case
        Text
"user" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
User
        Text
"assistant" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
Assistant
        Text
other -> String -> Parser Role
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Role) -> String -> Parser Role
forall a b. (a -> b) -> a -> b
$ String
"Unknown role: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other

{- | An opaque token used to represent a cursor for pagination.

Used in paginated requests to indicate the starting position for the next
set of results. If provided, the server should return results starting
after this cursor.
-}
newtype Cursor = Cursor Text
    deriving stock (Int -> Cursor -> ShowS
[Cursor] -> ShowS
Cursor -> String
(Int -> Cursor -> ShowS)
-> (Cursor -> String) -> ([Cursor] -> ShowS) -> Show Cursor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cursor -> ShowS
showsPrec :: Int -> Cursor -> ShowS
$cshow :: Cursor -> String
show :: Cursor -> String
$cshowList :: [Cursor] -> ShowS
showList :: [Cursor] -> ShowS
Show, Cursor -> Cursor -> Bool
(Cursor -> Cursor -> Bool)
-> (Cursor -> Cursor -> Bool) -> Eq Cursor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cursor -> Cursor -> Bool
== :: Cursor -> Cursor -> Bool
$c/= :: Cursor -> Cursor -> Bool
/= :: Cursor -> Cursor -> Bool
Eq)
    deriving newtype ([Cursor] -> Value
[Cursor] -> Encoding
Cursor -> Bool
Cursor -> Value
Cursor -> Encoding
(Cursor -> Value)
-> (Cursor -> Encoding)
-> ([Cursor] -> Value)
-> ([Cursor] -> Encoding)
-> (Cursor -> Bool)
-> ToJSON Cursor
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Cursor -> Value
toJSON :: Cursor -> Value
$ctoEncoding :: Cursor -> Encoding
toEncoding :: Cursor -> Encoding
$ctoJSONList :: [Cursor] -> Value
toJSONList :: [Cursor] -> Value
$ctoEncodingList :: [Cursor] -> Encoding
toEncodingList :: [Cursor] -> Encoding
$comitField :: Cursor -> Bool
omitField :: Cursor -> Bool
ToJSON, Maybe Cursor
Value -> Parser [Cursor]
Value -> Parser Cursor
(Value -> Parser Cursor)
-> (Value -> Parser [Cursor]) -> Maybe Cursor -> FromJSON Cursor
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Cursor
parseJSON :: Value -> Parser Cursor
$cparseJSONList :: Value -> Parser [Cursor]
parseJSONList :: Value -> Parser [Cursor]
$comittedField :: Maybe Cursor
omittedField :: Maybe Cursor
FromJSON)

{- | A progress token, used to associate progress notifications with the original request.

If specified in a request, the caller is requesting out-of-band progress
notifications (as represented by notifications/progress). The value is an
opaque token that will be attached to any subsequent notifications.
The receiver is not obligated to provide these notifications.
-}
newtype ProgressToken = ProgressToken Value
    deriving stock (Int -> ProgressToken -> ShowS
[ProgressToken] -> ShowS
ProgressToken -> String
(Int -> ProgressToken -> ShowS)
-> (ProgressToken -> String)
-> ([ProgressToken] -> ShowS)
-> Show ProgressToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProgressToken -> ShowS
showsPrec :: Int -> ProgressToken -> ShowS
$cshow :: ProgressToken -> String
show :: ProgressToken -> String
$cshowList :: [ProgressToken] -> ShowS
showList :: [ProgressToken] -> ShowS
Show, ProgressToken -> ProgressToken -> Bool
(ProgressToken -> ProgressToken -> Bool)
-> (ProgressToken -> ProgressToken -> Bool) -> Eq ProgressToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProgressToken -> ProgressToken -> Bool
== :: ProgressToken -> ProgressToken -> Bool
$c/= :: ProgressToken -> ProgressToken -> Bool
/= :: ProgressToken -> ProgressToken -> Bool
Eq)
    deriving newtype ([ProgressToken] -> Value
[ProgressToken] -> Encoding
ProgressToken -> Bool
ProgressToken -> Value
ProgressToken -> Encoding
(ProgressToken -> Value)
-> (ProgressToken -> Encoding)
-> ([ProgressToken] -> Value)
-> ([ProgressToken] -> Encoding)
-> (ProgressToken -> Bool)
-> ToJSON ProgressToken
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ProgressToken -> Value
toJSON :: ProgressToken -> Value
$ctoEncoding :: ProgressToken -> Encoding
toEncoding :: ProgressToken -> Encoding
$ctoJSONList :: [ProgressToken] -> Value
toJSONList :: [ProgressToken] -> Value
$ctoEncodingList :: [ProgressToken] -> Encoding
toEncodingList :: [ProgressToken] -> Encoding
$comitField :: ProgressToken -> Bool
omitField :: ProgressToken -> Bool
ToJSON, Maybe ProgressToken
Value -> Parser [ProgressToken]
Value -> Parser ProgressToken
(Value -> Parser ProgressToken)
-> (Value -> Parser [ProgressToken])
-> Maybe ProgressToken
-> FromJSON ProgressToken
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ProgressToken
parseJSON :: Value -> Parser ProgressToken
$cparseJSONList :: Value -> Parser [ProgressToken]
parseJSONList :: Value -> Parser [ProgressToken]
$comittedField :: Maybe ProgressToken
omittedField :: Maybe ProgressToken
FromJSON)

{- | 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
-}
data LoggingLevel
    = Emergency
    | Alert
    | Critical
    | Error
    | Warning
    | Notice
    | Info
    | Debug
    deriving stock (Int -> LoggingLevel -> ShowS
[LoggingLevel] -> ShowS
LoggingLevel -> String
(Int -> LoggingLevel -> ShowS)
-> (LoggingLevel -> String)
-> ([LoggingLevel] -> ShowS)
-> Show LoggingLevel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LoggingLevel -> ShowS
showsPrec :: Int -> LoggingLevel -> ShowS
$cshow :: LoggingLevel -> String
show :: LoggingLevel -> String
$cshowList :: [LoggingLevel] -> ShowS
showList :: [LoggingLevel] -> ShowS
Show, Eq LoggingLevel
Eq LoggingLevel =>
(LoggingLevel -> LoggingLevel -> Ordering)
-> (LoggingLevel -> LoggingLevel -> Bool)
-> (LoggingLevel -> LoggingLevel -> Bool)
-> (LoggingLevel -> LoggingLevel -> Bool)
-> (LoggingLevel -> LoggingLevel -> Bool)
-> (LoggingLevel -> LoggingLevel -> LoggingLevel)
-> (LoggingLevel -> LoggingLevel -> LoggingLevel)
-> Ord LoggingLevel
LoggingLevel -> LoggingLevel -> Bool
LoggingLevel -> LoggingLevel -> Ordering
LoggingLevel -> LoggingLevel -> LoggingLevel
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LoggingLevel -> LoggingLevel -> Ordering
compare :: LoggingLevel -> LoggingLevel -> Ordering
$c< :: LoggingLevel -> LoggingLevel -> Bool
< :: LoggingLevel -> LoggingLevel -> Bool
$c<= :: LoggingLevel -> LoggingLevel -> Bool
<= :: LoggingLevel -> LoggingLevel -> Bool
$c> :: LoggingLevel -> LoggingLevel -> Bool
> :: LoggingLevel -> LoggingLevel -> Bool
$c>= :: LoggingLevel -> LoggingLevel -> Bool
>= :: LoggingLevel -> LoggingLevel -> Bool
$cmax :: LoggingLevel -> LoggingLevel -> LoggingLevel
max :: LoggingLevel -> LoggingLevel -> LoggingLevel
$cmin :: LoggingLevel -> LoggingLevel -> LoggingLevel
min :: LoggingLevel -> LoggingLevel -> LoggingLevel
Ord, LoggingLevel -> LoggingLevel -> Bool
(LoggingLevel -> LoggingLevel -> Bool)
-> (LoggingLevel -> LoggingLevel -> Bool) -> Eq LoggingLevel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LoggingLevel -> LoggingLevel -> Bool
== :: LoggingLevel -> LoggingLevel -> Bool
$c/= :: LoggingLevel -> LoggingLevel -> Bool
/= :: LoggingLevel -> LoggingLevel -> Bool
Eq, (forall x. LoggingLevel -> Rep LoggingLevel x)
-> (forall x. Rep LoggingLevel x -> LoggingLevel)
-> Generic LoggingLevel
forall x. Rep LoggingLevel x -> LoggingLevel
forall x. LoggingLevel -> Rep LoggingLevel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LoggingLevel -> Rep LoggingLevel x
from :: forall x. LoggingLevel -> Rep LoggingLevel x
$cto :: forall x. Rep LoggingLevel x -> LoggingLevel
to :: forall x. Rep LoggingLevel x -> LoggingLevel
Generic)

instance ToJSON LoggingLevel where
    toJSON :: LoggingLevel -> Value
toJSON LoggingLevel
Emergency = Value
"emergency"
    toJSON LoggingLevel
Alert = Value
"alert"
    toJSON LoggingLevel
Critical = Value
"critical"
    toJSON LoggingLevel
Error = Value
"error"
    toJSON LoggingLevel
Warning = Value
"warning"
    toJSON LoggingLevel
Notice = Value
"notice"
    toJSON LoggingLevel
Info = Value
"info"
    toJSON LoggingLevel
Debug = Value
"debug"

instance FromJSON LoggingLevel where
    parseJSON :: Value -> Parser LoggingLevel
parseJSON = String
-> (Text -> Parser LoggingLevel) -> Value -> Parser LoggingLevel
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"LoggingLevel" ((Text -> Parser LoggingLevel) -> Value -> Parser LoggingLevel)
-> (Text -> Parser LoggingLevel) -> Value -> Parser LoggingLevel
forall a b. (a -> b) -> a -> b
$ \case
        Text
"alert" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Alert
        Text
"critical" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Critical
        Text
"debug" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Debug
        Text
"emergency" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Emergency
        Text
"error" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Error
        Text
"info" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Info
        Text
"notice" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Notice
        Text
"warning" -> LoggingLevel -> Parser LoggingLevel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingLevel
Warning
        Text
other -> String -> Parser LoggingLevel
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser LoggingLevel) -> String -> Parser LoggingLevel
forall a b. (a -> b) -> a -> b
$ String
"Unknown logging level: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other

{- | Optional annotations for the client.

The client can use annotations to inform how objects are used or displayed.
-}
data Annotations = Annotations
    { Annotations -> Maybe [Role]
audience :: Maybe [Role]
    {- ^ Describes who the intended customer of this object or data is.
    It can include multiple entries to indicate content useful for
    multiple audiences (e.g., ["user", "assistant"]).
    -}
    , Annotations -> Maybe Double
priority :: Maybe Double
    {- ^ Describes how important this data is for operating the server.
    A value of 1 means "most important," and indicates that the data is
    effectively required, while 0 means "least important," and indicates
    that the data is entirely optional. Range: 0.0 to 1.0
    -}
    , Annotations -> Maybe Text
lastModified :: Maybe Text
    {- ^ The moment the resource was last modified, as an ISO 8601 formatted string.
    Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z").
    Examples: last activity timestamp in an open file, timestamp when the resource
    was attached, etc.
    -}
    }
    deriving stock (Int -> Annotations -> ShowS
[Annotations] -> ShowS
Annotations -> String
(Int -> Annotations -> ShowS)
-> (Annotations -> String)
-> ([Annotations] -> ShowS)
-> Show Annotations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Annotations -> ShowS
showsPrec :: Int -> Annotations -> ShowS
$cshow :: Annotations -> String
show :: Annotations -> String
$cshowList :: [Annotations] -> ShowS
showList :: [Annotations] -> ShowS
Show, Annotations -> Annotations -> Bool
(Annotations -> Annotations -> Bool)
-> (Annotations -> Annotations -> Bool) -> Eq Annotations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Annotations -> Annotations -> Bool
== :: Annotations -> Annotations -> Bool
$c/= :: Annotations -> Annotations -> Bool
/= :: Annotations -> Annotations -> Bool
Eq, (forall x. Annotations -> Rep Annotations x)
-> (forall x. Rep Annotations x -> Annotations)
-> Generic Annotations
forall x. Rep Annotations x -> Annotations
forall x. Annotations -> Rep Annotations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Annotations -> Rep Annotations x
from :: forall x. Annotations -> Rep Annotations x
$cto :: forall x. Rep Annotations x -> Annotations
to :: forall x. Rep Annotations x -> Annotations
Generic)

$(deriveJSON mcpParseOpts ''Annotations)

{- | Metadata for results.

This result property is reserved by the protocol to allow clients and servers
to attach additional metadata to their responses.
-}
newtype Metadata = Metadata (Map Text Value)
    deriving stock (Int -> Metadata -> ShowS
[Metadata] -> ShowS
Metadata -> String
(Int -> Metadata -> ShowS)
-> (Metadata -> String) -> ([Metadata] -> ShowS) -> Show Metadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Metadata -> ShowS
showsPrec :: Int -> Metadata -> ShowS
$cshow :: Metadata -> String
show :: Metadata -> String
$cshowList :: [Metadata] -> ShowS
showList :: [Metadata] -> ShowS
Show, Metadata -> Metadata -> Bool
(Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool) -> Eq Metadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Metadata -> Metadata -> Bool
== :: Metadata -> Metadata -> Bool
$c/= :: Metadata -> Metadata -> Bool
/= :: Metadata -> Metadata -> Bool
Eq, (forall x. Metadata -> Rep Metadata x)
-> (forall x. Rep Metadata x -> Metadata) -> Generic Metadata
forall x. Rep Metadata x -> Metadata
forall x. Metadata -> Rep Metadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Metadata -> Rep Metadata x
from :: forall x. Metadata -> Rep Metadata x
$cto :: forall x. Rep Metadata x -> Metadata
to :: forall x. Rep Metadata x -> Metadata
Generic)
    deriving newtype ([Metadata] -> Value
[Metadata] -> Encoding
Metadata -> Bool
Metadata -> Value
Metadata -> Encoding
(Metadata -> Value)
-> (Metadata -> Encoding)
-> ([Metadata] -> Value)
-> ([Metadata] -> Encoding)
-> (Metadata -> Bool)
-> ToJSON Metadata
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Metadata -> Value
toJSON :: Metadata -> Value
$ctoEncoding :: Metadata -> Encoding
toEncoding :: Metadata -> Encoding
$ctoJSONList :: [Metadata] -> Value
toJSONList :: [Metadata] -> Value
$ctoEncodingList :: [Metadata] -> Encoding
toEncodingList :: [Metadata] -> Encoding
$comitField :: Metadata -> Bool
omitField :: Metadata -> Bool
ToJSON, Maybe Metadata
Value -> Parser [Metadata]
Value -> Parser Metadata
(Value -> Parser Metadata)
-> (Value -> Parser [Metadata])
-> Maybe Metadata
-> FromJSON Metadata
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Metadata
parseJSON :: Value -> Parser Metadata
$cparseJSONList :: Value -> Parser [Metadata]
parseJSONList :: Value -> Parser [Metadata]
$comittedField :: Maybe Metadata
omittedField :: Maybe Metadata
FromJSON)

{- | Text provided to or from an LLM.

This represents textual content that can be sent to or received from
a language model during conversations.
-}
data TextContent = TextContent
    { TextContent -> Text
textType :: Text -- Always "text"
    , TextContent -> Text
text :: Text
    -- ^ The text content of the message.
    , TextContent -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , TextContent -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> TextContent -> ShowS
[TextContent] -> ShowS
TextContent -> String
(Int -> TextContent -> ShowS)
-> (TextContent -> String)
-> ([TextContent] -> ShowS)
-> Show TextContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextContent -> ShowS
showsPrec :: Int -> TextContent -> ShowS
$cshow :: TextContent -> String
show :: TextContent -> String
$cshowList :: [TextContent] -> ShowS
showList :: [TextContent] -> ShowS
Show, TextContent -> TextContent -> Bool
(TextContent -> TextContent -> Bool)
-> (TextContent -> TextContent -> Bool) -> Eq TextContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextContent -> TextContent -> Bool
== :: TextContent -> TextContent -> Bool
$c/= :: TextContent -> TextContent -> Bool
/= :: TextContent -> TextContent -> Bool
Eq, (forall x. TextContent -> Rep TextContent x)
-> (forall x. Rep TextContent x -> TextContent)
-> Generic TextContent
forall x. Rep TextContent x -> TextContent
forall x. TextContent -> Rep TextContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TextContent -> Rep TextContent x
from :: forall x. TextContent -> Rep TextContent x
$cto :: forall x. Rep TextContent x -> TextContent
to :: forall x. Rep TextContent x -> TextContent
Generic)

instance ToJSON TextContent where
    toJSON :: TextContent -> Value
toJSON (TextContent Text
_ Text
txt Maybe Annotations
anns Maybe Metadata
m) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"text" :: Text)
            , Key
"text" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
txt
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Annotations -> [Pair]) -> Maybe Annotations -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Annotations
a -> [Key
"annotations" Key -> Annotations -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Annotations
a]) Maybe Annotations
anns
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Metadata -> [Pair]) -> Maybe Metadata -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Metadata
meta -> [Key
"_meta" Key -> Metadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Metadata
meta]) Maybe Metadata
m

instance FromJSON TextContent where
    parseJSON :: Value -> Parser TextContent
parseJSON = String
-> (Object -> Parser TextContent) -> Value -> Parser TextContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TextContent" ((Object -> Parser TextContent) -> Value -> Parser TextContent)
-> (Object -> Parser TextContent) -> Value -> Parser TextContent
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"text" :: Text)
            then Text -> Text -> Maybe Annotations -> Maybe Metadata -> TextContent
TextContent Text
ty (Text -> Maybe Annotations -> Maybe Metadata -> TextContent)
-> Parser Text
-> Parser (Maybe Annotations -> Maybe Metadata -> TextContent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text" Parser (Maybe Annotations -> Maybe Metadata -> TextContent)
-> Parser (Maybe Annotations)
-> Parser (Maybe Metadata -> TextContent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Annotations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotations" Parser (Maybe Metadata -> TextContent)
-> Parser (Maybe Metadata) -> Parser TextContent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Metadata)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_meta"
            else String -> Parser TextContent
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'text'"

{- | An image provided to or from an LLM.

Represents image data that can be included in messages to language models
that support multimodal input.
-}
data ImageContent = ImageContent
    { ImageContent -> Text
imageType :: Text -- Always "image"
    , ImageContent -> Text
data' :: Text
    -- ^ The base64-encoded image data.
    , ImageContent -> Text
mimeType :: Text
    -- ^ The MIME type of the image. Different providers may support different image types.
    , ImageContent -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , ImageContent -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> ImageContent -> ShowS
[ImageContent] -> ShowS
ImageContent -> String
(Int -> ImageContent -> ShowS)
-> (ImageContent -> String)
-> ([ImageContent] -> ShowS)
-> Show ImageContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImageContent -> ShowS
showsPrec :: Int -> ImageContent -> ShowS
$cshow :: ImageContent -> String
show :: ImageContent -> String
$cshowList :: [ImageContent] -> ShowS
showList :: [ImageContent] -> ShowS
Show, ImageContent -> ImageContent -> Bool
(ImageContent -> ImageContent -> Bool)
-> (ImageContent -> ImageContent -> Bool) -> Eq ImageContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImageContent -> ImageContent -> Bool
== :: ImageContent -> ImageContent -> Bool
$c/= :: ImageContent -> ImageContent -> Bool
/= :: ImageContent -> ImageContent -> Bool
Eq, (forall x. ImageContent -> Rep ImageContent x)
-> (forall x. Rep ImageContent x -> ImageContent)
-> Generic ImageContent
forall x. Rep ImageContent x -> ImageContent
forall x. ImageContent -> Rep ImageContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ImageContent -> Rep ImageContent x
from :: forall x. ImageContent -> Rep ImageContent x
$cto :: forall x. Rep ImageContent x -> ImageContent
to :: forall x. Rep ImageContent x -> ImageContent
Generic)

instance ToJSON ImageContent where
    toJSON :: ImageContent -> Value
toJSON (ImageContent Text
_ Text
dat Text
mime Maybe Annotations
anns Maybe Metadata
m) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"image" :: Text)
            , Key
"data" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
dat
            , Key
"mimeType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
mime
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Annotations -> [Pair]) -> Maybe Annotations -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Annotations
a -> [Key
"annotations" Key -> Annotations -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Annotations
a]) Maybe Annotations
anns
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Metadata -> [Pair]) -> Maybe Metadata -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Metadata
meta -> [Key
"_meta" Key -> Metadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Metadata
meta]) Maybe Metadata
m

instance FromJSON ImageContent where
    parseJSON :: Value -> Parser ImageContent
parseJSON = String
-> (Object -> Parser ImageContent) -> Value -> Parser ImageContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ImageContent" ((Object -> Parser ImageContent) -> Value -> Parser ImageContent)
-> (Object -> Parser ImageContent) -> Value -> Parser ImageContent
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"image" :: Text)
            then Text
-> Text
-> Text
-> Maybe Annotations
-> Maybe Metadata
-> ImageContent
ImageContent Text
ty (Text
 -> Text -> Maybe Annotations -> Maybe Metadata -> ImageContent)
-> Parser Text
-> Parser
     (Text -> Maybe Annotations -> Maybe Metadata -> ImageContent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data" Parser
  (Text -> Maybe Annotations -> Maybe Metadata -> ImageContent)
-> Parser Text
-> Parser (Maybe Annotations -> Maybe Metadata -> ImageContent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mimeType" Parser (Maybe Annotations -> Maybe Metadata -> ImageContent)
-> Parser (Maybe Annotations)
-> Parser (Maybe Metadata -> ImageContent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Annotations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotations" Parser (Maybe Metadata -> ImageContent)
-> Parser (Maybe Metadata) -> Parser ImageContent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Metadata)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_meta"
            else String -> Parser ImageContent
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'image'"

{- | Audio provided to or from an LLM.

Represents audio data that can be included in messages to language models
that support audio input.
-}
data AudioContent = AudioContent
    { AudioContent -> Text
audioType :: Text -- Always "audio"
    , AudioContent -> Text
data' :: Text
    -- ^ The base64-encoded audio data.
    , AudioContent -> Text
mimeType :: Text
    -- ^ The MIME type of the audio. Different providers may support different audio types.
    , AudioContent -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , AudioContent -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> AudioContent -> ShowS
[AudioContent] -> ShowS
AudioContent -> String
(Int -> AudioContent -> ShowS)
-> (AudioContent -> String)
-> ([AudioContent] -> ShowS)
-> Show AudioContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AudioContent -> ShowS
showsPrec :: Int -> AudioContent -> ShowS
$cshow :: AudioContent -> String
show :: AudioContent -> String
$cshowList :: [AudioContent] -> ShowS
showList :: [AudioContent] -> ShowS
Show, AudioContent -> AudioContent -> Bool
(AudioContent -> AudioContent -> Bool)
-> (AudioContent -> AudioContent -> Bool) -> Eq AudioContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AudioContent -> AudioContent -> Bool
== :: AudioContent -> AudioContent -> Bool
$c/= :: AudioContent -> AudioContent -> Bool
/= :: AudioContent -> AudioContent -> Bool
Eq, (forall x. AudioContent -> Rep AudioContent x)
-> (forall x. Rep AudioContent x -> AudioContent)
-> Generic AudioContent
forall x. Rep AudioContent x -> AudioContent
forall x. AudioContent -> Rep AudioContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AudioContent -> Rep AudioContent x
from :: forall x. AudioContent -> Rep AudioContent x
$cto :: forall x. Rep AudioContent x -> AudioContent
to :: forall x. Rep AudioContent x -> AudioContent
Generic)

instance ToJSON AudioContent where
    toJSON :: AudioContent -> Value
toJSON (AudioContent Text
_ Text
dat Text
mime Maybe Annotations
anns Maybe Metadata
m) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"audio" :: Text)
            , Key
"data" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
dat
            , Key
"mimeType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
mime
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Annotations -> [Pair]) -> Maybe Annotations -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Annotations
a -> [Key
"annotations" Key -> Annotations -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Annotations
a]) Maybe Annotations
anns
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Metadata -> [Pair]) -> Maybe Metadata -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Metadata
meta -> [Key
"_meta" Key -> Metadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Metadata
meta]) Maybe Metadata
m

instance FromJSON AudioContent where
    parseJSON :: Value -> Parser AudioContent
parseJSON = String
-> (Object -> Parser AudioContent) -> Value -> Parser AudioContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"AudioContent" ((Object -> Parser AudioContent) -> Value -> Parser AudioContent)
-> (Object -> Parser AudioContent) -> Value -> Parser AudioContent
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"audio" :: Text)
            then Text
-> Text
-> Text
-> Maybe Annotations
-> Maybe Metadata
-> AudioContent
AudioContent Text
ty (Text
 -> Text -> Maybe Annotations -> Maybe Metadata -> AudioContent)
-> Parser Text
-> Parser
     (Text -> Maybe Annotations -> Maybe Metadata -> AudioContent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"data" Parser
  (Text -> Maybe Annotations -> Maybe Metadata -> AudioContent)
-> Parser Text
-> Parser (Maybe Annotations -> Maybe Metadata -> AudioContent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mimeType" Parser (Maybe Annotations -> Maybe Metadata -> AudioContent)
-> Parser (Maybe Annotations)
-> Parser (Maybe Metadata -> AudioContent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Annotations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotations" Parser (Maybe Metadata -> AudioContent)
-> Parser (Maybe Metadata) -> Parser AudioContent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Metadata)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_meta"
            else String -> Parser AudioContent
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'audio'"

{- | Text resource contents.

Represents the contents of a resource that can be represented as text
(not binary data).
-}
data TextResourceContents = TextResourceContents
    { TextResourceContents -> Text
uri :: Text
    -- ^ The URI of this resource.
    , TextResourceContents -> Text
text :: Text
    {- ^ The text of the item. This must only be set if the item can
    actually be represented as text (not binary data).
    -}
    , TextResourceContents -> Maybe Text
mimeType :: Maybe Text
    -- ^ The MIME type of this resource, if known.
    , TextResourceContents -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> TextResourceContents -> ShowS
[TextResourceContents] -> ShowS
TextResourceContents -> String
(Int -> TextResourceContents -> ShowS)
-> (TextResourceContents -> String)
-> ([TextResourceContents] -> ShowS)
-> Show TextResourceContents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextResourceContents -> ShowS
showsPrec :: Int -> TextResourceContents -> ShowS
$cshow :: TextResourceContents -> String
show :: TextResourceContents -> String
$cshowList :: [TextResourceContents] -> ShowS
showList :: [TextResourceContents] -> ShowS
Show, TextResourceContents -> TextResourceContents -> Bool
(TextResourceContents -> TextResourceContents -> Bool)
-> (TextResourceContents -> TextResourceContents -> Bool)
-> Eq TextResourceContents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextResourceContents -> TextResourceContents -> Bool
== :: TextResourceContents -> TextResourceContents -> Bool
$c/= :: TextResourceContents -> TextResourceContents -> Bool
/= :: TextResourceContents -> TextResourceContents -> Bool
Eq, (forall x. TextResourceContents -> Rep TextResourceContents x)
-> (forall x. Rep TextResourceContents x -> TextResourceContents)
-> Generic TextResourceContents
forall x. Rep TextResourceContents x -> TextResourceContents
forall x. TextResourceContents -> Rep TextResourceContents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TextResourceContents -> Rep TextResourceContents x
from :: forall x. TextResourceContents -> Rep TextResourceContents x
$cto :: forall x. Rep TextResourceContents x -> TextResourceContents
to :: forall x. Rep TextResourceContents x -> TextResourceContents
Generic)

$( deriveJSON
    mcpParseOpts
    ''TextResourceContents
 )

{- | Blob resource contents.

Represents the contents of a resource as binary data, encoded in base64.
-}
data BlobResourceContents = BlobResourceContents
    { BlobResourceContents -> Text
uri :: Text
    -- ^ The URI of this resource.
    , BlobResourceContents -> Text
blob :: Text
    -- ^ A base64-encoded string representing the binary data of the item.
    , BlobResourceContents -> Maybe Text
mimeType :: Maybe Text
    -- ^ The MIME type of this resource, if known.
    , BlobResourceContents -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> BlobResourceContents -> ShowS
[BlobResourceContents] -> ShowS
BlobResourceContents -> String
(Int -> BlobResourceContents -> ShowS)
-> (BlobResourceContents -> String)
-> ([BlobResourceContents] -> ShowS)
-> Show BlobResourceContents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlobResourceContents -> ShowS
showsPrec :: Int -> BlobResourceContents -> ShowS
$cshow :: BlobResourceContents -> String
show :: BlobResourceContents -> String
$cshowList :: [BlobResourceContents] -> ShowS
showList :: [BlobResourceContents] -> ShowS
Show, BlobResourceContents -> BlobResourceContents -> Bool
(BlobResourceContents -> BlobResourceContents -> Bool)
-> (BlobResourceContents -> BlobResourceContents -> Bool)
-> Eq BlobResourceContents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlobResourceContents -> BlobResourceContents -> Bool
== :: BlobResourceContents -> BlobResourceContents -> Bool
$c/= :: BlobResourceContents -> BlobResourceContents -> Bool
/= :: BlobResourceContents -> BlobResourceContents -> Bool
Eq, (forall x. BlobResourceContents -> Rep BlobResourceContents x)
-> (forall x. Rep BlobResourceContents x -> BlobResourceContents)
-> Generic BlobResourceContents
forall x. Rep BlobResourceContents x -> BlobResourceContents
forall x. BlobResourceContents -> Rep BlobResourceContents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlobResourceContents -> Rep BlobResourceContents x
from :: forall x. BlobResourceContents -> Rep BlobResourceContents x
$cto :: forall x. Rep BlobResourceContents x -> BlobResourceContents
to :: forall x. Rep BlobResourceContents x -> BlobResourceContents
Generic)

$( deriveJSON
    mcpParseOpts
    ''BlobResourceContents
 )

{- | The contents of a specific resource or sub-resource.

A resource can contain either text or binary data.
-}
data ResourceContents
    = TextResource TextResourceContents
    | BlobResource BlobResourceContents
    deriving stock (Int -> ResourceContents -> ShowS
[ResourceContents] -> ShowS
ResourceContents -> String
(Int -> ResourceContents -> ShowS)
-> (ResourceContents -> String)
-> ([ResourceContents] -> ShowS)
-> Show ResourceContents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceContents -> ShowS
showsPrec :: Int -> ResourceContents -> ShowS
$cshow :: ResourceContents -> String
show :: ResourceContents -> String
$cshowList :: [ResourceContents] -> ShowS
showList :: [ResourceContents] -> ShowS
Show, ResourceContents -> ResourceContents -> Bool
(ResourceContents -> ResourceContents -> Bool)
-> (ResourceContents -> ResourceContents -> Bool)
-> Eq ResourceContents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourceContents -> ResourceContents -> Bool
== :: ResourceContents -> ResourceContents -> Bool
$c/= :: ResourceContents -> ResourceContents -> Bool
/= :: ResourceContents -> ResourceContents -> Bool
Eq, (forall x. ResourceContents -> Rep ResourceContents x)
-> (forall x. Rep ResourceContents x -> ResourceContents)
-> Generic ResourceContents
forall x. Rep ResourceContents x -> ResourceContents
forall x. ResourceContents -> Rep ResourceContents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ResourceContents -> Rep ResourceContents x
from :: forall x. ResourceContents -> Rep ResourceContents x
$cto :: forall x. Rep ResourceContents x -> ResourceContents
to :: forall x. Rep ResourceContents x -> ResourceContents
Generic)

instance ToJSON ResourceContents where
    toJSON :: ResourceContents -> Value
toJSON (TextResource TextResourceContents
t) = TextResourceContents -> Value
forall a. ToJSON a => a -> Value
toJSON TextResourceContents
t
    toJSON (BlobResource BlobResourceContents
b) = BlobResourceContents -> Value
forall a. ToJSON a => a -> Value
toJSON BlobResourceContents
b

instance FromJSON ResourceContents where
    parseJSON :: Value -> Parser ResourceContents
parseJSON Value
v =
        (TextResourceContents -> ResourceContents
TextResource (TextResourceContents -> ResourceContents)
-> Parser TextResourceContents -> Parser ResourceContents
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser TextResourceContents
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser ResourceContents
-> Parser ResourceContents -> Parser ResourceContents
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (BlobResourceContents -> ResourceContents
BlobResource (BlobResourceContents -> ResourceContents)
-> Parser BlobResourceContents -> Parser ResourceContents
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser BlobResourceContents
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)

{- | The contents of a resource, embedded into a prompt or tool call result.

It is up to the client how best to render embedded resources for the benefit
of the LLM and/or the user.
-}
data EmbeddedResource = EmbeddedResource
    { EmbeddedResource -> Text
resourceType :: Text -- Always "resource"
    , EmbeddedResource -> ResourceContents
resource :: ResourceContents
    , EmbeddedResource -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , EmbeddedResource -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> EmbeddedResource -> ShowS
[EmbeddedResource] -> ShowS
EmbeddedResource -> String
(Int -> EmbeddedResource -> ShowS)
-> (EmbeddedResource -> String)
-> ([EmbeddedResource] -> ShowS)
-> Show EmbeddedResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmbeddedResource -> ShowS
showsPrec :: Int -> EmbeddedResource -> ShowS
$cshow :: EmbeddedResource -> String
show :: EmbeddedResource -> String
$cshowList :: [EmbeddedResource] -> ShowS
showList :: [EmbeddedResource] -> ShowS
Show, EmbeddedResource -> EmbeddedResource -> Bool
(EmbeddedResource -> EmbeddedResource -> Bool)
-> (EmbeddedResource -> EmbeddedResource -> Bool)
-> Eq EmbeddedResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmbeddedResource -> EmbeddedResource -> Bool
== :: EmbeddedResource -> EmbeddedResource -> Bool
$c/= :: EmbeddedResource -> EmbeddedResource -> Bool
/= :: EmbeddedResource -> EmbeddedResource -> Bool
Eq, (forall x. EmbeddedResource -> Rep EmbeddedResource x)
-> (forall x. Rep EmbeddedResource x -> EmbeddedResource)
-> Generic EmbeddedResource
forall x. Rep EmbeddedResource x -> EmbeddedResource
forall x. EmbeddedResource -> Rep EmbeddedResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. EmbeddedResource -> Rep EmbeddedResource x
from :: forall x. EmbeddedResource -> Rep EmbeddedResource x
$cto :: forall x. Rep EmbeddedResource x -> EmbeddedResource
to :: forall x. Rep EmbeddedResource x -> EmbeddedResource
Generic)

instance ToJSON EmbeddedResource where
    toJSON :: EmbeddedResource -> Value
toJSON (EmbeddedResource Text
_ ResourceContents
res Maybe Annotations
anns Maybe Metadata
m) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"resource" :: Text)
            , Key
"resource" Key -> ResourceContents -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ResourceContents
res
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Annotations -> [Pair]) -> Maybe Annotations -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Annotations
a -> [Key
"annotations" Key -> Annotations -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Annotations
a]) Maybe Annotations
anns
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Metadata -> [Pair]) -> Maybe Metadata -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Metadata
meta -> [Key
"_meta" Key -> Metadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Metadata
meta]) Maybe Metadata
m

instance FromJSON EmbeddedResource where
    parseJSON :: Value -> Parser EmbeddedResource
parseJSON = String
-> (Object -> Parser EmbeddedResource)
-> Value
-> Parser EmbeddedResource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"EmbeddedResource" ((Object -> Parser EmbeddedResource)
 -> Value -> Parser EmbeddedResource)
-> (Object -> Parser EmbeddedResource)
-> Value
-> Parser EmbeddedResource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"resource" :: Text)
            then Text
-> ResourceContents
-> Maybe Annotations
-> Maybe Metadata
-> EmbeddedResource
EmbeddedResource Text
ty (ResourceContents
 -> Maybe Annotations -> Maybe Metadata -> EmbeddedResource)
-> Parser ResourceContents
-> Parser (Maybe Annotations -> Maybe Metadata -> EmbeddedResource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser ResourceContents
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"resource" Parser (Maybe Annotations -> Maybe Metadata -> EmbeddedResource)
-> Parser (Maybe Annotations)
-> Parser (Maybe Metadata -> EmbeddedResource)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Annotations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotations" Parser (Maybe Metadata -> EmbeddedResource)
-> Parser (Maybe Metadata) -> Parser EmbeddedResource
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Metadata)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_meta"
            else String -> Parser EmbeddedResource
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'resource'"

{- | A resource that the server is capable of reading, included in a prompt or tool call result.

Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
-}
data ResourceLink = ResourceLink
    { ResourceLink -> Text
linkType :: Text -- Always "resource_link"
    , ResourceLink -> Text
uri :: Text
    -- ^ The URI of this resource.
    , ResourceLink -> Text
name :: Text
    -- ^ A human-readable name for this resource.
    , ResourceLink -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , ResourceLink -> Maybe Text
description :: Maybe Text
    -- ^ A description of what this resource represents.
    , ResourceLink -> Maybe Text
mimeType :: Maybe Text
    -- ^ The MIME type of this resource, if known.
    , ResourceLink -> Maybe Int
size :: Maybe Int
    -- ^ The size of the raw resource content, in bytes.
    , ResourceLink -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , ResourceLink -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> ResourceLink -> ShowS
[ResourceLink] -> ShowS
ResourceLink -> String
(Int -> ResourceLink -> ShowS)
-> (ResourceLink -> String)
-> ([ResourceLink] -> ShowS)
-> Show ResourceLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceLink -> ShowS
showsPrec :: Int -> ResourceLink -> ShowS
$cshow :: ResourceLink -> String
show :: ResourceLink -> String
$cshowList :: [ResourceLink] -> ShowS
showList :: [ResourceLink] -> ShowS
Show, ResourceLink -> ResourceLink -> Bool
(ResourceLink -> ResourceLink -> Bool)
-> (ResourceLink -> ResourceLink -> Bool) -> Eq ResourceLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourceLink -> ResourceLink -> Bool
== :: ResourceLink -> ResourceLink -> Bool
$c/= :: ResourceLink -> ResourceLink -> Bool
/= :: ResourceLink -> ResourceLink -> Bool
Eq, (forall x. ResourceLink -> Rep ResourceLink x)
-> (forall x. Rep ResourceLink x -> ResourceLink)
-> Generic ResourceLink
forall x. Rep ResourceLink x -> ResourceLink
forall x. ResourceLink -> Rep ResourceLink x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ResourceLink -> Rep ResourceLink x
from :: forall x. ResourceLink -> Rep ResourceLink x
$cto :: forall x. Rep ResourceLink x -> ResourceLink
to :: forall x. Rep ResourceLink x -> ResourceLink
Generic)

instance ToJSON ResourceLink where
    toJSON :: ResourceLink -> Value
toJSON (ResourceLink Text
_ Text
u Text
n Maybe Text
t Maybe Text
d Maybe Text
mt Maybe Int
s Maybe Annotations
a Maybe Metadata
m) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"resource_link" :: Text)
            , Key
"uri" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
u
            , Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
n
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
ttl -> [Key
"title" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
ttl]) Maybe Text
t
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
desc -> [Key
"description" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
desc]) Maybe Text
d
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
mime -> [Key
"mimeType" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
mime]) Maybe Text
mt
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Int -> [Pair]) -> Maybe Int -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Int
sz -> [Key
"size" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
sz]) Maybe Int
s
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Annotations -> [Pair]) -> Maybe Annotations -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Annotations
ann -> [Key
"annotations" Key -> Annotations -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Annotations
ann]) Maybe Annotations
a
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Metadata -> [Pair]) -> Maybe Metadata -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Metadata
meta -> [Key
"_meta" Key -> Metadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Metadata
meta]) Maybe Metadata
m

instance FromJSON ResourceLink where
    parseJSON :: Value -> Parser ResourceLink
parseJSON = String
-> (Object -> Parser ResourceLink) -> Value -> Parser ResourceLink
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResourceLink" ((Object -> Parser ResourceLink) -> Value -> Parser ResourceLink)
-> (Object -> Parser ResourceLink) -> Value -> Parser ResourceLink
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"resource_link" :: Text)
            then
                Text
-> Text
-> Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Int
-> Maybe Annotations
-> Maybe Metadata
-> ResourceLink
ResourceLink Text
ty
                    (Text
 -> Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Int
 -> Maybe Annotations
 -> Maybe Metadata
 -> ResourceLink)
-> Parser Text
-> Parser
     (Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Int
      -> Maybe Annotations
      -> Maybe Metadata
      -> ResourceLink)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"uri"
                    Parser
  (Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Int
   -> Maybe Annotations
   -> Maybe Metadata
   -> ResourceLink)
-> Parser Text
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Int
      -> Maybe Annotations
      -> Maybe Metadata
      -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
                    Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Int
   -> Maybe Annotations
   -> Maybe Metadata
   -> ResourceLink)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe Int
      -> Maybe Annotations
      -> Maybe Metadata
      -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"title"
                    Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe Int
   -> Maybe Annotations
   -> Maybe Metadata
   -> ResourceLink)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Int
      -> Maybe Annotations
      -> Maybe Metadata
      -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"description"
                    Parser
  (Maybe Text
   -> Maybe Int
   -> Maybe Annotations
   -> Maybe Metadata
   -> ResourceLink)
-> Parser (Maybe Text)
-> Parser
     (Maybe Int -> Maybe Annotations -> Maybe Metadata -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"mimeType"
                    Parser
  (Maybe Int -> Maybe Annotations -> Maybe Metadata -> ResourceLink)
-> Parser (Maybe Int)
-> Parser (Maybe Annotations -> Maybe Metadata -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"size"
                    Parser (Maybe Annotations -> Maybe Metadata -> ResourceLink)
-> Parser (Maybe Annotations)
-> Parser (Maybe Metadata -> ResourceLink)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Annotations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotations"
                    Parser (Maybe Metadata -> ResourceLink)
-> Parser (Maybe Metadata) -> Parser ResourceLink
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Metadata)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_meta"
            else String -> Parser ResourceLink
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'resource_link'"

{- | Content that can be text, image, audio, or embedded resource.

This union type represents the different kinds of content that can be
included in messages, prompts, and tool results.
-}
data Content
    = TextContentType TextContent
    | ImageContentType ImageContent
    | AudioContentType AudioContent
    | EmbeddedResourceType EmbeddedResource
    deriving stock (Int -> Content -> ShowS
[Content] -> ShowS
Content -> String
(Int -> Content -> ShowS)
-> (Content -> String) -> ([Content] -> ShowS) -> Show Content
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Content -> ShowS
showsPrec :: Int -> Content -> ShowS
$cshow :: Content -> String
show :: Content -> String
$cshowList :: [Content] -> ShowS
showList :: [Content] -> ShowS
Show, Content -> Content -> Bool
(Content -> Content -> Bool)
-> (Content -> Content -> Bool) -> Eq Content
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Content -> Content -> Bool
== :: Content -> Content -> Bool
$c/= :: Content -> Content -> Bool
/= :: Content -> Content -> Bool
Eq, (forall x. Content -> Rep Content x)
-> (forall x. Rep Content x -> Content) -> Generic Content
forall x. Rep Content x -> Content
forall x. Content -> Rep Content x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Content -> Rep Content x
from :: forall x. Content -> Rep Content x
$cto :: forall x. Rep Content x -> Content
to :: forall x. Rep Content x -> Content
Generic)

instance ToJSON Content where
    toJSON :: Content -> Value
toJSON (TextContentType TextContent
c) = TextContent -> Value
forall a. ToJSON a => a -> Value
toJSON TextContent
c
    toJSON (ImageContentType ImageContent
c) = ImageContent -> Value
forall a. ToJSON a => a -> Value
toJSON ImageContent
c
    toJSON (AudioContentType AudioContent
c) = AudioContent -> Value
forall a. ToJSON a => a -> Value
toJSON AudioContent
c
    toJSON (EmbeddedResourceType EmbeddedResource
c) = EmbeddedResource -> Value
forall a. ToJSON a => a -> Value
toJSON EmbeddedResource
c

instance FromJSON Content where
    parseJSON :: Value -> Parser Content
parseJSON Value
v =
        (TextContent -> Content
TextContentType (TextContent -> Content) -> Parser TextContent -> Parser Content
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser TextContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser Content -> Parser Content -> Parser Content
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ImageContent -> Content
ImageContentType (ImageContent -> Content) -> Parser ImageContent -> Parser Content
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ImageContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser Content -> Parser Content -> Parser Content
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (AudioContent -> Content
AudioContentType (AudioContent -> Content) -> Parser AudioContent -> Parser Content
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser AudioContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser Content -> Parser Content -> Parser Content
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (EmbeddedResource -> Content
EmbeddedResourceType (EmbeddedResource -> Content)
-> Parser EmbeddedResource -> Parser Content
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser EmbeddedResource
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)

{- | ContentBlock union type that includes ResourceLink.

This is the unified content type used in new schema version.
-}
data ContentBlock
    = TextBlock TextContent
    | ImageBlock ImageContent
    | AudioBlock AudioContent
    | ResourceLinkBlock ResourceLink
    | EmbeddedResourceBlock EmbeddedResource
    deriving stock (Int -> ContentBlock -> ShowS
[ContentBlock] -> ShowS
ContentBlock -> String
(Int -> ContentBlock -> ShowS)
-> (ContentBlock -> String)
-> ([ContentBlock] -> ShowS)
-> Show ContentBlock
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ContentBlock -> ShowS
showsPrec :: Int -> ContentBlock -> ShowS
$cshow :: ContentBlock -> String
show :: ContentBlock -> String
$cshowList :: [ContentBlock] -> ShowS
showList :: [ContentBlock] -> ShowS
Show, ContentBlock -> ContentBlock -> Bool
(ContentBlock -> ContentBlock -> Bool)
-> (ContentBlock -> ContentBlock -> Bool) -> Eq ContentBlock
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ContentBlock -> ContentBlock -> Bool
== :: ContentBlock -> ContentBlock -> Bool
$c/= :: ContentBlock -> ContentBlock -> Bool
/= :: ContentBlock -> ContentBlock -> Bool
Eq, (forall x. ContentBlock -> Rep ContentBlock x)
-> (forall x. Rep ContentBlock x -> ContentBlock)
-> Generic ContentBlock
forall x. Rep ContentBlock x -> ContentBlock
forall x. ContentBlock -> Rep ContentBlock x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ContentBlock -> Rep ContentBlock x
from :: forall x. ContentBlock -> Rep ContentBlock x
$cto :: forall x. Rep ContentBlock x -> ContentBlock
to :: forall x. Rep ContentBlock x -> ContentBlock
Generic)

instance ToJSON ContentBlock where
    toJSON :: ContentBlock -> Value
toJSON (TextBlock TextContent
c) = TextContent -> Value
forall a. ToJSON a => a -> Value
toJSON TextContent
c
    toJSON (ImageBlock ImageContent
c) = ImageContent -> Value
forall a. ToJSON a => a -> Value
toJSON ImageContent
c
    toJSON (AudioBlock AudioContent
c) = AudioContent -> Value
forall a. ToJSON a => a -> Value
toJSON AudioContent
c
    toJSON (ResourceLinkBlock ResourceLink
c) = ResourceLink -> Value
forall a. ToJSON a => a -> Value
toJSON ResourceLink
c
    toJSON (EmbeddedResourceBlock EmbeddedResource
c) = EmbeddedResource -> Value
forall a. ToJSON a => a -> Value
toJSON EmbeddedResource
c

instance FromJSON ContentBlock where
    parseJSON :: Value -> Parser ContentBlock
parseJSON Value
v =
        (TextContent -> ContentBlock
TextBlock (TextContent -> ContentBlock)
-> Parser TextContent -> Parser ContentBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser TextContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser ContentBlock -> Parser ContentBlock -> Parser ContentBlock
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ImageContent -> ContentBlock
ImageBlock (ImageContent -> ContentBlock)
-> Parser ImageContent -> Parser ContentBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ImageContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser ContentBlock -> Parser ContentBlock -> Parser ContentBlock
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (AudioContent -> ContentBlock
AudioBlock (AudioContent -> ContentBlock)
-> Parser AudioContent -> Parser ContentBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser AudioContent
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser ContentBlock -> Parser ContentBlock -> Parser ContentBlock
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ResourceLink -> ContentBlock
ResourceLinkBlock (ResourceLink -> ContentBlock)
-> Parser ResourceLink -> Parser ContentBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ResourceLink
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)
            Parser ContentBlock -> Parser ContentBlock -> Parser ContentBlock
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (EmbeddedResource -> ContentBlock
EmbeddedResourceBlock (EmbeddedResource -> ContentBlock)
-> Parser EmbeddedResource -> Parser ContentBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser EmbeddedResource
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)

{- | A known resource that the server is capable of reading.

Resources represent files, documents, or other data sources that the
server can provide to clients.
-}
data Resource = Resource
    { Resource -> Text
uri :: Text
    -- ^ The URI of this resource.
    , Resource -> Text
name :: Text
    {- ^ A human-readable name for this resource.
    This can be used by clients to populate UI elements.
    -}
    , Resource -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , Resource -> Maybe Text
description :: Maybe Text
    {- ^ A description of what this resource represents.
    This can be used by clients to improve the LLM's understanding
    of available resources. It can be thought of like a "hint" to the model.
    -}
    , Resource -> Maybe Text
mimeType :: Maybe Text
    -- ^ The MIME type of this resource, if known.
    , Resource -> Maybe Int
size :: Maybe Int
    {- ^ The size of the raw resource content, in bytes (i.e., before base64
    encoding or any tokenization), if known. This can be used by Hosts
    to display file sizes and estimate context window usage.
    -}
    , Resource -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , Resource -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Resource -> ShowS
showsPrec :: Int -> Resource -> ShowS
$cshow :: Resource -> String
show :: Resource -> String
$cshowList :: [Resource] -> ShowS
showList :: [Resource] -> ShowS
Show, Resource -> Resource -> Bool
(Resource -> Resource -> Bool)
-> (Resource -> Resource -> Bool) -> Eq Resource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Resource -> Resource -> Bool
== :: Resource -> Resource -> Bool
$c/= :: Resource -> Resource -> Bool
/= :: Resource -> Resource -> Bool
Eq, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Resource -> Rep Resource x
from :: forall x. Resource -> Rep Resource x
$cto :: forall x. Rep Resource x -> Resource
to :: forall x. Rep Resource x -> Resource
Generic)

$( deriveJSON
    mcpParseOpts
    ''Resource
 )

{- | A template description for resources available on the server.

Resource templates allow servers to describe parameterized resources
that can be instantiated with specific values.
-}
data ResourceTemplate = ResourceTemplate
    { ResourceTemplate -> Text
name :: Text
    {- ^ A human-readable name for the type of resource this template refers to.
    This can be used by clients to populate UI elements.
    -}
    , ResourceTemplate -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , ResourceTemplate -> Text
uriTemplate :: Text
    -- ^ A URI template (according to RFC 6570) that can be used to construct resource URIs.
    , ResourceTemplate -> Maybe Text
description :: Maybe Text
    {- ^ A description of what this template is for.
    This can be used by clients to improve the LLM's understanding
    of available resources. It can be thought of like a "hint" to the model.
    -}
    , ResourceTemplate -> Maybe Text
mimeType :: Maybe Text
    {- ^ The MIME type for all resources that match this template.
    This should only be included if all resources matching this
    template have the same type.
    -}
    , ResourceTemplate -> Maybe Annotations
annotations :: Maybe Annotations
    -- ^ Optional annotations for the client.
    , ResourceTemplate -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> ResourceTemplate -> ShowS
[ResourceTemplate] -> ShowS
ResourceTemplate -> String
(Int -> ResourceTemplate -> ShowS)
-> (ResourceTemplate -> String)
-> ([ResourceTemplate] -> ShowS)
-> Show ResourceTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceTemplate -> ShowS
showsPrec :: Int -> ResourceTemplate -> ShowS
$cshow :: ResourceTemplate -> String
show :: ResourceTemplate -> String
$cshowList :: [ResourceTemplate] -> ShowS
showList :: [ResourceTemplate] -> ShowS
Show, ResourceTemplate -> ResourceTemplate -> Bool
(ResourceTemplate -> ResourceTemplate -> Bool)
-> (ResourceTemplate -> ResourceTemplate -> Bool)
-> Eq ResourceTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourceTemplate -> ResourceTemplate -> Bool
== :: ResourceTemplate -> ResourceTemplate -> Bool
$c/= :: ResourceTemplate -> ResourceTemplate -> Bool
/= :: ResourceTemplate -> ResourceTemplate -> Bool
Eq, (forall x. ResourceTemplate -> Rep ResourceTemplate x)
-> (forall x. Rep ResourceTemplate x -> ResourceTemplate)
-> Generic ResourceTemplate
forall x. Rep ResourceTemplate x -> ResourceTemplate
forall x. ResourceTemplate -> Rep ResourceTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ResourceTemplate -> Rep ResourceTemplate x
from :: forall x. ResourceTemplate -> Rep ResourceTemplate x
$cto :: forall x. Rep ResourceTemplate x -> ResourceTemplate
to :: forall x. Rep ResourceTemplate x -> ResourceTemplate
Generic)

$( deriveJSON
    mcpParseOpts
    ''ResourceTemplate
 )

{- | A reference to a resource or resource template definition.

Used in completion requests and other contexts where a resource
needs to be referenced.
-}
data ResourceReference = ResourceReference
    { ResourceReference -> Text
refType :: Text -- Always "ref/resource"
    , ResourceReference -> Text
uri :: Text
    -- ^ The URI or URI template of the resource.
    }
    deriving stock (Int -> ResourceReference -> ShowS
[ResourceReference] -> ShowS
ResourceReference -> String
(Int -> ResourceReference -> ShowS)
-> (ResourceReference -> String)
-> ([ResourceReference] -> ShowS)
-> Show ResourceReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceReference -> ShowS
showsPrec :: Int -> ResourceReference -> ShowS
$cshow :: ResourceReference -> String
show :: ResourceReference -> String
$cshowList :: [ResourceReference] -> ShowS
showList :: [ResourceReference] -> ShowS
Show, ResourceReference -> ResourceReference -> Bool
(ResourceReference -> ResourceReference -> Bool)
-> (ResourceReference -> ResourceReference -> Bool)
-> Eq ResourceReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourceReference -> ResourceReference -> Bool
== :: ResourceReference -> ResourceReference -> Bool
$c/= :: ResourceReference -> ResourceReference -> Bool
/= :: ResourceReference -> ResourceReference -> Bool
Eq, (forall x. ResourceReference -> Rep ResourceReference x)
-> (forall x. Rep ResourceReference x -> ResourceReference)
-> Generic ResourceReference
forall x. Rep ResourceReference x -> ResourceReference
forall x. ResourceReference -> Rep ResourceReference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ResourceReference -> Rep ResourceReference x
from :: forall x. ResourceReference -> Rep ResourceReference x
$cto :: forall x. Rep ResourceReference x -> ResourceReference
to :: forall x. Rep ResourceReference x -> ResourceReference
Generic)

instance ToJSON ResourceReference where
    toJSON :: ResourceReference -> Value
toJSON (ResourceReference Text
_ Text
u) =
        [Pair] -> Value
object
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"ref/resource" :: Text)
            , Key
"uri" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
u
            ]

instance FromJSON ResourceReference where
    parseJSON :: Value -> Parser ResourceReference
parseJSON = String
-> (Object -> Parser ResourceReference)
-> Value
-> Parser ResourceReference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ResourceReference" ((Object -> Parser ResourceReference)
 -> Value -> Parser ResourceReference)
-> (Object -> Parser ResourceReference)
-> Value
-> Parser ResourceReference
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"ref/resource" :: Text)
            then Text -> Text -> ResourceReference
ResourceReference Text
ty (Text -> ResourceReference)
-> Parser Text -> Parser ResourceReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"uri"
            else String -> Parser ResourceReference
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'ref/resource'"

{- | A reference to a resource template definition.

This is an alias for ResourceReference in the new schema.
-}
type ResourceTemplateReference = ResourceReference

{- | Additional properties describing a Tool to clients.

NOTE: all properties in ToolAnnotations are **hints**.
They are not guaranteed to provide a faithful description of
tool behavior (including descriptive properties like `title`).

Clients should never make tool use decisions based on ToolAnnotations
received from untrusted servers.
-}
data ToolAnnotations = ToolAnnotations
    { ToolAnnotations -> Maybe Text
title :: Maybe Text
    -- ^ A human-readable title for the tool.
    , ToolAnnotations -> Maybe Bool
readOnlyHint :: Maybe Bool
    -- ^ If true, the tool does not modify its environment. Default: false
    , ToolAnnotations -> Maybe Bool
destructiveHint :: Maybe Bool
    {- ^ If true, the tool may perform destructive updates to its environment.
    If false, the tool performs only additive updates.
    (This property is meaningful only when `readOnlyHint == false`)
    Default: true
    -}
    , ToolAnnotations -> Maybe Bool
idempotentHint :: Maybe Bool
    {- ^ If true, calling the tool repeatedly with the same arguments
    will have no additional effect on its environment.
    (This property is meaningful only when `readOnlyHint == false`)
    Default: false
    -}
    , ToolAnnotations -> Maybe Bool
openWorldHint :: Maybe Bool
    {- ^ If true, this tool may interact with an "open world" of external
    entities. If false, the tool's domain of interaction is closed.
    For example, the world of a web search tool is open, whereas that
    of a memory tool is not. Default: true
    -}
    }
    deriving stock (Int -> ToolAnnotations -> ShowS
[ToolAnnotations] -> ShowS
ToolAnnotations -> String
(Int -> ToolAnnotations -> ShowS)
-> (ToolAnnotations -> String)
-> ([ToolAnnotations] -> ShowS)
-> Show ToolAnnotations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ToolAnnotations -> ShowS
showsPrec :: Int -> ToolAnnotations -> ShowS
$cshow :: ToolAnnotations -> String
show :: ToolAnnotations -> String
$cshowList :: [ToolAnnotations] -> ShowS
showList :: [ToolAnnotations] -> ShowS
Show, ToolAnnotations -> ToolAnnotations -> Bool
(ToolAnnotations -> ToolAnnotations -> Bool)
-> (ToolAnnotations -> ToolAnnotations -> Bool)
-> Eq ToolAnnotations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ToolAnnotations -> ToolAnnotations -> Bool
== :: ToolAnnotations -> ToolAnnotations -> Bool
$c/= :: ToolAnnotations -> ToolAnnotations -> Bool
/= :: ToolAnnotations -> ToolAnnotations -> Bool
Eq, (forall x. ToolAnnotations -> Rep ToolAnnotations x)
-> (forall x. Rep ToolAnnotations x -> ToolAnnotations)
-> Generic ToolAnnotations
forall x. Rep ToolAnnotations x -> ToolAnnotations
forall x. ToolAnnotations -> Rep ToolAnnotations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ToolAnnotations -> Rep ToolAnnotations x
from :: forall x. ToolAnnotations -> Rep ToolAnnotations x
$cto :: forall x. Rep ToolAnnotations x -> ToolAnnotations
to :: forall x. Rep ToolAnnotations x -> ToolAnnotations
Generic)

$(deriveJSON mcpParseOpts ''ToolAnnotations)

{- | Input schema for a tool.

A JSON Schema object defining the expected parameters for the tool.
-}
data InputSchema = InputSchema
    { InputSchema -> Text
schemaType :: Text -- Always "object"
    , InputSchema -> Maybe (Map Text Value)
properties :: Maybe (Map Text Value)
    , InputSchema -> Maybe [Text]
required :: Maybe [Text]
    }
    deriving stock (Int -> InputSchema -> ShowS
[InputSchema] -> ShowS
InputSchema -> String
(Int -> InputSchema -> ShowS)
-> (InputSchema -> String)
-> ([InputSchema] -> ShowS)
-> Show InputSchema
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputSchema -> ShowS
showsPrec :: Int -> InputSchema -> ShowS
$cshow :: InputSchema -> String
show :: InputSchema -> String
$cshowList :: [InputSchema] -> ShowS
showList :: [InputSchema] -> ShowS
Show, InputSchema -> InputSchema -> Bool
(InputSchema -> InputSchema -> Bool)
-> (InputSchema -> InputSchema -> Bool) -> Eq InputSchema
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputSchema -> InputSchema -> Bool
== :: InputSchema -> InputSchema -> Bool
$c/= :: InputSchema -> InputSchema -> Bool
/= :: InputSchema -> InputSchema -> Bool
Eq, (forall x. InputSchema -> Rep InputSchema x)
-> (forall x. Rep InputSchema x -> InputSchema)
-> Generic InputSchema
forall x. Rep InputSchema x -> InputSchema
forall x. InputSchema -> Rep InputSchema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InputSchema -> Rep InputSchema x
from :: forall x. InputSchema -> Rep InputSchema x
$cto :: forall x. Rep InputSchema x -> InputSchema
to :: forall x. Rep InputSchema x -> InputSchema
Generic)

instance ToJSON InputSchema where
    toJSON :: InputSchema -> Value
toJSON (InputSchema Text
_ Maybe (Map Text Value)
props Maybe [Text]
req) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"object" :: Text)
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair]
-> (Map Text Value -> [Pair]) -> Maybe (Map Text Value) -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Map Text Value
p -> [Key
"properties" Key -> Map Text Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Map Text Value
p]) Maybe (Map Text Value)
props
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> ([Text] -> [Pair]) -> Maybe [Text] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\[Text]
r -> [Key
"required" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
r]) Maybe [Text]
req

instance FromJSON InputSchema where
    parseJSON :: Value -> Parser InputSchema
parseJSON = String
-> (Object -> Parser InputSchema) -> Value -> Parser InputSchema
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"InputSchema" ((Object -> Parser InputSchema) -> Value -> Parser InputSchema)
-> (Object -> Parser InputSchema) -> Value -> Parser InputSchema
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"object" :: Text)
            then Text -> Maybe (Map Text Value) -> Maybe [Text] -> InputSchema
InputSchema Text
ty (Maybe (Map Text Value) -> Maybe [Text] -> InputSchema)
-> Parser (Maybe (Map Text Value))
-> Parser (Maybe [Text] -> InputSchema)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe (Map Text Value))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"properties" Parser (Maybe [Text] -> InputSchema)
-> Parser (Maybe [Text]) -> Parser InputSchema
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"required"
            else String -> Parser InputSchema
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'object'"

{- | Definition for a tool the client can call.

Tools are functions that the MCP server exposes to clients,
allowing the client to perform specific actions or retrieve information.
-}
data Tool = Tool
    { Tool -> Text
name :: Text
    -- ^ The name of the tool.
    , Tool -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , Tool -> Maybe Text
description :: Maybe Text
    {- ^ A human-readable description of the tool.
    This can be used by clients to improve the LLM's understanding
    of available tools. It can be thought of like a "hint" to the model.
    -}
    , Tool -> InputSchema
inputSchema :: InputSchema
    -- ^ A JSON Schema object defining the expected parameters for the tool.
    , Tool -> Maybe InputSchema
outputSchema :: Maybe InputSchema
    {- ^ An optional JSON Schema object defining the structure of the tool's output
    returned in the structuredContent field of a CallToolResult.
    -}
    , Tool -> Maybe ToolAnnotations
annotations :: Maybe ToolAnnotations
    {- ^ Optional additional tool information.
    Display name precedence order is: title, annotations.title, then name.
    -}
    , Tool -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> Tool -> ShowS
[Tool] -> ShowS
Tool -> String
(Int -> Tool -> ShowS)
-> (Tool -> String) -> ([Tool] -> ShowS) -> Show Tool
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Tool -> ShowS
showsPrec :: Int -> Tool -> ShowS
$cshow :: Tool -> String
show :: Tool -> String
$cshowList :: [Tool] -> ShowS
showList :: [Tool] -> ShowS
Show, Tool -> Tool -> Bool
(Tool -> Tool -> Bool) -> (Tool -> Tool -> Bool) -> Eq Tool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Tool -> Tool -> Bool
== :: Tool -> Tool -> Bool
$c/= :: Tool -> Tool -> Bool
/= :: Tool -> Tool -> Bool
Eq, (forall x. Tool -> Rep Tool x)
-> (forall x. Rep Tool x -> Tool) -> Generic Tool
forall x. Rep Tool x -> Tool
forall x. Tool -> Rep Tool x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Tool -> Rep Tool x
from :: forall x. Tool -> Rep Tool x
$cto :: forall x. Rep Tool x -> Tool
to :: forall x. Rep Tool x -> Tool
Generic)

$(deriveJSON mcpParseOpts ''Tool)

{- | Describes an argument that a prompt can accept.

Prompt arguments allow prompts to be parameterized with user-provided values.
-}
data PromptArgument = PromptArgument
    { PromptArgument -> Text
name :: Text
    -- ^ The name of the argument.
    , PromptArgument -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , PromptArgument -> Maybe Text
description :: Maybe Text
    -- ^ A human-readable description of the argument.
    , PromptArgument -> Maybe Bool
required :: Maybe Bool
    -- ^ Whether this argument must be provided.
    }
    deriving stock (Int -> PromptArgument -> ShowS
[PromptArgument] -> ShowS
PromptArgument -> String
(Int -> PromptArgument -> ShowS)
-> (PromptArgument -> String)
-> ([PromptArgument] -> ShowS)
-> Show PromptArgument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PromptArgument -> ShowS
showsPrec :: Int -> PromptArgument -> ShowS
$cshow :: PromptArgument -> String
show :: PromptArgument -> String
$cshowList :: [PromptArgument] -> ShowS
showList :: [PromptArgument] -> ShowS
Show, PromptArgument -> PromptArgument -> Bool
(PromptArgument -> PromptArgument -> Bool)
-> (PromptArgument -> PromptArgument -> Bool) -> Eq PromptArgument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PromptArgument -> PromptArgument -> Bool
== :: PromptArgument -> PromptArgument -> Bool
$c/= :: PromptArgument -> PromptArgument -> Bool
/= :: PromptArgument -> PromptArgument -> Bool
Eq, (forall x. PromptArgument -> Rep PromptArgument x)
-> (forall x. Rep PromptArgument x -> PromptArgument)
-> Generic PromptArgument
forall x. Rep PromptArgument x -> PromptArgument
forall x. PromptArgument -> Rep PromptArgument x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PromptArgument -> Rep PromptArgument x
from :: forall x. PromptArgument -> Rep PromptArgument x
$cto :: forall x. Rep PromptArgument x -> PromptArgument
to :: forall x. Rep PromptArgument x -> PromptArgument
Generic)

$(deriveJSON mcpParseOpts ''PromptArgument)

{- | A prompt or prompt template that the server offers.

Prompts are reusable message templates that can be parameterized
with arguments to generate specific conversations.
-}
data Prompt = Prompt
    { Prompt -> Text
name :: Text
    -- ^ The name of the prompt or prompt template.
    , Prompt -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    , Prompt -> Maybe Text
description :: Maybe Text
    -- ^ An optional description of what this prompt provides.
    , Prompt -> Maybe [PromptArgument]
arguments :: Maybe [PromptArgument]
    -- ^ A list of arguments to use for templating the prompt.
    , Prompt -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> Prompt -> ShowS
[Prompt] -> ShowS
Prompt -> String
(Int -> Prompt -> ShowS)
-> (Prompt -> String) -> ([Prompt] -> ShowS) -> Show Prompt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Prompt -> ShowS
showsPrec :: Int -> Prompt -> ShowS
$cshow :: Prompt -> String
show :: Prompt -> String
$cshowList :: [Prompt] -> ShowS
showList :: [Prompt] -> ShowS
Show, Prompt -> Prompt -> Bool
(Prompt -> Prompt -> Bool)
-> (Prompt -> Prompt -> Bool) -> Eq Prompt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Prompt -> Prompt -> Bool
== :: Prompt -> Prompt -> Bool
$c/= :: Prompt -> Prompt -> Bool
/= :: Prompt -> Prompt -> Bool
Eq, (forall x. Prompt -> Rep Prompt x)
-> (forall x. Rep Prompt x -> Prompt) -> Generic Prompt
forall x. Rep Prompt x -> Prompt
forall x. Prompt -> Rep Prompt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Prompt -> Rep Prompt x
from :: forall x. Prompt -> Rep Prompt x
$cto :: forall x. Rep Prompt x -> Prompt
to :: forall x. Rep Prompt x -> Prompt
Generic)

$(deriveJSON mcpParseOpts ''Prompt)

{- | Describes a message returned as part of a prompt.

This is similar to `SamplingMessage`, but also supports the embedding of
resources from the MCP server.
-}
data PromptMessage = PromptMessage
    { PromptMessage -> Role
role :: Role
    , PromptMessage -> ContentBlock
content :: ContentBlock
    }
    deriving stock (Int -> PromptMessage -> ShowS
[PromptMessage] -> ShowS
PromptMessage -> String
(Int -> PromptMessage -> ShowS)
-> (PromptMessage -> String)
-> ([PromptMessage] -> ShowS)
-> Show PromptMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PromptMessage -> ShowS
showsPrec :: Int -> PromptMessage -> ShowS
$cshow :: PromptMessage -> String
show :: PromptMessage -> String
$cshowList :: [PromptMessage] -> ShowS
showList :: [PromptMessage] -> ShowS
Show, PromptMessage -> PromptMessage -> Bool
(PromptMessage -> PromptMessage -> Bool)
-> (PromptMessage -> PromptMessage -> Bool) -> Eq PromptMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PromptMessage -> PromptMessage -> Bool
== :: PromptMessage -> PromptMessage -> Bool
$c/= :: PromptMessage -> PromptMessage -> Bool
/= :: PromptMessage -> PromptMessage -> Bool
Eq, (forall x. PromptMessage -> Rep PromptMessage x)
-> (forall x. Rep PromptMessage x -> PromptMessage)
-> Generic PromptMessage
forall x. Rep PromptMessage x -> PromptMessage
forall x. PromptMessage -> Rep PromptMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PromptMessage -> Rep PromptMessage x
from :: forall x. PromptMessage -> Rep PromptMessage x
$cto :: forall x. Rep PromptMessage x -> PromptMessage
to :: forall x. Rep PromptMessage x -> PromptMessage
Generic)

$(deriveJSON mcpParseOpts ''PromptMessage)

{- | Identifies a prompt.

Used in completion requests and other contexts where a prompt
needs to be referenced.
-}
data PromptReference = PromptReference
    { PromptReference -> Text
refType :: Text -- Always "ref/prompt"
    , PromptReference -> Text
name :: Text
    -- ^ The name of the prompt or prompt template.
    , PromptReference -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for display purposes.
    }
    deriving stock (Int -> PromptReference -> ShowS
[PromptReference] -> ShowS
PromptReference -> String
(Int -> PromptReference -> ShowS)
-> (PromptReference -> String)
-> ([PromptReference] -> ShowS)
-> Show PromptReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PromptReference -> ShowS
showsPrec :: Int -> PromptReference -> ShowS
$cshow :: PromptReference -> String
show :: PromptReference -> String
$cshowList :: [PromptReference] -> ShowS
showList :: [PromptReference] -> ShowS
Show, PromptReference -> PromptReference -> Bool
(PromptReference -> PromptReference -> Bool)
-> (PromptReference -> PromptReference -> Bool)
-> Eq PromptReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PromptReference -> PromptReference -> Bool
== :: PromptReference -> PromptReference -> Bool
$c/= :: PromptReference -> PromptReference -> Bool
/= :: PromptReference -> PromptReference -> Bool
Eq, (forall x. PromptReference -> Rep PromptReference x)
-> (forall x. Rep PromptReference x -> PromptReference)
-> Generic PromptReference
forall x. Rep PromptReference x -> PromptReference
forall x. PromptReference -> Rep PromptReference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PromptReference -> Rep PromptReference x
from :: forall x. PromptReference -> Rep PromptReference x
$cto :: forall x. Rep PromptReference x -> PromptReference
to :: forall x. Rep PromptReference x -> PromptReference
Generic)

instance ToJSON PromptReference where
    toJSON :: PromptReference -> Value
toJSON (PromptReference Text
_ Text
n Maybe Text
t) =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"ref/prompt" :: Text)
            , Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
n
            ]
                [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
ttl -> [Key
"title" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
ttl]) Maybe Text
t

instance FromJSON PromptReference where
    parseJSON :: Value -> Parser PromptReference
parseJSON = String
-> (Object -> Parser PromptReference)
-> Value
-> Parser PromptReference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PromptReference" ((Object -> Parser PromptReference)
 -> Value -> Parser PromptReference)
-> (Object -> Parser PromptReference)
-> Value
-> Parser PromptReference
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
ty <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
        if Text
ty Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"ref/prompt" :: Text)
            then Text -> Text -> Maybe Text -> PromptReference
PromptReference Text
ty (Text -> Maybe Text -> PromptReference)
-> Parser Text -> Parser (Maybe Text -> PromptReference)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name" Parser (Maybe Text -> PromptReference)
-> Parser (Maybe Text) -> Parser PromptReference
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"title"
            else String -> Parser PromptReference
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected type 'ref/prompt'"

{- | Hints to use for model selection.

Keys not declared here are currently left unspecified by the spec and are up
to the client to interpret.
-}
data ModelHint where
    ModelHint ::
        { ModelHint -> Maybe Text
name :: Maybe Text
        {- ^ A hint for a model name.
        The client SHOULD treat this as a substring of a model name; for example:
        - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`
        - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.
        - `claude` should match any Claude model
        The client MAY also map the string to a different provider's model name
        or a different model family, as long as it fills a similar niche.
        -}
        } ->
        ModelHint
    deriving stock (Int -> ModelHint -> ShowS
[ModelHint] -> ShowS
ModelHint -> String
(Int -> ModelHint -> ShowS)
-> (ModelHint -> String)
-> ([ModelHint] -> ShowS)
-> Show ModelHint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModelHint -> ShowS
showsPrec :: Int -> ModelHint -> ShowS
$cshow :: ModelHint -> String
show :: ModelHint -> String
$cshowList :: [ModelHint] -> ShowS
showList :: [ModelHint] -> ShowS
Show, ModelHint -> ModelHint -> Bool
(ModelHint -> ModelHint -> Bool)
-> (ModelHint -> ModelHint -> Bool) -> Eq ModelHint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModelHint -> ModelHint -> Bool
== :: ModelHint -> ModelHint -> Bool
$c/= :: ModelHint -> ModelHint -> Bool
/= :: ModelHint -> ModelHint -> Bool
Eq, (forall x. ModelHint -> Rep ModelHint x)
-> (forall x. Rep ModelHint x -> ModelHint) -> Generic ModelHint
forall x. Rep ModelHint x -> ModelHint
forall x. ModelHint -> Rep ModelHint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ModelHint -> Rep ModelHint x
from :: forall x. ModelHint -> Rep ModelHint x
$cto :: forall x. Rep ModelHint x -> ModelHint
to :: forall x. Rep ModelHint x -> ModelHint
Generic)

$(deriveJSON mcpParseOpts ''ModelHint)

{- | The server's preferences for model selection, requested of the client during sampling.

Because LLMs can vary along multiple dimensions, choosing the "best" model is
rarely straightforward. Different models excel in different areas—some are
faster but less capable, others are more capable but more expensive, and so
on. This interface allows servers to express their priorities across multiple
dimensions to help clients make an appropriate selection for their use case.

These preferences are always advisory. The client MAY ignore them. It is also
up to the client to decide how to interpret these preferences and how to
balance them against other considerations.
-}
data ModelPreferences = ModelPreferences
    { ModelPreferences -> Maybe [ModelHint]
hints :: Maybe [ModelHint]
    {- ^ Optional hints to use for model selection.
    If multiple hints are specified, the client MUST evaluate them in order
    (such that the first match is taken).
    The client SHOULD prioritize these hints over the numeric priorities, but
    MAY still use the priorities to select from ambiguous matches.
    -}
    , ModelPreferences -> Maybe Double
costPriority :: Maybe Double
    {- ^ How much to prioritize cost when selecting a model. A value of 0 means cost
    is not important, while a value of 1 means cost is the most important
    factor. Range: 0.0 to 1.0
    -}
    , ModelPreferences -> Maybe Double
speedPriority :: Maybe Double
    {- ^ How much to prioritize sampling speed (latency) when selecting a model. A
    value of 0 means speed is not important, while a value of 1 means speed is
    the most important factor. Range: 0.0 to 1.0
    -}
    , ModelPreferences -> Maybe Double
intelligencePriority :: Maybe Double
    {- ^ How much to prioritize intelligence and capabilities when selecting a
    model. A value of 0 means intelligence is not important, while a value of 1
    means intelligence is the most important factor. Range: 0.0 to 1.0
    -}
    }
    deriving stock (Int -> ModelPreferences -> ShowS
[ModelPreferences] -> ShowS
ModelPreferences -> String
(Int -> ModelPreferences -> ShowS)
-> (ModelPreferences -> String)
-> ([ModelPreferences] -> ShowS)
-> Show ModelPreferences
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModelPreferences -> ShowS
showsPrec :: Int -> ModelPreferences -> ShowS
$cshow :: ModelPreferences -> String
show :: ModelPreferences -> String
$cshowList :: [ModelPreferences] -> ShowS
showList :: [ModelPreferences] -> ShowS
Show, ModelPreferences -> ModelPreferences -> Bool
(ModelPreferences -> ModelPreferences -> Bool)
-> (ModelPreferences -> ModelPreferences -> Bool)
-> Eq ModelPreferences
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModelPreferences -> ModelPreferences -> Bool
== :: ModelPreferences -> ModelPreferences -> Bool
$c/= :: ModelPreferences -> ModelPreferences -> Bool
/= :: ModelPreferences -> ModelPreferences -> Bool
Eq, (forall x. ModelPreferences -> Rep ModelPreferences x)
-> (forall x. Rep ModelPreferences x -> ModelPreferences)
-> Generic ModelPreferences
forall x. Rep ModelPreferences x -> ModelPreferences
forall x. ModelPreferences -> Rep ModelPreferences x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ModelPreferences -> Rep ModelPreferences x
from :: forall x. ModelPreferences -> Rep ModelPreferences x
$cto :: forall x. Rep ModelPreferences x -> ModelPreferences
to :: forall x. Rep ModelPreferences x -> ModelPreferences
Generic)

$(deriveJSON mcpParseOpts ''ModelPreferences)

{- | Include context options for sampling.

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.
-}
data IncludeContext = AllServers | None | ThisServer
    deriving stock (Int -> IncludeContext -> ShowS
[IncludeContext] -> ShowS
IncludeContext -> String
(Int -> IncludeContext -> ShowS)
-> (IncludeContext -> String)
-> ([IncludeContext] -> ShowS)
-> Show IncludeContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IncludeContext -> ShowS
showsPrec :: Int -> IncludeContext -> ShowS
$cshow :: IncludeContext -> String
show :: IncludeContext -> String
$cshowList :: [IncludeContext] -> ShowS
showList :: [IncludeContext] -> ShowS
Show, IncludeContext -> IncludeContext -> Bool
(IncludeContext -> IncludeContext -> Bool)
-> (IncludeContext -> IncludeContext -> Bool) -> Eq IncludeContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IncludeContext -> IncludeContext -> Bool
== :: IncludeContext -> IncludeContext -> Bool
$c/= :: IncludeContext -> IncludeContext -> Bool
/= :: IncludeContext -> IncludeContext -> Bool
Eq, (forall x. IncludeContext -> Rep IncludeContext x)
-> (forall x. Rep IncludeContext x -> IncludeContext)
-> Generic IncludeContext
forall x. Rep IncludeContext x -> IncludeContext
forall x. IncludeContext -> Rep IncludeContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IncludeContext -> Rep IncludeContext x
from :: forall x. IncludeContext -> Rep IncludeContext x
$cto :: forall x. Rep IncludeContext x -> IncludeContext
to :: forall x. Rep IncludeContext x -> IncludeContext
Generic)

instance ToJSON IncludeContext where
    toJSON :: IncludeContext -> Value
toJSON IncludeContext
AllServers = Value
"allServers"
    toJSON IncludeContext
None = Value
"none"
    toJSON IncludeContext
ThisServer = Value
"thisServer"

instance FromJSON IncludeContext where
    parseJSON :: Value -> Parser IncludeContext
parseJSON = String
-> (Text -> Parser IncludeContext)
-> Value
-> Parser IncludeContext
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"IncludeContext" ((Text -> Parser IncludeContext) -> Value -> Parser IncludeContext)
-> (Text -> Parser IncludeContext)
-> Value
-> Parser IncludeContext
forall a b. (a -> b) -> a -> b
$ \case
        Text
"allServers" -> IncludeContext -> Parser IncludeContext
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure IncludeContext
AllServers
        Text
"none" -> IncludeContext -> Parser IncludeContext
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure IncludeContext
None
        Text
"thisServer" -> IncludeContext -> Parser IncludeContext
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure IncludeContext
ThisServer
        Text
other -> String -> Parser IncludeContext
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser IncludeContext)
-> String -> Parser IncludeContext
forall a b. (a -> b) -> a -> b
$ String
"Unknown include context: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other

{- | Describes a message issued to or received from an LLM API.

Used in sampling requests to represent the conversation history
that should be sent to the language model.
-}
data SamplingMessage = SamplingMessage
    { SamplingMessage -> Role
role :: Role
    , SamplingMessage -> Content
content :: Content
    }
    deriving stock (Int -> SamplingMessage -> ShowS
[SamplingMessage] -> ShowS
SamplingMessage -> String
(Int -> SamplingMessage -> ShowS)
-> (SamplingMessage -> String)
-> ([SamplingMessage] -> ShowS)
-> Show SamplingMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SamplingMessage -> ShowS
showsPrec :: Int -> SamplingMessage -> ShowS
$cshow :: SamplingMessage -> String
show :: SamplingMessage -> String
$cshowList :: [SamplingMessage] -> ShowS
showList :: [SamplingMessage] -> ShowS
Show, SamplingMessage -> SamplingMessage -> Bool
(SamplingMessage -> SamplingMessage -> Bool)
-> (SamplingMessage -> SamplingMessage -> Bool)
-> Eq SamplingMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SamplingMessage -> SamplingMessage -> Bool
== :: SamplingMessage -> SamplingMessage -> Bool
$c/= :: SamplingMessage -> SamplingMessage -> Bool
/= :: SamplingMessage -> SamplingMessage -> Bool
Eq, (forall x. SamplingMessage -> Rep SamplingMessage x)
-> (forall x. Rep SamplingMessage x -> SamplingMessage)
-> Generic SamplingMessage
forall x. Rep SamplingMessage x -> SamplingMessage
forall x. SamplingMessage -> Rep SamplingMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SamplingMessage -> Rep SamplingMessage x
from :: forall x. SamplingMessage -> Rep SamplingMessage x
$cto :: forall x. Rep SamplingMessage x -> SamplingMessage
to :: forall x. Rep SamplingMessage x -> SamplingMessage
Generic)

$(deriveJSON mcpParseOpts ''SamplingMessage)

{- | Client capability for root directory management.

Present if the client supports listing roots (directories or files
that the server can operate on).
-}
data RootsCapability where
    RootsCapability ::
        { RootsCapability -> Maybe Bool
listChanged :: Maybe Bool
        -- ^ Whether the client supports notifications for changes to the roots list.
        } ->
        RootsCapability
    deriving stock (Int -> RootsCapability -> ShowS
[RootsCapability] -> ShowS
RootsCapability -> String
(Int -> RootsCapability -> ShowS)
-> (RootsCapability -> String)
-> ([RootsCapability] -> ShowS)
-> Show RootsCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RootsCapability -> ShowS
showsPrec :: Int -> RootsCapability -> ShowS
$cshow :: RootsCapability -> String
show :: RootsCapability -> String
$cshowList :: [RootsCapability] -> ShowS
showList :: [RootsCapability] -> ShowS
Show, RootsCapability -> RootsCapability -> Bool
(RootsCapability -> RootsCapability -> Bool)
-> (RootsCapability -> RootsCapability -> Bool)
-> Eq RootsCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RootsCapability -> RootsCapability -> Bool
== :: RootsCapability -> RootsCapability -> Bool
$c/= :: RootsCapability -> RootsCapability -> Bool
/= :: RootsCapability -> RootsCapability -> Bool
Eq, (forall x. RootsCapability -> Rep RootsCapability x)
-> (forall x. Rep RootsCapability x -> RootsCapability)
-> Generic RootsCapability
forall x. Rep RootsCapability x -> RootsCapability
forall x. RootsCapability -> Rep RootsCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RootsCapability -> Rep RootsCapability x
from :: forall x. RootsCapability -> Rep RootsCapability x
$cto :: forall x. Rep RootsCapability x -> RootsCapability
to :: forall x. Rep RootsCapability x -> RootsCapability
Generic)

$(deriveJSON mcpParseOpts ''RootsCapability)

{- | Server capability for prompt management.

Present if the server offers any prompt templates.
-}
data PromptsCapability where
    PromptsCapability ::
        { PromptsCapability -> Maybe Bool
listChanged :: Maybe Bool
        -- ^ Whether this server supports notifications for changes to the prompt list.
        } ->
        PromptsCapability
    deriving stock (Int -> PromptsCapability -> ShowS
[PromptsCapability] -> ShowS
PromptsCapability -> String
(Int -> PromptsCapability -> ShowS)
-> (PromptsCapability -> String)
-> ([PromptsCapability] -> ShowS)
-> Show PromptsCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PromptsCapability -> ShowS
showsPrec :: Int -> PromptsCapability -> ShowS
$cshow :: PromptsCapability -> String
show :: PromptsCapability -> String
$cshowList :: [PromptsCapability] -> ShowS
showList :: [PromptsCapability] -> ShowS
Show, PromptsCapability -> PromptsCapability -> Bool
(PromptsCapability -> PromptsCapability -> Bool)
-> (PromptsCapability -> PromptsCapability -> Bool)
-> Eq PromptsCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PromptsCapability -> PromptsCapability -> Bool
== :: PromptsCapability -> PromptsCapability -> Bool
$c/= :: PromptsCapability -> PromptsCapability -> Bool
/= :: PromptsCapability -> PromptsCapability -> Bool
Eq, (forall x. PromptsCapability -> Rep PromptsCapability x)
-> (forall x. Rep PromptsCapability x -> PromptsCapability)
-> Generic PromptsCapability
forall x. Rep PromptsCapability x -> PromptsCapability
forall x. PromptsCapability -> Rep PromptsCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PromptsCapability -> Rep PromptsCapability x
from :: forall x. PromptsCapability -> Rep PromptsCapability x
$cto :: forall x. Rep PromptsCapability x -> PromptsCapability
to :: forall x. Rep PromptsCapability x -> PromptsCapability
Generic)

$(deriveJSON mcpParseOpts ''PromptsCapability)

{- | Server capability for resource management.

Present if the server offers any resources to read.
-}
data ResourcesCapability = ResourcesCapability
    { ResourcesCapability -> Maybe Bool
listChanged :: Maybe Bool
    -- ^ Whether this server supports notifications for changes to the resource list.
    , ResourcesCapability -> Maybe Bool
subscribe :: Maybe Bool
    -- ^ Whether this server supports subscribing to resource updates.
    }
    deriving stock (Int -> ResourcesCapability -> ShowS
[ResourcesCapability] -> ShowS
ResourcesCapability -> String
(Int -> ResourcesCapability -> ShowS)
-> (ResourcesCapability -> String)
-> ([ResourcesCapability] -> ShowS)
-> Show ResourcesCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourcesCapability -> ShowS
showsPrec :: Int -> ResourcesCapability -> ShowS
$cshow :: ResourcesCapability -> String
show :: ResourcesCapability -> String
$cshowList :: [ResourcesCapability] -> ShowS
showList :: [ResourcesCapability] -> ShowS
Show, ResourcesCapability -> ResourcesCapability -> Bool
(ResourcesCapability -> ResourcesCapability -> Bool)
-> (ResourcesCapability -> ResourcesCapability -> Bool)
-> Eq ResourcesCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourcesCapability -> ResourcesCapability -> Bool
== :: ResourcesCapability -> ResourcesCapability -> Bool
$c/= :: ResourcesCapability -> ResourcesCapability -> Bool
/= :: ResourcesCapability -> ResourcesCapability -> Bool
Eq, (forall x. ResourcesCapability -> Rep ResourcesCapability x)
-> (forall x. Rep ResourcesCapability x -> ResourcesCapability)
-> Generic ResourcesCapability
forall x. Rep ResourcesCapability x -> ResourcesCapability
forall x. ResourcesCapability -> Rep ResourcesCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ResourcesCapability -> Rep ResourcesCapability x
from :: forall x. ResourcesCapability -> Rep ResourcesCapability x
$cto :: forall x. Rep ResourcesCapability x -> ResourcesCapability
to :: forall x. Rep ResourcesCapability x -> ResourcesCapability
Generic)

$(deriveJSON mcpParseOpts ''ResourcesCapability)

{- | Server capability for tool management.

Present if the server offers any tools to call.
-}
data ToolsCapability where
    ToolsCapability ::
        { ToolsCapability -> Maybe Bool
listChanged :: Maybe Bool
        -- ^ Whether this server supports notifications for changes to the tool list.
        } ->
        ToolsCapability
    deriving stock (Int -> ToolsCapability -> ShowS
[ToolsCapability] -> ShowS
ToolsCapability -> String
(Int -> ToolsCapability -> ShowS)
-> (ToolsCapability -> String)
-> ([ToolsCapability] -> ShowS)
-> Show ToolsCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ToolsCapability -> ShowS
showsPrec :: Int -> ToolsCapability -> ShowS
$cshow :: ToolsCapability -> String
show :: ToolsCapability -> String
$cshowList :: [ToolsCapability] -> ShowS
showList :: [ToolsCapability] -> ShowS
Show, ToolsCapability -> ToolsCapability -> Bool
(ToolsCapability -> ToolsCapability -> Bool)
-> (ToolsCapability -> ToolsCapability -> Bool)
-> Eq ToolsCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ToolsCapability -> ToolsCapability -> Bool
== :: ToolsCapability -> ToolsCapability -> Bool
$c/= :: ToolsCapability -> ToolsCapability -> Bool
/= :: ToolsCapability -> ToolsCapability -> Bool
Eq, (forall x. ToolsCapability -> Rep ToolsCapability x)
-> (forall x. Rep ToolsCapability x -> ToolsCapability)
-> Generic ToolsCapability
forall x. Rep ToolsCapability x -> ToolsCapability
forall x. ToolsCapability -> Rep ToolsCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ToolsCapability -> Rep ToolsCapability x
from :: forall x. ToolsCapability -> Rep ToolsCapability x
$cto :: forall x. Rep ToolsCapability x -> ToolsCapability
to :: forall x. Rep ToolsCapability x -> ToolsCapability
Generic)

$(deriveJSON mcpParseOpts ''ToolsCapability)

{- | Server capability for argument autocompletion.

Present if the server supports argument autocompletion suggestions.
-}
data CompletionsCapability = CompletionsCapability
    deriving stock (Int -> CompletionsCapability -> ShowS
[CompletionsCapability] -> ShowS
CompletionsCapability -> String
(Int -> CompletionsCapability -> ShowS)
-> (CompletionsCapability -> String)
-> ([CompletionsCapability] -> ShowS)
-> Show CompletionsCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompletionsCapability -> ShowS
showsPrec :: Int -> CompletionsCapability -> ShowS
$cshow :: CompletionsCapability -> String
show :: CompletionsCapability -> String
$cshowList :: [CompletionsCapability] -> ShowS
showList :: [CompletionsCapability] -> ShowS
Show, CompletionsCapability -> CompletionsCapability -> Bool
(CompletionsCapability -> CompletionsCapability -> Bool)
-> (CompletionsCapability -> CompletionsCapability -> Bool)
-> Eq CompletionsCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompletionsCapability -> CompletionsCapability -> Bool
== :: CompletionsCapability -> CompletionsCapability -> Bool
$c/= :: CompletionsCapability -> CompletionsCapability -> Bool
/= :: CompletionsCapability -> CompletionsCapability -> Bool
Eq, (forall x. CompletionsCapability -> Rep CompletionsCapability x)
-> (forall x. Rep CompletionsCapability x -> CompletionsCapability)
-> Generic CompletionsCapability
forall x. Rep CompletionsCapability x -> CompletionsCapability
forall x. CompletionsCapability -> Rep CompletionsCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CompletionsCapability -> Rep CompletionsCapability x
from :: forall x. CompletionsCapability -> Rep CompletionsCapability x
$cto :: forall x. Rep CompletionsCapability x -> CompletionsCapability
to :: forall x. Rep CompletionsCapability x -> CompletionsCapability
Generic)

instance ToJSON CompletionsCapability where
    toJSON :: CompletionsCapability -> Value
toJSON CompletionsCapability
_ = [Pair] -> Value
object []

instance FromJSON CompletionsCapability where
    parseJSON :: Value -> Parser CompletionsCapability
parseJSON = String
-> (Object -> Parser CompletionsCapability)
-> Value
-> Parser CompletionsCapability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CompletionsCapability" ((Object -> Parser CompletionsCapability)
 -> Value -> Parser CompletionsCapability)
-> (Object -> Parser CompletionsCapability)
-> Value
-> Parser CompletionsCapability
forall a b. (a -> b) -> a -> b
$ \Object
_ -> CompletionsCapability -> Parser CompletionsCapability
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CompletionsCapability
CompletionsCapability

{- | Server capability for logging.

Present if the server supports sending log messages to the client.
-}
data LoggingCapability = LoggingCapability
    deriving stock (Int -> LoggingCapability -> ShowS
[LoggingCapability] -> ShowS
LoggingCapability -> String
(Int -> LoggingCapability -> ShowS)
-> (LoggingCapability -> String)
-> ([LoggingCapability] -> ShowS)
-> Show LoggingCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LoggingCapability -> ShowS
showsPrec :: Int -> LoggingCapability -> ShowS
$cshow :: LoggingCapability -> String
show :: LoggingCapability -> String
$cshowList :: [LoggingCapability] -> ShowS
showList :: [LoggingCapability] -> ShowS
Show, LoggingCapability -> LoggingCapability -> Bool
(LoggingCapability -> LoggingCapability -> Bool)
-> (LoggingCapability -> LoggingCapability -> Bool)
-> Eq LoggingCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LoggingCapability -> LoggingCapability -> Bool
== :: LoggingCapability -> LoggingCapability -> Bool
$c/= :: LoggingCapability -> LoggingCapability -> Bool
/= :: LoggingCapability -> LoggingCapability -> Bool
Eq, (forall x. LoggingCapability -> Rep LoggingCapability x)
-> (forall x. Rep LoggingCapability x -> LoggingCapability)
-> Generic LoggingCapability
forall x. Rep LoggingCapability x -> LoggingCapability
forall x. LoggingCapability -> Rep LoggingCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LoggingCapability -> Rep LoggingCapability x
from :: forall x. LoggingCapability -> Rep LoggingCapability x
$cto :: forall x. Rep LoggingCapability x -> LoggingCapability
to :: forall x. Rep LoggingCapability x -> LoggingCapability
Generic)

instance ToJSON LoggingCapability where
    toJSON :: LoggingCapability -> Value
toJSON LoggingCapability
_ = [Pair] -> Value
object []

instance FromJSON LoggingCapability where
    parseJSON :: Value -> Parser LoggingCapability
parseJSON = String
-> (Object -> Parser LoggingCapability)
-> Value
-> Parser LoggingCapability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"LoggingCapability" ((Object -> Parser LoggingCapability)
 -> Value -> Parser LoggingCapability)
-> (Object -> Parser LoggingCapability)
-> Value
-> Parser LoggingCapability
forall a b. (a -> b) -> a -> b
$ \Object
_ -> LoggingCapability -> Parser LoggingCapability
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LoggingCapability
LoggingCapability

{- | Client capability for LLM sampling.

Present if the client supports sampling from an LLM.
-}
data SamplingCapability = SamplingCapability
    deriving stock (Int -> SamplingCapability -> ShowS
[SamplingCapability] -> ShowS
SamplingCapability -> String
(Int -> SamplingCapability -> ShowS)
-> (SamplingCapability -> String)
-> ([SamplingCapability] -> ShowS)
-> Show SamplingCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SamplingCapability -> ShowS
showsPrec :: Int -> SamplingCapability -> ShowS
$cshow :: SamplingCapability -> String
show :: SamplingCapability -> String
$cshowList :: [SamplingCapability] -> ShowS
showList :: [SamplingCapability] -> ShowS
Show, SamplingCapability -> SamplingCapability -> Bool
(SamplingCapability -> SamplingCapability -> Bool)
-> (SamplingCapability -> SamplingCapability -> Bool)
-> Eq SamplingCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SamplingCapability -> SamplingCapability -> Bool
== :: SamplingCapability -> SamplingCapability -> Bool
$c/= :: SamplingCapability -> SamplingCapability -> Bool
/= :: SamplingCapability -> SamplingCapability -> Bool
Eq, (forall x. SamplingCapability -> Rep SamplingCapability x)
-> (forall x. Rep SamplingCapability x -> SamplingCapability)
-> Generic SamplingCapability
forall x. Rep SamplingCapability x -> SamplingCapability
forall x. SamplingCapability -> Rep SamplingCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SamplingCapability -> Rep SamplingCapability x
from :: forall x. SamplingCapability -> Rep SamplingCapability x
$cto :: forall x. Rep SamplingCapability x -> SamplingCapability
to :: forall x. Rep SamplingCapability x -> SamplingCapability
Generic)

instance ToJSON SamplingCapability where
    toJSON :: SamplingCapability -> Value
toJSON SamplingCapability
_ = [Pair] -> Value
object []

instance FromJSON SamplingCapability where
    parseJSON :: Value -> Parser SamplingCapability
parseJSON = String
-> (Object -> Parser SamplingCapability)
-> Value
-> Parser SamplingCapability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SamplingCapability" ((Object -> Parser SamplingCapability)
 -> Value -> Parser SamplingCapability)
-> (Object -> Parser SamplingCapability)
-> Value
-> Parser SamplingCapability
forall a b. (a -> b) -> a -> b
$ \Object
_ -> SamplingCapability -> Parser SamplingCapability
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SamplingCapability
SamplingCapability

{- | Experimental, non-standard capabilities.

Experimental capabilities that the client or server supports.
This is not a closed set: any client or server can define its own,
additional capabilities.
-}
newtype ExperimentalCapability = ExperimentalCapability (Map Text Value)
    deriving stock (Int -> ExperimentalCapability -> ShowS
[ExperimentalCapability] -> ShowS
ExperimentalCapability -> String
(Int -> ExperimentalCapability -> ShowS)
-> (ExperimentalCapability -> String)
-> ([ExperimentalCapability] -> ShowS)
-> Show ExperimentalCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExperimentalCapability -> ShowS
showsPrec :: Int -> ExperimentalCapability -> ShowS
$cshow :: ExperimentalCapability -> String
show :: ExperimentalCapability -> String
$cshowList :: [ExperimentalCapability] -> ShowS
showList :: [ExperimentalCapability] -> ShowS
Show, ExperimentalCapability -> ExperimentalCapability -> Bool
(ExperimentalCapability -> ExperimentalCapability -> Bool)
-> (ExperimentalCapability -> ExperimentalCapability -> Bool)
-> Eq ExperimentalCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExperimentalCapability -> ExperimentalCapability -> Bool
== :: ExperimentalCapability -> ExperimentalCapability -> Bool
$c/= :: ExperimentalCapability -> ExperimentalCapability -> Bool
/= :: ExperimentalCapability -> ExperimentalCapability -> Bool
Eq, (forall x. ExperimentalCapability -> Rep ExperimentalCapability x)
-> (forall x.
    Rep ExperimentalCapability x -> ExperimentalCapability)
-> Generic ExperimentalCapability
forall x. Rep ExperimentalCapability x -> ExperimentalCapability
forall x. ExperimentalCapability -> Rep ExperimentalCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ExperimentalCapability -> Rep ExperimentalCapability x
from :: forall x. ExperimentalCapability -> Rep ExperimentalCapability x
$cto :: forall x. Rep ExperimentalCapability x -> ExperimentalCapability
to :: forall x. Rep ExperimentalCapability x -> ExperimentalCapability
Generic)
    deriving newtype ([ExperimentalCapability] -> Value
[ExperimentalCapability] -> Encoding
ExperimentalCapability -> Bool
ExperimentalCapability -> Value
ExperimentalCapability -> Encoding
(ExperimentalCapability -> Value)
-> (ExperimentalCapability -> Encoding)
-> ([ExperimentalCapability] -> Value)
-> ([ExperimentalCapability] -> Encoding)
-> (ExperimentalCapability -> Bool)
-> ToJSON ExperimentalCapability
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ExperimentalCapability -> Value
toJSON :: ExperimentalCapability -> Value
$ctoEncoding :: ExperimentalCapability -> Encoding
toEncoding :: ExperimentalCapability -> Encoding
$ctoJSONList :: [ExperimentalCapability] -> Value
toJSONList :: [ExperimentalCapability] -> Value
$ctoEncodingList :: [ExperimentalCapability] -> Encoding
toEncodingList :: [ExperimentalCapability] -> Encoding
$comitField :: ExperimentalCapability -> Bool
omitField :: ExperimentalCapability -> Bool
ToJSON, Maybe ExperimentalCapability
Value -> Parser [ExperimentalCapability]
Value -> Parser ExperimentalCapability
(Value -> Parser ExperimentalCapability)
-> (Value -> Parser [ExperimentalCapability])
-> Maybe ExperimentalCapability
-> FromJSON ExperimentalCapability
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ExperimentalCapability
parseJSON :: Value -> Parser ExperimentalCapability
$cparseJSONList :: Value -> Parser [ExperimentalCapability]
parseJSONList :: Value -> Parser [ExperimentalCapability]
$comittedField :: Maybe ExperimentalCapability
omittedField :: Maybe ExperimentalCapability
FromJSON)

{- | Client capability for elicitation.

Present if the client supports elicitation from the server.
-}
data ElicitationCapability = ElicitationCapability
    deriving stock (Int -> ElicitationCapability -> ShowS
[ElicitationCapability] -> ShowS
ElicitationCapability -> String
(Int -> ElicitationCapability -> ShowS)
-> (ElicitationCapability -> String)
-> ([ElicitationCapability] -> ShowS)
-> Show ElicitationCapability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ElicitationCapability -> ShowS
showsPrec :: Int -> ElicitationCapability -> ShowS
$cshow :: ElicitationCapability -> String
show :: ElicitationCapability -> String
$cshowList :: [ElicitationCapability] -> ShowS
showList :: [ElicitationCapability] -> ShowS
Show, ElicitationCapability -> ElicitationCapability -> Bool
(ElicitationCapability -> ElicitationCapability -> Bool)
-> (ElicitationCapability -> ElicitationCapability -> Bool)
-> Eq ElicitationCapability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ElicitationCapability -> ElicitationCapability -> Bool
== :: ElicitationCapability -> ElicitationCapability -> Bool
$c/= :: ElicitationCapability -> ElicitationCapability -> Bool
/= :: ElicitationCapability -> ElicitationCapability -> Bool
Eq, (forall x. ElicitationCapability -> Rep ElicitationCapability x)
-> (forall x. Rep ElicitationCapability x -> ElicitationCapability)
-> Generic ElicitationCapability
forall x. Rep ElicitationCapability x -> ElicitationCapability
forall x. ElicitationCapability -> Rep ElicitationCapability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ElicitationCapability -> Rep ElicitationCapability x
from :: forall x. ElicitationCapability -> Rep ElicitationCapability x
$cto :: forall x. Rep ElicitationCapability x -> ElicitationCapability
to :: forall x. Rep ElicitationCapability x -> ElicitationCapability
Generic)

instance ToJSON ElicitationCapability where
    toJSON :: ElicitationCapability -> Value
toJSON ElicitationCapability
_ = [Pair] -> Value
object []

instance FromJSON ElicitationCapability where
    parseJSON :: Value -> Parser ElicitationCapability
parseJSON = String
-> (Object -> Parser ElicitationCapability)
-> Value
-> Parser ElicitationCapability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ElicitationCapability" ((Object -> Parser ElicitationCapability)
 -> Value -> Parser ElicitationCapability)
-> (Object -> Parser ElicitationCapability)
-> Value
-> Parser ElicitationCapability
forall a b. (a -> b) -> a -> b
$ \Object
_ -> ElicitationCapability -> Parser ElicitationCapability
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ElicitationCapability
ElicitationCapability

{- | Capabilities a client may support.

Known capabilities are defined here, in this schema, but this is not a closed set:
any client can define its own, additional capabilities.
-}
data ClientCapabilities = ClientCapabilities
    { ClientCapabilities -> Maybe RootsCapability
roots :: Maybe RootsCapability
    -- ^ Present if the client supports listing roots.
    , ClientCapabilities -> Maybe SamplingCapability
sampling :: Maybe SamplingCapability
    -- ^ Present if the client supports sampling from an LLM.
    , ClientCapabilities -> Maybe ElicitationCapability
elicitation :: Maybe ElicitationCapability
    -- ^ Present if the client supports elicitation from the server.
    , ClientCapabilities -> Maybe ExperimentalCapability
experimental :: Maybe ExperimentalCapability
    -- ^ Experimental, non-standard capabilities that the client supports.
    }
    deriving stock (Int -> ClientCapabilities -> ShowS
[ClientCapabilities] -> ShowS
ClientCapabilities -> String
(Int -> ClientCapabilities -> ShowS)
-> (ClientCapabilities -> String)
-> ([ClientCapabilities] -> ShowS)
-> Show ClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientCapabilities -> ShowS
showsPrec :: Int -> ClientCapabilities -> ShowS
$cshow :: ClientCapabilities -> String
show :: ClientCapabilities -> String
$cshowList :: [ClientCapabilities] -> ShowS
showList :: [ClientCapabilities] -> ShowS
Show, ClientCapabilities -> ClientCapabilities -> Bool
(ClientCapabilities -> ClientCapabilities -> Bool)
-> (ClientCapabilities -> ClientCapabilities -> Bool)
-> Eq ClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClientCapabilities -> ClientCapabilities -> Bool
== :: ClientCapabilities -> ClientCapabilities -> Bool
$c/= :: ClientCapabilities -> ClientCapabilities -> Bool
/= :: ClientCapabilities -> ClientCapabilities -> Bool
Eq, (forall x. ClientCapabilities -> Rep ClientCapabilities x)
-> (forall x. Rep ClientCapabilities x -> ClientCapabilities)
-> Generic ClientCapabilities
forall x. Rep ClientCapabilities x -> ClientCapabilities
forall x. ClientCapabilities -> Rep ClientCapabilities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ClientCapabilities -> Rep ClientCapabilities x
from :: forall x. ClientCapabilities -> Rep ClientCapabilities x
$cto :: forall x. Rep ClientCapabilities x -> ClientCapabilities
to :: forall x. Rep ClientCapabilities x -> ClientCapabilities
Generic)

$(deriveJSON mcpParseOpts ''ClientCapabilities)

{- | Capabilities that a server may support.

Known capabilities are defined here, in this schema, but this is not a closed set:
any server can define its own, additional capabilities.
-}
data ServerCapabilities = ServerCapabilities
    { ServerCapabilities -> Maybe LoggingCapability
logging :: Maybe LoggingCapability
    -- ^ Present if the server supports sending log messages to the client.
    , ServerCapabilities -> Maybe PromptsCapability
prompts :: Maybe PromptsCapability
    -- ^ Present if the server offers any prompt templates.
    , ServerCapabilities -> Maybe ResourcesCapability
resources :: Maybe ResourcesCapability
    -- ^ Present if the server offers any resources to read.
    , ServerCapabilities -> Maybe ToolsCapability
tools :: Maybe ToolsCapability
    -- ^ Present if the server offers any tools to call.
    , ServerCapabilities -> Maybe CompletionsCapability
completions :: Maybe CompletionsCapability
    -- ^ Present if the server supports argument autocompletion suggestions.
    , ServerCapabilities -> Maybe ExperimentalCapability
experimental :: Maybe ExperimentalCapability
    -- ^ Experimental, non-standard capabilities that the server supports.
    }
    deriving stock (Int -> ServerCapabilities -> ShowS
[ServerCapabilities] -> ShowS
ServerCapabilities -> String
(Int -> ServerCapabilities -> ShowS)
-> (ServerCapabilities -> String)
-> ([ServerCapabilities] -> ShowS)
-> Show ServerCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ServerCapabilities -> ShowS
showsPrec :: Int -> ServerCapabilities -> ShowS
$cshow :: ServerCapabilities -> String
show :: ServerCapabilities -> String
$cshowList :: [ServerCapabilities] -> ShowS
showList :: [ServerCapabilities] -> ShowS
Show, ServerCapabilities -> ServerCapabilities -> Bool
(ServerCapabilities -> ServerCapabilities -> Bool)
-> (ServerCapabilities -> ServerCapabilities -> Bool)
-> Eq ServerCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ServerCapabilities -> ServerCapabilities -> Bool
== :: ServerCapabilities -> ServerCapabilities -> Bool
$c/= :: ServerCapabilities -> ServerCapabilities -> Bool
/= :: ServerCapabilities -> ServerCapabilities -> Bool
Eq, (forall x. ServerCapabilities -> Rep ServerCapabilities x)
-> (forall x. Rep ServerCapabilities x -> ServerCapabilities)
-> Generic ServerCapabilities
forall x. Rep ServerCapabilities x -> ServerCapabilities
forall x. ServerCapabilities -> Rep ServerCapabilities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ServerCapabilities -> Rep ServerCapabilities x
from :: forall x. ServerCapabilities -> Rep ServerCapabilities x
$cto :: forall x. Rep ServerCapabilities x -> ServerCapabilities
to :: forall x. Rep ServerCapabilities x -> ServerCapabilities
Generic)

$(deriveJSON mcpParseOpts ''ServerCapabilities)

{- | Base interface for metadata with name (identifier) and title (display name) properties.

This is the base type for various entities that need both programmatic
identifiers and human-readable names.
-}
data BaseMetadata = BaseMetadata
    { BaseMetadata -> Text
name :: Text
    {- ^ Intended for programmatic or logical use, but used as a display name in past specs
    or fallback (if title isn't present).
    -}
    , BaseMetadata -> Maybe Text
title :: Maybe Text
    {- ^ Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
    even by those unfamiliar with domain-specific terminology.
    If not provided, the name should be used for display (except for Tool,
    where `annotations.title` should be given precedence over using `name`,
    if present).
    -}
    }
    deriving stock (Int -> BaseMetadata -> ShowS
[BaseMetadata] -> ShowS
BaseMetadata -> String
(Int -> BaseMetadata -> ShowS)
-> (BaseMetadata -> String)
-> ([BaseMetadata] -> ShowS)
-> Show BaseMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BaseMetadata -> ShowS
showsPrec :: Int -> BaseMetadata -> ShowS
$cshow :: BaseMetadata -> String
show :: BaseMetadata -> String
$cshowList :: [BaseMetadata] -> ShowS
showList :: [BaseMetadata] -> ShowS
Show, BaseMetadata -> BaseMetadata -> Bool
(BaseMetadata -> BaseMetadata -> Bool)
-> (BaseMetadata -> BaseMetadata -> Bool) -> Eq BaseMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BaseMetadata -> BaseMetadata -> Bool
== :: BaseMetadata -> BaseMetadata -> Bool
$c/= :: BaseMetadata -> BaseMetadata -> Bool
/= :: BaseMetadata -> BaseMetadata -> Bool
Eq, (forall x. BaseMetadata -> Rep BaseMetadata x)
-> (forall x. Rep BaseMetadata x -> BaseMetadata)
-> Generic BaseMetadata
forall x. Rep BaseMetadata x -> BaseMetadata
forall x. BaseMetadata -> Rep BaseMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BaseMetadata -> Rep BaseMetadata x
from :: forall x. BaseMetadata -> Rep BaseMetadata x
$cto :: forall x. Rep BaseMetadata x -> BaseMetadata
to :: forall x. Rep BaseMetadata x -> BaseMetadata
Generic)

$(deriveJSON mcpParseOpts ''BaseMetadata)

{- | Describes the name and version of an MCP implementation.

Used to identify the client or server software in initialization.
-}
data Implementation = Implementation
    { Implementation -> Text
name :: Text
    , Implementation -> Text
version :: Text
    , Implementation -> Maybe Text
title :: Maybe Text
    -- ^ Optional title for UI representation.
    }
    deriving stock (Int -> Implementation -> ShowS
[Implementation] -> ShowS
Implementation -> String
(Int -> Implementation -> ShowS)
-> (Implementation -> String)
-> ([Implementation] -> ShowS)
-> Show Implementation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Implementation -> ShowS
showsPrec :: Int -> Implementation -> ShowS
$cshow :: Implementation -> String
show :: Implementation -> String
$cshowList :: [Implementation] -> ShowS
showList :: [Implementation] -> ShowS
Show, Implementation -> Implementation -> Bool
(Implementation -> Implementation -> Bool)
-> (Implementation -> Implementation -> Bool) -> Eq Implementation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Implementation -> Implementation -> Bool
== :: Implementation -> Implementation -> Bool
$c/= :: Implementation -> Implementation -> Bool
/= :: Implementation -> Implementation -> Bool
Eq, (forall x. Implementation -> Rep Implementation x)
-> (forall x. Rep Implementation x -> Implementation)
-> Generic Implementation
forall x. Rep Implementation x -> Implementation
forall x. Implementation -> Rep Implementation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Implementation -> Rep Implementation x
from :: forall x. Implementation -> Rep Implementation x
$cto :: forall x. Rep Implementation x -> Implementation
to :: forall x. Rep Implementation x -> Implementation
Generic)

$(deriveJSON mcpParseOpts ''Implementation)

{- | Represents a root directory or file that the server can operate on.

Roots allow servers to ask for specific directories or files to operate on.
A common example for roots is providing a set of repositories or directories
a server should operate on.
-}
data Root = Root
    { Root -> Text
uri :: Text
    {- ^ The URI identifying the root. This *must* start with file:// for now.
    This restriction may be relaxed in future versions of the protocol to allow
    other URI schemes.
    -}
    , Root -> Maybe Text
name :: Maybe Text
    {- ^ An optional name for the root. This can be used to provide a human-readable
    identifier for the root, which may be useful for display purposes or for
    referencing the root in other parts of the application.
    -}
    , Root -> Maybe Metadata
_meta :: Maybe Metadata
    -- ^ Optional metadata field.
    }
    deriving stock (Int -> Root -> ShowS
[Root] -> ShowS
Root -> String
(Int -> Root -> ShowS)
-> (Root -> String) -> ([Root] -> ShowS) -> Show Root
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Root -> ShowS
showsPrec :: Int -> Root -> ShowS
$cshow :: Root -> String
show :: Root -> String
$cshowList :: [Root] -> ShowS
showList :: [Root] -> ShowS
Show, Root -> Root -> Bool
(Root -> Root -> Bool) -> (Root -> Root -> Bool) -> Eq Root
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Root -> Root -> Bool
== :: Root -> Root -> Bool
$c/= :: Root -> Root -> Bool
/= :: Root -> Root -> Bool
Eq, (forall x. Root -> Rep Root x)
-> (forall x. Rep Root x -> Root) -> Generic Root
forall x. Rep Root x -> Root
forall x. Root -> Rep Root x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Root -> Rep Root x
from :: forall x. Root -> Rep Root x
$cto :: forall x. Rep Root x -> Root
to :: forall x. Rep Root x -> Root
Generic)

$(deriveJSON mcpParseOpts ''Root)

{- | Base result type.

All MCP result types include optional metadata that can be used
to attach additional information to responses.
-}
data Result where
    Result ::
        { Result -> Maybe Metadata
_meta :: Maybe Metadata
        {- ^ This result property is reserved by the protocol to allow clients and servers
        to attach additional metadata to their responses.
        -}
        } ->
        Result
    deriving stock (Int -> Result -> ShowS
[Result] -> ShowS
Result -> String
(Int -> Result -> ShowS)
-> (Result -> String) -> ([Result] -> ShowS) -> Show Result
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Result -> ShowS
showsPrec :: Int -> Result -> ShowS
$cshow :: Result -> String
show :: Result -> String
$cshowList :: [Result] -> ShowS
showList :: [Result] -> ShowS
Show, Result -> Result -> Bool
(Result -> Result -> Bool)
-> (Result -> Result -> Bool) -> Eq Result
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Result -> Result -> Bool
== :: Result -> Result -> Bool
$c/= :: Result -> Result -> Bool
/= :: Result -> Result -> Bool
Eq, (forall x. Result -> Rep Result x)
-> (forall x. Rep Result x -> Result) -> Generic Result
forall x. Rep Result x -> Result
forall x. Result -> Rep Result x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Result -> Rep Result x
from :: forall x. Result -> Rep Result x
$cto :: forall x. Rep Result x -> Result
to :: forall x. Rep Result x -> Result
Generic)

$(deriveJSON mcpParseOpts ''Result)