modelcontextprotocol / modelcontextprotocol/python-sdk
[v1.x] Server-side outputSchema validation blocks tool error reporting (isError: true)
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 24.3k
- Forks
- 4k
- Merge médio
- 1d 1h
- PRs com merge (30d)
- 31
Descrição
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
When a tool handler returns unstructured content for an error case, the low-level server's call_tool decorator validates the output against outputSchema before checking if the response is an error.
This prevents tools with outputSchema from reporting errors via isError: true, as the validation fails with "outputSchema defined but no structured output returned", replacing the original error message.
This was already fixed in the TypeScript SDK via modelcontextprotocol/typescript-sdk#654 / PR #655 (2025-06-24), but the equivalent fix has not been applied to the Python SDK v1.x branch.
The issue is in src/mcp/server/lowlevel/server.py, the call_tool decorator handler:
- Line ~560: outputSchema validation runs unconditionally — should skip when the result is an error
- Line ~575: isError=False is hardcoded — there is no path for the handler to signal an error through unstructured content while outputSchema is defined
Example Code
from mcp.server.lowlevel import Server
from mcp import types
server = Server("test")
@server.call_tool()
async def call_tool(name: str, arguments: dict):
# Tool has outputSchema but needs to return an error
# This gets blocked by outputSchema validation
return [types.TextContent(type="text", text="Resource not found")]
Python & MCP Python SDK
- Python: 3.11 / 3.12
- MCP SDK: v1.26.0+ (v1.x branch)
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Leia o handler do decorador call_tool em src/mcp/server/lowlevel/server.py por volta das linhas 560 e 575 e, em seguida, compare a correção correspondente do SDK TypeScript em modelcontextprotocol/typescript-sdk#654 / PR #655. Confirme que o caminho de erro evita a validação de outputSchema e preserva uma resposta isError para erros de ferramenta não estruturados, com uma verificação de regressão para o exemplo relatado.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- api, backend-api-design
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 70/100