-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Adding description field to the FastMCP get_prompt method #614
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
The character encoding of the stdin/stdout streams in Python is platform- dependent. On Windows it will be something weird, like CP437 or CP1252, depending on the locale. This change ensures that no matter the platform, UTF-8 is used.
…col#218) Adds sampling and list roots callbacks to the ClientSession, allowing the client to handle requests from the server. Co-authored-by: TerminalMan <[email protected]> Co-authored-by: David Soria Parra <[email protected]>
…/jerome/fix/request-context-typing Updated typing on request context for the server to use server session
…ontextprotocol#222) * feat: allow lowlevel servers to return a list of resources The resource/read message in MCP allows of multiple resources to be returned. However, in the SDK we do not allow this. This change is such that we allow returning multiple resource in the lowlevel API if needed. However in FastMCP we stick to one, since a FastMCP resource defines the mime_type in the decorator and hence a resource cannot dynamically return different mime_typed resources. It also is just the better default to only return one resource. However in the lowlevel API we will allow this. Strictly speaking this is not a BC break since the new return value is additive, but if people subclassed server, it will break them. * feat: lower the type requriements for call_tool to Iterable
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 for working on this!
Looks like there are some refactoring opportunities. Both get_prompt and render_prompt will look up the same prompt, which is inefficient.
The use of getattr(prompt, "description", None) suggests uncertainty about whether the prompt has a description attribute. It should always have one.
Please can you refactor and then we can merge.
src/mcp/server/fastmcp/server.py
Outdated
|
||
return GetPromptResult(messages=pydantic_core.to_jsonable_python(messages)) | ||
return GetPromptResult( | ||
description=getattr(prompt, "description", None), |
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.
description=getattr(prompt, "description", None), | |
description=prompt.description if prompt else None, |
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.
Seems reasonable
…xtprotocol#614) Co-authored-by: ihrpr <[email protected]>
Issue: #602
The
GetPromptResult
class has the field description, however it is not getting returned when using the FastMCP server.Example
Expected behavior
Motivation and Context
Currently, retrieving both the description and messages for a prompt requires two separate calls: one to list_prompts to get the prompt names, and then individual get_prompt calls for each prompt to fetch the full details. This adds unnecessary complexity and overhead, as we then have to manually map the results together to create a complete prompt object with both description and messages.
Proposed Change
Update the
get_prompt
to return the prompt details (including description and messages) directly, reducing complexity.How Has This Been Tested?
test_get_prompt_with_description
Breaking Changes
No breaking changes
Types of changes
Checklist
Additional context