feat: Add examples field to Tool schema for enhanced LLM guidance, discovery UX and automated testing #615
+315
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a comprehensive examples system to the MCP Tool schema that addresses three critical use cases: LLM guidance, human documentation, and automated testing. By adding concrete examples to tool definitions, we enable better tool discovery, understanding, and validation across the entire MCP ecosystem.
Motivation and Context
Organizations implementing MCP need better ways to help LLMs understand and use tools effectively. Currently, tools only have basic descriptions, which can lead to:
This change enables 1-shot learning for LLMs, provides clear documentation for developers, and establishes a foundation for automated testing and tool registries.
How Has This Been Tested?
npm run validate:schema
npm run generate:json
The examples have been tested with real tool implementations to ensure they provide meaningful guidance for both LLMs and human developers.
Breaking Changes
None. This is a purely additive change - the
examples
field is optional and all existing tool definitions remain valid.Types of changes
Checklist
Additional context
Key Implementation Details
New
ToolExample
interface with:id
: Unique identifier for automated testing and LLM disambiguationdescription
: Clear explanation targeting both humans and LLMsinput
: Example arguments matching the tool's input schemaoutput
: Expected result structure with content, structured data, and error statusEnhanced
Tool
interface to include:examples
array ofToolExample
objectsExample Usage
Impact and Benefits