mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 10:18:08 +02:00
Added to_data_uri method for Image class. (#2227)
* Added to_data_uri method and path_to_data_uri classmethod for Image class. * Removed path_to_data_uri classmethod and modified _get_mime_type to use mimetypes.guess_type function instead of hardcoded dictionary. * Register image/webp with mimetypes before guess_type to support WEBP mimetype detection on Python 3.10. * Improved branch coverage for Image.to_data_uri. * Added Image._to_data_uri example in the docs.
This commit is contained in:
parent
08c49e62e8
commit
321f404046
3 changed files with 75 additions and 30 deletions
|
|
@ -115,6 +115,7 @@ For small icons or when you want to embed the icon directly, use data URIs:
|
|||
|
||||
```python
|
||||
from mcp.types import Icon
|
||||
from fastmcp.utilities.types import Image
|
||||
|
||||
# SVG icon as data URI
|
||||
svg_icon = Icon(
|
||||
|
|
@ -126,4 +127,13 @@ svg_icon = Icon(
|
|||
def my_tool() -> str:
|
||||
"""A tool with an embedded SVG icon."""
|
||||
return "result"
|
||||
|
||||
# Generating a data URI from a local image file.
|
||||
img = Image(path="./assets/brand/favicon.png")
|
||||
icon = Icon(src=img.to_data_uri())
|
||||
|
||||
@mcp.tool(icons=[icon])
|
||||
def file_icon_tool() -> str:
|
||||
"""A tool with an icon generated from a local file."""
|
||||
return "result"
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue