Workspaces
Workspaces provide isolated environments within a single mockd instance. Each workspace has its own mocks, stateful resources, request logs, and custom operations — completely independent from other workspaces.
When to Use Workspaces
Section titled “When to Use Workspaces”- Multi-tenant testing — simulate different customer environments side by side
- Environment isolation — separate dev, staging, and QA mock configurations
- Parallel test runs — each test suite gets its own workspace so tests don’t interfere
- Team collaboration — teammates work on different API mocks without conflicts
Creating Workspaces
Section titled “Creating Workspaces”# Create a workspacemockd workspace create -n "Payment API" -d "Stripe mock environment"
# Create and switch to it immediatelymockd workspace create -n "Payment API" --use{ "action": "create", "name": "Payment API" }Admin API
Section titled “Admin API”curl -X POST http://localhost:4290/workspaces \ -H "Content-Type: application/json" \ -d '{"name": "Payment API", "description": "Stripe mock environment"}'Switching Workspaces
Section titled “Switching Workspaces”Once created, switch to a workspace so all subsequent commands target it:
# Switch to a workspace (persists in context config)mockd workspace use ws_abc123
# Verify current workspacemockd workspace showThe active workspace is saved in ~/.config/mockd/contexts.yaml and persists across terminal sessions.
Workspace Scoping
Section titled “Workspace Scoping”When a workspace is active, all operations are scoped to it:
| Resource | Scoped? | Details |
|---|---|---|
| Mocks | Yes | Each workspace has its own set of mocks |
| Stateful tables/resources | Yes | Data stores are independent per workspace |
| Request logs | Yes | Logs are filtered by workspace |
| Custom operations | Yes | Operations are registered per workspace |
| Import/Export | Yes | Imports go into the active workspace; exports come from it |
| Chaos config | No | Chaos injection is global across all workspaces |
The --workspace Flag
Section titled “The --workspace Flag”Instead of switching the persistent workspace, you can scope a single command with the --workspace flag:
# List mocks in a specific workspace without switchingmockd list --workspace ws_abc123
# Import into a specific workspacemockd import openapi.yaml --workspace ws_abc123
# Export from a specific workspacemockd export --workspace ws_abc123 -o mocks.yaml
# View logs for a specific workspacemockd logs --workspace ws_abc123This flag is available on every CLI command as a global flag.
Environment Variable
Section titled “Environment Variable”Set MOCKD_WORKSPACE to scope all commands to a workspace without using --workspace on every call:
export MOCKD_WORKSPACE=ws_abc123mockd list # scoped to ws_abc123mockd import ... # scoped to ws_abc123Resolution Order
Section titled “Resolution Order”When multiple sources specify a workspace, mockd uses this priority:
--workspaceflag (highest priority)MOCKD_WORKSPACEenvironment variable- Context config (
mockd workspace use) - Default workspace (no workspace — global scope)
Listing and Managing Workspaces
Section titled “Listing and Managing Workspaces”# List all workspacesmockd workspace list
# Output:# CURRENT ID NAME BASE PATH TYPE DESCRIPTION# * ws_abc123 Payment API / local Stripe mock environment# ws_def456 Comms API / local Twilio mock environment
# Delete a workspacemockd workspace delete ws_def456
# Force delete (skip confirmation)mockd workspace delete ws_def456 --force
# Clear workspace selection (revert to default)mockd workspace clearPractical Examples
Section titled “Practical Examples”Parallel Test Suites
Section titled “Parallel Test Suites”Give each test suite its own workspace so tests can run concurrently without mock collisions:
# In test setupWORKSPACE_ID=$(mockd workspace create -n "test-suite-$RANDOM" --json | jq -r '.id')
# Run tests scoped to this workspaceMOCKD_WORKSPACE=$WORKSPACE_ID pytest tests/
# Teardownmockd workspace delete $WORKSPACE_ID --forceMulti-API Development
Section titled “Multi-API Development”When building against multiple third-party APIs, use separate workspaces to keep configurations clean:
# Stripe mocksmockd workspace create -n "Stripe" --usemockd import stripe-openapi.yaml
# Switch to Twiliomockd workspace create -n "Twilio" --usemockd import twilio-openapi.yaml
# Switch between them as neededmockd workspace use ws_abc123 # back to StripeMCP Workflow
Section titled “MCP Workflow”AI assistants can manage workspaces via the manage_workspace MCP tool:
// List workspaces{ "action": "list" }
// Create a workspace{ "action": "create", "name": "Integration Tests" }
// Switch to a workspace{ "action": "switch", "id": "ws_abc123" }All subsequent manage_mock, manage_state, and import_mocks calls are automatically scoped to the active workspace.
Limitations
Section titled “Limitations”- Chaos config is global. Chaos fault injection (latency, error rates, circuit breakers) applies to all workspaces. You cannot configure chaos per workspace.
- Persistence does not round-trip workspace context. On server restart, persisted mocks retain their
workspaceIdfield, but the active workspace selection (set viamockd workspace use) resets. Re-select withmockd workspace useafter restart. - Port conflicts. If workspaces contain gRPC or MQTT mocks that bind to the same port, only one can be active at a time.
See Also
Section titled “See Also”- CLI Reference: workspace commands
- Admin API: workspace endpoints
- Stateful Mocking — stateful resources are workspace-scoped
- MCP Server —
manage_workspacetool