modelcontextprotocol / modelcontextprotocol/python-sdk
PydanticSchemaGenerationError: Unable to generate pydantic-core schema for Image type
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 24.3k
- Forks
- 4k
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 31
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par tests/server/fastmcp/test_server.py, en particulier test_tool_mixed_content et la reproduction de mixed_content_tool_fn. Lisez le type Image importé depuis mcp.server.fastmcp.utilities.types et suivez le traitement de son annotation de retour de tuple avec mcp 1.10.1. Le travail est terminé lorsque le test de contenu mixte réussit sans PydanticSchemaGenerationError, tout en préservant les assertions attendues concernant le contenu image et audio.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 62/100