You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -757,7 +757,11 @@ Completion providers enable MCP clients to offer auto-completion suggestions in
757
757
758
758
> **Note**: Tools and resources can be discovered via standard MCP commands (`tools/list`, `resources/list`), so completion providers are not needed for them. Completion providers are used only for resource templates (URI variables) and prompt arguments.
759
759
760
-
Completion providers must implement the `CompletionProviderInterface`:
760
+
The `#[CompletionProvider]` attribute supports three types of completion sources:
761
+
762
+
#### 1. Custom Provider Classes
763
+
764
+
For complex completion logic, implement the `CompletionProviderInterface`:
761
765
762
766
```php
763
767
use PhpMcp\Server\Contracts\CompletionProviderInterface;
@@ -766,34 +770,143 @@ use PhpMcp\Server\Attributes\{McpResourceTemplate, CompletionProvider};
766
770
767
771
class UserIdCompletionProvider implements CompletionProviderInterface
768
772
{
773
+
public function __construct(private DatabaseService $db) {}
774
+
769
775
public function getCompletions(string $currentValue, SessionInterface $session): array
770
776
{
771
-
// Return completion suggestions based on current input
return [['role' => 'user', 'content' => "Export data in {$format} format with {$priority} priority"]];
894
+
},
895
+
name: 'export_data'
896
+
)
897
+
898
+
->build();
899
+
```
900
+
901
+
#### Completion Provider Resolution
902
+
903
+
The server automatically handles provider resolution:
904
+
905
+
-**Class strings** (`MyProvider::class`) → Resolved from PSR-11 container with dependency injection
906
+
-**Instances** (`new MyProvider()`) → Used directly as-is
907
+
-**Values arrays** (`['a', 'b', 'c']`) → Automatically wrapped in `ListCompletionProvider`
908
+
-**Enum classes** (`MyEnum::class`) → Automatically wrapped in `EnumCompletionProvider`
909
+
797
910
> **Important**: Completion providers only offer suggestions to users in the MCP client interface. Users can still input any value, so always validate parameters in your handlers regardless of completion provider constraints.
0 commit comments