ManagedCode.MCPGateway already exposes the gateway as reusable meta-tools through McpGatewayToolSet and IMcpGateway.CreateMetaTools(...).
The package now also needs to prove that these tools integrate cleanly with two host-side consumption patterns:
- direct
IChatClienttool-calling - Microsoft Agent Framework agents that accept an
IChatClient
The user explicitly asked for:
- very lightweight host integration
- deterministic scenario-driven tests
- coverage both without embeddings and with embeddings
- a staged auto-discovery flow where the model starts with the gateway search, route, and invoke tools, then receives only the currently needed direct tools, and then sees those discovered tools replaced when a new search result arrives
At the same time, the repository still wants to keep the core package generic, library-first, and free from unnecessary host-framework dependencies.
ManagedCode.MCPGateway will keep the core integration surface generic around reusable AITool modules:
McpGatewayToolSet.CreateTools(...)remains the source of truth for the gateway meta-toolsMcpGatewayToolSet.AddTools(...)composes those tools into an existingIList<AITool>without duplicating namesChatOptions.AddMcpGatewayTools(...)attaches the same tools to chat-client requestsMcpGatewayToolSet.CreateDiscoveredTools(...)projects the latest search matches as direct proxy toolsMcpGatewayAutoDiscoveryChatClientandUseMcpGatewayAutoDiscovery(...)provide the recommended staged host wrapper for both plainIChatClientand Agent Framework hosts
The recommended host flow is:
- expose only
gateway_tools_search,gateway_tools_route, andgateway_tool_invoke - let the model search or route the gateway first
- project only the latest search matches as direct proxy tools
- replace that discovered proxy set when a new search result arrives
The core package will not take a hard runtime dependency on Microsoft Agent Framework just to provide agent-specific sugar. Agent hosts consume the same generic IChatClient wrapper.
flowchart LR
Gateway["IMcpGateway / McpGateway"] --> ToolSet["McpGatewayToolSet"]
ToolSet --> MetaTools["gateway_tools_search + gateway_tools_route + gateway_tool_invoke"]
ToolSet --> Discovered["CreateDiscoveredTools(...)"]
MetaTools --> ChatOptions["ChatOptions.AddMcpGatewayTools(...)"]
MetaTools --> AutoDiscovery["McpGatewayAutoDiscoveryChatClient"]
Discovered --> AutoDiscovery
AutoDiscovery --> ChatClient["IChatClient host"]
AutoDiscovery --> Agent["ChatClientAgent or other host agent"]
Pros:
- direct agent-specific extension methods in the base package
- fewer lines of host composition code for Agent Framework consumers
Cons:
- expands the dependency surface for every gateway consumer
- couples a generic library to one host framework
- makes the core package track preview or fast-moving agent APIs unnecessarily
Pros:
- one “gateway-aware agent” concept in the package
- room for framework-specific behavior later
Cons:
- duplicates what host frameworks already do with
AITool - adds app-host concerns to a library-first package
- obscures the simple search-then-invoke tool model
Pros:
- models see the full catalog explicitly
- no search step required for small catalogs
Cons:
- large catalogs become expensive for models and agents
- duplicates schema/metadata projection work
- weakens the package’s intended gateway pattern of semantic search followed by stable invocation
Positive:
- direct
IChatClienthosts get a one-line staged auto-discovery wrapper - agent hosts can reuse the same staged wrapper without a separate host-specific package module
- the core package stays generic and avoids a hard Agent Framework dependency
- deterministic tests can validate both chat-client and agent loops against the same 50-tool gateway catalog in default graph mode and opt-in vector mode
Trade-offs:
- the auto-discovery wrapper owns one more piece of host orchestration inside the base package
- the exposed direct tools are ephemeral proxies for the latest search result, not a permanent export of the full catalog
Mitigations:
- keep README examples for both
IChatClientand Agent Framework - keep
McpGatewayToolSet.AddTools(...)andChatOptions.AddMcpGatewayTools(...)as the low-level escape hatch - keep integration tests covering both host patterns with a scenario-driven test chat client and both graph/vector search modes
McpGatewayToolSet.CreateTools(...)MUST remain the canonical source of gateway meta-tools.McpGatewayToolSet.AddTools(...)MUST preserve existing tool entries and MUST avoid duplicate names.ChatOptions.AddMcpGatewayTools(...)MUST preserve existingChatOptions.Toolsentries and MUST avoid duplicate names.McpGatewayAutoDiscoveryChatClientMUST start each host loop with only the gateway search, route, and invoke meta-tools visible unless the host already supplied other non-gateway tools.McpGatewayAutoDiscoveryChatClientMUST replace the discovered proxy-tool set when a newer gateway search result is present instead of accumulating old discovered tools forever.- The core package MUST stay generic around
AIToolcomposition and MUST NOT require Microsoft Agent Framework for normal package use. - Chat-client and agent integration tests MUST prove the staged auto-discovery lifecycle against a realistic multi-tool catalog in both default graph mode and opt-in vector mode.
Rollout:
- Keep
McpGatewayToolSetas the reusable module entry point. - Add
McpGatewayAutoDiscoveryChatClientandUseMcpGatewayAutoDiscovery(...)as the recommended host wrapper. - Document both chat-client and agent composition examples in
README.md. - Keep architecture docs aligned with the generic
AITool-module approach.
Rollback:
- Remove the chat-options bridge only if the package intentionally stops supporting direct
IChatClienttool composition. - Remove the auto-discovery wrapper only if the package intentionally stops supporting staged host-side tool visibility.
- Add a hard Agent Framework dependency only if there is an explicit product decision to make Agent Framework a first-class runtime dependency of the base package.
dotnet restore ManagedCode.MCPGateway.slnxdotnet format ManagedCode.MCPGateway.slnxdotnet build ManagedCode.MCPGateway.slnx -c Release --no-restoredotnet build ManagedCode.MCPGateway.slnx -c Release --no-restore -p:RunAnalyzers=truedotnet test --solution ManagedCode.MCPGateway.slnx -c Release --no-build