需求管理顾问客户端

一个连接远程MCP服务器的需求管理指导工具,提供多LLM支持的聊天界面。

  • by arthurfantaci
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 arthurfantaci/requirements-advisor-client

使用说明

需求顾问客户端

MCP客户端web应用程序,用于需求管理指导。连接到远程MCP服务器,并提供具有多LLM支持的聊天界面。

特性

  • 多LLM支持:克劳德、GPT-4o和双子座通过LiteLLM
  • MCP集成:使用流式HTTP传输连接到远程MCP服务器
  • 主题聚焦:严格的系统提示确保响应保持在需求管理主题上
  • 聊天界面:基于流媒体的用户界面,带有对话历史记录
  • 会话保持:PostgreSQL/SQLite存储聊天记录
  • Docker支持:开发和生产的多阶段构建
  • 综合测试:具有异步支持和覆盖率的pytest

建筑

┌─────────────────────┐     REST API      ┌─────────────────────┐
│  Streamlit Frontend │ ←───────────────→ │   FastAPI Backend   │
│  (port 8501)        │                   │   (port 8000)       │
│  - Chat UI          │                   │   - MCP Client      │
│  - Session state    │                   │   - LLM Integration │
│  - Custom styling   │                   │   - Session storage │
└─────────────────────┘                   └─────────────────────┘
                                                   │
                                                   ▼
                                         ┌─────────────────────┐
                                         │   MCP Server        │
                                         │   (Railway)         │
                                         │   /mcp endpoint     │
                                         └─────────────────────┘

项目结构

requirements-advisor-client/
├── src/requirements_advisor_client/
│   ├── backend/              # FastAPI application
│   │   ├── main.py           # API endpoints
│   │   ├── config.py         # Pydantic settings
│   │   ├── logging.py        # Loguru setup
│   │   ├── mcp_client.py     # MCP client class
│   │   ├── llm.py            # LiteLLM integration
│   │   ├── models.py         # Pydantic models
│   │   └── database.py       # SQLAlchemy setup
│   └── frontend/             # Streamlit application
│       ├── app.py            # Chat UI
│       ├── config.py         # Frontend settings
│       ├── styles.py         # CSS/branding
│       └── .streamlit/
│           └── config.toml   # Theme configuration
├── tests/                    # pytest test suite
├── Dockerfile                # Multi-stage Docker build
├── docker-compose.yml        # Development setup
├── railway.toml              # Railway deployment config
└── pyproject.toml            # Project configuration

快速开始

先决条件

  • Python 3.11+
  • 紫外线 (推荐)或pip
  • 至少一个LLM提供程序的API密钥

紫外线安装(推荐)

# Clone the repository
git clone https://github.com/arthurfantaci/requirements-advisor-client.git
cd requirements-advisor-client

# Install dependencies
uv sync

# Install dev dependencies
uv sync --all-extras

管道安装

pip install -e ".[dev]"

配置

复制示例环境文件并配置API密钥:

cp .env.example .env

编辑 .env 根据您的配置:

# Required: At least one LLM API key
ANTHROPIC_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-...        # Optional
GOOGLE_API_KEY=...           # Optional

# Optional: Override defaults
MCP_SERVER_URL=https://requirements-advisor-production.up.railway.app/mcp
DATABASE_URL=sqlite+aiosqlite:///./data/sessions.db
LOG_LEVEL=INFO

本地运行

选项1:使用紫外线

# Terminal 1: Start backend
uv run uvicorn requirements_advisor_client.backend.main:app --reload --port 8000

# Terminal 2: Start frontend
uv run streamlit run src/requirements_advisor_client/frontend/app.py --server.port 8501

选项2:使用Docker Compose

# Start both services
docker compose up --build

# Or run in detached mode
docker compose up -d --build

打开http://localhost:8501在您的浏览器中。

发展

运行测试

# Run all tests
uv run pytest

# Run with coverage report
uv run pytest --cov

# Run specific test file
uv run pytest tests/backend/test_mcp_client.py

代码质量

# Run linter
uv run ruff check .

# Run formatter
uv run ruff format .

# Install pre-commit hooks
uv run pre-commit install

类型检查

代码库始终使用类型提示。使用IDE的类型检查器或运行:

uv run pyright src/

码头工人

构建图像

# Build backend
docker build --target backend -t advisor-backend .

# Build frontend
docker build --target frontend -t advisor-frontend .

Docker编写服务

# Start all services
docker compose up

# Start with PostgreSQL (optional)
docker compose --profile postgres up

# Stop services
docker compose down

环境变量

后端

变量 描述 默认值
MCP_SERVER_URL 远程MCP服务器URL https://requirements-advisor-production.up.railway.app/mcp
DATABASE_URL 数据库连接字符串 sqlite+aiosqlite:///./data/sessions.db
BACKEND_HOST 服务器绑定地址 0.0.0.0
BACKEND_PORT 服务器端口 8000
LOG_LEVEL 日志记录级别 INFO
LOG_JSON 以JSON格式输出日志 false
LLM_MAX_ITERATIONS 每个请求的最大工具调用迭代次数 10
ANTHROPIC_API_KEY 无烟煤API密钥 -
OPENAI_API_KEY OpenAI API密钥 -
GOOGLE_API_KEY 谷歌人工智能API密钥 -

前端

变量 描述 默认值
API_URL 后端API URL http://localhost:8000

部署

铁路

这两个服务都配置为使用Dockerfile进行Railway部署。

  1. 创建新的铁路项目
  2. 从存储库根添加后端服务(目标: backend)
  3. 从存储库根添加前端服务(目标: frontend)
  4. 添加PostgreSQL数据库
  5. 配置环境变量:
    • 后端:API密钥+ DATABASE_URL=${{Postgres.DATABASE_URL}}
    • 前端: API_URL=http://${{backend.RAILWAY_PRIVATE_DOMAIN}}:${{backend.PORT}}

API终点

GET /health

健康检查端点。

{
  "status": "healthy",
  "mcp_connected": true,
  "version": "0.1.0"
}

GET /tools

列出可用的MCP工具。

POST /chat

发送聊天消息。

{
  "message": "How do I write good requirements?",
  "provider": "gemini",
  "session_id": null,
  "history": []
}

答复:

{
  "response": "Here are some best practices...",
  "session_id": "abc123",
  "tools_used": []
}

### `GET /history/{session_id}`

Get chat history for a session.

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Install pre-commit hooks (`pre-commit install`)
4. Make your changes
5. Run tests (`pytest`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

## License

MIT