modelcontextprotocol / modelcontextprotocol/python-sdk

A tool with a *args or **kwargs parameter is registered with a schema it can never satisfy

Ouverte
#3,514 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

v1 v2
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 newest release of my line (2.x, main at 6affe5c)
  • I confirm that I searched for my issue in the issue tracker before opening this issue

Release line

2.x (current stable)

Description

Registering a tool whose function signature has a *args or **kwargs
parameter succeeds, and the tool shows up in list_tools, but it can never
actually be called: the generated JSON schema lists args/kwargs as a
required parameter of a plain scalar type, which doesn't match how the
function actually receives those values.

Expected: either the decorator rejects a signature it can't turn into a
schema (it already does this for a leading underscore in a parameter name),
or the schema reflects what the function accepts.

Actual: the tool is silently registered and permanently uncallable. Calling
it with only the named parameters filled in fails schema validation because
args/kwargs is "missing"; there's no way to actually supply it, since a
JSON object has no way to express "and then also a variable number of
positional values" for a single scalar field.

Example Code

from mcp.server.mcpserver import MCPServer

server = MCPServer("demo")


@server.tool()
def with_kwargs(x: int, **kwargs: str) -> str:
    return f"{x} {kwargs}"

Listing tools shows:

{'type': 'object', 'properties': {'x': {'title': 'X', 'type': 'integer'}, 'kwargs': {'title': 'Kwargs', 'type': 'string'}}, 'required': ['x', 'kwargs'], 'title': 'with_kwargsArguments'}

Calling it with {"x": 1} (the only arguments a caller could reasonably
guess) fails:

Error executing tool with_kwargs: 1 validation error for with_kwargsArguments
kwargs
  Field required [type=missing, input_value={'x': 1}, input_type=dict]

Same shape with *args instead of **kwargs.

Python & MCP Python SDK

Python 3.14.7, mcp-python-sdk main @ 6affe5c0d3588fd1705713b3703dc68015cfe3eb

I have a patch that raises InvalidSignature for a *args/**kwargs tool
parameter at registration time, scoped so it doesn't affect resource
templates (which legitimately use **kwargs for runtime-determined URI
variables); happy to open a PR against this issue if that's the direction
you'd want.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’enregistrement de MCPServer.tool, où les signatures de fonction deviennent des schémas d’outils, et comparez son traitement avec celui des modèles de ressources qui acceptent légitimement **kwargs. Confirmez le chemin InvalidSignature pour *args et **kwargs, puis vérifiez que les paramètres variadiques des outils sont rejetés lors de l’enregistrement, tandis que les modèles de ressources restent pris en charge.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend-api-design
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
68/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.