Skip to main content

Creating Context Provider Extensions

Context providers supply persistent context to the AI model through a QWEN.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 a QWEN.md file in your extension root:

Extension Structure

Configure in Manifest

Update qwen-extension.json:
Note: If you don’t specify 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:
All specified files will be loaded in order.

Example: MCP Server Context

If your extension provides MCP server tools:
Important:
  • 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_tables before querying
  • Use describe_table to 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 the aria-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:
  1. Always consider accessibility first
  2. Suggest using appropriate ARIA attributes
  3. Recommend screen reader detection for complex UIs
  4. Provide examples with accessibility built-in
  5. 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
README.md is for:
  • Human users
  • Installation instructions
  • Extension overview
  • Troubleshooting
Keep them separate and focused on their audiences.

Testing Context

To verify your context is effective:
  1. Link your extension: qwen extensions link .
  2. Start Qwen Code
  3. Ask questions that should trigger your tools/commands
  4. Verify the AI uses them correctly
  5. Refine context based on AI behavior

Context Loading

Context is loaded:
  • On Qwen Code startup
  • When extension is enabled
  • After extension updates
Context is NOT dynamically reloaded during sessions (unlike some other extension features).

Multiple Extensions

If multiple extensions are active, all their context files are loaded. This can increase token usage, so keep context concise.

Next Steps