Centralize MCP and RAG tool management in AIManagementChatClient #21636
BackSummary
- Centralize tool management: Move MCP tool loading and RAG tool preparation from
AIChatCompletionIntegrationServiceandAIManagementChatClient<T>intoAIManagementChatClient.PrepareOptionsAsync(), creating a single responsibility point for tool management during chat completions. - Add
HasEmbedderConfigurationflag toChatClientCreationConfigurationso RAG tools are only added when an embedder provider is actually configured for the workspace, preventing unnecessary tool injection. - Simplify
AIManagementChatClient<T>to a thin resolver wrapper that delegates directly to the resolvedIChatClient, removing duplicated MCP tool loading andFunctionInvokingChatClientwrapping logic. - Fix MCP argument parsing in both
McpServerAppServiceandMcpServerConfigurationStoreto support space-separated argument strings (e.g.-y @modelcontextprotocol/server-filesystem /tmp) in addition to JSON arrays. - Increase default MCP timeout from 30s to 120s and properly pass it as
InitializationTimeoutto bothHttpMcpClientFactoryandStdioMcpClientFactory. - Fix duplicate
[Route]attribute onChatCompletionsController(removed extraneous[Route("v1")]). - Add unit tests for
AIManagementChatClientcovering RAG+MCP tool merging, MCP-only tools,FunctionInvokingChatClientvalidation, and caller-provided tool preservation.
Test plan
- Add
AIManagementChatClient_Testswith 4 test cases:- RAG + MCP tools are both added when embedder is configured
- Only MCP tools are added when embedder is not configured
- Exception is thrown when RAG is enabled but inner client is not
FunctionInvokingChatClient - Caller-provided tools are preserved when merging with RAG and MCP tools