feat: support audio content (#725)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
Luca Chang
2025-06-07 07:32:11 -07:00
committed by GitHub
parent 2bce10bdb1
commit 7123556a34
9 changed files with 60 additions and 19 deletions

View File

@@ -7,9 +7,9 @@ from typing import Any, Literal
import pydantic_core
from pydantic import BaseModel, Field, TypeAdapter, validate_call
from mcp.types import EmbeddedResource, ImageContent, TextContent
from mcp.types import AudioContent, EmbeddedResource, ImageContent, TextContent
CONTENT_TYPES = TextContent | ImageContent | EmbeddedResource
CONTENT_TYPES = TextContent | ImageContent | AudioContent | EmbeddedResource
class Message(BaseModel):

View File

@@ -52,6 +52,7 @@ from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
from mcp.shared.context import LifespanContextT, RequestContext, RequestT
from mcp.types import (
AnyFunction,
AudioContent,
EmbeddedResource,
GetPromptResult,
ImageContent,
@@ -275,7 +276,7 @@ class FastMCP:
async def call_tool(
self, name: str, arguments: dict[str, Any]
) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
) -> Sequence[TextContent | ImageContent | AudioContent | EmbeddedResource]:
"""Call a tool by name with arguments."""
context = self.get_context()
result = await self._tool_manager.call_tool(name, arguments, context=context)
@@ -875,12 +876,12 @@ class FastMCP:
def _convert_to_content(
result: Any,
) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
) -> Sequence[TextContent | ImageContent | AudioContent | EmbeddedResource]:
"""Convert a result to a sequence of content objects."""
if result is None:
return []
if isinstance(result, TextContent | ImageContent | EmbeddedResource):
if isinstance(result, TextContent | ImageContent | AudioContent | EmbeddedResource):
return [result]
if isinstance(result, Image):

View File

@@ -405,7 +405,10 @@ class Server(Generic[LifespanResultT, RequestT]):
...,
Awaitable[
Iterable[
types.TextContent | types.ImageContent | types.EmbeddedResource
types.TextContent
| types.ImageContent
| types.AudioContent
| types.EmbeddedResource
]
],
],