modelcontextprotocol / modelcontextprotocol/python-sdk
Field alias is published in the tool schema but forwarded as an invalid Python keyword
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 the issue tracker before opening this issue.
Description
For a function parameter annotated with Field(alias="externalX"), the generated tool schema correctly requires externalX. At runtime, however, that wire name is forwarded directly to the original function, so the call fails with:
ToolError: Error executing tool f: f() got an unexpected keyword argument 'externalX'
I expected the schema-valid input to be mapped back to the Python parameter x before invocation.
Example Code
import asyncio
from typing import Annotated
try:
from mcp.server.mcpserver.tools.base import Tool
except ImportError: # MCP Python SDK 1.x
from mcp.server.fastmcp.tools.base import Tool
from pydantic import Field
AliasInt = Annotated[int, Field(alias="externalX", ge=1)]
def f(x: AliasInt) -> int:
return x
async def main() -> None:
tool = Tool.from_function(f)
print(tool.parameters)
print(await tool.run({"externalX": 1}, None))
asyncio.run(main())
The printed schema requires externalX, then the call fails with the error above.
Python & MCP Python SDK
Stable reproduction:
- Python 3.13.13
- mcp 1.28.1
- pydantic 2.13.4
Current main reproduction:
- modelcontextprotocol/python-sdk commit 2713b53b127afc094dc97d6067df9f69b647661c
- mcp 2.0.0b2
- mcp-types 2.0.0b2
- Python 3.13.13
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 lire les points d’entrée Tool.from_function et Tool.run et exécutez la reproduction fournie avec un paramètre doté d’un alias. Suivez la façon dont le nom de schéma externalX est transmis à la fonction, puis ajoutez une couverture montrant qu’une entrée valide selon le schéma appelle f avec x et retourne correctement.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 68/100