modelcontextprotocol / modelcontextprotocol/python-sdk
dict[str, T] tool return types lose Annotated/Field metadata in output schema
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
Tools that return a string-keyed dict (dict[str, T]) lose any Annotated/Field metadata on the return type when the output schema is generated. A Field(description=...) on the return annotation shows up in the output schema for every other return type, but for dict[str, T] it's dropped.
I'd expect the description to be preserved, the same as other return types. Looks like the dict[str, T] branch in _try_create_model_and_schema builds the model from the Annotated-stripped type instead of the original annotation (there's an existing TODO on that line).
Have a simple, tested fix ready to go. Love the project and would love to contribute if possible!
Example Code
from typing import Annotated
from pydantic import Field
from mcp.server.mcpserver.utilities.func_metadata import func_metadata
def get_config() -> Annotated[dict[str, int], Field(description="Configuration values")]:
return {"timeout": 30}
print(func_metadata(get_config).output_schema)
# {'type': 'object', 'additionalProperties': {'type': 'integer'}, 'title': 'get_configDictOutput'}
# expected to also include: 'description': 'Configuration values'
Python & MCP Python SDK
Python 3.14.5
mcp: main branch (mcpserver / V2)
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 dans mcp.server.mcpserver.utilities.func_metadata, au niveau de _try_create_model_and_schema, en vous concentrant sur la branche dict[str, T] et son TODO existant. Examinez l’exemple get_config fourni et les tests environnants de génération de schéma, puis vérifiez qu’une description Annotated Field apparaît dans le schéma de sortie pour les valeurs de retour de dictionnaires dont les clés sont des chaînes de caractères.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 78/100