[Schema] Drop SDK-only name pattern on resources and resource templates (#430)
* [Schema] Drop SDK-only name pattern on resources and resource templates * Update src/Schema/ResourceDefinition.php * Update src/Schema/ResourceTemplate.php
This commit is contained in:
parent
6f58fe596a
commit
d5351759d7
2 changed files with 49 additions and 16 deletions
|
|
@ -35,11 +35,6 @@ use Mcp\Exception\InvalidArgumentException;
|
|||
*/
|
||||
class ResourceDefinition implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Resource name pattern regex - must contain only alphanumeric characters, underscores, and hyphens.
|
||||
*/
|
||||
private const RESOURCE_NAME_PATTERN = '/^[a-zA-Z0-9_-]+$/';
|
||||
|
||||
/**
|
||||
* URI pattern regex - requires a valid scheme followed by colon and optional path (RFC 3986).
|
||||
* Example patterns: file://path, db://table, urn:isbn:123, config:key, etc.
|
||||
|
|
@ -68,9 +63,6 @@ class ResourceDefinition implements \JsonSerializable
|
|||
public readonly ?array $icons = null,
|
||||
public readonly ?array $meta = null,
|
||||
) {
|
||||
if (!preg_match(self::RESOURCE_NAME_PATTERN, $name)) {
|
||||
throw new InvalidArgumentException(\sprintf('Invalid resource name "%s": must contain only alphanumeric characters, underscores, and hyphens.', $name));
|
||||
}
|
||||
if (!preg_match(self::URI_PATTERN, $uri)) {
|
||||
throw new InvalidArgumentException(\sprintf('Invalid resource URI: "%s" must be a valid URI with a scheme and optional path.', $uri));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ use Mcp\Exception\InvalidArgumentException;
|
|||
*/
|
||||
class ResourceTemplate implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Resource name pattern regex - must contain only alphanumeric characters, underscores, and hyphens.
|
||||
*/
|
||||
private const RESOURCE_NAME_PATTERN = '/^[a-zA-Z0-9_-]+$/';
|
||||
|
||||
/**
|
||||
* URI Template pattern regex - requires a valid scheme followed by colon and path with at least one placeholder (RFC 3986).
|
||||
* Example patterns: file://{path}/contents.txt, db://{table}/{id}, config:{key}, etc.
|
||||
|
|
@ -61,9 +56,6 @@ class ResourceTemplate implements \JsonSerializable
|
|||
public readonly ?Annotations $annotations = null,
|
||||
public readonly ?array $meta = null,
|
||||
) {
|
||||
if (!preg_match(self::RESOURCE_NAME_PATTERN, $name)) {
|
||||
throw new InvalidArgumentException(\sprintf('Invalid resource name "%s": must contain only alphanumeric characters, underscores, and hyphens.', $name));
|
||||
}
|
||||
if (!preg_match(self::URI_TEMPLATE_PATTERN, $uriTemplate)) {
|
||||
throw new InvalidArgumentException(\sprintf('Invalid URI template : "%s" must be a valid URI template with at least one placeholder.', $uriTemplate));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue