Overview
The completion feature allows clients to request suggestions for:- Prompt arguments - Arguments marked with
completable()in the server’s prompt schema - Resource template URI variables - Variables in resource template URIs with completion support
complete() method, which sends a completion/complete request to the server and returns a list of suggested values.
Basic Usage with MCPClient
Request completions for a prompt argument:Using with useMcp Hook
TheuseMcp hook exposes a complete() method for requesting completions in React applications:
Using with McpClientProvider
When usingMcpClientProvider with multiple servers, get completions via useMcpServer:
Completion Request Parameters
Thecomplete() method accepts a CompleteRequestParams object with the following structure:
Completing Prompt Arguments
For prompt arguments, useref/prompt and specify the prompt name:
Completing Resource Template URIs
For resource template URI variables, useref/resource with the template URI:
Completion Response
The completion result contains:Contextual Completions
Some completions may depend on other argument values. Pass additional context in the request:Autocomplete UI Example
Here’s a complete example of building an autocomplete dropdown:Server Implementation
Servers define completions using thecompletable() helper:
Best Practices
Debounce Requests
Always debounce completion requests to avoid overwhelming the server:Handle Errors Gracefully
Completion requests may fail if the server doesn’t support completions for a specific argument:Check Server Capabilities
Before requesting completions, verify the server supports the feature:Limit UI Suggestions
The MCP spec enforces a maximum of 100 values per response, but you may want to show fewer in the UI:Error Handling
Common errors and how to handle them:| Error | Cause | Solution |
|---|---|---|
Client not ready | Calling complete() before connection | Wait for state === 'ready' |
Method not found (-32601) | Server doesn’t support completions | Check serverCapabilities?.completions |
Invalid argument | Argument not defined in schema | Verify argument name matches server schema |
Not completable | Argument doesn’t have completable() | Only request completions for completable arguments |
Run the Example
A full Node.js example is available in the mcp-use repository:examples/server/features/completion/ and examples/client/node/communication/completion-client.ts.
Related
- Prompts - Learn about prompt templates
- Resources - Learn about resource templates
- useMcp Hook - React hook documentation