Lightweight LLM with MCP Integration
This directory contains a lightweight LLM inference service that can connect to external MCP (Model Context Protocol) servers for enhanced capabilities.
ποΈ Quick Setup
Local Development
# Install dependencies
pip install -r requirements.txt
# Run the service
python app.py
# Or use the start script
./start.sh
Docker Deployment
# Build the image
docker build -t lightweight-llm .
# Run the container
docker run -p 8000:8000 \
-e MCP_SERVER_URL=https://your-mcp-server.hf.space \
lightweight-llm
Hugging Face Spaces
- Create a new Space with Docker SDK
- Upload all files from this directory
- Set
app_port: 8000in README.md header - Configure environment variables in Space settings
π‘ API Usage
Basic Inference
curl -X POST http://localhost:8000/ \
-H "Content-Type: application/json" \
-d '{
"inputs": "Hello, how are you?",
"parameters": {"max_new_tokens": 100}
}'
MCP-Enhanced Inference
curl -X POST http://localhost:8000/ \
-H "Content-Type: application/json" \
-d '{
"inputs": "Tell me about product 123",
"parameters": {
"max_new_tokens": 200,
"mcp_server_url": "https://your-mcp-server.hf.space"
}
}'
π§ Configuration
Set these environment variables:
MCP_SERVER_URL: Default MCP server URLMODEL_NAME: Hugging Face model nameMAX_NEW_TOKENS: Default max tokensPORT: Service port (default: 8000)
π§ͺ Testing
Run the test suite:
python test_service.py
π Production Notes
- The current implementation uses a simple text generation placeholder
- For production, integrate with:
- Transformers library with a small model
- vLLM for faster inference
- TensorRT for optimized inference
- Any other inference engine
π MCP Integration
This service automatically detects when to use MCP tools based on keywords in the input. It can connect to any MCP server that implements the standard protocol.
Keywords that trigger MCP usage:
- product, price, stock, inventory
- order, customer, database
- search, find, get, fetch, check
- prestashop, shop, cart, purchase
π Endpoints
POST /- Main inference endpoint (HF compatible)GET /health- Health checkGET /info- Service informationGET /docs- API documentation