Azure-Samples / Azure-Samples/azure-search-python-samples

Foundry Agent Service MCPTool fails with 405 error when connecting to Azure AI Search knowledge base MCP endpoint

オープン
#168 コメント 13 件 リアクション 2 件 担当者 0 名 GitHub で見る
主要言語
Jupyter Notebook
スター
178
フォーク
310
平均マージ
6日 11時間
マージ済み PR(30日)
2

説明

**Tutorial:[** agentic-retrieval-pipeline-example](https://github.com/Azure-Samples/azure-search-python-samples/tree/main/agentic-retrieval-pipeline-example)

The tutorial code in above location demonstrates using Foundry Agent Service with MCPTool to connect to an Azure AI Search knowledge base MCP endpoint. However, this integration fails with a 405 error during tool enumeration due to what appears to be a service-side bug in Foundry Agent Service.

**"Foundry Agent Service MCP Tool integration fails with 405 error when calling Azure AI Search knowledge base MCP endpoints. Despite the service correctly using POST method (line 1257: method="post"), it appears to omit the required Accept: application/json, text/event-stream header, causing the endpoint to reject the request"**

**My environment**

Azure AI Search: API version 2025-11-01-Preview
Foundry Agent Service: Latest (December 2024)
Python SDK: azure-ai-projects (latest)
Knowledge Base: Azure AI Search with EXTRACTIVE_DATA output mode
MCP Endpoint: https://{search-service}.search.windows.net/knowledgebases/{kb-name}/mcp?api-version=2025-11-01-Preview

**error**: BadRequestError: Failed to enumerate tools from remote server: https://{search-service}.search.windows.net:443/knowledgebases/{kb-name}/mcp. Details: Response status code does not indicate success: 405 (Method Not Allowed).

**Manual testing shows MCP endpoints works correctly without Foundry.**

# Manual POST with correct headers - returns 200 success
response = requests.post(
mcp_endpoint,
headers={
"Authorization": f"Bearer {token}",
"Accept": "application/json, text/event-stream" # Required header
},
json={"jsonrpc": "2.0", "id": 1, "method": "tools/list"}
)

This returns 200 with knowledge_base_retrieve tool.

Foundry Agent Service doesn't send the required Accept: application/json, text/event-stream header when calling the MCP endpoint.

**Main error message**-------------------
User code and stored connection contain clean URLs (no port)
Foundry Agent Service internally adds :443 port during tool enumeration.
Azure AI Search MCP endpoint rejects requests with explicit port in URL.1257 method="post", url=path, json_data=body, files=to_httpx_files(files), **options
1258 )

-----------------------------------------
**trace of error message**

-> [1259](file:///C:/Users/arpitaparmar/OneDrive%20-%20Microsoft/Documents/azure-search-python-samples/Full-Agentic-Retrieval/.venv/Lib/site-packages/openai/_base_client.py:1259) return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

File c:\Users\arpitaparmar\OneDrive - Microsoft\Documents\azure-search-python-samples\Full-Agentic-Retrieval\.venv\Lib\site-packages\openai\_base_client.py:1047, in SyncAPIClient.request(self, cast_to, options, stream, stream_cls)
1044 err.response.read()
1046 log.debug("Re-raising status error")
-> [1047](file:///C:/Users/arpitaparmar/OneDrive%20-%20Microsoft/Documents/azure-search-python-samples/Full-Agentic-Retrieval/.venv/Lib/site-packages/openai/_base_client.py:1047) raise self._make_status_error_from_response(err.response) from None
1049 break
1051 assert response is not None, "could not resolve response (should never happen)"

BadRequestError: Error code: 400 - {'error': {'message': 'Failed to enumerate tools from remote server: [htt](https://search-aparmar-1606.search.windows.net/knowledgebases/earth-knowledge-base/mcp)
--------------------------------------------------------------------------------------------------------------------------------------------
**summary**
--------------------------"**Foundry Agent Service MCP Tool integration fails with 405 error when calling Azure AI Search knowledge base MCP endpoints. Despite the service correctly using POST method (line 1257: method="post"), it appears to omit the required Accept: application/json, text/event-stream header, causing the endpoint to reject the request**..--------------

This prevents the tutorial from working as documented and blocks users from using Azure AI Search knowledge bases with Foundry Agent Service via MCP. This tutorial is linked in official MSFT learn site here.https://learn.microsoft.com/en-us/azure/search/agentic-retrieval-how-to-create-pipeline?tabs=search-perms%2Csearch-development%2Csearch-setup. I need guidance on how to make it work

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

agentic-retrieval-pipeline-example チュートリアルから始め、その Foundry MCP リクエストを issue に示されている手動の POST と比較します。1257 行目で報告されている openai クライアント呼び出しを調査し、サンプルで不足している header に対応できるか、それともサービスの制限を文書化する必要があるかを判断します。完了とは、チュートリアルが Azure AI Search MCP エンドポイントに対して動作すること、または制限と workaround が明確に記録されていることを意味します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
azure, python
領域
cloud, search
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。