Skip to content

Conversation

@bcallender
Copy link
Contributor

@bcallender bcallender commented Sep 18, 2025

TL;DR

Added parameter constraints and validators to tool parameters to enable better validation of user inputs.

What changed?

  • Added NumericConstraint and ToolParameterConstraints message types to the protocol buffer definitions
  • Added constraints field to ToolParameter message to support numeric bounds (gt, ge, lt, le), multiple_of, min/max length, and regex pattern validation
  • Added validator_names field to ToolParameter to support custom validators
  • Implemented a validator registry system with a ParamValidator protocol
  • Added a RegexValidator implementation with comprehensive regex validation
  • Updated serialization/deserialization to handle the new constraint fields
  • Modified the Pydantic model generation to apply constraints and validators
  • Updated the MCP demo setup to use regex validators for query parameters

How to test?

  1. Create a tool with parameter constraints:
tool = ToolParam(
    name="min_age",
    description="Filter `users` by minimum age.",
    constraints=ToolParamConstraints(gt=0, lt=120)
)
  1. Create a tool with a regex validator:
tool = ToolParam(
    name="search_query",
    description="Regex pattern for querying user profile information",
    validator_names=["regex"]
)
  1. Verify that invalid inputs are rejected with appropriate error messages when using the tool.

Why make this change?

This change enhances the tool parameter system by adding robust validation capabilities. By supporting both declarative constraints (like min/max values, length limits) and custom validators, we can ensure that user inputs meet specific requirements before executing tool functions. This improves error handling, security, and user experience by providing immediate feedback on invalid inputs rather than failing during execution.

Copy link
Contributor Author

bcallender commented Sep 18, 2025

@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 979a81e to 343929d Compare September 18, 2025 20:24
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 80d2d98 to 71fdd1d Compare September 18, 2025 20:24
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 343929d to 392169d Compare September 18, 2025 22:59
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 71fdd1d to 92e2cde Compare September 18, 2025 22:59
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 392169d to f5ebd6d Compare September 18, 2025 23:29
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 92e2cde to a9d001c Compare September 18, 2025 23:29
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from f5ebd6d to 581a62a Compare September 19, 2025 16:43
@bcallender bcallender force-pushed the feat/tool-param-validators branch from a9d001c to d0f2c71 Compare September 19, 2025 16:43
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 581a62a to 3214073 Compare September 19, 2025 17:23
@bcallender bcallender force-pushed the feat/tool-param-validators branch from d0f2c71 to 03488ff Compare September 19, 2025 17:23
@bcallender bcallender force-pushed the bc-automated-tool-creation branch 2 times, most recently from cddc32b to 99b3991 Compare September 22, 2025 00:05
@bcallender bcallender force-pushed the feat/tool-param-validators branch 2 times, most recently from e2b688c to 7f7c9f3 Compare September 22, 2025 00:20
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 99b3991 to 52be67d Compare September 22, 2025 17:00
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 7f7c9f3 to 133cc79 Compare September 22, 2025 17:00
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 52be67d to 17e9bbf Compare September 22, 2025 17:26
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 133cc79 to 5cf647b Compare September 22, 2025 17:27
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 17e9bbf to da184da Compare September 22, 2025 17:31
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 5cf647b to 60bd917 Compare September 22, 2025 17:31
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from da184da to 5d9d16a Compare September 22, 2025 18:46
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 60bd917 to 3ea2993 Compare September 22, 2025 18:46
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 5d9d16a to 95058fe Compare September 22, 2025 19:18
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 3ea2993 to 507902a Compare September 22, 2025 19:18
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 95058fe to 1cddcec Compare September 22, 2025 21:41
@bcallender bcallender force-pushed the feat/tool-param-validators branch from c74b8cc to 5d5f1bb Compare September 22, 2025 21:41
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 1cddcec to 97d0650 Compare September 22, 2025 22:11
@bcallender bcallender marked this pull request as ready for review September 22, 2025 22:36
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from b3c50ff to 52b0007 Compare September 22, 2025 22:53
@bcallender bcallender force-pushed the feat/tool-param-validators branch 3 times, most recently from 3257fef to 088602e Compare September 23, 2025 17:53
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 03ce63e to 2090362 Compare September 23, 2025 17:55
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 088602e to 00c5bb6 Compare September 23, 2025 17:55
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 2090362 to 57c7ef1 Compare September 23, 2025 17:56
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 00c5bb6 to 9d0212c Compare September 23, 2025 17:57
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 57c7ef1 to d41f806 Compare September 23, 2025 17:58
@bcallender bcallender force-pushed the feat/tool-param-validators branch 5 times, most recently from 3a55e47 to 63bbe0b Compare September 23, 2025 22:40
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from e101741 to 87d5ce7 Compare September 23, 2025 22:56
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 63bbe0b to ed2b8e8 Compare September 23, 2025 22:56
@bcallender bcallender force-pushed the bc-automated-tool-creation branch from 87d5ce7 to 9e7cb49 Compare September 23, 2025 22:57
@bcallender bcallender force-pushed the feat/tool-param-validators branch from ed2b8e8 to 9fbcb00 Compare September 23, 2025 22:58
Base automatically changed from bc-automated-tool-creation to main September 23, 2025 23:19
@bcallender bcallender force-pushed the feat/tool-param-validators branch 2 times, most recently from b6cf999 to 492d074 Compare September 25, 2025 22:45
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 492d074 to 79f4513 Compare October 4, 2025 04:14
@bcallender bcallender force-pushed the feat/tool-param-validators branch from 79f4513 to afc439c Compare October 22, 2025 23:10
@bcallender bcallender force-pushed the feat/tool-param-validators branch from afc439c to 3a3a04f Compare November 3, 2025 18:41
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.

2 participants