modelcontextprotocol / modelcontextprotocol/python-sdk
A tool with a *args or **kwargs parameter is registered with a schema it can never satisfy
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 24.3k
- Forks
- 4k
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 31
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en el registro de MCPServer.tool, donde las firmas de función se convierten en esquemas de herramientas, y compara su tratamiento con las plantillas de recursos que aceptan legítimamente **kwargs. Confirma la ruta de InvalidSignature tanto para *args como para **kwargs y, a continuación, verifica que los parámetros variádicos de las herramientas se rechacen durante el registro, mientras que las plantillas de recursos sigan siendo compatibles.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend-api-design
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 68/100