Qwen3-Qwen Agent-MCP Development
1. Introduction
Qwen-Agent is Alibaba's agent development framework based on Qwen3. It supports tool invocation and MCP integration, helping developers build AI applications with task-planning capability. MCP is a standardized protocol that decouples large models from external tools.
1. Features
- Enhanced tool-calling capability: the agent can automatically call built-in tools (code interpreter, browser assistant) and custom tools; Function Calling extends the functional boundary.
- Standardized MCP integration: integrates the MCP tool-access workflow; you only need to configure MCP parameters to call external tools (e.g. databases, APIs), reducing development cost.
- Task planning and context memory: automatically breaks down user requirements into execution steps while preserving dialogue state for a coherent interaction experience.
- Long-text handling and RAG integration: relying on the retrieval-augmented generation mechanism, supports long documents from 8K up to 1 million tokens, improving context-understanding efficiency via chunked retrieval.
- UI frontend interaction support: provides visual interface components that improve human-computer interaction and facilitate multi-turn dialogue and result display.
2. Running Steps
1. Qwen-Agent integrates mcp-server-sqlite
1.1 Import the relevant packages and initialize the Assistant class, and connect to the mcp-server-sqlite MCP server. To integrate MCP, you first need to define a tools array holding the MCP server configuration in JSON Schema format. You need to install the Cline plugin in VS Code and check Use MCP servers in Cline to ensure the MCP Server feature works, and you must ensure node.js is installed (the latest version is required).
1.2 Connect Cline to the MCP Server. First click Cline in VS Code, then click the MCP Servers icon, then click the small icon next to the plus sign in the upper right corner. After entering the new interface, click to edit the MCP Servers configuration file. The flow is shown below:


1.3 Import the relevant configuration at the MCP Servers configuration file:
from qwen_agent.agents import Assistant
from qwen_agent.utils.output_beautify import typewriter_print
def init_agent_service():
llm_cfg={
'model': 'qwen3-235b-a22b',
'model_server': 'dashscope',
'api_key': '你的api_key',
'generate_cfg':{
'top_p': 0.8
}
}
# 定义MCP服务配置,优点类似Function Calling调用的JSON Schema格式
tools = [{
"mcpServers": {
"sqlite": {
"command": "uvx",
"args": [
"mcp-server-sqlite",
"--db-path",
"test.db"
]
}
}
}]
bot = Assistant(
llm=llm_cfg,
name='数据库管理员',
description='你是一位数据库管理员,具有对本地数据库的增删改查能力',
system_message='你扮演一个数据库助手,你具有查询数据库的能力',
function_list=tools,
)
return bot2. Python Example
2.1 In VS Code, define the database assistant and construct a prompt so that Qwen-Agent helps us create a students table and add some data.
from qwen_agent.agents import Assistant
from qwen_agent.utils.output_beautify import typewriter_print
def init_agent_service():
llm_cfg={
'model': 'qwen3-235b-a22b',
'model_server': 'dashscope',
'api_key': '你的api_key',
'generate_cfg':{
'top_p': 0.8
}
}
# 定义MCP服务配置,优点类似Function Calling调用的JSON Schema格式
tools = [{
"mcpServers": {
"sqlite": {
"command": "uvx",
"args": [
"mcp-server-sqlite",
"--db-path",
"test.db"
]
}
}
}]
bot = Assistant(
llm=llm_cfg,
name='数据库管理员',
description='你是一位数据库管理员,具有对本地数据库的增删改查能力',
system_message='你扮演一个数据库助手,你具有查询数据库的能力',
function_list=tools,
)
return bot
def run_query(query=None):
# 定义数据库助手
bot = init_agent_service()
# 执行对话逻辑
messages = []
messages.append({'role': 'user', 'content': [{'text': query}]})
# 跟踪前一次的输出,用于增量打印
previous_text = ""
print('数据库管理员: ', end='', flush=True)
for response in bot.run(messages):
previous_text = typewriter_print(response, previous_text)
if __name__ == '__main__':
query = '帮我创建一个学生表,表名是students,包含id, name, age, gender, score字段,然后插入一条数据,id为1,name为张三,age为20,gender为男,score为95'
run_query(query)After executing the code, uvx detects that some dependency libraries are not installed and automatically installs the required dependencies. After the relevant dependencies are installed, Qwen-Agent detects that the user request asks to create a students table and insert data; the Qwen3 model generates a thinking process based on its understanding of the mcp-server-sqlite server functions, uses sqlite-create_table to create the table, and uses sqlite-write_query to insert data.
2.2 After the program runs, you will find an additional database file named test.db in the local directory.

This shows that Qwen-Agent successfully created the data table and inserted data. The hands-on of using the Qwen3 series large model and the Qwen-Agent tool to quickly integrate an MCP server and develop an AI Agent is now complete.
