Content
# code-agent: code reading and terminal execution agent based on mcp
## Project Introduction
This project is an experimental project based on Large Language Model (LLM), Model Context Protocol (MCP), and Retrieval-Augmented Generation (RAG). It demonstrates how to build an AI assistant system that can interact with external tools and utilize retrieval-augmented generation techniques.
Reference project: https://github.com/StrayDragon/exp-llm-mcp-rag
```mermaid
graph TD
%% 核心节点
U[用户]
G[Gradio界面]
S[状态管理]
A[Agent代理]
L[LLM模型]
M[MCP客户端]
Log[日志工具]
%% 主流程
U -->|输入查询/点击发送| G
G -->|获取状态| S
S -->|返回状态数据| G
G -->|初始化/调用| A
A -->|需要模型处理| L
L -->|生成响应/工具调用| A
A -->|需要工具执行| M
M -->|返回工具结果| A
A -->|整理结果| G
G -->|流式展示回复| U
%% 辅助流程
U -->|点击清空| G
G -->|重置历史| S
U -->|点击重置| G
G -->|销毁Agent| S
A -->|记录操作| Log
M -->|记录调用| Log
```
### Core Features
- Large language model calls based on OpenAI API
- LLM interaction with external tools via MCP (Model Context Protocol)
- Uses a third-party MCP server: Desktop Commander
- Supports file system operations, web content retrieval, and terminal command interaction
## Quick Start
### Environment Preparation
1. Make sure Python 3.12 or higher is installed
2. Clone this repository
3. In `.env` and fill in the necessary configuration information:
- `OPENAI_API_KEY`: OpenAI API key
- `OPENAI_BASE_URL`: OpenAI API base URL, be sure to keep '/v1' at the end (defaults to 'https://api.openai.com/v1')
- `DEFAULT_MODEL_NAME`: (Optional) Default model name (defaults to "gpt-4o-mini")
- `EMBEDDING_KEY`: (Optional) Embedding model API key (defaults to $OPENAI_API_KEY)
- `EMBEDDING_BASE_URL`: (Optional) Embedding model API base URL, such as Silicon-based flow API or OpenAI-compatible API (defaults to $OPENAI_BASE_URL)
- `USE_CN_MIRROR`: (Optional) Whether to use the Chinese mirror, set any value (such as '1') to true (defaults to false)
- `PROXY_URL`: (Optional) Proxy URL (such as "http(s)://xxx") for `fetch` (mcp-tool) to go through the proxy
### Install Node.js (including npm, npx, etc.)
Go to the official website to install the latest version
https://nodejs.org/en/blog/release/v20.19.3
### Install the scoop package management tool
```shell
# 安装 scoop
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Invoke-Expression (Invoke-RestMethod -Uri https://get.scoop.sh)
```
### Install the uv package management tool
```bash
# 安装 uv
scoop install main/uv
```
### Install dependencies
```bash
# 使用 uv 安装依赖
uv sync
uv pip install numpy
uv pip install opencv-python
uv pip install matplotlib
uv pip install pillow
```
### Activate the virtual environment
```bash
# 使用 uv 安装依赖
.venv/Scripts/activate
```
### Install desktop-commander
```bash
# 使用 npx 安装依赖
npx -y --verbose @wonderwhy-er/desktop-commander@latest setup --ignore-scripts
```
### Run the example
This project uses the `just` command tool to run different examples:
```bash
# 查看可用命令
just help
```
### Start chatting
```bash
# chat_openai启动
just chat_openai
```
### Start agent
```bash
# agent启动
just agent
```
## Project Structure
- `src/augmented/`: Main source code directory
- `agent.py`: Agent implementation, responsible for coordinating LLM and tools
- `chat_openai.py`: OpenAI API client encapsulation
- `mcp_client.py`: MCP client implementation
- `mcp_tools.py`: MCP tool definition
- `utils/`: Tool functions
- `info.py`: Project information and configuration
- `pretty.py`: Unified log output system
- `justfile`: Task execution configuration file
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.