Handle rate limiting, add runtime config and live tests for Functions toolset#2071
Handle rate limiting, add runtime config and live tests for Functions toolset#2071
Conversation
- 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>
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
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.jsonand expose them viafunctions_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. |
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
- 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>
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
tools/Azure.Mcp.Tools.Functions/src/Services/FunctionsService.cs
Outdated
Show resolved
Hide resolved
|
|
||
| [Fact] | ||
| [LiveTestOnly] | ||
| public async Task ExecuteAsync_LanguageListThenTemplate_UsesSharedCache() |
There was a problem hiding this comment.
I see that most of the Live Tests are marked as [LiveTestOnly]. Can we not have recorded tests for these to have better CI coverage?
There was a problem hiding this comment.
The [LiveTestOnly] tests rely on an in-memory cached manifest populated by the first test in each class. xUnit runs tests in non-deterministic order, so in Playback mode a cache-dependent test might run first with an empty cache, try to call the CDN, but have no recorded response.
The CDN functionality is well covered:
- 2 recorded live tests - validate real CDN integration and manifest structure
- 118 unit tests - mock HTTP responses to test CDN fetching, caching, fallback logic, error handling, and edge cases
The remaining 18 live tests focus on query variations using cached data and are validated during live mode.
- 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>
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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:
X-RateLimit-Remaining: 0header (distinguishes from 403 permission errors)Runtime Configuration:
runtimeVersionswith supported, preview, and default versions from CDN manifestTemplate Fetching (Tree API):
MaxTreeSizeBytes)Live Tests:
[LiveTestOnly]- run only in Live modeReview Feedback Addressed:
ArgumentNullException.ThrowIfNull()for httpClientFactory and loggerusing System.Net;instead of fully qualifiedHttpStatusCodeFetchTemplateFilesAsyncprivate (internal use only)InvalidOperationExceptionin ManifestService for size limitsConvertToRawGitHubUrlmethod (not used in production)FunctionTemplatesManifestJsonContextintoFunctionsJsonContext[JsonPropertyName]from 11 model files (CamelCase policy handles it)HttpClientHelperto use real assembly version viaAssemblyFileVersionAttributeFiles Changed:
FunctionsService,ManifestService, newHttpClientHelper[JsonPropertyName]from 11 filesFunctionsJsonContextGitHub issue number?
Related #1781
Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.md.\eng\scripts\Update-AzCommandsMetadata.ps1