Skip to content

Handle rate limiting, add runtime config and live tests for Functions toolset#2071

Merged
anannya03 merged 6 commits intomainfrom
manvkaur/updateruntimeconfig
Mar 18, 2026
Merged

Handle rate limiting, add runtime config and live tests for Functions toolset#2071
anannya03 merged 6 commits intomainfrom
manvkaur/updateruntimeconfig

Conversation

@manvkaur
Copy link
Copy Markdown
Contributor

@manvkaur manvkaur commented Mar 16, 2026

What does this PR do?

Handle GitHub API rate limiting, add runtime configuration, and live tests for Azure Functions toolset.

Key Fixes:

Rate Limiting Handling:

  • Switch to raw GitHub URLs (~5000 req/hr) after fetching GitHub tree to minimize API usage (60 req/hr unauthenticated)
  • Proper detection via X-RateLimit-Remaining: 0 header (distinguishes from 403 permission errors)

Runtime Configuration:

  • Language list now returns runtimeVersions with supported, preview, and default versions from CDN manifest

Template Fetching (Tree API):

  • Switched from GitHub Contents API to Tree API to handle rate limiting
  • Added 5MB size limit (MaxTreeSizeBytes)
  • 12-hour cache duration for manifests and templates

Live Tests:

  • 2 recorded tests for build pipeline (playback mode) - one per test class that fetches from CDN
  • 18 tests marked [LiveTestOnly] - run only in Live mode
  • Tests cover: language listing, template retrieval, runtime versions, error handling
  • Cache-dependent tests cannot be reliably recorded due to non-deterministic test execution order

Files Changed:

Area Changes
Services FunctionsService, ManifestService
Models Removed redundant [JsonPropertyName] from 11 files
JSON Context Consolidated into single FunctionsJsonContext
Tests 115 unit tests, 20 live tests (2 recorded + 18 live-only)

GitHub issue number?

Related #1781

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md
  • For MCP tool changes:
    • One tool per PR: This PR modifies the Functions toolset only
    • Updated documentation
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1

manvkaur and others added 2 commits March 16, 2026 14:44
- Fetch templates manifest from Azure CDN with GitHub fallback
- Add runtime version configuration to language metadata
- Add FunctionsCacheDurations for 12-hour template caching
- Add rate limit handling for GitHub template downloads
- Remove deprecated GitHubContentEntry model
- Add TemplateManifest model for CDN manifest structure
- Refactor FunctionsService and LanguageMetadataProvider for CDN support
- Update unit tests for new HTTP-based manifest fetching
- Add live tests for language list and template get commands

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manvkaur
Copy link
Copy Markdown
Contributor Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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 enhances the Azure Functions toolset by sourcing runtime version metadata from the CDN manifest, switching template file retrieval to GitHub’s Tree API (with caching), and adding recorded live tests to validate end-to-end behavior.

Changes:

  • Fetch runtime versions from manifest.json and expose them via functions_language_list (and related metadata flows).
  • Refactor template file fetching to use GitHub Tree API + raw URLs, add caching, and improve error handling for rate limit/network cases.
  • Add a new recorded live test project for Functions with tests covering language listing and template retrieval.

Reviewed changes

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

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Implements Tree API fetching, caching, and rate limit/network error handling; adds Tree API models and JSON context entries.
tools/Azure.Mcp.Tools.Functions/src/Services/LanguageMetadataProvider.cs Splits static language metadata from runtime versions; builds runtime-version-driven template parameters.
tools/Azure.Mcp.Tools.Functions/src/Services/ILanguageMetadataProvider.cs Extends API to accept optional manifest runtime versions for language info/validation.
tools/Azure.Mcp.Tools.Functions/src/Services/ManifestService.cs Uses centralized cache duration for manifest caching.
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsCacheDurations.cs Adds 12-hour cache duration constant used across Functions services.
tools/Azure.Mcp.Tools.Functions/src/Models/TemplateManifest.cs Adds runtimeVersions to the manifest model.
tools/Azure.Mcp.Tools.Functions/src/Models/GitHubContentEntry.cs Removes Contents API model (no longer used).
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.UnitTests/Services/FunctionsServiceTests.cs Removes tests tied to deleted Contents API URL builder.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.UnitTests/Services/FunctionsServiceHttpTests.cs Updates service construction for caching; adds Tree API error handling tests.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.UnitTests/Language/LanguageListCommandTests.cs Updates deserialization validation to include manifest-provided runtime versions.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.LiveTests/Azure.Mcp.Tools.Functions.LiveTests.csproj Adds new Functions live test project.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.LiveTests/assets.json Adds recorded-test assets configuration.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.LiveTests/BaseFunctionsCommandLiveTests.cs Adds recorded-test base class for Functions live tests.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.LiveTests/Language/LanguageListCommandLiveTests.cs Adds live tests for language list + runtime versions + template parameters.
tools/Azure.Mcp.Tools.Functions/tests/Azure.Mcp.Tools.Functions.LiveTests/Template/TemplateGetCommandLiveTests.cs Adds live tests for listing templates and fetching template files (incl. runtime-version replacement).
servers/Azure.Mcp.Server/changelog-entries/1773697825677.yaml Adds changelog entry for Functions toolset enhancements.

Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
- Add MaxTreeSizeBytes (5MB) size limit for Tree API response to prevent OOM
- Add IsRateLimited() helper to check X-RateLimit-Remaining header for 403
- Handle truncated tree response with warning log
- Move GitHubTreeResponse and GitHubTreeItem to separate model files
- Refactor live tests for better recording coverage (20 recorded vs 1 skipped)
- Add implicit cache verification test using test proxy recordings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manvkaur
Copy link
Copy Markdown
Contributor Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manvkaur
Copy link
Copy Markdown
Contributor Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/ManifestService.cs
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Comment thread tools/Azure.Mcp.Tools.Functions/src/Models/TemplateManifest.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs Outdated
Comment thread servers/Azure.Mcp.Server/changelog-entries/1773697825677.yaml Outdated
- Add null checks for httpClientFactory and logger with _ prefix
- Add using System.Net and use HttpStatusCode.TooManyRequests
- Make FetchTemplateFilesAsync private (only used internally)
- Add catch for InvalidOperationException in ManifestService
- Change changelog section to Other Changes
- Add comment documenting raw.githubusercontent.com rate limiting (~5000/hr)
- Remove unused ConvertToRawGitHubUrl method
- Consolidate FunctionTemplatesManifestJsonContext into FunctionsJsonContext
- Remove redundant [JsonPropertyName] attributes from 11 model files
- Fix tests to use FunctionsJsonContext for serialization
- Create HttpClientHelper for User-Agent with real assembly version
- Add doc comments explaining [LiveTestOnly] pattern in live tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manvkaur
Copy link
Copy Markdown
Contributor Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread tools/Azure.Mcp.Tools.Functions/src/Models/LanguageInfo.cs
Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/Helpers/HttpClientHelper.cs Outdated
HttpClientFactoryConfigurator in core already sets User-Agent header:
azmcp/{version} azmcp-{transport}/{version} (framework; os)

