|
| 1 | +// Create an API test with MCP steps returns "OK - Returns the created test details." response |
| 2 | + |
| 3 | +import com.datadog.api.client.ApiClient; |
| 4 | +import com.datadog.api.client.ApiException; |
| 5 | +import com.datadog.api.client.v1.api.SyntheticsApi; |
| 6 | +import com.datadog.api.client.v1.model.SyntheticsAPIStep; |
| 7 | +import com.datadog.api.client.v1.model.SyntheticsAPITest; |
| 8 | +import com.datadog.api.client.v1.model.SyntheticsAPITestConfig; |
| 9 | +import com.datadog.api.client.v1.model.SyntheticsAPITestStep; |
| 10 | +import com.datadog.api.client.v1.model.SyntheticsAPITestStepSubtype; |
| 11 | +import com.datadog.api.client.v1.model.SyntheticsAPITestType; |
| 12 | +import com.datadog.api.client.v1.model.SyntheticsAssertion; |
| 13 | +import com.datadog.api.client.v1.model.SyntheticsAssertionMCPRespectsSpecification; |
| 14 | +import com.datadog.api.client.v1.model.SyntheticsAssertionMCPRespectsSpecificationType; |
| 15 | +import com.datadog.api.client.v1.model.SyntheticsAssertionMCPServerCapabilitiesTarget; |
| 16 | +import com.datadog.api.client.v1.model.SyntheticsAssertionMCPServerCapabilitiesType; |
| 17 | +import com.datadog.api.client.v1.model.SyntheticsAssertionOperator; |
| 18 | +import com.datadog.api.client.v1.model.SyntheticsAssertionTarget; |
| 19 | +import com.datadog.api.client.v1.model.SyntheticsAssertionTargetValue; |
| 20 | +import com.datadog.api.client.v1.model.SyntheticsAssertionType; |
| 21 | +import com.datadog.api.client.v1.model.SyntheticsMCPProtocolVersion; |
| 22 | +import com.datadog.api.client.v1.model.SyntheticsMCPServerCapability; |
| 23 | +import com.datadog.api.client.v1.model.SyntheticsTestCallType; |
| 24 | +import com.datadog.api.client.v1.model.SyntheticsTestDetailsSubType; |
| 25 | +import com.datadog.api.client.v1.model.SyntheticsTestOptions; |
| 26 | +import com.datadog.api.client.v1.model.SyntheticsTestOptionsRetry; |
| 27 | +import com.datadog.api.client.v1.model.SyntheticsTestRequest; |
| 28 | +import java.util.Arrays; |
| 29 | +import java.util.Collections; |
| 30 | +import java.util.Map; |
| 31 | + |
| 32 | +public class Example { |
| 33 | + public static void main(String[] args) { |
| 34 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 35 | + SyntheticsApi apiInstance = new SyntheticsApi(defaultClient); |
| 36 | + |
| 37 | + SyntheticsAPITest body = |
| 38 | + new SyntheticsAPITest() |
| 39 | + .config( |
| 40 | + new SyntheticsAPITestConfig() |
| 41 | + .steps( |
| 42 | + Arrays.asList( |
| 43 | + new SyntheticsAPIStep( |
| 44 | + new SyntheticsAPITestStep() |
| 45 | + .name("Initialize MCP session") |
| 46 | + .subtype(SyntheticsAPITestStepSubtype.MCP) |
| 47 | + .allowFailure(false) |
| 48 | + .isCritical(true) |
| 49 | + .retry( |
| 50 | + new SyntheticsTestOptionsRetry().count(0L).interval(300.0)) |
| 51 | + .assertions( |
| 52 | + Arrays.asList( |
| 53 | + new SyntheticsAssertion( |
| 54 | + new SyntheticsAssertionTarget() |
| 55 | + .operator(SyntheticsAssertionOperator.IS) |
| 56 | + .type(SyntheticsAssertionType.STATUS_CODE) |
| 57 | + .target( |
| 58 | + new SyntheticsAssertionTargetValue(200.0))), |
| 59 | + new SyntheticsAssertion( |
| 60 | + new SyntheticsAssertionMCPRespectsSpecification() |
| 61 | + .type( |
| 62 | + SyntheticsAssertionMCPRespectsSpecificationType |
| 63 | + .MCP_RESPECTS_SPECIFICATION)), |
| 64 | + new SyntheticsAssertion( |
| 65 | + new SyntheticsAssertionMCPServerCapabilitiesTarget() |
| 66 | + .operator(SyntheticsAssertionOperator.CONTAINS) |
| 67 | + .type( |
| 68 | + SyntheticsAssertionMCPServerCapabilitiesType |
| 69 | + .MCP_SERVER_CAPABILITIES) |
| 70 | + .target( |
| 71 | + Collections.singletonList( |
| 72 | + SyntheticsMCPServerCapability.TOOLS))))) |
| 73 | + .request( |
| 74 | + new SyntheticsTestRequest() |
| 75 | + .url("https://example.org/mcp") |
| 76 | + .callType(SyntheticsTestCallType.INIT) |
| 77 | + .mcpProtocolVersion( |
| 78 | + SyntheticsMCPProtocolVersion.VERSION_2025_06_18) |
| 79 | + .headers( |
| 80 | + Map.ofEntries( |
| 81 | + Map.entry("DD-API-KEY", "<YOUR-API-KEY>"), |
| 82 | + Map.entry( |
| 83 | + "DD-APPLICATION-KEY", "<YOUR-APP-KEY>"))))), |
| 84 | + new SyntheticsAPIStep( |
| 85 | + new SyntheticsAPITestStep() |
| 86 | + .name("List MCP tools") |
| 87 | + .subtype(SyntheticsAPITestStepSubtype.MCP) |
| 88 | + .allowFailure(false) |
| 89 | + .isCritical(true) |
| 90 | + .retry( |
| 91 | + new SyntheticsTestOptionsRetry().count(0L).interval(300.0)) |
| 92 | + .assertions( |
| 93 | + Arrays.asList( |
| 94 | + new SyntheticsAssertion( |
| 95 | + new SyntheticsAssertionTarget() |
| 96 | + .operator(SyntheticsAssertionOperator.IS) |
| 97 | + .type(SyntheticsAssertionType.STATUS_CODE) |
| 98 | + .target( |
| 99 | + new SyntheticsAssertionTargetValue(200.0))), |
| 100 | + new SyntheticsAssertion( |
| 101 | + new SyntheticsAssertionTarget() |
| 102 | + .operator(SyntheticsAssertionOperator.MORE_THAN) |
| 103 | + .type(SyntheticsAssertionType.MCP_TOOL_COUNT) |
| 104 | + .target( |
| 105 | + new SyntheticsAssertionTargetValue(0.0))), |
| 106 | + new SyntheticsAssertion( |
| 107 | + new SyntheticsAssertionTarget() |
| 108 | + .operator(SyntheticsAssertionOperator.LESS_THAN) |
| 109 | + .type( |
| 110 | + SyntheticsAssertionType |
| 111 | + .MCP_TOOL_NAME_LENGTH) |
| 112 | + .target( |
| 113 | + new SyntheticsAssertionTargetValue(64.0))), |
| 114 | + new SyntheticsAssertion( |
| 115 | + new SyntheticsAssertionMCPRespectsSpecification() |
| 116 | + .type( |
| 117 | + SyntheticsAssertionMCPRespectsSpecificationType |
| 118 | + .MCP_RESPECTS_SPECIFICATION)))) |
| 119 | + .request( |
| 120 | + new SyntheticsTestRequest() |
| 121 | + .url("https://example.org/mcp") |
| 122 | + .callType(SyntheticsTestCallType.TOOL_LIST) |
| 123 | + .mcpProtocolVersion( |
| 124 | + SyntheticsMCPProtocolVersion.VERSION_2025_06_18) |
| 125 | + .headers( |
| 126 | + Map.ofEntries( |
| 127 | + Map.entry("DD-API-KEY", "<YOUR-API-KEY>"), |
| 128 | + Map.entry( |
| 129 | + "DD-APPLICATION-KEY", "<YOUR-APP-KEY>"))))), |
| 130 | + new SyntheticsAPIStep( |
| 131 | + new SyntheticsAPITestStep() |
| 132 | + .name("Call MCP search tool") |
| 133 | + .subtype(SyntheticsAPITestStepSubtype.MCP) |
| 134 | + .allowFailure(false) |
| 135 | + .isCritical(true) |
| 136 | + .retry( |
| 137 | + new SyntheticsTestOptionsRetry().count(0L).interval(300.0)) |
| 138 | + .assertions( |
| 139 | + Arrays.asList( |
| 140 | + new SyntheticsAssertion( |
| 141 | + new SyntheticsAssertionTarget() |
| 142 | + .operator(SyntheticsAssertionOperator.IS) |
| 143 | + .type(SyntheticsAssertionType.STATUS_CODE) |
| 144 | + .target( |
| 145 | + new SyntheticsAssertionTargetValue(200.0))), |
| 146 | + new SyntheticsAssertion( |
| 147 | + new SyntheticsAssertionTarget() |
| 148 | + .operator(SyntheticsAssertionOperator.LESS_THAN) |
| 149 | + .type(SyntheticsAssertionType.RESPONSE_TIME) |
| 150 | + .target( |
| 151 | + new SyntheticsAssertionTargetValue( |
| 152 | + 5000.0))), |
| 153 | + new SyntheticsAssertion( |
| 154 | + new SyntheticsAssertionMCPRespectsSpecification() |
| 155 | + .type( |
| 156 | + SyntheticsAssertionMCPRespectsSpecificationType |
| 157 | + .MCP_RESPECTS_SPECIFICATION)))) |
| 158 | + .request( |
| 159 | + new SyntheticsTestRequest() |
| 160 | + .url("https://example.org/mcp") |
| 161 | + .callType(SyntheticsTestCallType.TOOL_CALL) |
| 162 | + .mcpProtocolVersion( |
| 163 | + SyntheticsMCPProtocolVersion.VERSION_2025_06_18) |
| 164 | + .toolName("search") |
| 165 | + .toolArgs( |
| 166 | + Map.ofEntries( |
| 167 | + Map.entry("limit", "5"), |
| 168 | + Map.entry("query", "datadog synthetics"))) |
| 169 | + .headers( |
| 170 | + Map.ofEntries( |
| 171 | + Map.entry("DD-API-KEY", "<YOUR-API-KEY>"), |
| 172 | + Map.entry( |
| 173 | + "DD-APPLICATION-KEY", |
| 174 | + "<YOUR-APP-KEY>")))))))) |
| 175 | + .locations(Collections.singletonList("aws:us-east-2")) |
| 176 | + .message("BDD test payload: synthetics_api_test_mcp_payload.json") |
| 177 | + .name("Example-Synthetic") |
| 178 | + .options( |
| 179 | + new SyntheticsTestOptions() |
| 180 | + .minFailureDuration(10L) |
| 181 | + .minLocationFailed(1L) |
| 182 | + .monitorName("Example-Synthetic") |
| 183 | + .monitorPriority(5) |
| 184 | + .retry(new SyntheticsTestOptionsRetry().count(3L).interval(1000.0)) |
| 185 | + .tickEvery(900L)) |
| 186 | + .subtype(SyntheticsTestDetailsSubType.MULTI) |
| 187 | + .tags(Collections.singletonList("testing:api")) |
| 188 | + .type(SyntheticsAPITestType.API); |
| 189 | + |
| 190 | + try { |
| 191 | + SyntheticsAPITest result = apiInstance.createSyntheticsAPITest(body); |
| 192 | + System.out.println(result); |
| 193 | + } catch (ApiException e) { |
| 194 | + System.err.println("Exception when calling SyntheticsApi#createSyntheticsAPITest"); |
| 195 | + System.err.println("Status code: " + e.getCode()); |
| 196 | + System.err.println("Reason: " + e.getResponseBody()); |
| 197 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 198 | + e.printStackTrace(); |
| 199 | + } |
| 200 | + } |
| 201 | +} |
0 commit comments