modelcontextprotocol / modelcontextprotocol/python-sdk
Field alias is published in the tool schema but forwarded as an invalid Python keyword
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 31
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit, die Einstiegspunkte Tool.from_function und Tool.run zu lesen, und führen Sie die bereitgestellte Reproduktion mit einem mit einem Alias versehenen Parameter aus. Verfolgen Sie, wie der Schemaname externalX an die Funktion übergeben wird, und fügen Sie eine Abdeckung hinzu, die zeigt, dass eine schema-konforme Eingabe f mit x aufruft und erfolgreich zurückkehrt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 68/100