-
Notifications
You must be signed in to change notification settings - Fork 43
Add source_url to MCP get_document_by_url output #3476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using System.Text.Json; | ||
| using AwesomeAssertions; | ||
| using Elastic.Documentation.Mcp.Remote.Gateways; | ||
| using Elastic.Documentation.Mcp.Remote.Responses; | ||
| using Elastic.Documentation.Mcp.Remote.Tools; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| namespace Mcp.Remote.Tests; | ||
|
|
||
| public class DocumentToolsTests | ||
| { | ||
| [Fact] | ||
| public async Task GetDocumentByUrl_MapsSourceUrlIntoResponse() | ||
| { | ||
| const string expectedSourceUrl = "https://github.com/elastic/docs-content/blob/main/docs/some-page.md"; | ||
| var gateway = new StubDocumentGateway(new DocumentResult | ||
| { | ||
| Url = "/docs/some-page", | ||
| Title = "Some Page", | ||
| Type = "doc", | ||
| SourceUrl = expectedSourceUrl | ||
| }); | ||
| var tools = new DocumentTools(gateway, NullLogger<DocumentTools>.Instance); | ||
|
|
||
| var json = await tools.GetDocumentByUrl("/docs/some-page"); | ||
|
|
||
| var response = JsonSerializer.Deserialize(json, McpJsonContext.Default.DocumentResponse); | ||
| response.Should().NotBeNull(); | ||
| response!.SourceUrl.Should().Be(expectedSourceUrl); | ||
|
Comment on lines
+31
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests won’t catch a JSON field-name contract regression. Because both assertions deserialize into Also applies to: 50-52 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetDocumentByUrl_OmitsSourceUrlWhenNull() | ||
| { | ||
| var gateway = new StubDocumentGateway(new DocumentResult | ||
| { | ||
| Url = "/docs/some-page", | ||
| Title = "Some Page", | ||
| Type = "doc", | ||
| SourceUrl = null | ||
| }); | ||
| var tools = new DocumentTools(gateway, NullLogger<DocumentTools>.Instance); | ||
|
|
||
| var json = await tools.GetDocumentByUrl("/docs/some-page"); | ||
|
|
||
| var response = JsonSerializer.Deserialize(json, McpJsonContext.Default.DocumentResponse); | ||
| response.Should().NotBeNull(); | ||
| response!.SourceUrl.Should().BeNull(); | ||
| } | ||
|
|
||
| private sealed class StubDocumentGateway(DocumentResult? result) : IDocumentGateway | ||
| { | ||
| public Task<DocumentResult?> GetByUrlAsync(string url, CancellationToken ct = default) => | ||
| Task.FromResult(result); | ||
|
|
||
| public Task<DocumentStructure?> GetStructureAsync(string url, CancellationToken ct = default) => | ||
| Task.FromResult<DocumentStructure?>(null); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SourceUrlcurrently serializes assourceUrl, notsource_url(contract mismatch).Line 113 needs an explicit JSON name override if the MCP contract is
source_urlas stated in the PR objective. With current options, this will emitsourceUrland can break clients expectingsource_url.Proposed fix
public sealed record DocumentResponse { @@ + [JsonPropertyName("source_url")] public string? SourceUrl { get; init; } @@ }📝 Committable suggestion
🤖 Prompt for AI Agents