python-matter-server
Copilot instructions1k starsChanged 15 months agoApache-2.0Archived repositoryView on GitHub
Python Matter Server is an officially certified Software Component that provides Matter controller support. It serves as the foundation for Matter support in Home Assistant and other projects. The server implements a Matter Controller over WebSockets using the official Matter SDK. Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. ALWAYS manually validate changes using complete end-to-end scenarios:
- Installs packages
Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.
Of the Copilot instructions files we read, the 2,336 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
24 rules. About 2 are common, 11 are distinctive, and 11 are very specific to this project.
≈2
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 19
NETWORK ISSUE: If pip install fails with timeout errors (common with Matter SDK dependencies), this is due to network limitations, not code …
- Distinctive: line 23
Start the Matter server:
- Very specific: line 34
Create /data directory with proper permissions if it doesn't exist
- Very specific: line 94
Start the server: python -m matter_server.server --log-level debug
- Common: line 95
Verify WebSocket endpoint responds (server starts without errors)
- Very specific: line 96
Check dashboard is accessible if built: verify matter_server/dashboard/ contains files
- Very specific: line 97
Test example client: python scripts/example.py (requires dependencies)
- Very specific: line 101
Verify build artifacts: check matter_server/dashboard/js/ contains compiled JavaScript
- Very specific: line 102
Start development server: cd dashboard && script/develop
- Distinctive: line 104
Test WebSocket connection input (should prompt for server URL)
- Distinctive: line 107
CRITICAL: Always run before pushing changes or CI will fail:
- Very specific: line 152
Use pip install --timeout 300 for extended timeout
- Distinctive: line 153
Document as known issue: if persistent
- Distinctive: line 160
No multicast filtering on network equipment
- Very specific: line 176
SOLUTION: Run scripts/setup.sh first to install Python dependencies
- Very specific: line 181
Use scripts/run-in-env.sh for consistent tool execution across environments
- Distinctive: line 193
Always ensure pre-commit passes locally: before pushing to avoid CI failures
- Distinctive: line 208
CRITICAL: All code changes MUST pass linting checks before submitting PRs.
- Distinctive: line 212
Always run these commands before committing and pushing changes:
- Distinctive: line 237
Trailing Whitespace: Remove all trailing spaces from lines
- Distinctive: line 238
Missing Newline: Ensure files end with a single newline character
- Very specific: line 239
Import Order: Use ruff format to fix import sorting
- Distinctive: line 240
Type Annotations: Add type hints where mypy reports missing annotations
- Very specific: line 241
Spelling: Use codespell to check for typos in code and comments
≈ “Common” is an estimate: at least 1 in 5 of the 3,779 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Matter Server
Python Matter Server is an officially certified Software Component that provides Matter controller support. It serves as the foundation for Matter support in Home Assistant and other projects. The server implements a Matter Controller over WebSockets using the official Matter SDK.
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
Working Effectively
Bootstrap and Setup
- CRITICAL: Matter Server requires Linux or macOS with specific IPv6 networking configuration. Windows/WSL is NOT supported.
- Set up the complete development environment:
scripts/setup.sh- Creates Python virtual environment in
.venv/ - Installs Python dependencies including Matter SDK components
- Installs pre-commit hooks for code quality
- TIMING: Typically takes 3-5 minutes. NEVER CANCEL - wait up to 10 minutes for completion.
- NETWORK ISSUE: If pip install fails with timeout errors (common with Matter SDK dependencies), this is due to network limitations, not code issues.
- Creates Python virtual environment in
Python Server Development
- Always run the bootstrapping steps first before any Python development
- Start the Matter server:
# Basic server (info log level) python -m matter_server.server # Debug mode python -m matter_server.server --log-level debug # SDK debug mode python -m matter_server.server --log-level-sdk progress - Create
/datadirectory with proper permissions if it doesn't exist - Server runs on port 5580 by default (WebSocket endpoint)
- Alternative entry point:
python main.py
Dashboard Development
- Dashboard setup (requires Python dependencies to be available):
cd dashboard script/setup- Runs
npm install(~15 seconds) - Generates descriptions file from Python source
- TIMING: ~30 seconds total. NEVER CANCEL - set timeout to 2+ minutes.
- Runs
- Development server:
cd dashboard script/develop- Starts TypeScript compiler in watch mode
- Starts development server on http://localhost:5010
- Live reload for development changes
- TIMING: Starts in ~5 seconds
- Production build:
cd dashboard script/build- Builds optimized TypeScript/JavaScript bundle
- Copies build to
matter_server/dashboard/directory - TIMING: ~10 seconds. NEVER CANCEL - set timeout to 2+ minutes.
Testing and Code Quality
- Run complete test suite:
scripts/run-in-env.sh pytest --durations 10 --cov-report term-missing --cov=matter_server --cov-report=xml tests/- TIMING: Typically 2-3 minutes. NEVER CANCEL - set timeout to 10+ minutes.
- Pre-commit validation (REQUIRED before commits):
SKIP=no-commit-to-branch pre-commit run --all-files- Runs ruff (linting + formatting), pylint, mypy, codespell, and other checks
- TIMING: 1-2 minutes for all files. NEVER CANCEL - set timeout to 5+ minutes.
- Individual linting tools:
scripts/run-in-env.sh ruff check --fix scripts/run-in-env.sh ruff format scripts/run-in-env.sh pylint matter_server/ tests/ scripts/run-in-env.sh mypy
Validation Scenarios
ALWAYS manually validate changes using complete end-to-end scenarios:
Python Server Validation
- Start the server:
python -m matter_server.server --log-level debug - Verify WebSocket endpoint responds (server starts without errors)
- Check dashboard is accessible if built: verify
matter_server/dashboard/contains files - Test example client:
python scripts/example.py(requires dependencies)
Dashboard Validation
- Build dashboard:
cd dashboard && script/build - Verify build artifacts: check
matter_server/dashboard/js/contains compiled JavaScript - Start development server:
cd dashboard && script/develop - Access http://localhost:5010 and verify dashboard loads
- Test WebSocket connection input (should prompt for server URL)
Pre-commit Validation
CRITICAL: Always run before pushing changes or CI will fail:
SKIP=no-commit-to-branch pre-commit run --all-filesRepository Structure
Key Directories
matter_server/ # Main Python package
├── client/ # Matter client library
├── server/ # Matter server implementation
├── common/ # Shared utilities
└── dashboard/ # Built web dashboard (auto-generated)
dashboard/ # Dashboard source code (TypeScript/Lit)
├── src/ # TypeScript source files
├── script/ # Build and development scripts
└── public/ # Static assets
scripts/ # Development utilities
├── setup.sh # Main environment setup
├── example.py # Server/client example
└── generate_descriptions.py # Generates dashboard type definitions
tests/ # Test suite (pytest-based)
docs/ # Documentation
├── os_requirements.md # Operating system setup requirements
├── docker.md # Docker deployment guide
└── websockets_api.md # WebSocket API documentationImportant Files
pyproject.toml- Python packaging and tool configurationmain.py- Alternative server entry point.pre-commit-config.yaml- Code quality hooks configurationDEVELOPMENT.md- Detailed development setup guide
Common Issues and Solutions
Network Timeouts During Setup
SYMPTOM: pip install fails with ReadTimeoutError from PyPI
CAUSE: Matter SDK dependencies are large and can timeout on slow connections
SOLUTION:
- Retry setup:
scripts/setup.sh - Use
pip install --timeout 300for extended timeout - Document as known issue if persistent
IPv6/Networking Issues
SYMPTOM: Matter devices not discoverable or connection failures
REFERENCE: See docs/os_requirements.md for complete networking requirements
KEY REQUIREMENTS:
- IPv6 support enabled on host interface
- No multicast filtering on network equipment
- Proper ICMPv6 Router Advertisement processing
- For Thread devices: specific kernel options and sysctl settings
Pre-commit Hook Failures
SYMPTOM: Git commits rejected due to formatting/linting issues SOLUTION:
SKIP=no-commit-to-branch pre-commit run --all-files
scripts/run-in-env.sh ruff format # Fix formatting
scripts/run-in-env.sh ruff check --fix # Fix linting issuesDashboard Build Issues
SYMPTOM: script/setup fails with "No module named 'chip'"
CAUSE: Python Matter SDK dependencies not installed
SOLUTION: Run scripts/setup.sh first to install Python dependencies
Development Tips
- Always activate virtual environment:
source .venv/bin/activate - Use
scripts/run-in-env.shfor consistent tool execution across environments - Dashboard development can proceed independently once built once
- Server requires
/datadirectory for persistent storage - Matter protocol requires specific OS and network configuration (see
docs/os_requirements.md) - Example usage patterns available in
scripts/example.py - WebSocket API documentation in
docs/websockets_api.md
CI/CD Integration
The project uses GitHub Actions (.github/workflows/test.yml):
- Linting: pre-commit hooks on Python 3.12
- Testing: pytest on Python 3.12 and 3.13
- Always ensure pre-commit passes locally before pushing to avoid CI failures
Project Context
This project implements both server and client components:
- Server: Runs Matter Controller with WebSocket API
- Client: Python library for consuming the WebSocket API (used by Home Assistant)
- Dashboard: Web-based debugging and testing interface
- Architecture: Allows multiple consumers to connect to same Matter fabric
- Deployment: Available as Home Assistant add-on, Docker container, or standalone
The separation enables scenarios where the Matter fabric continues running while consumers (like Home Assistant) restart or disconnect.
Linting and Code Quality Requirements
CRITICAL: All code changes MUST pass linting checks before submitting PRs. The CI will fail if linting issues are present.
Required Linting Steps Before PR Submission
Always run these commands before committing and pushing changes:
# Run all pre-commit checks (REQUIRED)
SKIP=no-commit-to-branch pre-commit run --all-files
# Individual linting tools for troubleshooting
scripts/run-in-env.sh ruff check --fix # Fix linting issues
scripts/run-in-env.sh ruff format # Fix formatting
scripts/run-in-env.sh pylint matter_server/ tests/ # Check code quality
scripts/run-in-env.sh mypy # Check type annotationsLinting Tools Used
The project uses multiple linting tools enforced via pre-commit hooks:
- ruff: Fast Python linter and formatter (replaces flake8, isort, etc.)
- pylint: Static code analysis for code quality
- mypy: Static type checking
- codespell: Spell checking for code and documentation
- File format checks: JSON, TOML validation, trailing whitespace, end-of-file fixers
Common Linting Failures
Trailing Whitespace: Remove all trailing spaces from lines
Missing Newline: Ensure files end with a single newline character
Import Order: Use ruff format to fix import sorting
Type Annotations: Add type hints where mypy reports missing annotations
Spelling: Use codespell to check for typos in code and comments
Automated Fixing
Most linting issues can be automatically fixed:
scripts/run-in-env.sh ruff check --fix # Auto-fix many linting issues
scripts/run-in-env.sh ruff format # Auto-format codeAlways verify changes after auto-fixing and run the full pre-commit suite before submitting.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

