completion/complete request naming the prompt or template, the argument being completed, and the partial value so far. The server answers with candidate strings, which the client offers as autocomplete suggestions.
This is the server side of the feature. A client requests completions with Client.complete(); this page covers how a server answers.
Register a completion handler
A server has a single completion handler, registered with the@mcp.completion decorator. The handler receives every completion request and switches on which reference and argument is being completed.
ref: which component is being completed — aPromptReference(carrying the promptname) or aResourceTemplateReference(carrying the templateuri).argument: aCompletionArgumentwith the argumentnameand the partialvaluetyped so far.context: an optionalCompletionContextcarrying the values of arguments the user has already supplied (see Using already-supplied arguments).
argument.value so the suggestions narrow as the user types. Returning None means “I have no suggestions for this reference and argument” — the client receives an empty list, which is the correct answer for a reference the server does not recognize.
Completing resource template parameters
The same handler answers completion for resource template parameters. AResourceTemplateReference identifies the template by its URI template, and argument.name is the parameter being completed.
ref first, then on argument.name. Grouping the branches by reference keeps the handler readable as it grows.
Using already-supplied arguments
Completions often depend on values the user has already entered. A repository suggestion, for example, depends on which owner was chosen. The client sends those resolved values in the completion context, and the handler reads them fromcontext.arguments.
repo are scoped to the owner the user already selected. The context is only present once at least one argument has been resolved, so guard against context being None.
Returning results
A handler may return any of three things:- A list of strings — the simplest form, wrapped into a completion response automatically.
None— treated as an empty completion, for references and arguments the handler does not recognize.- A
Completionobject — when you want to include pagination hints alongside the values.
Completion and set total (how many candidates match in all) and has_more (whether values were truncated) so the client can indicate that the list is partial.
Accessing the request context
A completion handler may be sync or async, and it can reach the active request through FastMCP’s dependency functions the same way any handler does. Useget_context() to access session information, authentication, or server state while computing suggestions.
Authorization
Completion runs behind the server’s connection-level authentication: an unauthenticated client never reaches the handler. It is independent of per-componentauth=, though. FastMCP does not resolve the referenced prompt or resource template, so a completion request is not filtered by that component’s visibility the way prompts/get or a resource read is — the single handler answers for whatever reference the client names.
A completion response carries only candidate strings for one argument, never component content or schema, so this exposes nothing about a hidden component on its own. If a handler computes candidates that should themselves be restricted — matching a prompt hidden from unauthorized callers, say — check the auth context inside the handler (via get_context()) and return None when the caller is not permitted.
