Spaces:
Running
title: Mcp Discussion Bot
emoji: π
colorFrom: purple
colorTo: yellow
sdk: gradio
sdk_version: 5.31.0
app_file: app.py
pinned: false
π€ Hugging Face Discussion Bot
A FastAPI and Gradio application that automatically responds to Hugging Face Hub discussion comments using AI-powered responses via Hugging Face Inference API with MCP integration.
β¨ Features
- Webhook Integration: Receives real-time webhooks from Hugging Face Hub when new discussion comments are posted
- AI-Powered Responses: Uses Hugging Face Inference API with MCP support for intelligent, context-aware responses
- Interactive Dashboard: Beautiful Gradio interface to monitor comments and test functionality
- Automatic Posting: Posts AI responses back to the original discussion thread
- Testing Tools: Built-in webhook simulation and AI testing capabilities
- MCP Server: Includes a Model Context Protocol server for advanced tool integration
π Quick Start
1. Installation
# Clone the repository
git clone <your-repo-url>
cd mcp-course-unit3-example
# Install dependencies
pip install -e .
2. Environment Setup
Copy the example environment file and configure your API keys:
cp env.example .env
Edit .env
with your credentials:
# Webhook Configuration
WEBHOOK_SECRET=your-secure-webhook-secret
# Hugging Face Configuration
HF_TOKEN=hf_your_hugging_face_token_here
# Model Configuration (optional)
HF_MODEL=microsoft/DialoGPT-medium
HF_PROVIDER=huggingface
3. Run the Application
python server.py
The application will start on http://localhost:8000
with:
- π Gradio Dashboard:
http://localhost:8000/gradio
- π Webhook Endpoint:
http://localhost:8000/webhook
- π API Documentation:
http://localhost:8000/docs
π§ Configuration
Hugging Face Hub Webhook Setup
- Go to your Hugging Face repository settings
- Navigate to the "Webhooks" section
- Create a new webhook with:
- URL:
https://your-domain.com/webhook
- Secret: Same as
WEBHOOK_SECRET
in your.env
- Events: Subscribe to "Community (PR & discussions)"
- URL:
Required API Keys
Hugging Face Token
- Go to Hugging Face Settings
- Create a new token with "Write" permissions
- Add it to your
.env
asHF_TOKEN
π Dashboard Features
Recent Comments Tab
- View all processed discussion comments
- See AI responses in real-time
- Refresh and filter capabilities
Test HF Inference Tab
- Direct testing of the Hugging Face Inference API
- Custom prompt input
- Response preview
Simulate Webhook Tab
- Test webhook processing without real HF events
- Mock discussion scenarios
- Validate AI response generation
Configuration Tab
- View current setup status
- Check API key configuration
- Monitor processing statistics
π API Endpoints
POST /webhook
Receives webhooks from Hugging Face Hub.
Headers:
X-Webhook-Secret
: Your webhook secret
Body: HF Hub webhook payload
GET /comments
Returns all processed comments and responses.
GET /
Basic API information and available endpoints.
π€ MCP Server
The application includes a Model Context Protocol (MCP) server that provides tools for:
- get_discussions: Retrieve discussions from HF repositories
- get_discussion_details: Get detailed information about specific discussions
- comment_on_discussion: Add comments to discussions
- generate_ai_response: Generate AI responses using HF Inference
- respond_to_discussion: Generate and post AI responses automatically
Running the MCP Server
python mcp_server.py
The MCP server uses stdio transport and can be integrated with MCP clients following the Tiny Agents pattern.
π§ͺ Testing
Local Testing
Use the "Simulate Webhook" tab in the Gradio dashboard to test without real webhooks.
Webhook Testing
You can test the webhook endpoint directly:
curl -X POST http://localhost:8000/webhook \
-H "Content-Type: application/json" \
-H "X-Webhook-Secret: your-webhook-secret" \
-d '{
"event": {"action": "create", "scope": "discussion.comment"},
"comment": {
"content": "@discussion-bot How do I use this model?",
"author": "test-user",
"created_at": "2024-01-01T00:00:00Z"
},
"discussion": {
"title": "Test Discussion",
"num": 1,
"url": {"api": "https://huggingface.co/api/repos/test/repo/discussions"}
},
"repo": {"name": "test/repo"}
}'
ποΈ Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β HF Hub βββββΆβ FastAPI βββββΆβ HF Inference β
β Webhook β β Server β β API β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Gradio β
β Dashboard β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β MCP Server β
β (Tools) β
βββββββββββββββββββ
π Security
- Webhook secret verification prevents unauthorized requests
- Environment variables keep sensitive data secure
- CORS middleware configured for safe cross-origin requests
π Deployment
Using Docker (Recommended)
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -e .
EXPOSE 8000
CMD ["python", "server.py"]
Using Cloud Platforms
The application can be deployed on:
- Hugging Face Spaces (recommended for HF integration)
- Railway
- Render
- Heroku
- AWS/GCP/Azure
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
π License
This project is licensed under the MIT License.
π Support
If you encounter issues:
- Check the Configuration tab in the dashboard
- Verify your API keys are correct
- Ensure webhook URL is accessible
- Check the application logs
For additional help, please open an issue in the repository.