|
| 1 | +# MCP Conformance Tests - JDK HTTP Client |
| 2 | + |
| 3 | +This module provides a conformance test client implementation for the Java MCP SDK using the JDK HTTP Client with Streamable HTTP transport. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The conformance test client is designed to work with the [MCP Conformance Test Framework](https://github.com/modelcontextprotocol/conformance). It validates that the Java MCP SDK client properly implements the MCP specification. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +The client reads test scenarios from environment variables and accepts the server URL as a command-line argument, following the conformance framework's conventions: |
| 12 | + |
| 13 | +- **MCP_CONFORMANCE_SCENARIO**: Environment variable specifying which test scenario to run |
| 14 | +- **Server URL**: Passed as the last command-line argument |
| 15 | + |
| 16 | +## Supported Scenarios |
| 17 | + |
| 18 | +Currently implemented scenarios: |
| 19 | + |
| 20 | +- **initialize**: Tests the MCP client initialization handshake only |
| 21 | + - ✅ Validates protocol version negotiation |
| 22 | + - ✅ Validates clientInfo (name and version) |
| 23 | + - ✅ Validates proper handling of server capabilities |
| 24 | + - Does NOT call any tools or perform additional operations |
| 25 | + |
| 26 | +- **tools_call**: Tests tool discovery and invocation |
| 27 | + - ✅ Initializes the client |
| 28 | + - ✅ Lists available tools from the server |
| 29 | + - ✅ Calls the `add_numbers` tool with test arguments (a=5, b=3) |
| 30 | + - ✅ Validates the tool result |
| 31 | + |
| 32 | +- **elicitation-sep1034-client-defaults**: Tests client applies default values for omitted elicitation fields (SEP-1034) |
| 33 | + - ✅ Initializes the client |
| 34 | + - ✅ Lists available tools from the server |
| 35 | + - ✅ Calls the `test_client_elicitation_defaults` tool |
| 36 | + - ✅ Validates that the client properly applies default values from JSON schema to elicitation responses (5/5 checks pass) |
| 37 | + |
| 38 | +- **sse-retry**: Tests client respects SSE retry field timing and reconnects properly (SEP-1699) |
| 39 | + - ⚠️ Initializes the client |
| 40 | + - ⚠️ Lists available tools from the server |
| 41 | + - ⚠️ Calls the `test_reconnection` tool which triggers SSE stream closure |
| 42 | + - ✅ Client reconnects after stream closure (PASSING) |
| 43 | + - ❌ Client does not respect retry timing (FAILING) |
| 44 | + - ⚠️ Client does not send Last-Event-ID header (WARNING - SHOULD requirement) |
| 45 | + |
| 46 | +## Building |
| 47 | + |
| 48 | +Build the executable JAR: |
| 49 | + |
| 50 | +```bash |
| 51 | +cd conformance-tests/client-jdk-http-client |
| 52 | +../../mvnw clean package -DskipTests |
| 53 | +``` |
| 54 | + |
| 55 | +This creates an executable JAR at: |
| 56 | +``` |
| 57 | +target/client-jdk-http-client-0.18.0-SNAPSHOT.jar |
| 58 | +``` |
| 59 | + |
| 60 | +## Running Tests |
| 61 | + |
| 62 | +### Using the Conformance Framework |
| 63 | + |
| 64 | +Run a single scenario: |
| 65 | + |
| 66 | +```bash |
| 67 | +npx @modelcontextprotocol/conformance client \ |
| 68 | + --command "java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar" \ |
| 69 | + --scenario initialize |
| 70 | + |
| 71 | +npx @modelcontextprotocol/conformance client \ |
| 72 | + --command "java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar" \ |
| 73 | + --scenario tools_call |
| 74 | + |
| 75 | +npx @modelcontextprotocol/conformance client \ |
| 76 | + --command "java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar" \ |
| 77 | + --scenario elicitation-sep1034-client-defaults |
| 78 | + |
| 79 | +npx @modelcontextprotocol/conformance client \ |
| 80 | + --command "java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar" \ |
| 81 | + --scenario sse-retry |
| 82 | +``` |
| 83 | + |
| 84 | +Run with verbose output: |
| 85 | + |
| 86 | +```bash |
| 87 | +npx @modelcontextprotocol/conformance client \ |
| 88 | + --command "java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar" \ |
| 89 | + --scenario initialize \ |
| 90 | + --verbose |
| 91 | +``` |
| 92 | + |
| 93 | +### Manual Testing |
| 94 | + |
| 95 | +You can also run the client manually if you have a test server: |
| 96 | + |
| 97 | +```bash |
| 98 | +export MCP_CONFORMANCE_SCENARIO=initialize |
| 99 | +java -jar conformance-tests/client-jdk-http-client/target/client-jdk-http-client-0.18.0-SNAPSHOT.jar http://localhost:3000/mcp |
| 100 | +``` |
| 101 | + |
| 102 | +## Test Results |
| 103 | + |
| 104 | +The conformance framework generates test results showing: |
| 105 | + |
| 106 | +**Current Status (3/4 scenarios passing):** |
| 107 | +- ✅ initialize: 1/1 checks passed |
| 108 | +- ✅ tools_call: 1/1 checks passed |
| 109 | +- ✅ elicitation-sep1034-client-defaults: 5/5 checks passed |
| 110 | +- ⚠️ sse-retry: 1/2 checks passed, 1 warning |
| 111 | + |
| 112 | +Test result files are generated in `results/<scenario>-<timestamp>/`: |
| 113 | +- `checks.json`: Array of conformance check results with pass/fail status |
| 114 | +- `stdout.txt`: Client stdout output |
| 115 | +- `stderr.txt`: Client stderr output |
| 116 | + |
| 117 | +### Known Issue: SSE Retry Handling |
| 118 | + |
| 119 | +The `sse-retry` scenario currently fails because: |
| 120 | +1. The client treats the SSE `retry:` field as invalid instead of parsing it |
| 121 | +2. The client does not implement retry timing (reconnects immediately) |
| 122 | +3. The client does not send the Last-Event-ID header on reconnection |
| 123 | + |
| 124 | +This is a known limitation in the `HttpClientStreamableHttpTransport` implementation. |
| 125 | + |
| 126 | +## Next Steps |
| 127 | + |
| 128 | +Future enhancements: |
| 129 | + |
| 130 | +- Fix SSE retry field handling (SEP-1699) to properly parse and respect retry timing |
| 131 | +- Implement Last-Event-ID header on reconnection for resumability |
| 132 | +- Add auth scenarios (currently excluded as per requirements) |
| 133 | +- Implement a comprehensive "everything-client" pattern |
| 134 | +- Add to CI/CD pipeline |
| 135 | +- Create expected-failures baseline for known issues |
0 commit comments