Include context into completions (#966)

This commit is contained in:
Inna Harper 2025-06-17 09:33:25 +01:00 • committed by GitHub
commit a3bcabdce2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -364,6 +364,24 @@ class FastMCP:
return decorator
def completion(self):
"""Decorator to register a completion handler.
The completion handler receives:
- ref: PromptReference or ResourceTemplateReference
- argument: CompletionArgument with name and partial value
- context: Optional CompletionContext with previously resolved arguments
Example:
@mcp.completion()
async def handle_completion(ref, argument, context):
if isinstance(ref, ResourceTemplateReference):
# Return completions based on ref, argument, and context
return Completion(values=["option1", "option2"])
return None
"""
return self._mcp_server.completion()
def add_resource(self, resource: Resource) -> None:
"""Add a resource to the server.