mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 06:54:18 +01:00
feat: support audio content (#725)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user