

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 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_tw/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 伺服器並叫用工具。這可提供方便的 UI 和範例網路請求，以便在設定 AI 用戶端之前測試 MCP 伺服器連線。

**注意**  
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. 按一下**連線**以建立連線。

![\[MCP Inspector 組態畫面\]](http://docs.aws.amazon.com/zh_tw/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_tw/solutions/latest/distributed-load-testing-on-aws/images/mcp-inspector-tools.png)


## 步驟 3：設定 AI 開發用戶端
<a name="configuring-ai-clients"></a>

使用 MCP Inspector 驗證 MCP 伺服器連線後，您可以設定偏好的 AI 開發用戶端。

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

Amazon Q CLI 透過 MCP 伺服器整合，提供 AI 輔助開發的命令列存取。

 **組態步驟** 

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 伺服器整合的 AI 編碼助理。

 **組態步驟** 

1. 在 Cline 中，導覽至**管理 MCP 伺服器** > **設定** > **設定 MCP 伺服器**。

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 以套用變更。

### Amazon Q Suite
<a name="amazon-q-suite-configuration"></a>

Amazon Q Suite 提供全方位的 AI 助理平台，支援 MCP 伺服器動作。

 **先決條件** 

在 Amazon Q Suite 中設定 MCP 伺服器之前，您需要從 DLT 部署的 Cognito 使用者集區擷取 OAuth 憑證：

1. 導覽至 [AWS CloudFormation 主控台](https://console.aws.amazon.com/cloudformation/)。

1. 選取分散式負載測試堆疊。

1. 在**輸出**索引標籤中，尋找並複製與您的 DLT 部署相關聯的 **Cognito 使用者集區 ID**。  
![\[DLT CloudFormation Cognito 使用者集區\]](http://docs.aws.amazon.com/zh_tw/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_tw/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_tw/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_tw/solutions/latest/distributed-load-testing-on-aws/images/q-suite-agent-actions.png)  
![\[QuickSuite MCP 伺服器工具\]](http://docs.aws.amazon.com/zh_tw/solutions/latest/distributed-load-testing-on-aws/images/q-suite-mcp-action.png)

1. 設定 MCP 伺服器詳細資訊：
   +  **MCP 伺服器 URL**：您的 DLT MCP 端點  
![\[QuickSuite MCP 工具網域設定\]](http://docs.aws.amazon.com/zh_tw/solutions/latest/distributed-load-testing-on-aws/images/q-suite-mcp-setup.png)
   +  **身分驗證類型**：服務型身分驗證
   +  **權杖端點**：您的 Cognito 權杖端點 URL
   +  **用戶端 ID**：來自 m2m 應用程式用戶端的用戶端 ID
   +  **用戶端秘密**：來自 m2m 應用程式用戶端的用戶端秘密  
![\[QuickSuite MCP 工具代理程式驗證\]](http://docs.aws.amazon.com/zh_tw/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 Server 的正式語言互動可以像 一樣簡單`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].
```