Skip to content

fix: align everything server resource URI numbering with array indices #2570

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

olaservo
Copy link
Member

Fixes issue #475 where array indices (0-based) didn't match URI numbers (1-based), causing confusion.

Changes

  • Resource URIs now use 0-based numbering to match array indices
  • Resource 0 is now accessed via test://static/resource/0
  • Even indices now map to even URI numbers (more intuitive)

Resolves #475

Note: this is technically a breaking change, but since this is a demo server for testing, it seems like this shouldn't actually be an issue?

Generated with Claude Code

Fixes issue where array indices (0-based) didn't match URI numbers (1-based),
causing confusion where:
- Resource at index 0 was accessed via 'test://static/resource/1'
- Even indices (text resources) mapped to odd URI numbers

Changes:
- Resource URIs now use 0-based numbering to match array indices
- Resource 0 is now accessed via 'test://static/resource/0'
- Even indices now map to even URI numbers (more intuitive)

Resolves #475

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Ola Hungerford <olaservo@users.noreply.github.com>
Copy link
Member

@domdomegg domdomegg left a comment

Choose a reason for hiding this comment

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

LGTM.

I am a bit confused why we used 1-indexing in the first place, so am a bit wary (something something Chesterton's Fence). But seems fairly low risk.

@cliffhall
Copy link
Member

LGTM.

I am a bit confused why we used 1-indexing in the first place, so am a bit wary (something something Chesterton's Fence). But seems fairly low risk.

@domdomegg I'm guessing it was so that in the Inspector when you look at the resource list it is human-aligned, i.e., only programmers would not scratch their head at "Resource 0".

Guess we'll never really know, since this was part of the Initial Commit for the repo, and there is no associated detail in the commit message.

Screenshot 2025-08-18 at 2 33 04 PM

Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

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

Is this what we want? Seems confusing.

Screenshot 2025-08-18 at 2 40 01 PM

Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

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

This is what we had. The URI matched the resource name and resources started at 1 for human readability.
Screenshot 2025-08-18 at 2 42 04 PM

Now you have name out of sync with URI. The array index matches the URI, but is there a clear win in that? In the real world, URI and array index may have no correlation. I see no clear benefit to this change. You could make the resource name match the zero-based URI and index, I suppose, but I still don't see how it's an improvement that needs to be made.
Screenshot 2025-08-18 at 2 40 01 PM

Alternative approach?

I discussed with the author of issue #475 who agreed that the index is not important and that it probably has no correlation to URIs in the real world.

I think the better thing to do here is take his alternative suggestion and just change the README to state that odd numbered resources are text and even numbered resources are blobs. Currently it is backward.

Current odd numbered resources are text

Screenshot 2025-08-18 at 3 35 47 PM

Current event numbered resources are blobs

Screenshot 2025-08-18 at 3 36 09 PM

Current README says the opposite

Screenshot 2025-08-18 at 3 32 16 PM

@domdomegg
Copy link
Member

Sorry to maybe cause more chaos by introducing a new idea (which might be wrong because I don't have a huge amount of context on this server), but maybe we avoid all this weirdness by just using intentionally random ids?

E.g. just generate a uuid for everything, and either:

  • drop the note about odd/evens being particular types of resources
  • put things under proper paths if we want the paths to convey this info e.g. test://static/resource/text/{uuid} and test://static/resource/blob/{uuid}

@cliffhall
Copy link
Member

cliffhall commented Aug 19, 2025

Sorry to maybe cause more chaos by introducing a new idea (which might be wrong because I don't have a huge amount of context on this server), but maybe we avoid all this weirdness by just using intentionally random ids?

E.g. just generate a uuid for everything, and either:

  • drop the note about odd/evens being particular types of resources
  • put things under proper paths if we want the paths to convey this info e.g. test://static/resource/text/{uuid} and test://static/resource/blob/{uuid}

@domdomegg excellent suggestion. Removes any assumptions about array index being meaningful, axes the admittedly strange "even/odd" language from the description, and delivers the point that URIs can carry meaning.

@domdomegg
Copy link
Member

@claude can you give a shot at implementing the proposal from @domdomegg above? create it as a separate branch, if you can please.

Copy link
Contributor

claude bot commented Aug 22, 2025

Claude finished @domdomegg's task —— View job


Implementation Complete! ✅

Successfully implemented UUID-based resources as proposed by @domdomegg.

Changes Made

  • Read repository setup instructions (CLAUDE.md)
  • Examine current everything server implementation
  • Create new branch for UUID implementation
  • Replace array index-based URIs with UUID-based system
  • Update resource paths to be more semantic (text/blob separation)
  • Update README documentation
  • Test the implementation
  • Commit and push changes

Summary

Created a new branch uuid-based-resources that implements the UUID-based resource system:

Key Changes:

  • 100 resources now use UUID-based identifiers instead of array indices
  • Semantic paths:
    • Text resources: test://static/resource/text/{uuid}
    • Blob resources: test://static/resource/blob/{uuid}
  • Clear naming: "Text Resource 1-50" and "Blob Resource 1-50"
  • Updated tools: getResourceReference now accepts resourceUri instead of resourceId
  • Updated prompts: resource_prompt argument changed to resourceUri
  • Eliminated confusion between 0-based array indices and 1-based display numbers

Benefits:

  • No more index/URI numbering mismatch issues
  • Clear resource type indication through paths (/text/ vs /blob/)
  • UUIDs provide truly unique identifiers
  • More realistic real-world URI patterns

The implementation builds successfully and the server starts without errors. You can create a PR from the new branch: https://github.com/modelcontextprotocol/servers/pull/new/uuid-based-resources

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.

[everything] Unintuitive / misleading resource indexing
3 participants