modelcontextprotocol / modelcontextprotocol/java-sdk

[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout

Aberta
#546 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

bug P2
Linguagem predominante
Java
Estrelas
3.7k
Forks
1.1k
Merge médio
1d 15h
PRs com merge (30d)
9

Descrição

Problem
Currently, when the SSE Endpoint is misconfigured, the client waits until the initialization timeout (e.g., 60s) before throwing an generic initialization exception. This causes unnecessary delays and makes debugging difficult.

Examples settings:

  • If MCP Server SSE Endpoint is: http://localhost:8080/sse
  • When MCP Client is configured:
    • SSE Endpoint: http://localhost:8080/incorrect-sse
    • Request timeout: 60s
    • Initialization timeout: 60s

Behavior:

  • Calling Client.initialize() waits 60s before throwing an exception. The test code and exception are shown in the figure below:
    Image

  • Same issue occurs when:

    • The base URL points to a non-existent server. The test code and exception are shown in the figure below:
      Image

    • Access Token is misconfigured and the server requires authorization.

Expected Behavior

  • Initialization exception should be thrown immediately when the server responds with an error (e.g., 404, 401, access denied), instead of waiting for the timeout.
  • Exception should include status code and/or response body from the SSE endpoint to help diagnose configuration errors.

Technical Details

I checked the code, and the timeout issue occurs in the HttpClientSseClientTransport class when assigning the messageEndpointSink member variable. The initialization POST request keeps waiting for messageEndpointSink to be assigned. However, when the SSE Endpoint is incorrectly specified, the GET request never successfully returns the message endpoint, causing the initialization POST request to hang until the timeout occurs.

Affected Versions

  • SDK 0.11.2
  • SDK 0.12.1
  • ...

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em HttpClientSseClientTransport e rastreie como a solicitação POST de inicialização aguarda messageEndpointSink e como a solicitação GET de SSE lida com endpoints inválidos. Reproduza os casos de um endpoint incorreto, de um servidor inexistente e de um erro de autorização e, em seguida, verifique se a inicialização relata prontamente o erro do servidor com seu código de status ou corpo da resposta, em vez de aguardar o tempo limite da inicialização.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java
Domínio
api, networking
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.