Skip to content
Star -

Resource Schema

Related Topics: Endpoints (resource concepts) | SQL Endpoints (tutorial) | Python Endpoints (tutorial) | Type System (parameter types)

This reference documents the complete YAML schema for resource definitions in MXCP.

mxcp: 1
resource:
uri: "employee://{employee_id}/profile"
name: Employee Profile
description: Retrieve employee profile information by ID
language: sql
mime_type: application/json
tags:
- hr
- employee
parameters:
- name: employee_id
type: integer
description: The employee's unique identifier
minimum: 1
examples: [1, 42, 100]
return:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
sensitive: true
department:
type: string
hire_date:
type: string
format: date
source:
file: ../sql/get_employee_profile.sql
policies:
input:
- condition: "user.role == 'guest'"
action: deny
reason: "Guests cannot access employee profiles"
output:
- condition: "user.role != 'hr'"
action: filter_sensitive_fields
reason: "Sensitive data restricted to HR"
tests:
- name: get_existing_employee
arguments:
- key: employee_id
value: 1
result_contains:
id: 1
name: "Alice"
enabled: true
FieldTypeRequiredDefaultDescription
mxcpintegerYes-Schema version. Must be 1.
resourceobjectYes-Resource definition object.
metadataobjectNo-Custom metadata (not processed by MXCP).

Note: The mxcp field accepts both integer (1) and string ("1") values - strings are automatically coerced to integers.

FieldTypeRequiredDefaultDescription
uristringYes-URI pattern with {param} placeholders.
namestringNo-Human-readable display name.
descriptionstringNo-Human-readable description for AI clients.
languagestringNo"sql"Implementation language: sql or python.
mime_typestringNo-Content type of the resource.
tagsarrayNo-List of tags for categorization.
parametersarrayNo-URI parameter definitions.
returnobjectNo-Return type definition.
sourceobjectYes-Implementation source (code or file).
policiesobjectNo-Input and output policy rules.
testsarrayNo-Test case definitions.
enabledbooleanNotrueWhether the resource is enabled.

Resources are accessed via URI patterns with parameter placeholders.

uri: "user://{user_id}"
uri: "org://{org_id}/team/{team_id}/member/{member_id}"
  • Use {param_name} for parameter placeholders
  • Parameter names must match entries in the parameters array
  • All parameters must be used in the URI - parameters not in the URI will cause validation errors (use a tool instead if you need extra parameters)
  • Use hierarchical paths for nested resources
  • Avoid query strings (use parameters instead)
# Simple resource
uri: "config://settings"
# Single parameter
uri: "user://{user_id}"
# Multiple parameters
uri: "order://{order_id}/item/{item_id}"
# Hierarchical resource
uri: "project://{project_id}/environment/{env_name}/config"

Common MIME types for resources:

MIME TypeUse Case
application/jsonStructured data (default)
text/plainPlain text content
text/markdownMarkdown documents
text/htmlHTML content
application/xmlXML data
text/csvCSV data
resource:
uri: "report://{report_id}"
mime_type: text/markdown
# ...

Each parameter defines a URI placeholder.

FieldTypeRequiredDefaultDescription
namestringYes-Parameter identifier (must match URI placeholder).
typestringYes-Data type: string, integer, number, boolean, array, object.
descriptionstringNo-Human-readable description.
defaultanyNo-Default value (makes parameter optional).
examplesarrayNo-Example values for documentation.
enumarrayNo-Allowed values.
sensitivebooleanNofalseMark as sensitive (for filtering).

String constraints:

FieldTypeDescription
minLengthintegerMinimum string length.
maxLengthintegerMaximum string length.
patternstringRegex pattern to match.
formatstringFormat hint: email, uri, date, time, date-time, duration, timestamp.

Number/Integer constraints:

FieldTypeDescription
minimumnumberMinimum value (inclusive).
maximumnumberMaximum value (inclusive).
exclusiveMinimumnumberMinimum value (exclusive).
exclusiveMaximumnumberMaximum value (exclusive).
multipleOfnumberValue must be multiple of this.

Array constraints:

FieldTypeDescription
itemsobjectType definition for array items.
minItemsintegerMinimum array length.
maxItemsintegerMaximum array length.
uniqueItemsbooleanWhether items must be unique.

Object constraints:

FieldTypeDescription
propertiesobjectMap of property names to type definitions.
requiredarrayList of required property names.
additionalPropertiesbooleanWhether extra (unspecified) object properties are accepted and preserved. Default: true (if omitted). Use false to reject unknown keys.

