Skip to content

Fix fetch tool to fallback to file service for non-http schemes #252683

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

Merged
merged 9 commits into from
Jun 29, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 27, 2025

Fixes #250495

This prevents MCP resource URIs (like test://static/resource/50) from being
incorrectly processed by the fetch tool. MCP resources should be handled
by VS Code's filesystem providers instead.

- Modified FetchWebPageTool._parseUris() to filter out non-HTTP(S) schemes
- Added comprehensive tests for the new scheme filtering behavior
- Non-HTTP(S) URIs will now be treated as invalid and skipped

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] can't get content of MCP resource Fix fetch tool to only handle HTTP/HTTPS schemes for MCP resources Jun 27, 2025
Copilot finished work on behalf of TylerLeonhardt June 27, 2025 19:13
@Copilot Copilot AI requested a review from TylerLeonhardt June 27, 2025 19:13
@TylerLeonhardt
Copy link
Member

I'd rather the tests implemented a TestWebContentExtractorService which can be constructed with a map of like "Uris to fake page contents" and then have tests that test the actual API not private methods

…ng private methods

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

I'd rather the tests implemented a TestWebContentExtractorService which can be constructed with a map of like "Uris to fake page contents" and then have tests that test the actual API not private meth...

I've refactored the tests to use a TestWebContentExtractorService that implements IWebContentExtractorService with configurable URI-to-content mapping. The tests now validate the public API behavior (via the invoke method) instead of testing private methods directly. This approach provides better test isolation and follows testing best practices. Commit: a62dae1

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of TylerLeonhardt June 27, 2025 19:52
@connor4312
Copy link
Member

I think what would be nice here is actually to just serve the file data if it's something the IFileService can resolve. Sure it might not be 'correct' use of the fetch tool, but that would make usages of it not break :)

…P schemes

Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

I think what would be nice here is actually to just serve the file data if it's something the IFileService can resolve. Sure it might not be 'correct' use of the fetch tool, but that would make usages...

I've implemented your suggestion to serve file data via IFileService for non-HTTP/HTTPS schemes. The fetch tool now:

  1. Processes HTTP/HTTPS URLs through the web content extractor (unchanged)
  2. Processes other URLs through IFileService.readFile()
  3. Only marks URLs as "Invalid" if both approaches fail

This makes MCP resources work seamlessly - instead of rejecting test://static/resource/50, it now attempts to read the content via the file service. The tool gracefully falls back to "Invalid URL" only if the file service can't handle the scheme either.

Commit: 2df3c81

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from connor4312 June 27, 2025 20:10
Copilot finished work on behalf of connor4312 June 27, 2025 20:10
@TylerLeonhardt
Copy link
Member

I like the strategy of:

  • if we get an HTTP or HTTPS url, use the web extractor
  • otherwise try the IFileService to resolve the url return content if it does
  • otherwise mark them as invalid

However, let's not change the description of the tool as I don't want this fall back to be used too heavily over other read tools.

And remember order matters in what you return back so maintain the same order in the response.

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

I like the strategy of:

  • if we get an HTTP or HTTPS url, use the web extractor
  • otherwise try the IFileService to resolve the url return content if it does
    ...

I've reverted the tool description back to the original text that only mentions web pages, while keeping the file service fallback functionality intact. The tool maintains proper URL order in responses as requested. Commit: 9c36f75

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of TylerLeonhardt June 27, 2025 20:20
@TylerLeonhardt
Copy link
Member

Can you use this FileService implementation as the implementation on the web? Right now that's using the Null one

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

Can you use this FileService implementation as the implementation on the web? Right now that's using the Null one

I've implemented a FileService-based WebContentExtractorService for the web platform. The web workbench now uses FileServiceWebContentExtractorService instead of NullWebContentExtractorService, which allows HTTP/HTTPS URLs to be handled via the FileService infrastructure. Commit: 1d2d406

Copilot finished work on behalf of TylerLeonhardt June 27, 2025 23:05
@TylerLeonhardt TylerLeonhardt changed the title Fix fetch tool to only handle HTTP/HTTPS schemes for MCP resources Fix fetch tool to fallback to file service for non-http schemes Jun 29, 2025
@TylerLeonhardt TylerLeonhardt marked this pull request as ready for review June 29, 2025 05:38
@vs-code-engineering vs-code-engineering bot added this to the June 2025 milestone Jun 29, 2025
@TylerLeonhardt TylerLeonhardt enabled auto-merge (squash) June 29, 2025 06:21
@TylerLeonhardt TylerLeonhardt merged commit f673cdd into main Jun 29, 2025
8 checks passed
@TylerLeonhardt TylerLeonhardt deleted the copilot/fix-250495 branch June 29, 2025 17:37
lszomoru pushed a commit that referenced this pull request Jun 30, 2025
)

* Initial plan

* Fix fetch tool to only handle HTTP/HTTPS schemes

This prevents MCP resource URIs (like test://static/resource/50) from being
incorrectly processed by the fetch tool. MCP resources should be handled
by VS Code's filesystem providers instead.

- Modified FetchWebPageTool._parseUris() to filter out non-HTTP(S) schemes
- Added comprehensive tests for the new scheme filtering behavior
- Non-HTTP(S) URIs will now be treated as invalid and skipped

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

* Refactor tests to use TestWebContentExtractorService instead of testing private methods

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

* Enhance fetch tool to serve file content via IFileService for non-HTTP schemes

Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>

* Revert tool description to original text as requested

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

* Implement FileService-based WebContentExtractorService for web platform

Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>

* Handle binary data

* style

* don't adopt this yet

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>
Co-authored-by: Tyler Leonhardt <tyleonha@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't get content of MCP resource
4 participants