Skip to content

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

@ArpitaisAn0maly

Description

@ArpitaisAn0maly

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions