Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to `mcp/sdk` will be documented in this file.
* Prompt generators returning content as typed arrays (`['type' => 'text', ...]` etc.) no longer lose the optional fields: `annotations` on every content type, and `_meta` and an explicit `mimeType` on embedded resource contents, now carry through to the resulting `PromptMessage` instead of being silently dropped. A missing resource `mimeType` still defaults to `text/plain`/`application/octet-stream` as before.
* Add `annotations` support to `ImageContent` (constructor, `fromArray()`, `fromFile()`, `fromString()`, `jsonSerialize()`), matching `TextContent` and `AudioContent`.
* Add client-side `roots/list` handler (`ListRootsRequestHandler` + `RootsCallbackInterface`) and `Client::sendRootsListChanged()`, plus server-side `ClientGateway::listRoots()` / `supportsRoots()` and `ListRootsResult::fromArray()`.
* Add `ClientGateway::supportsSampling()`, so a tool can check the client's advertised capabilities before issuing a `sampling/createMessage` request instead of asking and catching the refusal. Matches the existing `supportsRoots()` and `supportsElicitation()`.
* Add `Mcp\Schema\Content\ResourceLink` for the spec's `resource_link` content block (protocol revision 2025-06-18+), letting tool results and prompt messages reference a resource by URI/name without embedding its contents. Accepted anywhere `resource` (`EmbeddedResource`) content is (de)serialized: `CallToolResult::fromArray()`, `PromptMessage::fromArray()`, and `PromptResultFormatter`.

0.7.0
Expand Down
17 changes: 17 additions & 0 deletions src/Server/ClientGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ public function supportsElicitation(): bool
return \array_key_exists('elicitation', $capabilities);
}

/**
* Check if the connected client supports sampling.
*
* Sampling lets a server borrow the client's model during tool execution.
* This method checks the client's advertised capabilities to determine if
* sampling/createMessage requests are supported.
*
* @return bool True if the client supports sampling, false otherwise
*/
public function supportsSampling(): bool
{
$capabilities = (array) $this->session->get('client_capabilities', []);

// MCP spec: capability presence indicates support (value is typically {} or [])
return \array_key_exists('sampling', $capabilities);
}

/**
* Send a request to the client and wait for a response (blocking).
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Server/ClientGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ public function testSupportsRootsReturnsFalseWhenNotAdvertised(): void
$this->assertFalse($gateway->supportsRoots());
}

public function testSupportsSamplingReturnsTrueWhenAdvertised(): void
{
$session = $this->createMock(SessionInterface::class);
$session->method('get')->with('client_capabilities', [])->willReturn(['sampling' => []]);

$gateway = new ClientGateway($session);

$this->assertTrue($gateway->supportsSampling());
}

public function testSupportsSamplingReturnsFalseWhenNotAdvertised(): void
{
$session = $this->createMock(SessionInterface::class);
$session->method('get')->with('client_capabilities', [])->willReturn(['roots' => []]);

$gateway = new ClientGateway($session);

$this->assertFalse($gateway->supportsSampling());
}

public function testListRootsReturnsRootsFromClient(): void
{
$session = $this->createMock(SessionInterface::class);
Expand Down