Skip to content

feat: enable ListResourcesRequest with multiplexing#1478

Open
ayx106179 wants to merge 1 commit intoagentgateway:mainfrom
ayx106179:fix/enable-list-resources-with-multiplexing
Open

feat: enable ListResourcesRequest with multiplexing#1478
ayx106179 wants to merge 1 commit intoagentgateway:mainfrom
ayx106179:fix/enable-list-resources-with-multiplexing

Conversation

@ayx106179
Copy link
Copy Markdown

Previously, ListResourcesRequest was blocked when multiplexing was enabled, returning InvalidMethodWithMultiplexing error. This was due to potential URI conflicts when multiple upstream servers had resources with the same URI.

This change:

  • Removes the multiplexing check in session.rs for ListResourcesRequest
  • Adds URI prefixing in handler.rs merge_resources() function, similar to how merge_tools() and merge_prompts() handle multiplexing
  • Resources from different services are now prefixed with service names (e.g., 'service1_/path/to/resource') to avoid conflicts

Fixes #404

@ayx106179 ayx106179 requested a review from a team as a code owner April 7, 2026 09:58
Comment thread crates/agentgateway/src/mcp/handler.rs Outdated
// if we add support for multiple services.
// Prefix URI with service name when multiplexing to avoid conflicts
.map(|mut r| {
r.uri = resource_name(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is going to work quite right. https://0mg.github.io/tools/uri/

foo_http://foo.com is an invalid URI.

We can do foo-http://, foo+http://, http+foo://, agw://http:// but not this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards foo+http://. Or maybe agw-foo+http:// such that we can reject anything without agw- prefix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apexlnc thoughts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use agw-{service-name}+resource://{uri}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I personally prefer it with the agw prefix. I vaguely remember "+" prefixing not being ideal in some edge cases, but probably out of scope for this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the fix. Please review and let me know :)

@ayx106179 ayx106179 force-pushed the fix/enable-list-resources-with-multiplexing branch from 0edc9dd to dfae8b1 Compare April 10, 2026 05:52
Comment thread crates/agentgateway/src/mcp/handler.rs Outdated
let (scheme, rest) = uri.split_at(scheme_end);
format!("agw-{target}+{scheme}{rest}")
} else {
// Fallback for URIs without schemes
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the spec requires a URI which should always have a scheme. I worry this would make it impossible to correctly distinguish "explicit resource:// schema" vs "no schema set" when we translate it back?

Comment thread crates/agentgateway/src/mcp/handler.rs Outdated
.split_once(DELIMITER)
.ok_or(UpstreamError::InvalidRequest(
"invalid resource name".to_string(),
// Handle both old name format (service_name) and new URI format (agw-service+scheme://)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to handle the old format.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well we do but not like this. Its not 'old and new', its 'URI format' and 'tool format'. We should not mix these paths ,they are separate functions used for different things.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@howardjohn Thanks for the feedback. I've updated the implementation to address these concerns:

  • Removed the backwards compatibility logic and kept parse_resource_name() separate for tools.
  • Making sure only URIs that already have schemes get transformed, and URIs without schemes are left as-is.

@ayx106179 ayx106179 force-pushed the fix/enable-list-resources-with-multiplexing branch from dfae8b1 to 2986d7c Compare April 15, 2026 05:58
@howardjohn howardjohn enabled auto-merge (squash) April 15, 2026 18:08
Previously, ListResourcesRequest was blocked when multiplexing was enabled,
returning InvalidMethodWithMultiplexing error. This was due to potential
URI conflicts when multiple upstream servers had resources with the same URI.

This change:
- Removes the multiplexing check in session.rs for ListResourcesRequest
- Adds proper URI prefixing in handler.rs using valid URI syntax
- Uses simple service+scheme:// format (e.g., myservice+http://example.com)
- Only handles URIs that already have schemes (no fallback)
- Updates ServerCapabilities to advertise resource support when multiplexing

Examples:
- http://example.com → myservice+http://example.com
- file:///path/file → otherservice+file:///path/file

Fixes agentgateway#404
auto-merge was automatically disabled April 16, 2026 08:43

Head branch was pushed to by a user without write access

@ayx106179 ayx106179 force-pushed the fix/enable-list-resources-with-multiplexing branch from 2986d7c to d6b4fb2 Compare April 16, 2026 08:44
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.

Ensure MCP resources are fully supported

3 participants