[Server] Add support for icons on explicit builder registration and attributes (#142)
* Add support for icons on explicit builder registration and attributes * Update docs/server-builder.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
7a8fbe9b20
commit
056c7b6103
2 changed files with 173 additions and 39 deletions
|
|
@ -72,6 +72,8 @@ class Calculator
|
|||
- **`name`** (optional): Tool identifier. Defaults to method name if not provided.
|
||||
- **`description`** (optional): Tool description. Defaults to docblock summary if not provided, otherwise uses method name.
|
||||
- **`annotations`** (optional): `ToolAnnotations` object for additional metadata.
|
||||
- **`icons`** (optional): Array of `Icon` objects for visual representation.
|
||||
- **`meta`** (optional): Arbitrary key-value pairs for custom metadata.
|
||||
|
||||
**Priority for name/description**: Attribute parameters → DocBlock content → Method name
|
||||
|
||||
|
|
@ -217,6 +219,9 @@ class ConfigProvider
|
|||
- **`description`** (optional): Resource description. Defaults to docblock summary if not provided.
|
||||
- **`mimeType`** (optional): MIME type of the resource content.
|
||||
- **`size`** (optional): Size in bytes if known.
|
||||
- **`annotations`** (optional): Additional metadata.
|
||||
- **`icons`** (optional): Array of `Icon` objects for visual representation.
|
||||
- **`meta`** (optional): Arbitrary key-value pairs for custom metadata.
|
||||
|
||||
**Standard Protocol URI Schemes**: `https://` (web resources), `file://` (filesystem), `git://` (version control).
|
||||
**Custom schemes**: `config://`, `data://`, `db://`, `api://` or any RFC 3986 compliant scheme.
|
||||
|
|
@ -399,6 +404,8 @@ class PromptGenerator
|
|||
|
||||
- **`name`** (optional): Prompt identifier. Defaults to method name if not provided.
|
||||
- **`description`** (optional): Prompt description. Defaults to docblock summary if not provided.
|
||||
- **`icons`** (optional): Array of `Icon` objects for visual representation.
|
||||
- **`meta`** (optional): Arbitrary key-value pairs for custom metadata.
|
||||
|
||||
### Prompt Return Values
|
||||
|
||||
|
|
|
|||
|
|
@ -52,14 +52,25 @@ final `Server` instance ready for use.
|
|||
Set the server's identity with name, version, and optional description:
|
||||
|
||||
```php
|
||||
use Mcp\Schema\Icon;
|
||||
use Mcp\Server;
|
||||
|
||||
$server = Server::builder()
|
||||
->setServerInfo('Calculator Server', '1.2.0', 'Advanced mathematical calculations');
|
||||
->setServerInfo(
|
||||
name: 'Calculator Server',
|
||||
version: '1.2.0',
|
||||
description: 'Advanced mathematical calculations',
|
||||
icons: [new Icon('https://example.com/icon.png', 'image/png', ['64x64'])],
|
||||
websiteUrl: 'https://example.com'
|
||||
');
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `$name` (string): The server name
|
||||
- `$version` (string): Version string (semantic versioning recommended)
|
||||
- `$description` (string|null): Optional description
|
||||
- `$icons` (Icon[]|null): Optional array of server icons
|
||||
- `$websiteUrl` (string|null): Optional server website URL
|
||||
|
||||
### Pagination Limit
|
||||
|
||||
|
|
@ -263,6 +274,16 @@ $server = Server::builder()
|
|||
);
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `handler` (callable|string): The tool handler
|
||||
- `name` (string|null): Optional tool name
|
||||
- `description` (string|null): Optional tool description
|
||||
- `annotations` (ToolAnnotations|null): Optional annotations for the tool
|
||||
- `inputSchema` (array|null): Optional input schema for the tool
|
||||
- `icons` (Icon[]|null): Optional array of icons for the tool
|
||||
- `meta` (array|null): Optional metadata for the tool
|
||||
|
||||
### Manual Resource Registration
|
||||
|
||||
Register static resources:
|
||||
|
|
@ -278,6 +299,18 @@ $server = Server::builder()
|
|||
);
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `handler` (callable|string): The resource handler
|
||||
- `uri` (string): The resource URI
|
||||
- `name` (string|null): Optional resource name
|
||||
- `description` (string|null): Optional resource description
|
||||
- `mimeType` (string|null): Optional MIME type of the resource
|
||||
- `size` (int|null): Optional size of the resource in bytes
|
||||
- `annotations` (Annotations|null): Optional annotations for the resource
|
||||
- `icons` (Icon[]|null): Optional array of icons for the resource
|
||||
- `meta` (array|null): Optional metadata for the resource
|
||||
|
||||
### Manual Resource Template Registration
|
||||
|
||||
Register dynamic resources with URI templates:
|
||||
|
|
@ -293,6 +326,15 @@ $server = Server::builder()
|
|||
);
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `handler` (callable|string): The resource template handler
|
||||
- `uriTemplate` (string): The resource URI template
|
||||
- `name` (string|null): Optional resource template name
|
||||
- `description` (string|null): Optional resource template description
|
||||
- `mimeType` (string|null): Optional MIME type of the resource
|
||||
- `annotations` (Annotations|null): Optional annotations for the resource template
|
||||
|
||||
### Manual Prompt Registration
|
||||
|
||||
Register prompt generators:
|
||||
|
|
@ -306,6 +348,13 @@ $server = Server::builder()
|
|||
);
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `handler` (callable|string): The prompt handler
|
||||
- `name` (string|null): Optional prompt name
|
||||
- `description` (string|null): Optional prompt description
|
||||
- `icons` (Icon[]|null): Optional array of icons for the prompt
|
||||
|
||||
**Note:** `name` and `description` are optional for all manual registrations. If not provided, they will be derived from
|
||||
the handler's method name and docblock.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue