Qwen CodeΒΆ
Building AI Scientists with Qwen Code and ToolUniverse

OverviewΒΆ
Qwen Code is a coding agent CLI that can query and edit large codebases and automate workflows. Integrated with the Model Context Protocol (MCP), it can connect to ToolUniverse to power evidence-based scientific research from your terminal.
ββββββββββββββββ
β Qwen Code β β Command Line Interface & Reasoning
β β
ββββββββ¬ββββββββ
β MCP Protocol
β
ββββββββΌββββββββ
β ToolUniverse β β MCP Server
β MCP Server β
ββββββββ¬ββββββββ
β
ββββββββΌββββββββ
β 600+ Scientific Tools β
βββββββββββββββββββββββββ
Benefits of Qwen Code Integration:
Command-Line Efficiency: Scriptable, terminal-first scientific workflows
Advanced Reasoning: Qwen Coder models optimized for code and tooling
Comprehensive Tools: Access 600+ scientific tools via ToolUniverse
Automated Execution: Natural language to tool execution
Batch Processing: Efficient multi-task research
PrerequisitesΒΆ
Before setting up Qwen Code integration, ensure you have:
Qwen Code: Installed and runnable (qwen βversion)
ToolUniverse: Installed
UV Package Manager: For running the MCP server
System Requirements: macOS, Windows, or Linux with Python 3.10+
API Keys: For tools and optional summarization hooks
Installation and SetupΒΆ
Command LegendΒΆ
System terminal (your shell: zsh/bash): run installation and file editing commands
Qwen Code prompt (inside qwen): run slash commands like
/mcp
,/stats
,/memory show
Step 1: Install Qwen CodeΒΆ
You can install Qwen Code via npm or Homebrew.
# From npm (requires Node.js >= 20)
npm install -g @qwen-code/qwen-code@latest
qwen --version
# Or install from source
git clone https://github.com/QwenLM/qwen-code.git
cd qwen-code
npm install
npm install -g .
# Or install with Homebrew (macOS/Linux)
brew install qwen-code
For details, see the official repository Qwen Code on GitHub.
Step 2: Install ToolUniverseΒΆ
pip install tooluniverse
Verify installation:
python -c "import tooluniverse; print('ToolUniverse installed successfully')"
Step 3: Locate Qwen Code ConfigurationΒΆ
Qwen Code reads settings from a home directory config at ~/.qwen/settings.json
or from a project-local .qwen/settings.json
.
Create or open your settings file:
# Global configuration
mkdir -p ~/.qwen
vim ~/.qwen/settings.json
# Or project-specific configuration
mkdir -p .qwen
vim .qwen/settings.json
Note: These commands are run in your system terminal.
Step 4: Configure ToolUniverse MCP ServerΒΆ
Add the ToolUniverse MCP server configuration to your Qwen settings settings.json
.
Note: Edit the JSON in your system terminal/editor.
Basic Configuration:
{
"mcpServers": {
"tooluniverse": {
"command": "uv",
"args": [
"--directory",
"/path/to/your/qwen_running_env",
"run",
"tooluniverse-smcp-stdio"
]
}
}
}
Optimized Configuration for Research Users (Recommended):
{
"mcpServers": {
"tooluniverse": {
"command": "uv",
"args": [
"--directory",
"/path/to/your/qwen_running_env",
"run",
"tooluniverse-smcp-stdio",
"--exclude-tool-types",
"PackageTool",
"--hook-type",
"SummarizationHook"
],
"env": {
"AZURE_OPENAI_API_KEY": "your-azure-openai-api-key",
"AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com"
}
}
}
}
Configuration Benefits:
--exclude-tool-types PackageTool
: Saves context if you donβt need coding package tools--hook-type SummarizationHook
: Summarizes long outputs to fit contextAZURE_OPENAI_*
: Required for SummarizationHook
Important Notes:
Replace
/path/to/your/qwen_running_env
with the absolute path to your Qwen working folderPrefer absolute paths for reliability
Step 5: Configure Context File (QWEN.md)ΒΆ
You can provide project-specific research instructions to Qwen Code using a context file.
Create QWEN.md in your project root:
vim QWEN.md
Add ToolUniverse-specific context:
# ToolUniverse Scientific Research Project ## General Instructions - Use ToolUniverse's scientific tools ecosystem for evidence-based research - Prefer tools from the `tooluniverse` MCP server first - Cross-validate findings across multiple sources - Use appropriate scientific terminology
Step 6: Start Qwen Code and Verify MCPΒΆ
Start Qwen Code:
qwen
Note: Run this in your system terminal.
Verify MCP Server Connection:
In the Qwen Code prompt, run:
/mcp
Verify context loading:
Enter In the Qwen Code prompt, run:
/memory show
For authentication methods (OAuth and API keys), see: Authorization (Qwen Code README).
This will display connection status, available ToolUniverse tools, configuration details, and any errors.
Step 7: Verify IntegrationΒΆ
Try these prompts inside Qwen Code:
List available tools:
What scientific tools are available?
Execute a simple tool:
Search for information about Alzheimer's disease
Perform literature search:
Find recent papers about CRISPR gene editing in cancer therapy
Scientific Research CapabilitiesΒΆ
Drug Discovery and DevelopmentΒΆ
With ToolUniverse, Qwen Code supports comprehensive drug discovery workflows:
Target Identification: - Disease analysis and EFO ID lookup - Target discovery and validation - Literature-based assessment
Drug Analysis: - Drug information retrieval - Safety profile analysis - Drug interaction checking - Clinical trial data access
Genomics and Molecular BiologyΒΆ
Access genomics tools for molecular research:
Gene Analysis: - Gene information from UniProt - Protein structure analysis - Expression patterns and pathways
Molecular Interactions: - Protein-protein and drug-target interactions - Pathway analysis and functional annotation
Literature Research and AnalysisΒΆ
Perform literature search and analysis:
Literature Search: - PubMed, Europe PMC, Semantic Scholar - Citation analysis and filtering
Content Analysis: - Abstract summarization and key finding extraction - Trend analysis and gap identification
Settings and ConfigurationΒΆ
Tool Selection StrategiesΒΆ
Optimize tool usage:
Selective Tool Loading:
{
"mcpServers": {
"tooluniverse": {
"command": "uv",
"args": [
"--directory",
"/path/to/your/qwen_running_env",
"run",
"tooluniverse-smcp-stdio"
],
"includeTools": [
"EuropePMC_search_articles",
"ChEMBL_search_similar_molecules",
"openalex_literature_search",
"search_clinical_trials"
]
}
}
}
Multiple MCP ServersΒΆ
Run multiple ToolUniverse instances for different purposes:
{
"mcpServers": {
"tooluniverse-research": {
"command": "uv",
"args": [
"--directory",
"/path/to/your/qwen_running_env",
"run",
"tooluniverse-smcp-stdio"
],
"timeout": 30000
},
"tooluniverse-analysis": {
"command": "uv",
"args": [
"--directory",
"/path/to/your/qwen_running_env",
"run",
"tooluniverse-smcp-stdio"
],
"timeout": 45000
}
}
}
TroubleshootingΒΆ
Common Issues and SolutionsΒΆ
MCP Server Not Loading:
- Verify ToolUniverse installation path
- Check UV package manager installation
- Ensure proper JSON syntax in configuration
- Use /stats
to confirm session info and limits
No Tools Discovered:
- Verify the ToolUniverse MCP server is working
- Check if your includeTools
or excludeTools
filter is too restrictive
- Ensure all ToolUniverse dependencies are installed
Tools Not Executing:
- Check your env
configuration for needed API keys
- Verify network connectivity
- Increase the timeout
value
Debug and Session ManagementΒΆ
Qwen Code provides built-in session commands:
/compress
: Compress conversation history to stay within token limits/clear
: Clear history and start fresh/stats
: Show current session token usage and limits
Authentication OptionsΒΆ
Qwen Code supports multiple authentication methods.
1. Qwen OAuth (Recommended)
Start Qwen Code and follow the browser-based login.
qwen
Benefits include generous free-tier quotas and automatic credential management. See Qwen Code on GitHub.
2. OpenAI-Compatible API
Configure environment variables or a project .env
file:
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="your_api_endpoint"
export OPENAI_MODEL="your_model_choice"
For regional guidance and provider options (Bailian, ModelScope, ModelStudio, OpenRouter), refer to the repository docs: Qwen Code on GitHub.
TipsΒΆ
Tool Selection: Use includeTools
to load only necessary tools.
Status Check: Use /mcp
to confirm server status and available tools.
Session Control: Use /compress
and /stats
to manage token usage.
ReferencesΒΆ
Qwen Code repository: https://github.com/QwenLM/qwen-code