modelcontextprotocol / modelcontextprotocol/java-sdk

Support running test cases in offline environments

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

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

enhancement P3 tests
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ả

Description:

Several test cases in mcp-test and other src/test rely on external HTTP endpoints, which cause test failures in offline CI/CD environments.

For example, test case testToolCallSuccess of AbstractStatelessIntegrationTest.java throws an AssertionError if a GET request to raw.githubusercontent.com/modelcontextprotocol/java-sdk/refs/heads/main/README.md has null or empty response.

Goal:

  • Support running maven test lifecycle for offline environments.
  • Specifically, all test cases shall pass when -o option is appended to mvn test command, provided that all required docker images have already been imported (the default container pull policy will allow this to work offline).

Proposed changes:

Instead of sending GET request using an HTTP client, use a mock client that reads README.md from local file.

HttpClient mockClient = mock(HttpClient.class);
HttpResponse<String> mockResponse = mock(HttpResponse.class);

// Relative path of README.md depending on project directory
when(mockResponse.body()).thenReturn(Files.readString(Path.of("../README.md").toAbsolutePath()));
when(mockResponse.statusCode()).thenReturn(200);
when(mockClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(mockResponse);

Environment:

  • MCP Java SDK: current main branch
  • JDK: 21
  • OS: Linux

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 với testToolCallSuccess trong AbstractStatelessIntegrationTest.java và kiểm tra các test liên quan trong mcp-test và src/test để tìm các endpoint HTTP bên ngoài. Chạy vòng đời test của Maven với -o sau khi các image Docker cần thiết đã sẵn sàng. Hoàn tất khi bộ test chạy thành công trong môi trường offline mà không liên hệ với các endpoint bên ngoài.

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

Đánh giá

Công nghệ
docker, java
Lĩnh vực
build-system, testing-qa
Loại issue
Tính năng
Độ 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
48/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.