add_pattern_restriction
Apply regex pattern restrictions to IDS specification parameters to enforce data format compliance in buildingSMART Information Delivery Specifications.
Instructions
Add pattern restriction (regex matching).
Args: spec_id: Specification identifier or name facet_index: Index of facet in location (0-based) parameter_name: Which parameter to restrict (e.g., "value") base_type: XSD base type (e.g., "xs:string") pattern: Regular expression pattern ctx: FastMCP Context (auto-injected) location: "applicability" or "requirements" (default: "requirements")
Returns: {"status": "added", "restriction_type": "pattern", "spec_id": "S1"}
Example: Add pattern to attribute value: Name must match "EW-[0-9]{3}"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spec_id | Yes | ||
| facet_index | Yes | ||
| parameter_name | Yes | ||
| base_type | Yes | ||
| pattern | Yes | ||
| location | No | requirements |
Implementation Reference
- The async handler function that implements the add_pattern_restriction tool logic. It retrieves the specification, locates the facet, creates a pattern restriction using ids.Restriction, applies it to the specified parameter, and returns a status dictionary.async def add_pattern_restriction( spec_id: str, facet_index: int, parameter_name: str, base_type: str, pattern: str, ctx: Context, location: str = "requirements" ) -> Dict[str, Any]: """ Add pattern restriction (regex matching). Args: spec_id: Specification identifier or name facet_index: Index of facet in location (0-based) parameter_name: Which parameter to restrict (e.g., "value") base_type: XSD base type (e.g., "xs:string") pattern: Regular expression pattern ctx: FastMCP Context (auto-injected) location: "applicability" or "requirements" (default: "requirements") Returns: {"status": "added", "restriction_type": "pattern", "spec_id": "S1"} Example: Add pattern to attribute value: Name must match "EW-[0-9]{3}" """ try: ids_obj = await get_or_create_session(ctx) spec = _find_specification(ids_obj, spec_id) await ctx.info(f"Adding pattern restriction to {spec_id}, facet {facet_index}") # Get the facet facet = _get_facet_from_spec(spec, location, facet_index) # Create pattern restriction using IfcTester # Normalize base type (remove 'xs:' prefix if present) normalized_base = _normalize_base_type(base_type) restriction = ids.Restriction( base=normalized_base, options={"pattern": pattern} ) # Apply restriction to the parameter _apply_restriction_to_facet(facet, parameter_name, restriction) await ctx.info(f"Pattern restriction added: {pattern}") return { "status": "added", "restriction_type": "pattern", "spec_id": spec_id, "facet_index": facet_index, "parameter": parameter_name, "pattern": pattern } except ToolError: raise except Exception as e: await ctx.error(f"Failed to add pattern restriction: {str(e)}") raise ToolError(f"Failed to add pattern restriction: {str(e)}")
- src/ids_mcp_server/server.py:46-46 (registration)Registration of the add_pattern_restriction tool handler in the FastMCP server instance.mcp_server.tool(restrictions.add_pattern_restriction)