Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
spec_idYes
facet_indexYes
parameter_nameYes
base_typeYes
patternYes
locationNorequirements

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)}")
  • Registration of the add_pattern_restriction tool handler in the FastMCP server instance.
    mcp_server.tool(restrictions.add_pattern_restriction)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vinnividivicci/ifc-ids-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server