Add a pluggable server extension API with MCP Apps (#3003)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
fe9723853d
commit
4b519782f1
2 changed files with 2598 additions and 24 deletions
|
|
@ -217,6 +217,10 @@ class Client:
|
|||
`read_resource` give up. Use `client.session.<method>(..., allow_input_required=True)`
|
||||
to drive the loop manually instead."""
|
||||
|
||||
extensions: dict[str, dict[str, Any]] | None = None
|
||||
"""SEP-2133 extension support to advertise under `ClientCapabilities.extensions`
|
||||
(identifier -> settings), e.g. `{"io.modelcontextprotocol/ui": {"mimeTypes": [...]}}`."""
|
||||
|
||||
_entered: bool = field(init=False, default=False)
|
||||
_session: ClientSession | None = field(init=False, default=None)
|
||||
_exit_stack: AsyncExitStack | None = field(init=False, default=None)
|
||||
|
|
@ -255,6 +259,7 @@ class Client:
|
|||
message_handler=self.message_handler,
|
||||
client_info=self.client_info,
|
||||
elicitation_callback=self.elicitation_callback,
|
||||
extensions=self.extensions,
|
||||
)
|
||||
|
||||
async def __aenter__(self) -> Client:
|
||||
|
|
|
|||
|
|
@ -224,12 +224,14 @@ class ClientSession:
|
|||
client_info: types.Implementation | None = None,
|
||||
*,
|
||||
sampling_capabilities: types.SamplingCapability | None = None,
|
||||
extensions: dict[str, dict[str, Any]] | None = None,
|
||||
dispatcher: Dispatcher[Any] | None = None,
|
||||
) -> None:
|
||||
self._session_read_timeout_seconds = read_timeout_seconds
|
||||
self._client_info = client_info or DEFAULT_CLIENT_INFO
|
||||
self._sampling_callback = sampling_callback or _default_sampling_callback
|
||||
self._sampling_capabilities = sampling_capabilities
|
||||
self._extensions = extensions
|
||||
self._elicitation_callback = elicitation_callback or _default_elicitation_callback
|
||||
self._list_roots_callback = list_roots_callback or _default_list_roots_callback
|
||||
self._logging_callback = logging_callback or _default_logging_callback
|
||||
|
|
@ -369,7 +371,9 @@ class ClientSession:
|
|||
if self._list_roots_callback is not _default_list_roots_callback
|
||||
else None
|
||||
)
|
||||
return types.ClientCapabilities(sampling=sampling, elicitation=elicitation, experimental=None, roots=roots)
|
||||
return types.ClientCapabilities(
|
||||
sampling=sampling, elicitation=elicitation, experimental=None, extensions=self._extensions, roots=roots
|
||||
)
|
||||
|
||||
async def initialize(self) -> types.InitializeResult:
|
||||
if self._initialize_result is not None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue