Commit
·
a8cbd11
1
Parent(s):
f613c0d
Submit Gradio MCP Playground - Open-source MCP tools without expensive LLM subscriptions
Browse filesCreated by Sean Poyner and Ranadeep Laskar (
@flickinshots
)
This project democratizes access to MCP technology, allowing developers and enthusiasts to experiment with MCP servers, agents, and LLM-tool integrations while showcasing the powerful features of Gradio.
- README.md +309 -9
- __pycache__/app.cpython-312.pyc +0 -0
- app.py +840 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -1,14 +1,314 @@
|
|
| 1 |
---
|
| 2 |
-
title: Gradio
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
-
license:
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Gradio MCP Playground
|
| 3 |
+
emoji: 🛝
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.31.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
tags:
|
| 12 |
+
- mcp
|
| 13 |
+
- agents
|
| 14 |
+
- gradio
|
| 15 |
+
- hackathon
|
| 16 |
+
short_description: Open-source MCP tools without expensive LLM subscriptions!
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# 🛝 Gradio MCP Playground
|
| 20 |
+
|
| 21 |
+
<div align="center">
|
| 22 |
+
|
| 23 |
+
[](https://huggingface.co/spaces/seanpoyner/gradio-mcp-playground)
|
| 24 |
+
[](https://github.com/seanpoyner/gradio-mcp-playground)
|
| 25 |
+
[](LICENSE)
|
| 26 |
+
[](https://huggingface.co/hackathon)
|
| 27 |
+
|
| 28 |
+
**Open-source access to MCP tools without expensive LLM subscriptions**
|
| 29 |
+
|
| 30 |
+
[Try Demo](https://huggingface.co/spaces/seanpoyner/gradio-mcp-playground) | [Documentation](https://github.com/seanpoyner/gradio-mcp-playground) | [Report Bug](https://github.com/seanpoyner/gradio-mcp-playground/issues)
|
| 31 |
+
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
## 🎯 Our Mission
|
| 35 |
+
|
| 36 |
+
This project was created to solve a critical problem: **Most MCP tools require expensive LLM API subscriptions**, limiting access for developers, students, and enthusiasts.
|
| 37 |
+
|
| 38 |
+
We believe everyone should be able to:
|
| 39 |
+
- **🎆 Experiment with MCP servers** without financial barriers
|
| 40 |
+
- **👩💻 Learn AI agent development** through hands-on experience
|
| 41 |
+
- **🌈 Build and deploy tools** using Gradio's intuitive interface
|
| 42 |
+
- **🤝 Contribute to the open-source ecosystem** regardless of budget
|
| 43 |
+
|
| 44 |
+
## ✨ What is Gradio MCP Playground?
|
| 45 |
+
|
| 46 |
+
A comprehensive platform for building, managing, and deploying Model Context Protocol (MCP) servers using Gradio. This playground democratizes access to MCP technology, allowing developers and enthusiasts to "play" with MCP servers, agents, and LLM-tool integrations while showcasing the powerful features of Gradio.
|
| 47 |
+
|
| 48 |
+
### Key Benefits
|
| 49 |
+
|
| 50 |
+
- **💰 No API Keys Required** - Use the demo features without any LLM subscriptions
|
| 51 |
+
- **🚀 Zero to Agent in Minutes** - Create functional MCP servers quickly
|
| 52 |
+
- **🎨 Visual Development** - Build complex agents through an intuitive UI
|
| 53 |
+
- **📚 Learning Platform** - Understand MCP concepts through interactive examples
|
| 54 |
+
- **🌍 Community Driven** - Share and discover agents built by others
|
| 55 |
+
|
| 56 |
+
## 🏆 Features Overview
|
| 57 |
+
|
| 58 |
+
### 🛝 AI Assistant Hub
|
| 59 |
+
Three specialized AI assistants to guide your journey:
|
| 60 |
+
|
| 61 |
+
- **Adam (General Assistant)** - Your friendly companion with access to MCP tools like screenshots, web search, and file operations
|
| 62 |
+
- **Liam (MCP Specialist)** - Expert in MCP development, server creation, and pipeline building
|
| 63 |
+
- **Arthur (Agent Builder)** - Architect for sophisticated autonomous agents and custom implementations
|
| 64 |
+
|
| 65 |
+
### 🔧 Server Builder
|
| 66 |
+
Create MCP servers without extensive coding:
|
| 67 |
+
|
| 68 |
+
- **Quick Create** - Build servers from templates in seconds
|
| 69 |
+
- **Pipeline Builder** - Visual drag-and-drop interface for complex workflows
|
| 70 |
+
- **Templates Gallery** - Pre-built templates for common use cases:
|
| 71 |
+
- Calculator (arithmetic operations)
|
| 72 |
+
- Text Processor (text manipulation)
|
| 73 |
+
- Image Generator (AI image creation)
|
| 74 |
+
- Data Analyzer (CSV/data analysis)
|
| 75 |
+
- Web Scraper (data extraction)
|
| 76 |
+
- API Wrapper (turn any API into MCP)
|
| 77 |
+
|
| 78 |
+
### 🖥️ Server Management
|
| 79 |
+
Professional-grade server lifecycle management:
|
| 80 |
+
|
| 81 |
+
- **Active Servers** - Monitor running MCP servers in real-time
|
| 82 |
+
- **Server Registry** - Browse and install community servers
|
| 83 |
+
- **Quick Deploy** - One-click deployment to Hugging Face Spaces
|
| 84 |
+
- **Performance Monitoring** - Track server health and usage
|
| 85 |
+
|
| 86 |
+
### 🔌 MCP Connections
|
| 87 |
+
Connect to any MCP server with ease:
|
| 88 |
+
|
| 89 |
+
- **Quick Connect** - Pre-configured connections to popular servers:
|
| 90 |
+
- Filesystem (file operations)
|
| 91 |
+
- Memory (persistent storage)
|
| 92 |
+
- GitHub (repository management)
|
| 93 |
+
- Brave Search (web search)
|
| 94 |
+
- **Custom Connections** - Connect to any MCP server via stdio or SSE
|
| 95 |
+
- **Tool Discovery** - Automatically discover and test available tools
|
| 96 |
+
- **Activity Log** - Track all tool executions and results
|
| 97 |
+
|
| 98 |
+
### 🤖 Agent Control Panel
|
| 99 |
+
Build and manage autonomous agents:
|
| 100 |
+
|
| 101 |
+
- **Agent Creation** - Visual interface for building AI agents
|
| 102 |
+
- **Agent Templates** - Start from proven agent architectures
|
| 103 |
+
- **Testing Suite** - Real-time testing and debugging
|
| 104 |
+
- **Deployment Options** - Deploy agents to various platforms
|
| 105 |
+
|
| 106 |
+
### 📚 Help & Resources
|
| 107 |
+
Comprehensive documentation and support:
|
| 108 |
+
|
| 109 |
+
- **Interactive Tutorials** - Step-by-step guides
|
| 110 |
+
- **API Reference** - Complete documentation
|
| 111 |
+
- **Video Guides** - Visual learning resources
|
| 112 |
+
- **Community Forum** - Get help and share knowledge
|
| 113 |
+
|
| 114 |
+
## 🚀 Quick Start
|
| 115 |
+
|
| 116 |
+
### Try the Demo (This Space)
|
| 117 |
+
|
| 118 |
+
This Hugging Face Space provides a **demo version** showcasing all features. Some functionality is limited in the demo - for full features, install locally.
|
| 119 |
+
|
| 120 |
+
### Local Installation (Full Features)
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
# Clone the repository
|
| 124 |
+
git clone https://github.com/seanpoyner/gradio-mcp-playground
|
| 125 |
+
cd gradio-mcp-playground
|
| 126 |
+
|
| 127 |
+
# Install with all dependencies
|
| 128 |
+
pip install -e ".[all]"
|
| 129 |
+
|
| 130 |
+
# Launch the unified dashboard
|
| 131 |
+
gmp dashboard
|
| 132 |
+
|
| 133 |
+
# Or start on a custom port
|
| 134 |
+
gmp dashboard --port 8081
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
### CLI Tools
|
| 138 |
+
|
| 139 |
+
Powerful command-line tools for automation:
|
| 140 |
+
|
| 141 |
+
```bash
|
| 142 |
+
# Create servers from templates
|
| 143 |
+
gmp create calculator my-calc-server
|
| 144 |
+
gmp create image-generator my-image-server
|
| 145 |
+
|
| 146 |
+
# List available templates
|
| 147 |
+
gmp templates
|
| 148 |
+
|
| 149 |
+
# Manage servers
|
| 150 |
+
gmp server list # List all servers
|
| 151 |
+
gmp server start my-server # Start a server
|
| 152 |
+
gmp server stop my-server # Stop a server
|
| 153 |
+
|
| 154 |
+
# Connect to MCP servers
|
| 155 |
+
gmp connect filesystem /path/to/directory
|
| 156 |
+
gmp connect github --token YOUR_GITHUB_TOKEN
|
| 157 |
+
|
| 158 |
+
# Deploy servers
|
| 159 |
+
gmp deploy my-server # Deploy to Hugging Face Spaces
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
## 💡 Use Cases
|
| 163 |
+
|
| 164 |
+
### For Developers
|
| 165 |
+
- **Rapid Prototyping** - Test MCP concepts without setup overhead
|
| 166 |
+
- **Tool Development** - Create reusable tools for AI assistants
|
| 167 |
+
- **API Integration** - Wrap any API as an MCP server
|
| 168 |
+
- **Learning Platform** - Understand MCP through hands-on examples
|
| 169 |
+
|
| 170 |
+
### For Educators & Students
|
| 171 |
+
- **Free Learning** - No expensive API keys needed
|
| 172 |
+
- **Interactive Teaching** - Demonstrate AI concepts visually
|
| 173 |
+
- **Student Projects** - Build without infrastructure worries
|
| 174 |
+
- **Research Platform** - Experiment with MCP implementations
|
| 175 |
+
|
| 176 |
+
### For Enthusiasts
|
| 177 |
+
- **Explore MCP** - Play with cutting-edge AI technology
|
| 178 |
+
- **Build Tools** - Create useful automation tools
|
| 179 |
+
- **Share Creations** - Contribute to the community
|
| 180 |
+
- **Learn by Doing** - Hands-on experience with AI agents
|
| 181 |
+
|
| 182 |
+
### For Businesses
|
| 183 |
+
- **Proof of Concepts** - Test ideas before investing
|
| 184 |
+
- **Custom Assistants** - Build domain-specific agents
|
| 185 |
+
- **Team Collaboration** - Share tools internally
|
| 186 |
+
- **Cost-Effective Development** - Prototype without API costs
|
| 187 |
+
|
| 188 |
+
## 🛠️ Creating MCP Servers
|
| 189 |
+
|
| 190 |
+
### Basic Example
|
| 191 |
+
|
| 192 |
+
```python
|
| 193 |
+
import gradio as gr
|
| 194 |
+
|
| 195 |
+
def greet(name: str) -> str:
|
| 196 |
+
"""Greet someone by name."""
|
| 197 |
+
return f"Hello, {name}!"
|
| 198 |
+
|
| 199 |
+
# Create a Gradio interface
|
| 200 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 201 |
+
|
| 202 |
+
# Launch as an MCP server
|
| 203 |
+
demo.launch(mcp_server=True)
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
### Multi-Tool Server
|
| 207 |
+
|
| 208 |
+
```python
|
| 209 |
+
import gradio as gr
|
| 210 |
+
|
| 211 |
+
def summarize_text(text: str, max_length: int = 100) -> str:
|
| 212 |
+
"""Summarize a long text."""
|
| 213 |
+
return text[:max_length] + "..."
|
| 214 |
+
|
| 215 |
+
def translate_text(text: str, target_language: str = "es") -> str:
|
| 216 |
+
"""Translate text to another language."""
|
| 217 |
+
# Translation logic here
|
| 218 |
+
return f"Translated: {text}"
|
| 219 |
+
|
| 220 |
+
# Create tabbed interface with multiple tools
|
| 221 |
+
demo = gr.TabbedInterface(
|
| 222 |
+
[
|
| 223 |
+
gr.Interface(fn=summarize_text, inputs=["text", "number"], outputs="text"),
|
| 224 |
+
gr.Interface(fn=translate_text, inputs=["text", "text"], outputs="text")
|
| 225 |
+
],
|
| 226 |
+
["Summarizer", "Translator"]
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
# Launch as MCP server
|
| 230 |
+
demo.launch(mcp_server=True)
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
## 📊 Architecture & Technology
|
| 234 |
+
|
| 235 |
+
### Core Technologies
|
| 236 |
+
- **Frontend**: Gradio 4.31.0 with custom themes and components
|
| 237 |
+
- **Backend**: Python with async support for high performance
|
| 238 |
+
- **Protocol**: Model Context Protocol (MCP) by Anthropic
|
| 239 |
+
- **Deployment**: Optimized for Hugging Face Spaces
|
| 240 |
+
|
| 241 |
+
### Key Components
|
| 242 |
+
- **Unified Dashboard** - Single interface for all MCP operations
|
| 243 |
+
- **MCP Client Manager** - Handles connections to multiple servers
|
| 244 |
+
- **Template Engine** - Generates server code from templates
|
| 245 |
+
- **Pipeline Builder** - Visual workflow creation
|
| 246 |
+
- **Agent Framework** - Autonomous agent construction
|
| 247 |
+
|
| 248 |
+
### Security & Performance
|
| 249 |
+
- **Secure Storage** - Encrypted credential management
|
| 250 |
+
- **Rate Limiting** - Prevent API abuse
|
| 251 |
+
- **Caching** - Optimized response times
|
| 252 |
+
- **Error Handling** - Graceful failure recovery
|
| 253 |
+
|
| 254 |
+
## 🤝 Project Team & Contributors
|
| 255 |
+
|
| 256 |
+
### Core Team
|
| 257 |
+
- **Sean Poyner** - Project Lead & Creator
|
| 258 |
+
- **Ranadeep Laskar ([@flickinshots](https://github.com/flickinshots))** - Project Member & Collaborator
|
| 259 |
+
|
| 260 |
+
We welcome contributions from the community! See our [Contributing Guide](CONTRIBUTING.md) for details.
|
| 261 |
+
|
| 262 |
+
## 📈 Roadmap
|
| 263 |
+
|
| 264 |
+
### Current Features (v1.0)
|
| 265 |
+
- ✅ Unified Dashboard
|
| 266 |
+
- ✅ CLI Tools
|
| 267 |
+
- ✅ Template Library
|
| 268 |
+
- ✅ Basic MCP Connections
|
| 269 |
+
- ✅ HF Space Deployment
|
| 270 |
+
|
| 271 |
+
### Coming Soon (v1.1)
|
| 272 |
+
- 🔄 Advanced Pipeline Builder
|
| 273 |
+
- 🔄 More Server Templates
|
| 274 |
+
- 🔄 Enhanced Agent Capabilities
|
| 275 |
+
- 🔄 Community Marketplace
|
| 276 |
+
- 🔄 Mobile-Responsive UI
|
| 277 |
+
|
| 278 |
+
### Future Vision (v2.0)
|
| 279 |
+
- 🔮 Multi-Agent Orchestration
|
| 280 |
+
- 🔮 Custom Model Integration
|
| 281 |
+
- 🔮 Enterprise Features
|
| 282 |
+
- 🔮 Advanced Analytics
|
| 283 |
+
- 🔮 Plugin System
|
| 284 |
+
|
| 285 |
+
## 📄 License
|
| 286 |
+
|
| 287 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 288 |
+
|
| 289 |
+
## 🙏 Acknowledgments
|
| 290 |
+
|
| 291 |
+
### Special Thanks To
|
| 292 |
+
- **Hugging Face** - For hosting this space and organizing the MCP Hackathon
|
| 293 |
+
- **Gradio Team** - For the amazing framework that makes this possible
|
| 294 |
+
- **Anthropic** - For creating the Model Context Protocol
|
| 295 |
+
- **Open Source Community** - For inspiration and support
|
| 296 |
+
|
| 297 |
+
### Built With
|
| 298 |
+
- [Gradio](https://gradio.app) - The UI framework powering our interface
|
| 299 |
+
- [Model Context Protocol](https://github.com/anthropics/mcp) - The protocol enabling tool integration
|
| 300 |
+
- [Python](https://python.org) - Our primary development language
|
| 301 |
+
|
| 302 |
+
## 📞 Support & Contact
|
| 303 |
+
|
| 304 |
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/seanpoyner/gradio-mcp-playground/issues)
|
| 305 |
+
- **Discussions**: [Join the conversation](https://huggingface.co/spaces/seanpoyner/gradio-mcp-playground/discussions)
|
| 306 |
+
- **Documentation**: [Full docs on GitHub](https://github.com/seanpoyner/gradio-mcp-playground)
|
| 307 |
+
|
| 308 |
+
---
|
| 309 |
+
|
| 310 |
+
<div align="center">
|
| 311 |
+
<b>Made with ❤️ to democratize MCP technology for everyone</b>
|
| 312 |
+
<br>
|
| 313 |
+
<i>No expensive subscriptions required - just creativity and curiosity!</i>
|
| 314 |
+
</div>
|
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (39 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,840 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py - Gradio MCP Playground for HF Spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from typing import Dict, List, Optional, Tuple, Any
|
| 7 |
+
import uuid
|
| 8 |
+
import asyncio
|
| 9 |
+
import time
|
| 10 |
+
import subprocess
|
| 11 |
+
import sys
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
import tempfile
|
| 14 |
+
import shutil
|
| 15 |
+
|
| 16 |
+
# Configuration
|
| 17 |
+
HF_SPACE_MODE = True
|
| 18 |
+
HF_SPACE_ID = os.getenv("SPACE_ID", "seanpoyner/gradio-mcp-playground")
|
| 19 |
+
GITHUB_REPO = "https://github.com/seanpoyner/gradio-mcp-playground"
|
| 20 |
+
|
| 21 |
+
class MCPPlaygroundApp:
|
| 22 |
+
"""Gradio MCP Playground - Functional demo for HF Spaces"""
|
| 23 |
+
|
| 24 |
+
def __init__(self):
|
| 25 |
+
self.sessions = {}
|
| 26 |
+
self.templates = self.load_templates()
|
| 27 |
+
self.active_servers = {}
|
| 28 |
+
self.demo_chat_history = []
|
| 29 |
+
|
| 30 |
+
def load_templates(self) -> List[Dict]:
|
| 31 |
+
"""Load available MCP server templates"""
|
| 32 |
+
return [
|
| 33 |
+
{
|
| 34 |
+
"name": "Calculator",
|
| 35 |
+
"id": "calculator",
|
| 36 |
+
"description": "Basic arithmetic operations server",
|
| 37 |
+
"code": '''import json
|
| 38 |
+
import sys
|
| 39 |
+
|
| 40 |
+
class CalculatorServer:
|
| 41 |
+
def handle_add(self, a, b):
|
| 42 |
+
return {"result": a + b}
|
| 43 |
+
|
| 44 |
+
def handle_subtract(self, a, b):
|
| 45 |
+
return {"result": a - b}
|
| 46 |
+
|
| 47 |
+
def handle_multiply(self, a, b):
|
| 48 |
+
return {"result": a * b}
|
| 49 |
+
|
| 50 |
+
def handle_divide(self, a, b):
|
| 51 |
+
if b == 0:
|
| 52 |
+
return {"error": "Division by zero"}
|
| 53 |
+
return {"result": a / b}
|
| 54 |
+
|
| 55 |
+
# Simple stdin/stdout handler
|
| 56 |
+
server = CalculatorServer()
|
| 57 |
+
while True:
|
| 58 |
+
try:
|
| 59 |
+
line = sys.stdin.readline()
|
| 60 |
+
if not line:
|
| 61 |
+
break
|
| 62 |
+
request = json.loads(line)
|
| 63 |
+
|
| 64 |
+
method = request.get("method", "")
|
| 65 |
+
params = request.get("params", {})
|
| 66 |
+
|
| 67 |
+
if method == "add":
|
| 68 |
+
result = server.handle_add(params.get("a", 0), params.get("b", 0))
|
| 69 |
+
elif method == "subtract":
|
| 70 |
+
result = server.handle_subtract(params.get("a", 0), params.get("b", 0))
|
| 71 |
+
elif method == "multiply":
|
| 72 |
+
result = server.handle_multiply(params.get("a", 0), params.get("b", 0))
|
| 73 |
+
elif method == "divide":
|
| 74 |
+
result = server.handle_divide(params.get("a", 0), params.get("b", 1))
|
| 75 |
+
else:
|
| 76 |
+
result = {"error": f"Unknown method: {method}"}
|
| 77 |
+
|
| 78 |
+
response = {"id": request.get("id"), "result": result}
|
| 79 |
+
print(json.dumps(response))
|
| 80 |
+
sys.stdout.flush()
|
| 81 |
+
except Exception as e:
|
| 82 |
+
print(json.dumps({"error": str(e)}))
|
| 83 |
+
sys.stdout.flush()
|
| 84 |
+
'''
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"name": "Text Processor",
|
| 88 |
+
"id": "text_processor",
|
| 89 |
+
"description": "Text manipulation and analysis",
|
| 90 |
+
"code": '''import json
|
| 91 |
+
import sys
|
| 92 |
+
|
| 93 |
+
class TextProcessor:
|
| 94 |
+
def count_words(self, text):
|
| 95 |
+
return {"count": len(text.split())}
|
| 96 |
+
|
| 97 |
+
def reverse_text(self, text):
|
| 98 |
+
return {"reversed": text[::-1]}
|
| 99 |
+
|
| 100 |
+
def to_uppercase(self, text):
|
| 101 |
+
return {"uppercase": text.upper()}
|
| 102 |
+
|
| 103 |
+
def to_lowercase(self, text):
|
| 104 |
+
return {"lowercase": text.lower()}
|
| 105 |
+
|
| 106 |
+
# Simple stdin/stdout handler
|
| 107 |
+
processor = TextProcessor()
|
| 108 |
+
while True:
|
| 109 |
+
try:
|
| 110 |
+
line = sys.stdin.readline()
|
| 111 |
+
if not line:
|
| 112 |
+
break
|
| 113 |
+
request = json.loads(line)
|
| 114 |
+
|
| 115 |
+
method = request.get("method", "")
|
| 116 |
+
params = request.get("params", {})
|
| 117 |
+
text = params.get("text", "")
|
| 118 |
+
|
| 119 |
+
if method == "count_words":
|
| 120 |
+
result = processor.count_words(text)
|
| 121 |
+
elif method == "reverse":
|
| 122 |
+
result = processor.reverse_text(text)
|
| 123 |
+
elif method == "uppercase":
|
| 124 |
+
result = processor.to_uppercase(text)
|
| 125 |
+
elif method == "lowercase":
|
| 126 |
+
result = processor.to_lowercase(text)
|
| 127 |
+
else:
|
| 128 |
+
result = {"error": f"Unknown method: {method}"}
|
| 129 |
+
|
| 130 |
+
response = {"id": request.get("id"), "result": result}
|
| 131 |
+
print(json.dumps(response))
|
| 132 |
+
sys.stdout.flush()
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print(json.dumps({"error": str(e)}))
|
| 135 |
+
sys.stdout.flush()
|
| 136 |
+
'''
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"name": "Echo Server",
|
| 140 |
+
"id": "echo",
|
| 141 |
+
"description": "Simple echo server for testing",
|
| 142 |
+
"code": '''import json
|
| 143 |
+
import sys
|
| 144 |
+
import datetime
|
| 145 |
+
|
| 146 |
+
# Simple echo server
|
| 147 |
+
while True:
|
| 148 |
+
try:
|
| 149 |
+
line = sys.stdin.readline()
|
| 150 |
+
if not line:
|
| 151 |
+
break
|
| 152 |
+
request = json.loads(line)
|
| 153 |
+
|
| 154 |
+
response = {
|
| 155 |
+
"id": request.get("id"),
|
| 156 |
+
"result": {
|
| 157 |
+
"echo": request,
|
| 158 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 159 |
+
"server": "echo-server-v1"
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
print(json.dumps(response))
|
| 163 |
+
sys.stdout.flush()
|
| 164 |
+
except Exception as e:
|
| 165 |
+
print(json.dumps({"error": str(e)}))
|
| 166 |
+
sys.stdout.flush()
|
| 167 |
+
'''
|
| 168 |
+
}
|
| 169 |
+
]
|
| 170 |
+
|
| 171 |
+
def create_interface(self) -> gr.Blocks:
|
| 172 |
+
"""Create the Gradio interface"""
|
| 173 |
+
with gr.Blocks(
|
| 174 |
+
title="🛝 Gradio MCP Playground",
|
| 175 |
+
theme=gr.themes.Soft(
|
| 176 |
+
primary_hue="blue",
|
| 177 |
+
secondary_hue="gray",
|
| 178 |
+
font=["Inter", "system-ui", "sans-serif"]
|
| 179 |
+
),
|
| 180 |
+
css=self.get_custom_css()
|
| 181 |
+
) as demo:
|
| 182 |
+
# Banner directing to GitHub
|
| 183 |
+
gr.HTML(f"""
|
| 184 |
+
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; border-radius: 10px; margin-bottom: 20px; text-align: center; color: white;">
|
| 185 |
+
<h2 style="margin: 0 0 10px 0; color: white;">🎯 Demo Version - Limited Functionality</h2>
|
| 186 |
+
<p style="margin: 0 0 15px 0; font-size: 16px;">
|
| 187 |
+
This is a demonstration of the Gradio MCP Playground with limited features.
|
| 188 |
+
For full functionality including AI assistants, agent building, and live MCP connections:
|
| 189 |
+
</p>
|
| 190 |
+
<a href="{GITHUB_REPO}" target="_blank" style="background: white; color: #667eea; padding: 12px 30px; border-radius: 25px; text-decoration: none; font-weight: bold; display: inline-block; transition: transform 0.2s;">
|
| 191 |
+
🚀 Get Full Version on GitHub
|
| 192 |
+
</a>
|
| 193 |
+
</div>
|
| 194 |
+
""")
|
| 195 |
+
|
| 196 |
+
# Header
|
| 197 |
+
gr.Markdown("""
|
| 198 |
+
# 🛝 Gradio MCP Playground
|
| 199 |
+
|
| 200 |
+
Build, test, and deploy Model Context Protocol (MCP) servers directly in your browser.
|
| 201 |
+
This demo showcases core MCP capabilities with functional examples.
|
| 202 |
+
""")
|
| 203 |
+
|
| 204 |
+
# Session state
|
| 205 |
+
session_id = gr.State(value=lambda: str(uuid.uuid4()))
|
| 206 |
+
|
| 207 |
+
with gr.Tabs() as tabs:
|
| 208 |
+
# Tab 1: AI Assistant (Demo)
|
| 209 |
+
with gr.Tab("🛝 AI Assistant"):
|
| 210 |
+
gr.Markdown("## AI Assistant Hub [DEMO]")
|
| 211 |
+
|
| 212 |
+
with gr.Row():
|
| 213 |
+
assistant_mode = gr.Radio(
|
| 214 |
+
choices=["General Assistant", "MCP Development", "Agent Builder"],
|
| 215 |
+
value="General Assistant",
|
| 216 |
+
label="Assistant Mode",
|
| 217 |
+
info="Choose your assistant type"
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
# General Assistant Mode
|
| 221 |
+
with gr.Group(visible=True) as general_assistant_group:
|
| 222 |
+
gr.Markdown("### Adam - General Assistant [DEMO]")
|
| 223 |
+
gr.Markdown(
|
| 224 |
+
"In the full version, Adam has access to all connected MCP tools and can help with any task. "
|
| 225 |
+
"This demo shows a simulated conversation."
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
# Demo chat interface
|
| 229 |
+
demo_chatbot = gr.Chatbot(
|
| 230 |
+
label="Chat with Adam [DEMO]",
|
| 231 |
+
height=500,
|
| 232 |
+
value=[
|
| 233 |
+
[None, "👋 Hello! I'm Adam, your general-purpose assistant. In the full version, I have access to MCP tools like screenshot capture, web search, file operations, and more!"],
|
| 234 |
+
["Can you take a screenshot of a website?", None],
|
| 235 |
+
[None, "In the full version, I would use the MCP screenshot tool to capture any website. This demo version doesn't have live MCP connections, but you can see how it would work in the full GitHub version!"]
|
| 236 |
+
]
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
with gr.Row():
|
| 240 |
+
demo_input = gr.Textbox(
|
| 241 |
+
label="Message [DEMO]",
|
| 242 |
+
placeholder="This is a demo - messages won't be processed. Get the full version on GitHub!",
|
| 243 |
+
scale=4
|
| 244 |
+
)
|
| 245 |
+
demo_send_btn = gr.Button("Send [DEMO]", variant="primary", scale=1)
|
| 246 |
+
|
| 247 |
+
# MCP Agent Mode
|
| 248 |
+
with gr.Group(visible=False) as mcp_agent_group:
|
| 249 |
+
gr.Markdown("### Liam - MCP Development Specialist [DEMO]")
|
| 250 |
+
gr.Markdown(
|
| 251 |
+
"In the full version, Liam helps with MCP server development, best practices, and troubleshooting."
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
mcp_demo_chatbot = gr.Chatbot(
|
| 255 |
+
label="Chat with Liam [DEMO]",
|
| 256 |
+
height=500,
|
| 257 |
+
value=[
|
| 258 |
+
[None, "👋 I'm Liam, your MCP development specialist. In the full version, I can help you build, test, and deploy MCP servers!"]
|
| 259 |
+
]
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
# Agent Builder Mode
|
| 263 |
+
with gr.Group(visible=False) as agent_builder_group:
|
| 264 |
+
gr.Markdown("### Arthur - Agent Builder [DEMO]")
|
| 265 |
+
gr.Markdown(
|
| 266 |
+
"In the full version, Arthur helps create custom Gradio agents using system prompts from top AI assistants."
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
agent_demo_chatbot = gr.Chatbot(
|
| 270 |
+
label="Agent Builder Assistant [DEMO]",
|
| 271 |
+
height=500,
|
| 272 |
+
value=[
|
| 273 |
+
[None, "👋 I'm Arthur, your agent creation specialist. In the full version, I can help you create custom agents for data analysis, creative writing, code review, and more!"]
|
| 274 |
+
]
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
# Tab 2: Server Builder
|
| 278 |
+
with gr.Tab("🔧 Server Builder"):
|
| 279 |
+
gr.Markdown("### Build MCP Servers")
|
| 280 |
+
|
| 281 |
+
with gr.Tabs():
|
| 282 |
+
# Quick Create
|
| 283 |
+
with gr.Tab("⚡ Quick Create"):
|
| 284 |
+
with gr.Row():
|
| 285 |
+
with gr.Column(scale=1):
|
| 286 |
+
template_gallery = gr.Radio(
|
| 287 |
+
choices=[t["name"] for t in self.templates],
|
| 288 |
+
label="Available Templates",
|
| 289 |
+
value="Calculator"
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
template_info = gr.JSON(
|
| 293 |
+
value=self.templates[0],
|
| 294 |
+
label="Template Details"
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
with gr.Column(scale=2):
|
| 298 |
+
server_name = gr.Textbox(
|
| 299 |
+
label="Server Name",
|
| 300 |
+
placeholder="my-calculator-server"
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
server_code = gr.Code(
|
| 304 |
+
value=self.templates[0]["code"],
|
| 305 |
+
language="python",
|
| 306 |
+
label="Server Code",
|
| 307 |
+
lines=20
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
with gr.Row():
|
| 311 |
+
create_btn = gr.Button("✨ Create Server", variant="primary")
|
| 312 |
+
test_btn = gr.Button("🧪 Test Server")
|
| 313 |
+
|
| 314 |
+
creation_output = gr.JSON(label="Server Status")
|
| 315 |
+
|
| 316 |
+
# Pipeline Builder
|
| 317 |
+
with gr.Tab("🔗 Pipeline Builder"):
|
| 318 |
+
gr.Markdown("### Visual Pipeline Builder [DEMO]")
|
| 319 |
+
gr.Markdown(
|
| 320 |
+
"The full version includes a visual pipeline builder for creating complex workflows. "
|
| 321 |
+
"This feature requires the agent components from the GitHub repository."
|
| 322 |
+
)
|
| 323 |
+
gr.Image(
|
| 324 |
+
value=None,
|
| 325 |
+
label="Pipeline Builder Preview [DEMO]"
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
# Templates Gallery
|
| 329 |
+
with gr.Tab("📚 Templates"):
|
| 330 |
+
gr.Markdown("## 🎨 Server Template Gallery")
|
| 331 |
+
gr.Markdown(
|
| 332 |
+
"Choose from our collection of pre-built MCP server templates. "
|
| 333 |
+
"Full versions include AI/ML templates, database connectors, and more!"
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
with gr.Row():
|
| 337 |
+
for template in self.templates:
|
| 338 |
+
with gr.Column():
|
| 339 |
+
gr.Markdown(f"### {template['name']}")
|
| 340 |
+
gr.Markdown(f"_{template['description']}_")
|
| 341 |
+
gr.Button(f"Use {template['name']} Template", variant="secondary")
|
| 342 |
+
|
| 343 |
+
# Tab 3: Server Management
|
| 344 |
+
with gr.Tab("🖥️ Server Management"):
|
| 345 |
+
with gr.Tabs():
|
| 346 |
+
# Active Servers
|
| 347 |
+
with gr.Tab("🟢 Active Servers"):
|
| 348 |
+
gr.Markdown("### Currently Running Servers")
|
| 349 |
+
|
| 350 |
+
with gr.Row():
|
| 351 |
+
server_status = gr.JSON(
|
| 352 |
+
value={"message": "Demo mode - showing simulated servers", "count": 2},
|
| 353 |
+
label="Server Status"
|
| 354 |
+
)
|
| 355 |
+
refresh_btn = gr.Button("🔄 Refresh", scale=0)
|
| 356 |
+
|
| 357 |
+
# Simulated active servers
|
| 358 |
+
with gr.Row():
|
| 359 |
+
with gr.Column():
|
| 360 |
+
gr.Markdown("**Calculator Server** 🟢")
|
| 361 |
+
gr.Markdown("Port: 8080 | Status: Running")
|
| 362 |
+
with gr.Column():
|
| 363 |
+
gr.Markdown("**Text Processor** 🟢")
|
| 364 |
+
gr.Markdown("Port: 8081 | Status: Running")
|
| 365 |
+
|
| 366 |
+
# Browse Registry
|
| 367 |
+
with gr.Tab("📦 Browse Registry"):
|
| 368 |
+
gr.Markdown("### MCP Server Registry [DEMO]")
|
| 369 |
+
gr.Markdown(
|
| 370 |
+
"The full version includes access to a registry of community MCP servers. "
|
| 371 |
+
"Install servers from npm, PyPI, or custom sources!"
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
# Tab 4: Agent Control Panel
|
| 375 |
+
with gr.Tab("🤖 Agent Control Panel"):
|
| 376 |
+
gr.Markdown("## Agent Control Panel [DEMO]")
|
| 377 |
+
gr.Markdown(
|
| 378 |
+
"In the full version, this panel allows you to:\n"
|
| 379 |
+
"- Create and manage custom agents\n"
|
| 380 |
+
"- Configure agent behaviors and tools\n"
|
| 381 |
+
"- Monitor agent performance\n"
|
| 382 |
+
"- Export and share agent configurations"
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
with gr.Row():
|
| 386 |
+
with gr.Column():
|
| 387 |
+
gr.Markdown("### Available Agents [DEMO]")
|
| 388 |
+
gr.Markdown("- 🤖 Data Analysis Agent\n- ✍️ Creative Writing Agent\n- 🔍 Code Review Agent")
|
| 389 |
+
with gr.Column():
|
| 390 |
+
gr.Markdown("### Agent Status [DEMO]")
|
| 391 |
+
gr.JSON(value={"status": "demo", "agents": 3})
|
| 392 |
+
|
| 393 |
+
# Tab 5: MCP Connections
|
| 394 |
+
with gr.Tab("🔌 MCP Connections"):
|
| 395 |
+
with gr.Tabs():
|
| 396 |
+
# Quick Connect
|
| 397 |
+
with gr.Tab("⚡ Quick Connect"):
|
| 398 |
+
gr.Markdown("### Quick Connect to MCP Servers [DEMO]")
|
| 399 |
+
gr.Markdown(
|
| 400 |
+
"The full version allows instant connection to MCP servers via stdio, HTTP, or WebSocket."
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
with gr.Row():
|
| 404 |
+
connection_type = gr.Radio(
|
| 405 |
+
choices=["stdio", "http", "websocket"],
|
| 406 |
+
label="Connection Type [DEMO]",
|
| 407 |
+
value="stdio"
|
| 408 |
+
)
|
| 409 |
+
connect_btn = gr.Button("Connect [DEMO]", variant="primary")
|
| 410 |
+
|
| 411 |
+
# Active Connections
|
| 412 |
+
with gr.Tab("🔗 Active Connections"):
|
| 413 |
+
gr.Markdown("### Currently Connected Servers [DEMO]")
|
| 414 |
+
gr.Markdown("No active connections in demo mode")
|
| 415 |
+
|
| 416 |
+
# Custom Connection
|
| 417 |
+
with gr.Tab("➕ Custom Connection"):
|
| 418 |
+
gr.Markdown("### Add Custom MCP Connection [DEMO]")
|
| 419 |
+
gr.Textbox(label="Server Command [DEMO]", placeholder="python my_server.py")
|
| 420 |
+
gr.Textbox(label="Arguments [DEMO]", placeholder="--port 8080")
|
| 421 |
+
|
| 422 |
+
# Tab 6: Help & Resources
|
| 423 |
+
with gr.Tab("📚 Help & Resources"):
|
| 424 |
+
with gr.Tabs():
|
| 425 |
+
# User Guides
|
| 426 |
+
with gr.Tab("📖 User Guides"):
|
| 427 |
+
gr.Markdown("""
|
| 428 |
+
## User Guides
|
| 429 |
+
|
| 430 |
+
### Getting Started
|
| 431 |
+
1. **Install the full version** from [GitHub]({GITHUB_REPO})
|
| 432 |
+
2. **Set up your environment** with required dependencies
|
| 433 |
+
3. **Launch the playground** and start building!
|
| 434 |
+
|
| 435 |
+
### Key Features
|
| 436 |
+
- 🤖 **AI Assistants** - Three specialized assistants for different tasks
|
| 437 |
+
- 🔧 **Server Builder** - Create MCP servers from templates
|
| 438 |
+
- 🔌 **Live Connections** - Connect to any MCP server
|
| 439 |
+
- 📊 **Visual Pipeline Builder** - Create complex workflows
|
| 440 |
+
""".replace("{GITHUB_REPO}", GITHUB_REPO))
|
| 441 |
+
|
| 442 |
+
# Configuration
|
| 443 |
+
with gr.Tab("⚙️ Configuration"):
|
| 444 |
+
gr.Markdown("### Configuration Guide [DEMO]")
|
| 445 |
+
gr.Code(
|
| 446 |
+
value='{\n "servers": [\n {\n "name": "example-server",\n "command": "python",\n "args": ["server.py"]\n }\n ]\n}',
|
| 447 |
+
language="json",
|
| 448 |
+
label="Example Configuration"
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
# Quick Start
|
| 452 |
+
with gr.Tab("🚀 Quick Start"):
|
| 453 |
+
gr.Markdown(f"""
|
| 454 |
+
## Quick Start Guide
|
| 455 |
+
|
| 456 |
+
### 1. Get the Full Version
|
| 457 |
+
```bash
|
| 458 |
+
git clone {GITHUB_REPO}
|
| 459 |
+
cd gradio-mcp-playground
|
| 460 |
+
```
|
| 461 |
+
|
| 462 |
+
### 2. Install Dependencies
|
| 463 |
+
```bash
|
| 464 |
+
pip install -e ".[all]"
|
| 465 |
+
```
|
| 466 |
+
|
| 467 |
+
### 3. Launch the Playground
|
| 468 |
+
```bash
|
| 469 |
+
gmp --help # See all options
|
| 470 |
+
gmp ui # Launch the full UI
|
| 471 |
+
```
|
| 472 |
+
""")
|
| 473 |
+
|
| 474 |
+
# Tutorials
|
| 475 |
+
with gr.Tab("💡 Tutorials"):
|
| 476 |
+
gr.Markdown("### Available Tutorials [DEMO]")
|
| 477 |
+
gr.Markdown(
|
| 478 |
+
"- Building Your First MCP Server\n"
|
| 479 |
+
"- Connecting Multiple Servers\n"
|
| 480 |
+
"- Creating Custom Agents\n"
|
| 481 |
+
"- Advanced Pipeline Workflows"
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
# API Reference
|
| 485 |
+
with gr.Tab("🔧 API Reference"):
|
| 486 |
+
gr.Markdown("### MCP API Reference [DEMO]")
|
| 487 |
+
gr.Markdown("Full API documentation available in the GitHub repository.")
|
| 488 |
+
|
| 489 |
+
# Troubleshooting
|
| 490 |
+
with gr.Tab("🛠️ Troubleshooting"):
|
| 491 |
+
gr.Markdown("### Common Issues [DEMO]")
|
| 492 |
+
gr.Markdown(
|
| 493 |
+
"- **Connection Issues**: Check server logs and ports\n"
|
| 494 |
+
"- **Performance**: Optimize server code and connections\n"
|
| 495 |
+
"- **Compatibility**: Ensure MCP protocol version match"
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# Event handlers
|
| 499 |
+
|
| 500 |
+
# Assistant mode switching
|
| 501 |
+
def switch_assistant_mode(mode):
|
| 502 |
+
return (
|
| 503 |
+
gr.update(visible=mode == "General Assistant"),
|
| 504 |
+
gr.update(visible=mode == "MCP Development"),
|
| 505 |
+
gr.update(visible=mode == "Agent Builder")
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
assistant_mode.change(
|
| 509 |
+
switch_assistant_mode,
|
| 510 |
+
inputs=[assistant_mode],
|
| 511 |
+
outputs=[general_assistant_group, mcp_agent_group, agent_builder_group]
|
| 512 |
+
)
|
| 513 |
+
|
| 514 |
+
# Demo chat handlers
|
| 515 |
+
def demo_chat_response(message, history):
|
| 516 |
+
"""Simulate chat responses for demo"""
|
| 517 |
+
history = history or []
|
| 518 |
+
history.append({"role": "user", "content": message})
|
| 519 |
+
|
| 520 |
+
# Simple demo responses
|
| 521 |
+
if "screenshot" in message.lower():
|
| 522 |
+
response = "In the full version, I would capture a screenshot using the MCP screenshot tool. This demo doesn't have live MCP connections, but you can get the full functionality on GitHub!"
|
| 523 |
+
elif "file" in message.lower():
|
| 524 |
+
response = "In the full version, I can read, write, and manipulate files using MCP file tools. Check out the GitHub repository for the complete experience!"
|
| 525 |
+
elif "search" in message.lower():
|
| 526 |
+
response = "In the full version, I can search the web using MCP search tools. This demo shows what's possible - get the full version for actual functionality!"
|
| 527 |
+
else:
|
| 528 |
+
response = f"This is a demo response. In the full version, I would process your request: '{message}' using connected MCP tools. Visit our GitHub repository for the complete Gradio MCP Playground!"
|
| 529 |
+
|
| 530 |
+
history.append({"role": "assistant", "content": response})
|
| 531 |
+
return "", history
|
| 532 |
+
|
| 533 |
+
demo_send_btn.click(
|
| 534 |
+
demo_chat_response,
|
| 535 |
+
inputs=[demo_input, demo_chatbot],
|
| 536 |
+
outputs=[demo_input, demo_chatbot]
|
| 537 |
+
)
|
| 538 |
+
|
| 539 |
+
# Server management handlers
|
| 540 |
+
refresh_btn.click(
|
| 541 |
+
self.refresh_status,
|
| 542 |
+
inputs=[session_id],
|
| 543 |
+
outputs=[server_status]
|
| 544 |
+
)
|
| 545 |
+
|
| 546 |
+
template_gallery.change(
|
| 547 |
+
self.update_template_view,
|
| 548 |
+
inputs=[template_gallery],
|
| 549 |
+
outputs=[template_info, server_code]
|
| 550 |
+
)
|
| 551 |
+
|
| 552 |
+
create_btn.click(
|
| 553 |
+
self.create_server,
|
| 554 |
+
inputs=[server_name, server_code, session_id],
|
| 555 |
+
outputs=[creation_output]
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
test_btn.click(
|
| 559 |
+
self.test_server,
|
| 560 |
+
inputs=[server_code],
|
| 561 |
+
outputs=[creation_output]
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
return demo
|
| 565 |
+
|
| 566 |
+
def get_custom_css(self) -> str:
|
| 567 |
+
"""Custom CSS for the interface"""
|
| 568 |
+
return """
|
| 569 |
+
.gradio-container {
|
| 570 |
+
max-width: 1400px !important;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
/* Banner styling */
|
| 574 |
+
.banner a:hover {
|
| 575 |
+
transform: scale(1.05);
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
/* Demo labels */
|
| 579 |
+
button:has-text("[DEMO]"),
|
| 580 |
+
.label:has-text("[DEMO]") {
|
| 581 |
+
position: relative;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
button:has-text("[DEMO]")::after,
|
| 585 |
+
.label:has-text("[DEMO]")::after {
|
| 586 |
+
content: "DEMO";
|
| 587 |
+
position: absolute;
|
| 588 |
+
top: -8px;
|
| 589 |
+
right: -8px;
|
| 590 |
+
background: #ff6b6b;
|
| 591 |
+
color: white;
|
| 592 |
+
padding: 2px 6px;
|
| 593 |
+
border-radius: 4px;
|
| 594 |
+
font-size: 10px;
|
| 595 |
+
font-weight: bold;
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
/* Dark mode friendly styles */
|
| 599 |
+
.template-card {
|
| 600 |
+
background: #374151;
|
| 601 |
+
border: 2px solid #4b5563;
|
| 602 |
+
border-radius: 8px;
|
| 603 |
+
padding: 16px;
|
| 604 |
+
margin: 8px 0;
|
| 605 |
+
transition: all 0.3s ease;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
.template-card:hover {
|
| 609 |
+
border-color: #60a5fa;
|
| 610 |
+
transform: translateY(-2px);
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
.server-status {
|
| 614 |
+
padding: 12px;
|
| 615 |
+
border-radius: 8px;
|
| 616 |
+
margin: 8px 0;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
.status-active {
|
| 620 |
+
background: #10b981;
|
| 621 |
+
color: white;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
.status-inactive {
|
| 625 |
+
background: #ef4444;
|
| 626 |
+
color: white;
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
/* Tab styling */
|
| 630 |
+
.tabs {
|
| 631 |
+
margin-top: 20px;
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
/* Demo mode indicators */
|
| 635 |
+
.demo-indicator {
|
| 636 |
+
background: #ff6b6b;
|
| 637 |
+
color: white;
|
| 638 |
+
padding: 4px 8px;
|
| 639 |
+
border-radius: 4px;
|
| 640 |
+
font-size: 12px;
|
| 641 |
+
display: inline-block;
|
| 642 |
+
margin-left: 8px;
|
| 643 |
+
}
|
| 644 |
+
"""
|
| 645 |
+
|
| 646 |
+
def refresh_status(self, session_id: str) -> Dict:
|
| 647 |
+
"""Refresh server status"""
|
| 648 |
+
session = self.sessions.get(session_id, {})
|
| 649 |
+
servers = session.get("servers", [])
|
| 650 |
+
|
| 651 |
+
return {
|
| 652 |
+
"message": f"Active servers: {len(servers)}",
|
| 653 |
+
"count": len(servers),
|
| 654 |
+
"servers": servers,
|
| 655 |
+
"timestamp": datetime.now().isoformat()
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
def quick_deploy(self, template_name: str, session_id: str) -> Tuple[Dict, Dict]:
|
| 659 |
+
"""Quick deploy a template"""
|
| 660 |
+
template = next((t for t in self.templates if t["name"] == template_name), None)
|
| 661 |
+
|
| 662 |
+
if not template:
|
| 663 |
+
return {"error": "Template not found"}, self.refresh_status(session_id)
|
| 664 |
+
|
| 665 |
+
# Initialize session
|
| 666 |
+
if session_id not in self.sessions:
|
| 667 |
+
self.sessions[session_id] = {"servers": []}
|
| 668 |
+
|
| 669 |
+
# Add server to session
|
| 670 |
+
server_id = f"{template['id']}-{int(time.time())}"
|
| 671 |
+
server_info = {
|
| 672 |
+
"id": server_id,
|
| 673 |
+
"name": template_name,
|
| 674 |
+
"status": "active",
|
| 675 |
+
"created": datetime.now().isoformat()
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
self.sessions[session_id]["servers"].append(server_info)
|
| 679 |
+
|
| 680 |
+
return {
|
| 681 |
+
"success": True,
|
| 682 |
+
"message": f"Deployed {template_name}",
|
| 683 |
+
"server_id": server_id
|
| 684 |
+
}, self.refresh_status(session_id)
|
| 685 |
+
|
| 686 |
+
def update_template_view(self, template_name: str) -> Tuple[Dict, str]:
|
| 687 |
+
"""Update template view when selection changes"""
|
| 688 |
+
template = next((t for t in self.templates if t["name"] == template_name), None)
|
| 689 |
+
|
| 690 |
+
if template:
|
| 691 |
+
return template, template["code"]
|
| 692 |
+
return {"error": "Template not found"}, ""
|
| 693 |
+
|
| 694 |
+
def create_server(self, name: str, code: str, session_id: str) -> Dict:
|
| 695 |
+
"""Create a new server"""
|
| 696 |
+
if not name:
|
| 697 |
+
return {"error": "Server name is required"}
|
| 698 |
+
|
| 699 |
+
# Save server code temporarily
|
| 700 |
+
temp_dir = tempfile.mkdtemp()
|
| 701 |
+
server_file = Path(temp_dir) / f"{name}.py"
|
| 702 |
+
|
| 703 |
+
try:
|
| 704 |
+
server_file.write_text(code)
|
| 705 |
+
|
| 706 |
+
# Test if code is valid Python
|
| 707 |
+
result = subprocess.run(
|
| 708 |
+
[sys.executable, "-m", "py_compile", str(server_file)],
|
| 709 |
+
capture_output=True,
|
| 710 |
+
text=True
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
if result.returncode != 0:
|
| 714 |
+
return {"error": f"Invalid Python code: {result.stderr}"}
|
| 715 |
+
|
| 716 |
+
return {
|
| 717 |
+
"success": True,
|
| 718 |
+
"message": f"Server '{name}' created successfully",
|
| 719 |
+
"path": str(server_file)
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
except Exception as e:
|
| 723 |
+
return {"error": f"Failed to create server: {str(e)}"}
|
| 724 |
+
finally:
|
| 725 |
+
# Cleanup
|
| 726 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 727 |
+
|
| 728 |
+
def test_server(self, code: str) -> Dict:
|
| 729 |
+
"""Test server code"""
|
| 730 |
+
try:
|
| 731 |
+
# Basic syntax check
|
| 732 |
+
compile(code, '<string>', 'exec')
|
| 733 |
+
return {
|
| 734 |
+
"success": True,
|
| 735 |
+
"message": "Code syntax is valid",
|
| 736 |
+
"timestamp": datetime.now().isoformat()
|
| 737 |
+
}
|
| 738 |
+
except SyntaxError as e:
|
| 739 |
+
return {
|
| 740 |
+
"error": f"Syntax error at line {e.lineno}: {e.msg}",
|
| 741 |
+
"line": e.lineno
|
| 742 |
+
}
|
| 743 |
+
except Exception as e:
|
| 744 |
+
return {"error": f"Validation error: {str(e)}"}
|
| 745 |
+
|
| 746 |
+
def update_tool_methods(self, server: str) -> Tuple[gr.Dropdown, Dict]:
|
| 747 |
+
"""Update available methods based on selected server"""
|
| 748 |
+
methods_map = {
|
| 749 |
+
"calculator": {
|
| 750 |
+
"methods": ["add", "subtract", "multiply", "divide"],
|
| 751 |
+
"default_params": {"a": 10, "b": 5}
|
| 752 |
+
},
|
| 753 |
+
"text_processor": {
|
| 754 |
+
"methods": ["count_words", "reverse", "uppercase", "lowercase"],
|
| 755 |
+
"default_params": {"text": "Hello, World!"}
|
| 756 |
+
},
|
| 757 |
+
"echo": {
|
| 758 |
+
"methods": ["echo"],
|
| 759 |
+
"default_params": {"message": "Test message"}
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
server_info = methods_map.get(server, {"methods": [], "default_params": {}})
|
| 764 |
+
|
| 765 |
+
return gr.Dropdown(
|
| 766 |
+
choices=server_info["methods"],
|
| 767 |
+
value=server_info["methods"][0] if server_info["methods"] else None
|
| 768 |
+
), server_info["default_params"]
|
| 769 |
+
|
| 770 |
+
def execute_tool(self, server: str, method: str, params: Dict, session_id: str) -> Tuple[Dict, str]:
|
| 771 |
+
"""Execute a tool method"""
|
| 772 |
+
log_lines = []
|
| 773 |
+
log_lines.append(f"[{datetime.now().strftime('%H:%M:%S')}] Executing {server}.{method}")
|
| 774 |
+
log_lines.append(f"Parameters: {json.dumps(params, indent=2)}")
|
| 775 |
+
|
| 776 |
+
try:
|
| 777 |
+
# Simulate execution based on server type
|
| 778 |
+
if server == "calculator":
|
| 779 |
+
if method == "add":
|
| 780 |
+
result = {"result": params.get("a", 0) + params.get("b", 0)}
|
| 781 |
+
elif method == "subtract":
|
| 782 |
+
result = {"result": params.get("a", 0) - params.get("b", 0)}
|
| 783 |
+
elif method == "multiply":
|
| 784 |
+
result = {"result": params.get("a", 0) * params.get("b", 0)}
|
| 785 |
+
elif method == "divide":
|
| 786 |
+
b = params.get("b", 1)
|
| 787 |
+
if b == 0:
|
| 788 |
+
result = {"error": "Division by zero"}
|
| 789 |
+
else:
|
| 790 |
+
result = {"result": params.get("a", 0) / b}
|
| 791 |
+
else:
|
| 792 |
+
result = {"error": f"Unknown method: {method}"}
|
| 793 |
+
|
| 794 |
+
elif server == "text_processor":
|
| 795 |
+
text = params.get("text", "")
|
| 796 |
+
if method == "count_words":
|
| 797 |
+
result = {"count": len(text.split())}
|
| 798 |
+
elif method == "reverse":
|
| 799 |
+
result = {"reversed": text[::-1]}
|
| 800 |
+
elif method == "uppercase":
|
| 801 |
+
result = {"uppercase": text.upper()}
|
| 802 |
+
elif method == "lowercase":
|
| 803 |
+
result = {"lowercase": text.lower()}
|
| 804 |
+
else:
|
| 805 |
+
result = {"error": f"Unknown method: {method}"}
|
| 806 |
+
|
| 807 |
+
elif server == "echo":
|
| 808 |
+
result = {
|
| 809 |
+
"echo": params,
|
| 810 |
+
"timestamp": datetime.now().isoformat(),
|
| 811 |
+
"server": server
|
| 812 |
+
}
|
| 813 |
+
else:
|
| 814 |
+
result = {"error": f"Unknown server: {server}"}
|
| 815 |
+
|
| 816 |
+
log_lines.append(f"Result: {json.dumps(result, indent=2)}")
|
| 817 |
+
log_lines.append(f"[{datetime.now().strftime('%H:%M:%S')}] Execution completed")
|
| 818 |
+
|
| 819 |
+
return result, "\n".join(log_lines)
|
| 820 |
+
|
| 821 |
+
except Exception as e:
|
| 822 |
+
error_result = {"error": str(e), "type": type(e).__name__}
|
| 823 |
+
log_lines.append(f"Error: {str(e)}")
|
| 824 |
+
return error_result, "\n".join(log_lines)
|
| 825 |
+
|
| 826 |
+
def demo_notification(self, action: str) -> str:
|
| 827 |
+
"""Return a demo notification message"""
|
| 828 |
+
return f"[DEMO MODE] {action} - This feature requires the full version. Visit {GITHUB_REPO} for complete functionality!"
|
| 829 |
+
|
| 830 |
+
# Create and launch the app
|
| 831 |
+
app = MCPPlaygroundApp()
|
| 832 |
+
demo = app.create_interface()
|
| 833 |
+
|
| 834 |
+
if __name__ == "__main__":
|
| 835 |
+
demo.queue(api_open=False).launch(
|
| 836 |
+
server_name="0.0.0.0",
|
| 837 |
+
server_port=7860,
|
| 838 |
+
favicon_path="🛝",
|
| 839 |
+
show_api=False
|
| 840 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# requirements.txt for HF Space
|
| 2 |
+
gradio
|
| 3 |
+
huggingface-hub>=0.23.0
|
| 4 |
+
pydantic>=2.0.0
|
| 5 |
+
typing-extensions>=4.5.0
|