Skip to content
Open
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 @@ -14,6 +14,7 @@ All notable changes to `mcp/sdk` will be documented in this file.
* Fix `InMemorySessionStore::exists()` reporting a session past its TTL as existing, while `read()` already treated it as gone.
* Fix `Psr16NotificationBus` subscribers missing the notifications published after the bus stayed quiet for longer than its TTL: the sequence counter no longer expires, and a subscriber whose cursor is ahead of a lost counter reads what the bus holds.
* Fix `Session::save()` wiping the other keys of a session that the store failed to read, e.g. when `Psr16SessionStore` hits a cache error: it now returns `false` instead of writing the changed keys alone.
* Fix tool name validation not following the spec's rule (1 to 128 characters of `A-Z`, `a-z`, `0-9`, `_`, `-` and `.`): names of 65 to 128 characters no longer log a warning, while names with a `/` or a trailing newline now do.
* Add `Psr6SessionStore` and `Psr6NotificationBus`, which work like `Psr16SessionStore` and `Psr16NotificationBus` over a PSR-6 cache pool. `Builder::setDiscovery()` also accepts a PSR-6 pool as `$cache`.

### Client
Expand Down
2 changes: 1 addition & 1 deletion src/Capability/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function registerTool(Tool $tool, callable|array|string $handler): ToolRe
{
if (!$this->nameValidator->isValid($tool->name)) {
$this->logger->warning(
\sprintf('Tool name "%s" is invalid. Tool names should only contain letters (a-z, A-Z), numbers, dots, hyphens, underscores, and forward slashes.', $tool->name),
\sprintf('Tool name "%s" is invalid. Tool names should be 1 to 128 characters long and only contain letters (a-z, A-Z), numbers, dots, hyphens and underscores.', $tool->name),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Capability/Tool/NameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ final class NameValidator
{
public function isValid(string $name): bool
{
return 1 === preg_match('/^[a-zA-Z0-9._\/-]{1,64}$/', $name);
return 1 === preg_match('/^[a-zA-Z0-9._-]{1,128}$/D', $name);
}
}
6 changes: 4 additions & 2 deletions tests/Unit/Capability/Tool/NameValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static function provideValidNames(): array
['MyTool123'],
['my.tool'],
['my-tool'],
['my/tool'],
['my_tool-01.02'],
['my_long_toolname_that_is_exactly_sixty_four_characters_long_1234'],
[str_repeat('a', 128)],
];
}

Expand All @@ -50,7 +50,9 @@ public static function provideInvalidNames(): array
['my@tool'],
['my!tool'],
['my_tool#1'],
['this_tool_name_is_way_too_long_because_it_exceeds_the_sixty_four_character_limit_set_by_the_validator'],
['my/tool'],
["my_tool\n"],
[str_repeat('a', 129)],
];
}
}
Loading