

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# MCP 服务器集成
<a name="mcp-server-integration"></a>

如果您在解决方案部署期间部署了可选的 MCP 服务器组件，则可以将分布式负载测试解决方案与支持模型上下文协议的 AI 开发工具集成。MCP 服务器提供编程访问权限，以便通过 AI 助手检索、管理和分析负载测试。

客户可以使用自己选择的客户端（Amazon Q、Claude 等）连接到 DLT MCP 服务器，每个客户端的配置说明略有不同。本节提供 MCP Inspector、Amazon Q CLI、Cline 和 Amazon Q Suite 的设置说明。

## 第 1 步：获取 MCP 端点和访问令牌
<a name="get-mcp-credentials"></a>

在配置任何 MCP 客户端之前，您需要从 DLT Web 控制台检索 MCP 服务器端点和访问令牌。

1. 导航到分布式负载测试 Web 控制台中的 **MCP 服务器**页面。

1. 找到 “**MCP 服务器端点**” 部分。

1. 使用复制终端节点 URL 按钮**复制终端节点 URL**。终端节点 URL 遵循以下格式：`https://{gateway-id}.gateway.bedrock-agentcore.{region}.amazonaws.com/mcp`

1. 找到 “**访问令牌**” 部分。

1. 使用 “复制访问令牌” 按钮**复制访问令牌**。

**重要**  
请妥善保管您的访问令牌，不要将其公开共享。该令牌通过 MCP 接口提供对分布式负载测试解决方案的只读访问权限。

