chore: create union for working with message content (#939)
This commit is contained in:
parent
185fa49fd1
commit
d69b290b65
1 changed files with 25 additions and 51 deletions
|
|
@ -52,10 +52,8 @@ from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
|||
from mcp.shared.context import LifespanContextT, RequestContext, RequestT
|
||||
from mcp.types import (
|
||||
AnyFunction,
|
||||
AudioContent,
|
||||
EmbeddedResource,
|
||||
Content,
|
||||
GetPromptResult,
|
||||
ImageContent,
|
||||
TextContent,
|
||||
ToolAnnotations,
|
||||
)
|
||||
|
|
@ -256,9 +254,7 @@ class FastMCP:
|
|||
request_context = None
|
||||
return Context(request_context=request_context, fastmcp=self)
|
||||
|
||||
async def call_tool(
|
||||
self, name: str, arguments: dict[str, Any]
|
||||
) -> Sequence[TextContent | ImageContent | AudioContent | EmbeddedResource]:
|
||||
async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[Content]:
|
||||
"""Call a tool by name with arguments."""
|
||||
context = self.get_context()
|
||||
result = await self._tool_manager.call_tool(name, arguments, context=context)
|
||||
|
|
@ -842,12 +838,12 @@ class FastMCP:
|
|||
|
||||
def _convert_to_content(
|
||||
result: Any,
|
||||
) -> Sequence[TextContent | ImageContent | AudioContent | EmbeddedResource]:
|
||||
) -> Sequence[Content]:
|
||||
"""Convert a result to a sequence of content objects."""
|
||||
if result is None:
|
||||
return []
|
||||
|
||||
if isinstance(result, TextContent | ImageContent | AudioContent | EmbeddedResource):
|
||||
if isinstance(result, Content):
|
||||
return [result]
|
||||
|
||||
if isinstance(result, Image):
|
||||
|
|
|
|||
Loading…
Reference in a new issue