Removed redundant HttpClientHelper and its tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@manvkaur
Copy link
Copy Markdown
Contributor Author

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anannya03
Copy link
Copy Markdown
Contributor

@manvkaur, please run all the three mcp tools locally using MCP server to make sure that nothing has broken and there are no regressions.

@manvkaur
Copy link
Copy Markdown
Contributor Author

please run all the three mcp tools locally using MCP server to make sure that nothing has broken and there are no regressions.

@anannya03 - Yes, I did test with random prompts as well, but here is the summary using E2E prompts you added in initial PR:

Prompt Command Result
What languages does Azure Functions support? functions language list 6 languages returned
What runtime versions are available? functions language list runtimeVersions for each language
Set up a new Python project functions project get --language python initInstructions, projectFiles
Generate TypeScript project files functions project get --language typescript With templateParameters
Java with JDK 21 functions project get --language java javaVersion parameter
C# triggers and bindings functions template get --language csharp 12+ templates listed
Python templates functions template get --language python 25 templates listed
Timer trigger C# functions template get --language csharp --template timer-trigger-csharp 6 files returned
Cosmos DB trigger Java functions template get --language java --template cosmos-trigger-java 5 files returned
MCP Tool trigger TypeScript functions template get --language typescript --template mcp-tool-trigger-typescript 8 files returned

Test Summary:

  • Unit Tests: 115 passed
  • Live Tests: 20 passed (Live mode runs all tests against real CDN/GitHub endpoints for additional validation)
  • Local CLI: All prompts working

@anannya03
Copy link
Copy Markdown
Contributor

Looks good. :)

@manvkaur manvkaur enabled auto-merge (squash) March 18, 2026 18:07
@anannya03 anannya03 disabled auto-merge March 18, 2026 18:08
@anannya03 anannya03 merged commit d25ebd4 into main Mar 18, 2026
28 checks passed
@anannya03 anannya03 deleted the manvkaur/updateruntimeconfig branch March 18, 2026 18:08
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in Azure MCP Server Mar 18, 2026
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Apr 20, 2026
… toolset (microsoft#2071)

* Refactor Functions toolset: CDN manifest, rate limiting, and live tests

- Fetch templates manifest from Azure CDN with GitHub fallback
- Add runtime version configuration to language metadata
- Add FunctionsCacheDurations for 12-hour template caching
- Add rate limit handling for GitHub template downloads
- Remove deprecated GitHubContentEntry model
- Add TemplateManifest model for CDN manifest structure
- Refactor FunctionsService and LanguageMetadataProvider for CDN support
- Update unit tests for new HTTP-based manifest fetching
- Add live tests for language list and template get commands

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add changelog entry for Functions toolset improvements

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address Copilot code review feedback for Functions toolset

- Add MaxTreeSizeBytes (5MB) size limit for Tree API response to prevent OOM
- Add IsRateLimited() helper to check X-RateLimit-Remaining header for 403
- Handle truncated tree response with warning log
- Move GitHubTreeResponse and GitHubTreeItem to separate model files
- Refactor live tests for better recording coverage (20 recorded vs 1 skipped)
- Add implicit cache verification test using test proxy recordings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Mark cache-dependent Functions tests as LiveTestOnly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review feedback for Functions toolset

- Add null checks for httpClientFactory and logger with _ prefix
- Add using System.Net and use HttpStatusCode.TooManyRequests
- Make FetchTemplateFilesAsync private (only used internally)
- Add catch for InvalidOperationException in ManifestService
- Change changelog section to Other Changes
- Add comment documenting raw.githubusercontent.com rate limiting (~5000/hr)
- Remove unused ConvertToRawGitHubUrl method
- Consolidate FunctionTemplatesManifestJsonContext into FunctionsJsonContext
- Remove redundant [JsonPropertyName] attributes from 11 model files
- Fix tests to use FunctionsJsonContext for serialization
- Create HttpClientHelper for User-Agent with real assembly version
- Add doc comments explaining [LiveTestOnly] pattern in live tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove HttpClientHelper - factory already sets User-Agent

HttpClientFactoryConfigurator in core already sets User-Agent header:
azmcp/{version} azmcp-{transport}/{version} (framework; os)

Removed redundant HttpClientHelper and its tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants