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

Abierto
#168 13 comentarios 2 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Jupyter Notebook
Estrellas
178
Forks
310
Merge medio
6 d 11 h
PR fusionados (30 d)
2

Descripción

**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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start with the agentic-retrieval-pipeline-example tutorial and compare its Foundry MCP request with the manual POST shown in the issue. Inspect the reported openai client call at line 1257 and determine whether the sample can address the missing header or whether the service limitation must be documented. Done means the tutorial works against the Azure AI Search MCP endpoint, or the limitation and workaround are clearly recorded.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
azure, python
Área
cloud, search
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.