Module: OdataDuty::McpIdentifierValidator
- Extended by:
- McpIdentifierValidator
- Included in:
- McpIdentifierValidator
- Defined in:
- lib/odata_duty/mcp_identifier_validator.rb
Overview
Guards McpServerBuilder's generated tool names and input_schema property keys against the
Anthropic Messages API's tool-schema identifier constraints, before a tool is registered on
the MCP server. Raises InvalidMcpIdentifierError on the first violation found.
Constant Summary collapse
- PROPERTY_KEY_REGEXP =
Property keys additionally allow
.. /\A[a-zA-Z0-9_.-]{1,64}\z/- TOOL_NAME_REGEXP =
/\A[a-zA-Z0-9_-]{1,64}\z/
Instance Method Summary collapse
- #validate_properties!(endpoint, tool_name, input_schema) ⇒ Object
- #validate_tool_name!(name) ⇒ Object
Instance Method Details
#validate_properties!(endpoint, tool_name, input_schema) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/odata_duty/mcp_identifier_validator.rb', line 20 def validate_properties!(endpoint, tool_name, input_schema) input_schema.fetch('properties').each_key do |key| next if key.match?(PROPERTY_KEY_REGEXP) raise InvalidMcpIdentifierError, "#{endpoint.entity_type.name} property \"#{key}\" cannot be used as an MCP tool " \ "input key — it must match #{PROPERTY_KEY_REGEXP.inspect} (#{tool_name})" end end |
#validate_tool_name!(name) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/odata_duty/mcp_identifier_validator.rb', line 12 def validate_tool_name!(name) return if name.match?(TOOL_NAME_REGEXP) raise InvalidMcpIdentifierError, "tool name \"#{name}\" is #{name.length} characters — MCP tool names must " \ "match #{TOOL_NAME_REGEXP.inspect}" end |