modelcontextprotocol / modelcontextprotocol/java-sdk

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

Đang mở
#546 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P2
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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
  • ...

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong HttpClientSseClientTransport và theo dõi cách yêu cầu POST khởi tạo chờ messageEndpointSink cũng như cách yêu cầu GET SSE xử lý các endpoint không hợp lệ. Tái hiện các trường hợp endpoint không chính xác, máy chủ không tồn tại và lỗi ủy quyền, sau đó xác minh rằng quá trình khởi tạo báo cáo lỗi máy chủ ngay lập tức cùng với mã trạng thái hoặc nội dung phản hồi của lỗi, thay vì chờ hết thời gian chờ khởi tạo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api, networking
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.