modelcontextprotocol / modelcontextprotocol/python-sdk
PydanticSchemaGenerationError: Unable to generate pydantic-core schema for Image type
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 31
Mô tả
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
The Image type in question is imported like this: from mcp.server.fastmcp.utilities.types import Image
We are upgrading our dependency on mcp from 1.9.4 to 1.10.1.
Once on 1.10.1 our application and tests began to fail with error like this:
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema
for <class 'mcp.server.fastmcp.utilities.types.Image'>. Set `arbitrary_types_allowed=True` in
the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your
type to fully support it.
I found a test tool function among this repo's unit tests, that is pretty close to the mixed content
use case in our server. So I tweaked it to create a repro case for you:
diff --git a/tests/server/fastmcp/test_server.py b/tests/server/fastmcp/test_server.py
index c30930f..20c25af 100644
--- a/tests/server/fastmcp/test_server.py
+++ b/tests/server/fastmcp/test_server.py
@@ -194,12 +194,12 @@ def image_tool_fn(path: str) -> Image:
return Image(path)
-def mixed_content_tool_fn() -> list[ContentBlock]:
- return [
- TextContent(type="text", text="Hello"),
- ImageContent(type="image", data="abc", mimeType="image/png"),
+def mixed_content_tool_fn() -> tuple[str, Image, AudioContent]:
+ return (
+ "Hello",
+ Image(data=b"abc", format="png"),
AudioContent(type="audio", data="def", mimeType="audio/wav"),
- ]
+ )
class TestServerTools:
@@ -311,7 +311,7 @@ class TestServerTools:
assert content1.text == "Hello"
assert isinstance(content2, ImageContent)
assert content2.mimeType == "image/png"
- assert content2.data == "abc"
+ assert content2.data == "YWJj"
assert isinstance(content3, AudioContent)
assert content3.mimeType == "audio/wav"
assert content3.data == "def"
test_tool_mixed_content fails with PydanticSchemaGenerationError on 1.10.1 but succeeds on 1.9.4.
Python & MCP Python SDK
Python 3.12, mcp 1.10.1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với tests/server/fastmcp/test_server.py, đặc biệt là test_tool_mixed_content và bản tái hiện mixed_content_tool_fn. Đọc kiểu Image được import từ mcp.server.fastmcp.utilities.types và theo dõi cách chú thích giá trị trả về dạng tuple của nó được xử lý trong mcp 1.10.1. Hoàn tất khi bài kiểm tra nội dung hỗn hợp chạy qua mà không có PydanticSchemaGenerationError, đồng thời vẫn giữ nguyên các assertion mong đợi về nội dung hình ảnh và âm thanh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 62/100