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
还没有人认领这个 Issue。
- 主要语言
- Jupyter Notebook
- 星标
- 179
- 派生
- 310
- 平均合并
- 6 天 11 小时
- 30 天内合并 PR
- 2
描述
**Tutorial:** 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 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 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
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 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