![\[显示端点和访问令牌的 MCP 服务器凭证页面\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/mcp-credentials.png)


## 第 2 步：使用 MCP Inspector 进行测试
<a name="mcp-inspector-setup"></a>

模型上下文协议提供了 [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector)，这是一种直接连接到 MCP 服务器和调用工具的工具。这为在配置 AI 客户端之前测试 MCP 服务器连接提供了便捷的 UI 和示例网络请求。

**注意**  
MCP Inspector 需要版本 0.17 或更高版本。也可以直接使用 JSON RPC 发出所有请求，但是 MCP Inspector 提供了一个更加用户友好的界面。

 **安装并启动 MCP Inspector** 

1. 如有必要，请安装 npm。

1. 运行以下命令启动 MCP Inspector：

   ```
   npx @modelcontextprotocol/inspector
   ```

 **配置连接** 

1. 在 MCP Inspector 界面中，输入你的 MCP 服务器端点 URL。

1. 添加带有访问令牌的授权标头。

1. 单击 “**连接**” (Connect) 建立连接。

![\[MCP Inspector 配置屏幕\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/mcp-inspector-config.png)


 **调用工具** 

连接后，您可以测试可用的 MCP 工具：

1. 浏览左侧面板中的可用工具列表。

1. 选择一个工具（例如，`list_scenarios`）。

1. 提供任何必需的参数。

1. 单击 “**调用**” 以执行该工具并查看响应。

![\[MCP Inspector 显示可用的工具和调用\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/mcp-inspector-tools.png)


## 步骤 3：配置 AI 开发客户端
<a name="configuring-ai-clients"></a>

在验证您的 MCP 服务器与 MCP Inspector 的连接后，您可以配置首选的 AI 开发客户端。

### Amazon Q CLI
<a name="q-cli-configuration"></a>

Amazon Q CLI 通过 MCP 服务器集成，通过命令行访问人工智能辅助开发。

 **配置步骤** 

1. 编辑 `mcp.json` 配置文件。有关配置文件位置的更多信息，请参阅 *Amazon Q 开发者用户指南*中的[配置远程 MCP 服务器](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-config-CLI.html#command-line-mcp-remote-servers)。

1. 添加您的 DLT MCP 服务器配置：

   ```
   {
     "mcpServers": {
       "dlt-mcp": {
         "type": "http",
         "url": "https://[api-id].execute-api.[region].amazonaws.com/[stage]/gateway/backend-agent/sse/mcp",
         "headers": {
           "Authorization": "your_access_token_here"
         }
       }
     }
   }
   ```

 **验证配置** 

1. 在终端中，键入`q`以启动 Amazon Q CLI。

1. 键`/mcp`入查看所有可用的 MCP 服务器。

1. 键入`/tools`以查看由`dlt-mcp`和其他已配置的 MCP 服务器提供的可用工具。

1. 验证是否`dlt-mcp`成功初始化。

### 克莱恩
<a name="cline-configuration"></a>

Cline 是一款支持 MCP 服务器集成的人工智能编码助手。

 **配置步骤** 

1. 在 Cline 中，导航到**管理 MCP 服务器** > **配置 > 配置** **MC** P 服务器。

1. 更新 `cline_mcp_settings.json` 文件：

   ```
   {
     "mcpServers": {
       "dlt-mcp": {
         "type": "streamableHttp",
         "url": "https://[api-id].execute-api.[region].amazonaws.com/[stage]/gateway/backend-agent/sse/mcp",
         "headers": {
           "Authorization": "your_access_token_here"
         }
       }
     }
   }
   ```

1. 保存配置文件。

1. 重新启动 Cline 以应用更改。

### 亚马逊 Q Suite
<a name="amazon-q-suite-configuration"></a>

Amazon Q Suite 提供了一个全面的人工智能助手平台，支持 MCP 服务器操作。

 **先决条件** 

在 Amazon Q Suite 中配置 MCP 服务器之前，您需要从 DLT 部署的 Cognito 用户池中检索 OAuth 证书：

1. 导航到 [AWS CloudFormation 控制台](https://console.aws.amazon.com/cloudformation/)。

1. 选择分布式负载测试堆栈。

1. 在**输出**选项卡中，找到并复制与您的 DLT 部署关联的 **Cognito 用户池 ID**。  
![\[DLT C CloudFormation ognito 用户池\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/cognito-user-pool.png)

1. 导航到 [Amazon Cognito 控制台](https://console.aws.amazon.com/cognito/)。

1. 使用 CloudFormation 输出中的用户池 ID 选择用户池。

1. 在左侧导航栏中，选择**应用程序集成** > **应用程序客户端**。  
![\[Cognito 客户端 ID 和密钥\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/client-id-and-secret.png)

1. 找到名称以 `m2m` (machine-to-machine) 结尾的应用程序客户端。

1. 复制**客户端 ID** 和**客户机密钥**。

1. 从 “域” 选项卡获取用户池**域**。  
![\[Cognito 客户端 ID 和密钥\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/token-endpoint.png)

1. 通过追加`/oauth2/token`到域名末尾来构造令牌端点 URL。

 **配置步骤** 

1. 在 Amazon Q Suite 中，创建新代理或选择现有代理。

1. 添加描述如何与 DLT MCP 服务器交互的代理提示符。

1. 添加新操作并选择 **MCP 服务器操作**。  
![\[QuickSuite 代理操作\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/q-suite-agent-actions.png)  
![\[QuickSuite MCP 服务器工具\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/q-suite-mcp-action.png)

1. 配置 MCP 服务器的详细信息：
   +  **MCP 服务器网址**：你的 DLT MCP 端点  
![\[QuickSuite MCP 工具域设置\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/q-suite-mcp-setup.png)
   +  **身份验证类型**：基于服务的身份验证
   +  **令牌端点**：您的 Cognito 令牌端点网址
   +  **客户端 ID**：来自 m2m 应用程序客户端的客户端 ID
   +  **客户端密钥**：来自 m2m 应用程序客户端的客户端密钥  
![\[QuickSuite MCP 工具代理身份验证\]](http://docs.aws.amazon.com/zh_cn/solutions/latest/distributed-load-testing-on-aws/images/configure-agent-action-mcp.png)

1. 保存 MCP 服务器操作配置。

1. 将新的 MCP 服务器操作添加到您的代理。

 **启动并测试代理** 

1. 在 Amazon Q Suite 中启动代理。

1. 使用自然语言提示与代理开始对话。

1. 代理将使用 MCP 工具检索和分析您的负载测试数据。

## 提示示例
<a name="example-prompts"></a>

以下示例演示如何与 AI 助手交互以通过 MCP 接口分析负载测试数据。自定义测试 IDs、日期范围和标准，以满足您的特定测试需求。

有关可用的 MCP 工具及其参数的详细信息，请参阅《开发人员指南》中的 [MCP 工具规范](mcp-tools-specification.md)。

### 简单的测试结果查询
<a name="simple-test-results-query"></a>

与 MCP 服务器的自然语言交互可以很简单，`Show me the load tests that have completed in the last 24 hours with their associated completion status`也可以更具描述性，例如

```
Use list_scenarios to find my load tests. Then use get_latest_test_run to show me the basic execution data and performance metrics for the most recent test. If the results look concerning, also get the detailed performance metrics using get_test_run.
```

### 采用渐进式披露的交互式绩效分析
<a name="interactive-performance-analysis"></a>

```
I need to analyze my load test performance, but I'm not sure which specific tests to focus on. Please help me by:

1. First, use list_scenarios to show me available test scenarios
2. Ask me which tests I want to analyze based on the list you show me
3. For my selected tests, use list_test_runs to get the test run history
4. Then use get_test_run with the test_run_id to get detailed response times, throughput, and error rates
5. If I want to compare tests, use get_baseline_test_run to compare against the baseline
6. If there are any issues, use get_test_run_artifacts to help me understand what went wrong

Please guide me through this step by step, asking for clarification whenever you need more specific information.
```

### 生产就绪性验证
<a name="production-readiness-validation"></a>

```
Help me validate if my API is ready for production deployment:

1. Use list_scenarios to find recent test scenarios
2. For the most recent test scenario, use get_latest_test_run to get basic execution data
3. Use get_test_run with that test_run_id to get detailed response times, error rates, and throughput
4. Use get_scenario_details with the test_id to show me what load patterns and endpoints were tested
5. If I have a baseline, use get_baseline_test_run to compare current results with the baseline
6. Provide a clear go/no-go recommendation based on the performance data
7. If there are any concerns, use get_test_run_artifacts to help identify potential issues

My SLA requirements are: response time under [X]ms, error rate under [Y]%.
```

### 性能趋势分析
<a name="performance-trend-analysis"></a>

```
Analyze the performance trend for my load tests over the past [TIME_PERIOD]:

1. Use list_scenarios to get all test scenarios
2. For each scenario, use list_test_runs with start_date and end_date to get tests from that period
3. Use get_test_run for the key test runs to get detailed metrics
4. Use get_baseline_test_run to compare against the baseline
5. Identify any significant changes in response times, error rates, or throughput
6. If you detect performance degradation, use get_test_run_artifacts on the problematic tests to help identify causes
7. Present the trend analysis in a clear format showing whether performance is improving, stable, or degrading

Focus on completed tests and limit results to [N] tests if there are too many.
```

### 排除失败的测试故障
<a name="troubleshooting-failed-tests"></a>

```
Help me troubleshoot my failed load tests:

1. Use list_scenarios to find test scenarios
2. For each scenario, use list_test_runs to find recent test runs
3. Use get_test_run with the test_run_id to get the basic execution data and failure information
4. Use get_test_run_artifacts to get detailed error messages and logs
5. Use get_scenario_details to understand what was being tested when it failed
6. If I have a similar test that passed, use get_baseline_test_run to identify differences
7. Summarize the causes of failure and suggest next steps for resolution

Show me the most recent [N] failed tests from the past [TIME_PERIOD].
```