Skip to content
Star -

Common Tasks

Quick answers to “How do I…?” questions. Each task links to full documentation.

Terminal window
mkdir my-project && cd my-project
mxcp init --bootstrap # Creates example endpoint

Full guide →

Terminal window
mxcp run tool hello_world --param name=Alice

Hello World tutorial →

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
"mcpServers": {
"my-project": {
"command": "mxcp",
"args": ["serve", "--transport", "stdio"],
"cwd": "/path/to/my-project"
}
}
}

Full guide →

tools/my-tool.yml
mxcp: 1
tool:
name: my_tool
description: What this tool does
parameters:
- name: param_name
type: string
description: Parameter description
return:
type: object
source:
file: ../sql/my-tool.sql

SQL endpoints tutorial →

tools/my-tool.yml
mxcp: 1
tool:
name: my_tool
description: What this tool does
language: python
parameters:
- name: param_name
type: string
description: Parameter description
return:
type: object
source:
file: ../python/my_module.py
python/my_module.py
from mxcp.runtime import db
def my_tool(param_name: str) -> dict:
results = db.execute("SELECT * FROM data WHERE name = $name", {"name": param_name})
return {"data": results}

Python endpoints tutorial →

resources/user.yml
mxcp: 1
resource:
uri: users://{id}
description: Get user by ID
parameters:
- name: id
type: integer
description: User ID
return:
type: object
source:
code: "SELECT * FROM users WHERE id = $id"

Endpoints concept →

Add to ~/.mxcp/config.yml:

projects:
my-project:
profiles:
default:
auth:
provider: github
github:
client_id: your_client_id
client_secret: your_client_secret

Authentication guide →

Add input policy:

policies:
input:
- condition: "user.role != 'admin'"
action: deny
reason: "Admin access required"

Policies guide →

Add output policy:

policies:
output:
- condition: "user.role != 'admin'"
action: filter_fields
fields: ["salary", "ssn"]
reason: "Restricted to admins"

Or mark fields as sensitive:

return:
type: object
properties:
ssn:
type: string
sensitive: true

Policies guide →

Add to mxcp-site.yml:

profiles:
default:
audit:
enabled: true
path: audit/logs.jsonl

Query logs:

Terminal window
mxcp log --since 1h
mxcp log --tool my_tool --status error

Auditing guide →

Add tests section to your endpoint YAML:

tests:
- name: basic_test
arguments:
- key: param_name
value: "test_value"
result_contains:
expected_field: "expected_value"

Run tests:

Terminal window
mxcp test

Testing guide →

Terminal window
mxcp run tool my_tool \
--param id=123 \
--user-context '{"role": "admin", "permissions": ["read", "write"]}'

Or in YAML tests:

tests:
- name: admin_access
user_context:
role: admin
arguments:
- key: id
value: 123

Policies guide →

Terminal window
mxcp validate # All endpoints
mxcp validate tools/my_tool.yml # Specific endpoint
mxcp validate --debug # Detailed output

Validation guide →

Terminal window
mxcp lint

Linting guide →

How do I use environment-specific settings?

Section titled “How do I use environment-specific settings?”

Define profiles in mxcp-site.yml:

profiles:
development:
duckdb:
path: dev.db
audit:
enabled: false
production:
duckdb:
path: /data/prod.db
audit:
enabled: true

Use profile:

Terminal window
mxcp serve --profile production
# or
export MXCP_PROFILE=production

Configuration guide →

Add to ~/.mxcp/config.yml:

projects:
my-project:
profiles:
default:
secrets:
- name: api_key
type: custom
parameters:
value: "secret-value"

Access in Python:

from mxcp.runtime import config
secret = config.get_secret("api_key")
api_key = secret["value"] if secret else None

Configuration guide →

~/.mxcp/config.yml
vault:
enabled: true
address: https://vault.example.com
token_env: VAULT_TOKEN
projects:
my-project:
profiles:
default:
secrets:
- name: db_password
parameters:
password: "vault://secret/database#password"

Configuration guide →

With Docker:

FROM python:3.11-slim
RUN pip install mxcp
COPY . /app
WORKDIR /app
CMD ["mxcp", "serve", "--transport", "streamable-http", "--port", "8000"]

Deployment guide →

Set OpenTelemetry environment variables:

Terminal window
export OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
export OTEL_SERVICE_NAME=mxcp-prod
export MXCP_TELEMETRY_ENABLED=true

Monitoring guide →

How do I reload configuration without restart?

Section titled “How do I reload configuration without restart?”
Terminal window
# Send SIGHUP
kill -HUP $(pgrep -f "mxcp serve")
# Or use admin socket
curl --unix-socket /run/mxcp/mxcp.sock -X POST http://localhost/reload

Admin socket guide →

Terminal window
# Create baseline
mxcp drift-snapshot
# Check for changes
mxcp drift-check

Drift detection guide →

from mxcp.runtime import db
# Execute query
results = db.execute(
"SELECT * FROM users WHERE id = $id",
{"id": 123}
)
# results is a list of dicts
for row in results:
print(row["name"])

Python reference →

Add to mxcp-site.yml:

extensions:
- httpfs
- parquet
- name: h3
repo: community

DuckDB integration →

Enable in mxcp-site.yml:

dbt:
enabled: true
model_paths: ["models"]

Run dbt through MXCP:

Terminal window
mxcp dbt run

dbt integration →

Terminal window
mxcp list # See available endpoints

Check that:

  • File is in tools/ directory
  • enabled: true is set
  • YAML is valid (mxcp validate)
Terminal window
mxcp validate --debug

Check YAML indentation and required fields.

Terminal window
mxcp run tool my_tool --user-context '{"role": "admin"}' --debug

Check policy conditions match user context.

Terminal window
# Ensure virtual environment
source .venv/bin/activate
# Debug
mxcp run tool my_tool --debug

Quickstart →