Larks MCP服务器-Python实现
使用FastMCP的Larks MCP服务器的Python实现,由Node.js/TypeScript转换而来。
安装
cd python
pip install -r requirements.txt运行服务器
选项1:使用Docker Compose(推荐)
# Copy .env.example to .env and fill in your credentials
cp .env.example .env
# Edit .env with your credentials
# Build and start the container
docker compose up -d
# View logs
docker compose logs -f
# Stop the container
docker compose down选项2:使用.env文件(本地)
# Copy .env.example to .env and fill in your credentials
cp .env.example .env
# Edit .env with your credentials
# Run the server
python server.py选项3:使用环境变量
# Set environment variables
export LARKS_CLIENT_ID=your_client_id
export LARKS_CLIENT_SECRET=your_client_secret
export MCP_PORT=48080
# Run the server
python server.py备注:环境变量优先于 .env 文件值。
配置
服务器从以下位置加载配置 .env 文件和环境变量(环境变量优先):
LARKS_CLIENT_ID:OAuth应用程序ID(必需)LARKS_CLIENT_SECRET:OAuth应用程序密钥(必需)LARKS_REDIRECT_URI:OAuth重定向类型(默认值:http://localhost:48080/oauth/callback)LARKS_BEARER_TOKEN:直接承载令牌(可选,如果不使用OAuth,则回退)LARKS_DOMAIN:OAuth域(默认值:https://open.larksuite.com)LARKS_API_DOMAIN:API域(默认值:https://open.larksuite.com)MCP_PORT:服务器端口(默认值:48080)MCP_HOST:服务器主机(默认值:0.0.0.0)
光标MCP配置
使用流式HTTP传输:
{
"mcpServers": {
"larks-docs": {
"transport": "streamableHttp",
"url": "http://localhost:48080/mcp"
}
}
}单独启动服务器:
python server.py码头工人
塑造形象
docker build -t larks-mcp-python .使用Docker Compose运行
# Start the service
docker compose up -d
# View logs
docker compose logs -f larks-mcp-python
# Stop the service
docker compose downDocker中的环境变量
您可以通过多种方式提供环境变量:
- 通过docker-compose.yml (推荐给Docker):
environment:
- LARKS_CLIENT_ID=your_client_id
- LARKS_CLIENT_SECRET=your_client_secret- 通过.env文件 (按体积安装):
volumes:
- ./.env:/app/.env:ro- 通过主机环境变量:
export LARKS_CLIENT_ID=your_client_id
export LARKS_CLIENT_SECRET=your_client_secret
docker compose up -d特性
- ✅ 流式HTTP传输(纯HTTP POST,无SSE)
- ✅ OAuth身份验证流程
- ✅ 文档内容提取
- ✅ 与Node.js版本相同的API
- ✅ 环境变量和.env文件配置
- ✅ 自动令牌刷新处理
- ✅ Docker支持Docker编写
与Node.js版本的差异
- 使用FastMCP简化服务器设置
- 异步/等待模式贯穿始终
- Python原生HTTP客户端(httpx)
- 功能相同,Python代码更简洁
- 使用python dotenv来支持.env文件
