Adding description field to the FastMCP get_prompt method#614
Merged
ihrpr merged 16 commits intomodelcontextprotocol:mainfrom Jul 9, 2025
Merged
Adding description field to the FastMCP get_prompt method#614ihrpr merged 16 commits intomodelcontextprotocol:mainfrom
ihrpr merged 16 commits intomodelcontextprotocol:mainfrom
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 <84923604+SecretiveShell@users.noreply.github.com> Co-authored-by: David Soria Parra <davidsp@anthropic.com>
…/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
ihrpr
previously requested changes
May 23, 2025
Contributor
ihrpr
left a comment
There was a problem hiding this comment.
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), |
Contributor
There was a problem hiding this comment.
Suggested change
| description=getattr(prompt, "description", None), | |
| description=prompt.description if prompt else None, |
felixweinberger
previously approved these changes
Jul 9, 2025
Contributor
felixweinberger
left a comment
There was a problem hiding this comment.
Seems reasonable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: #602
The
GetPromptResultclass 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_promptto return the prompt details (including description and messages) directly, reducing complexity.How Has This Been Tested?
test_get_prompt_with_descriptionBreaking Changes
No breaking changes
Types of changes
Checklist
Additional context