Skip to content

Conversation

@bb-c24
Copy link
Contributor

@bb-c24 bb-c24 commented Nov 14, 2025

Summary

Add missing meta parameter to Builder::addResourceTemplate() and Builder::addPrompt() methods to complete the metadata support across all registration methods.

Motivation and Context

The ResourceTemplate and Prompt schemas support a _meta field for passing additional metadata. However, the Builder::addResourceTemplate() and Builder::addPrompt() methods didn't expose this parameter, creating an inconsistency with other registration methods like addTool() and addResource() which already support meta.

This change completes the metadata support across all manual registration methods, providing a consistent API for users to attach arbitrary metadata to any MCP element.

How Has This Been Tested?

  • Verified that the meta parameter is properly added to both methods
  • Confirmed that the compact() calls include the new meta parameter
  • Checked that the parameters are optional with null defaults for backward compatibility
  • Ensured consistency with existing addTool() and addResource() implementations

Breaking Changes

None. This is a backward-compatible change:

  • The meta parameter is optional with a default value of null
  • Existing code will continue to work without modifications
  • The meta field is only included when explicitly provided

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Changes made:

  1. Added meta parameter to Builder::addResourceTemplate() method
  2. Added meta parameter to Builder::addPrompt() method
  3. Updated compact() calls to include meta in both methods

This completes the metadata support that was previously added to addTool() and addResource() in PR #144, ensuring all manual registration methods have feature parity with the underlying schema classes.

Note: The corresponding PHPDoc type definitions and ArrayLoader changes will need to be updated separately to fully support these fields throughout the registration pipeline.

@bb-c24 bb-c24 force-pushed the add_meta_to_prompt branch from 3cafd18 to 27fd2f7 Compare November 14, 2025 14:02
@bb-c24 bb-c24 marked this pull request as draft November 14, 2025 14:28
@bb-c24 bb-c24 marked this pull request as ready for review November 14, 2025 14:37
@bb-c24 bb-c24 force-pushed the add_meta_to_prompt branch from 461c0b5 to cd1fe73 Compare November 14, 2025 14:41
@bb-c24 bb-c24 force-pushed the add_meta_to_prompt branch from cd1fe73 to 5918e6c Compare November 14, 2025 14:42
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Thanks for that! 👍

@chr-hertel
Copy link
Member

that setup just doesn't feel that robust, but that's not on you - your basically just cleaning up - thanks for that!

@chr-hertel chr-hertel merged commit 7a58ab3 into modelcontextprotocol:main Nov 14, 2025
10 checks passed
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Nov 14, 2025
@chr-hertel chr-hertel changed the title Add meta to addPrompt and addResourceTemplate methods [Server]Add meta to addPrompt and addResourceTemplate methods Nov 14, 2025
@chr-hertel chr-hertel changed the title [Server]Add meta to addPrompt and addResourceTemplate methods [Server] Add meta to addPrompt and addResourceTemplate methods Nov 14, 2025
@bb-c24
Copy link
Contributor Author

bb-c24 commented Nov 14, 2025

@chr-hertel There was also an issue because meta was not null-coalesced also when using addPrompt it was not added to the prompt array, which then caused that undefined key error.

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

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants