Skip to content

Conversation

ryanRfox
Copy link

Summary

Fixes #3: Add support for prefixed resource names in MCP clients

This PR implements consistent resource name parsing to handle prefixed tool names (e.g., "ngrok weather:get-alerts") that MCP clients may use when routing through proxies or different transports.

Changes

  • Created src/utils/resource-parser.ts utility module with functions for parsing resource names
  • Integrated extractToolName() into the SDK's authentication flow at two key points:
    • When logging the requested tool name
    • When comparing proof resource names with request names
  • Added comprehensive test coverage for various prefix patterns and edge cases

Key Features

  • Backward Compatible: Non-prefixed names continue to work exactly as before
  • Flexible Prefix Support: Handles single or multiple colons (e.g., "org:dept:service:tool")
  • Consistent Extraction: Tool name is always the part after the last colon
  • Edge Case Handling: Gracefully handles empty strings, undefined values, and malformed names

Testing

Added 33 new tests covering:

  • Basic prefix extraction ("client:tool" → "tool")
  • Multiple colons ("a:b:c:d" → "d")
  • Real-world examples ("ngrok weather:get-alerts" → "get-alerts")
  • Edge cases (empty strings, undefined, colon-only strings)
  • Integration with authentication flow

All tests pass with 100% coverage of the new utility module.

Example Usage

// These all authenticate successfully for the same tool:
params.name = "ngrok weather:get-alerts"
proof.resourceName = "get-alerts"

params.name = "claude-web:fetch-data"  
proof.resourceName = "another-proxy:fetch-data"

params.name = "simple-tool"
proof.resourceName = "simple-tool"

Technical Approach

The solution uses a simple, efficient approach:

  1. If the resource name contains a colon, extract everything after the last colon as the tool name
  2. If no colon exists, use the entire string as the tool name
  3. Apply this consistently in both the request handler and proof validation

This minimal change ensures compatibility across different MCP client implementations without requiring clients to modify their naming schemes.

Fixes radiustechsystems#3: Add support for prefixed resource names in MCP clients

- Added resource-parser utility with extractToolName() function
- Handles prefixed names like "ngrok weather:get-alerts"
- Integrated parser into SDK authentication flow
- Added comprehensive tests for various prefix patterns
- Maintains backward compatibility with non-prefixed names

This allows MCP clients to use consistent naming schemes across
different proxies and transports without authentication failures.
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.

Inconsistent Resource Name Parsing Causes Authentication Failures

1 participant