mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
41 lines
1.5 KiB
Text
41 lines
1.5 KiB
Text
---
|
|
title: completions
|
|
sidebarTitle: completions
|
|
---
|
|
|
|
# `fastmcp.server.completions`
|
|
|
|
|
|
Server-side argument completion for FastMCP.
|
|
|
|
A completion request names a reference — a specific prompt or resource
|
|
template — and the argument being completed, plus a context of the argument
|
|
values already supplied. The server answers with candidate string values.
|
|
|
|
FastMCP surfaces this as a single server-level handler registered with
|
|
``@mcp.completion``, mirroring the MCP SDK's own ``completion/complete`` shape
|
|
and FastMCP's client-side ``Client.complete()``. The handler receives the
|
|
reference, the argument, and the optional context, and returns candidates for
|
|
whichever reference/argument pair it recognizes.
|
|
|
|
|
|
## Functions
|
|
|
|
### `normalize_completion` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/completions.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
normalize_completion(result: CompletionValues) -> mcp_types.Completion
|
|
```
|
|
|
|
|
|
Coerce a handler's return value into a wire ``Completion``.
|
|
|
|
A returned ``str`` is rejected: it is almost always a mistake (the value
|
|
would iterate into one-character candidates), so it raises rather than
|
|
silently producing surprising output.
|
|
|
|
The MCP contract caps a completion at 100 values, so a longer result is
|
|
truncated to the first 100 with ``has_more`` set — a handler that returns
|
|
thousands of matches emits a conforming response rather than an oversized
|
|
one that strict clients reject.
|
|
|