Creating Context Provider Extensions
Context providers supply persistent context to the AI model through aQWEN.md file included in your extension. This context is loaded in every session where the extension is active, allowing you to provide instructions, documentation, or domain knowledge.
What are Context Providers?
Context providers:- Supply Markdown content loaded into system context
- Are always available to the AI in sessions
- Describe tools, commands, and capabilities
- Provide instructions and guidelines
- Document domain-specific knowledge
When to Use Context
Use context files when you need to:- Explain Extension Tools: Describe when and how to use your MCP server tools
- Provide Instructions: Give the AI guidelines for working with your extension
- Document Conventions: Share project-specific patterns or standards
- Supply Domain Knowledge: Add specialized information relevant to your extension
- Guide Behavior: Influence how the AI responds when using your extension
Context File Format
Create aQWEN.md file in your extension root:
Extension Structure
Configure in Manifest
Updateqwen-extension.json:
contextFileName but a QWEN.md file exists in your extension directory, it will be loaded automatically.
Multiple Context Files
You can specify multiple context files:Example: MCP Server Context
If your extension provides MCP server tools:- Always use parameterized queries
- Be cautious with DELETE/UPDATE operations
- Verify table names before querying
list_tables
Lists all available tables in the database. When to use:- User asks what data is available
- Need to discover database schema
- Before querying unknown tables
describe_table
Provides schema information for a specific table. When to use:- Need to know column names and types
- Before constructing complex queries
- User asks about table structure
Guidelines
- Always verify table existence with
list_tablesbefore querying - Use
describe_tableto understand schema before complex queries - Limit query results appropriately to avoid overwhelming responses
- Explain query results in user-friendly language
- Suggest optimizations for slow queries
Safety
- Never execute DELETE or DROP operations without explicit user confirmation
- Always use LIMIT clauses for SELECT queries
- Validate user input before incorporating into queries
Example: Domain Knowledge Context
Leverage ARIA Props
For components that have a specific role (e.g., a checkbox or a button), use thearia-role, aria-state, and aria-label props on <Box> and <Text> to provide semantic meaning to screen readers.
Guidelines for This Extension
When the user asks for help building CLI components:- Always consider accessibility first
- Suggest using appropriate ARIA attributes
- Recommend screen reader detection for complex UIs
- Provide examples with accessibility built-in
- Explain why accessibility matters
Common Patterns
Accessible Input
Accessible Buttons
Status Messages
2. Include Examples
Show how to use tools and commands:3. Document Constraints
Explain limitations and requirements:4. Provide Context
Help the AI understand when to use your extension:5. Keep It Concise
Context consumes tokens. Be comprehensive but concise:Context vs Documentation
Context (QWEN.md) is for:- Information the AI needs during sessions
- Tool usage instructions
- Behavioral guidelines
- Domain knowledge
- Human users
- Installation instructions
- Extension overview
- Troubleshooting
Testing Context
To verify your context is effective:- Link your extension:
qwen extensions link . - Start Qwen Code
- Ask questions that should trigger your tools/commands
- Verify the AI uses them correctly
- Refine context based on AI behavior
Context Loading
Context is loaded:- On Qwen Code startup
- When extension is enabled
- After extension updates
Multiple Extensions
If multiple extensions are active, all their context files are loaded. This can increase token usage, so keep context concise.Next Steps
- Creating Extensions - Build a complete extension
- MCP Servers - Add custom tools
- Commands - Create custom commands
- Best Practices - Extension development guidelines