Note: If additionalProperties is omitted, MXCP treats it as true (extra keys are allowed and preserved). Set additionalProperties: false to forbid unknown keys.

# Allow unknown keys (default behavior)
type: object
properties:
objid:
type: integer
required: ["objid"]
# Forbid unknown keys
type: object
properties:
objid:
type: integer
required: ["objid"]
additionalProperties: false
parameters:
# Required integer parameter
- name: user_id
type: integer
description: User's unique identifier
minimum: 1
# String with pattern
- name: slug
type: string
description: URL-friendly identifier
pattern: "^[a-z0-9-]+$"
minLength: 1
maxLength: 100
# Enum parameter
- name: format
type: string
description: Output format
enum: ["json", "xml", "csv"]
default: "json"

The return type defines the structure of the resource’s content.

return:
type: object
properties:
id:
type: integer
title:
type: string
content:
type: string
metadata:
type: object
properties:
created_at:
type: string
format: date-time
author:
type: string

Same fields as parameters, minus name and default.

The source defines where the implementation lives.

FieldTypeDescription
codestringInline SQL or Python code.
filestringPath to external file (relative to YAML file).
languagestringOverride language detection: sql or python.

Note: Exactly one of code or file must be specified.

source:
code: |
SELECT id, title, content, created_at
FROM documents
WHERE id = $document_id
source:
file: ../sql/get_document.sql

For Python resources, the function name in the Python file must match the resource name (derived from the URI pattern):

resources/user_profile.yml
resource:
uri: "user://{user_id}/profile"
name: user_profile # Function name must match
language: python
source:
file: ../python/profiles.py
python/profiles.py
def user_profile(user_id: int) -> dict:
"""Function name must match resource name."""
return {"id": user_id, "name": "Alice"}

Policies control access and data filtering.

policies:
input:
- condition: "user.role == 'guest'"
action: deny
reason: "Guests cannot access this resource"
output:
- condition: "user.role != 'admin'"
action: filter_fields
fields: ["internal_notes", "audit_log"]
reason: "Internal fields restricted"
FieldTypeRequiredDescription
conditionstringYesCEL expression to evaluate.
actionstringYesAction to take: deny, filter_fields, mask_fields, filter_sensitive_fields.
reasonstringNoHuman-readable reason.
fieldsarrayNoFields to filter/mask (for filter_fields, mask_fields).
ActionTypeDescription
denyinputBlock the request entirely.
filter_fieldsoutputRemove specified fields from response.
mask_fieldsoutputReplace field values with masks.
filter_sensitive_fieldsoutputRemove fields marked sensitive: true.

See Policies for complete documentation.

Tests verify resource behavior.

tests:
- name: get_document_success
description: Successfully retrieves a document
arguments:
- key: document_id
value: 1
result_contains:
id: 1
title: "Welcome"
- name: get_document_not_found
description: Returns null for non-existent document
arguments:
- key: document_id
value: 99999
result: null
- name: admin_sees_internal_fields
description: Admin can see internal fields
arguments:
- key: document_id
value: 1
user_context:
role: admin
result_contains:
internal_notes: "Review scheduled"
FieldTypeRequiredDescription
namestringYesUnique test identifier.
descriptionstringNoHuman-readable description.
argumentsarrayYesInput arguments as key-value pairs.
user_contextobjectNoSimulated user context for policy testing.
FieldTypeDescription
resultanyExpected exact result.
result_containsanyPartial match - fields must exist with values.
result_not_containsarrayField names that must NOT exist.
result_contains_itemobjectFor arrays - at least one item must match.
result_contains_allarrayFor arrays - all items must be present.
result_lengthintegerFor arrays - exact length required.
result_contains_textstringFor strings - must contain substring.

See Testing for complete documentation.

AspectResourceTool
PurposeRetrieve data/contentPerform actions
AccessVia URI patternVia name
SemanticsRead-only by conventionAny operation
Use caseDocuments, configs, profilesCRUD, calculations, API calls
  • Static or semi-static content
  • Document retrieval
  • Configuration access
  • User profiles
  • File content
  • Data modifications
  • Complex calculations
  • External API calls
  • Multi-step operations
  • URI patterns: Use hierarchical paths (e.g., user://{id}/settings)
  • Parameter names: Use snake_case (e.g., user_id, document_slug)
  • File paths: Relative to the YAML file location

Validate your resource definitions:

Terminal window
mxcp validate
mxcp validate resources/my-resource.yml