Skip to content

Conversation

kfischer-okarin
Copy link
Contributor

I added logic to auto-determine a server's capabilities based on the protocol features actually used in the server.

  • If the server has at least 1 tool or defines a custom tools_list_handler, it returns the tools capability
  • If the server has at least 1 prompt or defines a custom prompts_list_handler, it returns the prompts capability
  • If the server has at least 1 resource or template or defines a custom list handler for either of those it returns the resources capability

Motivation and Context

I found it unnecessary that you have to manually specify the capabilities when they could be actually auto-determined from the server definition.

How Has This Been Tested?

I tried out a few patterns in my local mcp inspector

Breaking Changes

This should not be a breaking change since an empty tool list and no capability should make no practical difference to a procotol conform MCP client.

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

I was even thinking about completely removing the ability to set or override the capabilities manually but maybe that would have been going too far - and it would have also made testing of ensure_capability! more complicated

@topherbullock topherbullock self-requested a review May 20, 2025 20:58
Copy link
Contributor

@topherbullock topherbullock left a comment

Choose a reason for hiding this comment

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

Good idea! Thanks for this!

I tested with examples/stdio_server.rb in MCP inspector.
Removed resources, tools, prompts and got the expected capabilities in the initialize response.

@topherbullock topherbullock requested a review from atesgoral May 20, 2025 21:12
@atesgoral
Copy link
Contributor

Neat DX idea!

@topherbullock topherbullock merged commit 18f3e87 into modelcontextprotocol:main May 21, 2025
4 checks passed
@topherbullock
Copy link
Contributor

ty @kfischer-okarin

@kfischer-okarin kfischer-okarin deleted the auto-determine-capabilities branch June 6, 2025 15:02
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.

3 participants