-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Include context into completions #966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG! Couple stray late-in-the-day thoughts inline but prob not worth doing immediately
return Completion(values=["users_db", "products_db", "analytics_db"], total=3, hasMore=False) | ||
elif argument.name == "table": | ||
# Complete table names based on selected database | ||
if context and context.arguments: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe overpolishing, but do we want a test where the server errors on not enough context (e.g. "need a database to complete tables" and the client receives it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, added!
@@ -364,6 +364,24 @@ def decorator(fn: AnyFunction) -> AnyFunction: | |||
|
|||
return decorator | |||
|
|||
def completion(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it weird to route all completions to the same function in the high level API? Alternative would be to defer adding the fastmcp decorator for now and do something fancier that routes on URI, but agree that it's nice to bring fastmcp decorator coverage to parity with the lowlevel server.
Also a) maybe it's natural for "real" servers to route all completion requests through the same handler, and b) we could always add new decorators (resource_completion
, prompt_completion
) later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it is quite weird even on the lowlevel, TS has completions handling on a field that needs to be completed, which I found quite nice.
I'd love to make it nicer, but for now to have at least a way to handle completions on FastMCP level and not do to things like _server
.
Details: modelcontextprotocol/modelcontextprotocol#598
Closes: #917
Implementation:
CompletionContext
type with optional arguments field to store previously resolved parametersCompleteRequestParams
to include optional context parametercomplete()
method to accept context_arguments parameterAPI Improvements:
completion()
decorator method to FastMCP for cleaner API (lowlevel already had it)