Addressed initial PR comments.

This commit is contained in:
Peter Ibekwe
2026-05-13 15:34:27 -07:00
Unverified
parent d1d95d0d75
commit 3f971550bd
3 changed files with 19 additions and 16 deletions
@@ -37,7 +37,7 @@ trigger:
toolName: tools/list
conversationId: =System.ConversationId
headers:
Foundry-Features: Toolboxes=V1Preview
Foundry-Features: Toolboxes=V1Preview
output:
autoSend: true
result: Local.ToolboxTools
@@ -50,7 +50,7 @@ trigger:
toolName: =Env.FOUNDRY_TOOLBOX_DOCS_SERVER_LABEL & "___microsoft_docs_search"
conversationId: =System.ConversationId
headers:
Foundry-Features: Toolboxes=V1Preview
Foundry-Features: Toolboxes=V1Preview
arguments:
query: =Local.SearchQuery
output:
@@ -67,7 +67,7 @@ trigger:
toolName: =Env.FOUNDRY_TOOLBOX_WEB_SEARCH_TOOL_NAME
conversationId: =System.ConversationId
headers:
Foundry-Features: Toolboxes=V1Preview
Foundry-Features: Toolboxes=V1Preview
arguments:
search_query: =Local.SearchQuery
output:
@@ -6,6 +6,7 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Concurrent;
using System.Net.Http.Headers;
using Azure.AI.Projects;
using Azure.AI.Projects.Agents;
@@ -60,11 +61,15 @@ internal sealed class Program
// Ensure sample toolbox and agent exist in Foundry
string toolboxEndpoint = await CreateSampleToolboxAsync(toolboxName, docsServerLabel, foundryEndpoint, credential);
string toolboxMcpServerUrl = BuildToolboxMcpServerUrl(toolboxEndpoint, toolboxName, toolboxApiVersion);
Environment.SetEnvironmentVariable(ToolboxMcpServerUrlSetting, toolboxMcpServerUrl);
// Expose the server label to the workflow so the YAML can build prefixed MCP tool names dynamically.
Environment.SetEnvironmentVariable(DocsServerLabelSetting, docsServerLabel);
// Expose the web search tool name so the YAML can reference it without hard-coding.
Environment.SetEnvironmentVariable(WebSearchToolNameSetting, webSearchToolName);
IConfiguration workflowConfiguration = new ConfigurationBuilder()
.AddConfiguration(configuration)
.AddInMemoryCollection(new Dictionary<string, string?>
{
[ToolboxMcpServerUrlSetting] = toolboxMcpServerUrl,
[DocsServerLabelSetting] = docsServerLabel,
[WebSearchToolNameSetting] = webSearchToolName,
})
.Build();
await CreateAgentAsync(foundryEndpoint, configuration, credential);
@@ -72,7 +77,7 @@ internal sealed class Program
string workflowInput = Application.GetInput(args);
// Create the MCP tool handler for invoking the Foundry toolbox MCP proxy.
List<HttpClient> createdHttpClients = [];
ConcurrentBag<HttpClient> createdHttpClients = [];
DefaultMcpToolHandler mcpToolHandler = new(
httpClientProvider: async (serverUrl, _) =>
{
@@ -97,6 +102,7 @@ internal sealed class Program
// Create the workflow factory with MCP tool provider
WorkflowFactory workflowFactory = new("InvokeFoundryToolboxMcp.yaml", foundryEndpoint)
{
Configuration = workflowConfiguration,
McpToolHandler = mcpToolHandler
};
@@ -67,16 +67,13 @@ public sealed class DefaultMcpToolHandler : IMcpToolHandler, IAsyncDisposable
if (IsListToolsToolName(toolName))
{
ThrowIfListToolsArgumentsSpecified(arguments);
McpClient listToolsClient = await this.GetOrCreateClientAsync(serverUrl, serverLabel, headers, cancellationToken).ConfigureAwait(false);
IList<McpClientTool> tools = await listToolsClient.ListToolsAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
return CreateListToolsResultContent(tools.Select(tool => tool.ProtocolTool));
}
McpClient client = await this.GetOrCreateClientAsync(serverUrl, serverLabel, headers, cancellationToken).ConfigureAwait(false);
if (IsListToolsToolName(toolName))
{
IList<McpClientTool> tools = await client.ListToolsAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
return CreateListToolsResultContent(tools.Select(tool => tool.ProtocolTool));
}
McpServerToolResultContent resultContent = new(Guid.NewGuid().ToString());
// Convert IDictionary to IReadOnlyDictionary for CallToolAsync
@@ -349,6 +346,6 @@ public sealed class DefaultMcpToolHandler : IMcpToolHandler, IAsyncDisposable
writer.WriteEndObject();
}
return Encoding.UTF8.GetString(stream.ToArray());
return Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length);
}
}