chore: create union for working with message content (#939)
This commit is contained in:
parent
185fa49fd1
commit
d69b290b65
2 changed files with 25 additions and 51 deletions
|
|
@ -11,7 +11,7 @@ from anyio.abc import TaskStatus
|
|||
from mcp.client.session import ClientSession
|
||||
from mcp.server.lowlevel import Server
|
||||
from mcp.shared.exceptions import McpError
|
||||
from mcp.types import AudioContent, EmbeddedResource, ImageContent, TextContent
|
||||
from mcp.types import Content, TextContent
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
|
@ -31,7 +31,7 @@ async def test_notification_validation_error(tmp_path: Path):
|
|||
slow_request_complete = anyio.Event()
|
||||
|
||||
@server.call_tool()
|
||||
async def slow_tool(name: str, arg) -> Sequence[TextContent | ImageContent | AudioContent | EmbeddedResource]:
|
||||
async def slow_tool(name: str, arg) -> Sequence[Content]:
|
||||
nonlocal request_count
|
||||
request_count += 1
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pydantic import AnyUrl
|
|||
from starlette.routing import Mount, Route
|
||||
|
||||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.fastmcp.prompts.base import EmbeddedResource, Message, UserMessage
|
||||
from mcp.server.fastmcp.prompts.base import Message, UserMessage
|
||||
from mcp.server.fastmcp.resources import FileResource, FunctionResource
|
||||
from mcp.server.fastmcp.utilities.types import Image
|
||||
from mcp.shared.exceptions import McpError
|
||||
|
|
@ -18,6 +18,8 @@ from mcp.shared.memory import (
|
|||
from mcp.types import (
|
||||
AudioContent,
|
||||
BlobResourceContents,
|
||||
Content,
|
||||
EmbeddedResource,
|
||||
ImageContent,
|
||||
TextContent,
|
||||
TextResourceContents,
|
||||
|
|
@ -192,7 +194,7 @@ def image_tool_fn(path: str) -> Image:
|
|||
return Image(path)
|
||||
|
||||
|
||||
def mixed_content_tool_fn() -> list[TextContent | ImageContent | AudioContent]:
|
||||
def mixed_content_tool_fn() -> list[Content]:
|
||||
return [
|
||||
TextContent(type="text", text="Hello"),
|
||||
ImageContent(type="image", data="abc", mimeType="image/png"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue