Skip to content
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

fix: respect resource mime type in responses #170

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

dsp-ant
Copy link
Member

@dsp-ant dsp-ant commented Jan 24, 2025

Summary

  • Fix resource MIME type handling to ensure types are properly preserved in responses
  • Add comprehensive test coverage for both FastMCP and low-level server implementations

Notable this is a BC breaking change due to the new return values in read_resource() on FastMCP.

Test plan

  • Verify MIME type preservation for text resources
  • Verify MIME type preservation for binary resources
  • Test both FastMCP and low-level server implementations
  • Ensure proper error handling for invalid cases

@dsp-ant dsp-ant force-pushed the fix/152-resource-mime-type branch from 9dec4ba to 83a3853 Compare January 24, 2025 16:51
@dsp-ant dsp-ant linked an issue Jan 24, 2025 that may be closed by this pull request
@dsp-ant dsp-ant force-pushed the fix/152-resource-mime-type branch from 83a3853 to 2c3a283 Compare January 24, 2025 16:54
The server was ignoring mime types set on resources, defaulting to text/plain
for strings and application/octet-stream for bytes. Now properly preserves
the specified mime type in both FastMCP and low-level server implementations.

Note that this is breaks backwards compatibility as it changes the return
values of read_resource() on FastMCP. It is BC compatible on lowlevel since
it only extends the callback.

Github-Issue: #152
Reported-by: eiseleMichael
Update README examples to show proper handling of the new read_resource() return value
that includes mime type information.

Github-Issue:#152
@dsp-ant dsp-ant force-pushed the fix/152-resource-mime-type branch from 89eca5b to f90cf6a Compare January 27, 2025 15:52

- For commits related to a Github issue, add
```bash
git commit --trailer "Github-Issue:#<number>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git commit --trailer "Github-Issue:#<number>"
git commit --trailer "GitHub-Issue:#<number>"

@jspahrsummers
Copy link
Member

I think we should make this follow the spec more closely if we're going to break backwards compatibility anyway.

Introduce ReadResourceContents type to properly handle MIME types in resource responses. Breaking change in FastMCP read_resource() return type.

Github-Issue:#152
@dsp-ant dsp-ant requested a review from jspahrsummers January 27, 2025 20:38
Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about multiple result values, per my comment?

@dsp-ant
Copy link
Member Author

dsp-ant commented Jan 28, 2025

What about multiple result values, per my comment?

I thought about it, but honestly, i want to converge to one return value so people dont have to match on the return value. I chose the current appraoch as I want to keep lowlevel fairly BC compatible until v2.0.0 but I am okay changing the higher level FastMCP return value around, since its a bit more faster moving for 1.3.0.

@dsp-ant dsp-ant requested a review from jspahrsummers January 28, 2025 16:28
@dsp-ant dsp-ant merged commit 44c0004 into main Jan 28, 2025
5 checks passed
@dsp-ant dsp-ant deleted the fix/152-resource-mime-type branch January 28, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource Mime Type is ignored
2 participants