Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add RequestIdGenerator for custom request ID generation #732

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
rhtnr wants to merge 1 commit into modelcontextprotocol:main
base: main
Choose a base branch
Loading
from rhtnr:feature/custom-request-id-generator

Conversation

@rhtnr
Copy link
Contributor

@rhtnr rhtnr commented Dec 20, 2025

Summary

Fixes #703

Adds support for configuring custom request ID generators, enabling compatibility with MCP servers that require specific ID formats (e.g., numeric-only IDs like the Snowflake MCP server).

Changes

  • Added RequestIdGenerator functional interface in io.modelcontextprotocol.spec with:
    • generate() method for creating unique request IDs
    • ofDefault() factory method for UUID-prefixed incrementing IDs (existing behavior)
    • ofIncremental() factory method for simple numeric IDs
  • Updated McpClientSession to accept a custom RequestIdGenerator
  • Added requestIdGenerator() builder methods to both McpClient.SyncSpec and McpClient.AsyncSpec
  • Added 3 comprehensive tests for custom ID generators

Usage Example

// Using the built-in numeric ID generator
McpClient.sync(transport)
 .requestIdGenerator(RequestIdGenerator.ofIncremental())
 .build();
// Using a custom generator
AtomicLong counter = new AtomicLong(0);
McpClient.async(transport)
 .requestIdGenerator(() -> String.valueOf(counter.incrementAndGet()))
 .build();

Backward Compatibility

This change is fully backward compatible:

  • Existing code continues to work without changes
  • Default behavior remains the same (UUID-prefixed incrementing IDs)
  • New requestIdGenerator() method is optional

Test plan

  • All 3 new tests pass for custom ID generators
  • All 89 existing schema and session tests pass
  • Project compiles successfully

Adds support for configuring custom request ID generators, enabling
compatibility with MCP servers that require specific ID formats (e.g.,
numeric-only IDs).
Changes:
- Add RequestIdGenerator functional interface with factory methods
 for default (UUID-prefixed) and incremental (numeric) generators
- Update McpClientSession to accept a custom RequestIdGenerator
- Add requestIdGenerator() builder methods to McpClient.SyncSpec
 and McpClient.AsyncSpec
- Add comprehensive tests for custom ID generators
Copy link
Contributor

He-Pin commented Dec 20, 2025

This is actually a nice addition, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Allow custom or numeric request ID generation (Snowflake MCP server rejects string IDs)

2 participants

AltStyle によって変換されたページ (->オリジナル) /