Skip to content

NamespaceToolLoader: the tool loader that supports namespace mode without creating child azmcp processes#704

Merged
anuchandy merged 8 commits intomicrosoft:mainfrom
anuchandy:no-child-azmcp-processes
Oct 7, 2025
Merged

NamespaceToolLoader: the tool loader that supports namespace mode without creating child azmcp processes#704
anuchandy merged 8 commits intomicrosoft:mainfrom
anuchandy:no-child-azmcp-processes

Conversation

@anuchandy
Copy link
Copy Markdown
Member

@anuchandy anuchandy commented Oct 5, 2025

What does this PR do?

Today, when we start azmcp in default mode (which is equivalent to --mode namespace , the default mode for VS Code as well), the server creates a new azmcp process for every command group (child namespace name) and uses a stdio channel to invoke commands.

Below is the output of all azmcp processes after I used the "Azure MCP Server" (via VS Code extension) in Copilot and tried a few tool calls. Each azmcp process uses approximately 80-140 MB of memory.

Process ID Memory Command
56044 157.9 MB server/azmcp server start --mode namespace
56326 137.1 MB server/azmcp server start --mode all --namespace subscription
56441 180.9 MB server/azmcp server start --mode all --namespace marketplace
56476 138.5 MB server/azmcp server start --mode all --namespace storage
56505 143.4 MB server/azmcp server start --mode all --namespace cosmos
56526 140.9 MB server/azmcp server start --mode all --namespace aks
56552 139.3 MB server/azmcp server start --mode all --namespace acr
56579 84.0 MB server/azmcp server start --mode all --namespace postgres
56631 138.4 MB server/azmcp server start --mode all --namespace group
56824 79.2 MB server/azmcp server start --mode all --namespace keyvault
56833 135.7 MB server/azmcp server start --mode all --namespace kusto
56838 80.7 MB server/azmcp server start --mode all --namespace appservice

This PR introduces direct in-process command execution via the new NamespaceToolLoader, eliminating all child azmcp process spawning in namespace mode. This new tool loader executes Azure namespace commands directly in-process via CommandFactory.GroupCommands()

Benefits

  • Memory reduction: Eliminates 80-140 MB overhead per command group (e.g., ~1+ GB savings for 10+ active namespaces)
  • Faster startup: No child process spawn latency for namespace tools
  • Lower latency: Direct in-process method calls replace cross-process stdio communication
  • Better scalability: Memory usage no longer grows linearly with active namespaces
  • Same client experience: Maintains hierarchical tool structure and learn mode behavior
  • Zero child processes: Only single azmcp process runs

Follow-up work item, another pr: Apply a similar concept to the less frequently used --mode single, which collapses everything under a single azure tool.

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Updated command list in /docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

@anuchandy
Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anuchandy anuchandy force-pushed the no-child-azmcp-processes branch from c5dad6f to ef1a683 Compare October 5, 2025 21:06
@anuchandy anuchandy marked this pull request as ready for review October 5, 2025 22:59
@anuchandy anuchandy requested a review from a team as a code owner October 5, 2025 22:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new NamespaceToolLoader that enables direct in-process command execution for Azure namespace tools, eliminating the need for child azmcp processes in namespace mode. This approach significantly reduces memory usage (80-140 MB per namespace), improves performance, and maintains the same hierarchical tool structure and learn mode behavior.

  • Memory optimization: Eliminates child process overhead through direct in-process command execution
  • Performance improvement: Replaces cross-process stdio communication with direct method calls
  • Architecture enhancement: Maintains existing client experience while improving scalability

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.

File Description
NamespaceToolLoader.cs New tool loader implementing direct in-process Azure command execution with hierarchical namespace support and learn mode
NamespaceToolLoaderTests.cs Comprehensive unit tests covering tool loading, command execution, caching, thread safety, and error handling scenarios
ServiceCollectionExtensions.cs Updated dependency injection configuration to use NamespaceToolLoader in namespace mode and simplified discovery strategy registration

Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
@anuchandy anuchandy marked this pull request as draft October 6, 2025 15:41
@anuchandy anuchandy force-pushed the no-child-azmcp-processes branch from 2f16aad to 96de765 Compare October 6, 2025 22:18
@anuchandy
Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anuchandy anuchandy marked this pull request as ready for review October 6, 2025 23:38
@jongio jongio requested a review from Copilot October 7, 2025 17:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs Outdated
@joshfree joshfree moved this from Untriaged to In Progress in Azure MCP Server Oct 7, 2025
@joshfree joshfree added this to the 2025-10 milestone Oct 7, 2025
@anuchandy
Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anuchandy anuchandy merged commit 1116123 into microsoft:main Oct 7, 2025
26 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Oct 7, 2025
@anuchandy anuchandy deleted the no-child-azmcp-processes branch October 7, 2025 19:59
@joshfree
Copy link
Copy Markdown
Member

@anuchandy please add the missing changelog entry retroactively

@xiangyan99 xiangyan99 mentioned this pull request Oct 15, 2025
18 tasks
@anuchandy anuchandy mentioned this pull request Oct 16, 2025
18 tasks
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Dec 8, 2025
…hout creating child azmcp processes (microsoft#704)

* NamespaceToolLoader: the tool loader that supports namespace without creating child azmcp processes

* Remove ConvertToJsonElements and rely on the guarantees provided by mcp-libs.

* Using JsonSerializer.SerializeToElement for tests

* Simplify CreateNamespaceTool

* Align NamespaceToolLoader logic closer to ServerToolLoader (enabling common logic extraction later)

* align command exclusion behavior with ServerToolLoader

* simplify methods (remove unnecessary async attributes)

* adjust tests to adapt exclusion behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants