|
| 1 | +""" |
| 2 | +FastMCP Icons Demo Server |
| 3 | +
|
| 4 | +Demonstrates using icons with tools, resources, prompts, and implementation. |
| 5 | +""" |
| 6 | + |
| 7 | +import base64 |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +from mcp.server.fastmcp import FastMCP, Icon |
| 11 | + |
| 12 | +# Load the icon file and convert to data URI |
| 13 | +icon_path = Path(__file__).parent / "mcp.png" |
| 14 | +icon_data = base64.standard_b64encode(icon_path.read_bytes()).decode() |
| 15 | +icon_data_uri = f"data:image/png;base64,{icon_data}" |
| 16 | + |
| 17 | +icon_data = Icon(src=icon_data_uri, mimeType="image/png", sizes=["64x64"]) |
| 18 | + |
| 19 | +# Create server with icons in implementation |
| 20 | +mcp = FastMCP("Icons Demo Server", website_url="https://github.com/modelcontextprotocol/python-sdk", icons=[icon_data]) |
| 21 | + |
| 22 | + |
| 23 | +@mcp.tool(icons=[icon_data]) |
| 24 | +def demo_tool(message: str) -> str: |
| 25 | + """A demo tool with an icon.""" |
| 26 | + return message |
| 27 | + |
| 28 | + |
| 29 | +@mcp.resource("demo://readme", icons=[icon_data]) |
| 30 | +def readme_resource() -> str: |
| 31 | + """A demo resource with an icon""" |
| 32 | + return "This resource has an icon" |
| 33 | + |
| 34 | + |
| 35 | +@mcp.prompt("prompt_with_icon", icons=[icon_data]) |
| 36 | +def prompt_with_icon(text: str) -> str: |
| 37 | + """A demo prompt with an icon""" |
| 38 | + return text |
| 39 | + |
| 40 | + |
| 41 | +@mcp.tool( |
| 42 | + icons=[ |
| 43 | + Icon(src=icon_data_uri, mimeType="image/png", sizes=["16x16"]), |
| 44 | + Icon(src=icon_data_uri, mimeType="image/png", sizes=["32x32"]), |
| 45 | + Icon(src=icon_data_uri, mimeType="image/png", sizes=["64x64"]), |
| 46 | + ] |
| 47 | +) |
| 48 | +def multi_icon_tool(action: str) -> str: |
| 49 | + """A tool demonstrating multiple icons.""" |
| 50 | + return "multi_icon_tool" |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + # Run the server |
| 55 | + mcp.run() |
0 commit comments