modelcontextprotocol / modelcontextprotocol/python-sdk

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

Aperta
#3,514 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

v1 v2
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla registrazione di MCPServer.tool, dove le firme delle funzioni diventano schemi degli strumenti, e confronta la relativa gestione con quella dei template delle risorse che accettano legittimamente **kwargs. Conferma il percorso InvalidSignature sia per *args che per **kwargs, quindi verifica che i parametri variadici degli strumenti vengano rifiutati durante la registrazione, mentre i template delle risorse rimangano supportati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend-api-design
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.