fix(mcp): fix GetDocumentByUrl and AnalyzeDocumentStructure returning 'Document not found'#2727
Merged
theletterf merged 2 commits intomainfrom Feb 18, 2026
Merged
Conversation
… "Document not found"
Two bugs caused all URL lookups to fail:
1. The Elasticsearch query used `url.keyword` via `.Suffix("keyword")`, but the
index mapping defines `url` as `type: keyword` directly (with sub-fields
`url.match` and `url.prefix`). The `url.keyword` path does not exist, so
the term query matched nothing. Fixed by querying `url` directly.
2. No URL normalization was applied before querying, so full URLs such as
`https://www.elastic.co/docs/deploy-manage/api-keys` never matched the
path-only values stored in the index. Added a `NormalizeUrl` helper that
extracts the path from absolute URLs, ensures a leading slash, and strips
trailing slashes.
The tool parameter descriptions are updated to document the accepted formats.
Closes #2722
Co-authored-by: Claude <claude@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Extracts NormalizeUrl as internal static and adds InternalsVisibleTo so it can be tested without an Elasticsearch connection. Covers all URL formats reported in issue #2722: path-only, bare path, full https URL, preview URL, trailing slash, query string, fragment, and leading/trailing whitespace. Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
reakaleek
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Closes #2722.
GetDocumentByUrlandAnalyzeDocumentStructurereturned"Document not found"for every URL, including paths returned by other MCP tools such asSemanticSearch.Root cause
Two independent bugs in
DocumentGateway:1. Non-existent Elasticsearch field (
url.keyword)The query used
.Suffix("keyword")to construct the field pathurl.keyword. However, the index mapping definesurlastype: keyworddirectly — its only sub-fields areurl.matchandurl.prefix. The fieldurl.keyworddoes not exist, so theTermquery produced zero hits for every input.Fix: remove
.Suffix("keyword")and query theurlfield directly.2. No URL normalization
The URL was passed to the
Termquery unchanged. The index stores path-only values like/docs/deploy-manage/api-keys, so full URLs such ashttps://www.elastic.co/docs/deploy-manage/api-keysnever matched, nor did bare paths without a leading slash.Fix: added
NormalizeUrl, which:Uri.AbsolutePath.Changes
DocumentGateway.GetByUrlAsync/GetStructureAsync: fix field reference, add normalization call.DocumentGateway.NormalizeUrl: new private static helper.DocumentTools: updated parameter descriptions to document accepted URL formats.Trade-offs
/docs/, because path prefixes may change across deployments and the gateway should not encode that assumption.#heading) in absolute URLs are silently dropped byUri.AbsolutePath; this is the correct behavior since the index does not store fragment-level granularity.LLM usage
This fix was developed with Claude 4.6 Sonnet and Cursor.
Made with Cursor