modelcontextprotocol / modelcontextprotocol/java-sdk
MCP server to be able to return custom http codes
Chưa có ai nhận issue này.
- 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ả
Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
I am writing a custom MCP server. I am using an existing HttpServletStatelessServerTransport but mine is a stateful server with multiple pods. But since I do not have control on the session Id generation & validation & moreover, the validation in stateful transport is based on memory, I have chosen a stateless transport. But now on validating the sessionId in every MCP request, I want to be able to return an 404, if session id is not found or return 500 or other status codes. But I do not have this control now.
I was looking if there is a way in HttpServletStatelessServerTransport by which the MCP Error message can be passed by the McpStatelessServerHandler in the exception thrown by it
Current Behavior
In the below code, we can see that even if handleRequest method of McpStatelessServerHandler throws IllegalArgumentException, a customized error message cannot be returned to the client.
logger.error("Failed to deserialize message: {}", e.getMessage());
this.responseError(response, HttpServletResponse.SC_BAD_REQUEST, new McpError("Invalid message format"));
}
catch (Exception e) {
logger.error("Unexpected error handling message: {}", e.getMessage());
this.responseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
new McpError("Unexpected error: " + e.getMessage()));
}```
**Context**
The only work around is to find the MCP request method before calling the transport's service method and return appropriate http code with required message. This is not ideal though
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với HttpServletStatelessServerTransport và McpStatelessServerHandler, đặc biệt là handleRequest và phương thức service của transport. Theo dõi cách các ngoại lệ đến được responseError và cách workaround hiện tại kiểm tra phương thức của yêu cầu MCP trước khi gọi transport. Công việc được xem là hoàn tất khi các lỗi của handler có thể trả về HTTP status và thông báo lỗi MCP do bên gọi lựa chọn, bao gồm cả các lỗi xác thực phiên.
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, backend
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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