Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions community_usecase/Docker-Toolkit-MCP/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# 🔍 CAMEL-AI + MCP: Docker Toolkit Search Tool

This example demonstrates how to use the [CAMEL-AI OWL framework](https://github.com/camel-ai/owl) and **MCP (Model Context Protocol)** to search for Docker Toolkit related content. The tool leverages intelligent agents to gather and organize documentation, tutorials, best practices, and troubleshooting guides.

---

## ✨ Use Case

> _"Search and organize Docker Toolkit related content including technical documentation, video tutorials, best practices, and optimization guides. Return results in a structured format with descriptions and links."_

Agents coordinate to perform comprehensive searches and return well-organized results in Markdown format.

---

## 📦 Setup

### 1. Clone and install dependencies

```bash
git clone https://github.com/camel-ai/owl
cd owl
pip install -r requirements.txt
```

### 2. Configure MCP Server

Create `mcp_servers_config.json` in the project directory:

```json
{
"mcpServers": {
"MCP_DOCKER": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-l",
"--rm",
"-i",
"alpine/socat",
"STDIO",
"TCP:host.docker.internal:8811"
]
}
}
}
```

> 🛠️ Make sure to set up your environment variables in `.env` file.

### 3. Run the Search Tool

```bash
python docker_content_search.py
```

You can customize the search query by modifying the `default_task` in `docker_content_search.py`:

```python
default_task = (
"Please help me search for Docker Toolkit related content:\n"
"1. Docker Toolkit technical documentation and official guides\n"
"2. Docker Toolkit video tutorials and practical cases\n"
# ...customize your search requirements...
)
```

---

## 🧠 How It Works

- **MCPToolkit** connects to the search service
- **OWL RolePlaying Agents** simulate a conversation between:
- `docker_content_curator`: Manages content requirements
- `docker_tech_expert`: Executes searches and formats results
- Results are saved as Markdown files in the `search_results` directory

## 📄 Output Format

Search results are organized in the following sections:
- Documentation and Guides
- Video Tutorials
- Best Practices
- Troubleshooting and Optimization

Each entry includes:
- Title with link
- Brief description
- Additional metadata (duration, author for videos)

---

## 🚧 Notes

### Prerequisites
- Docker Desktop must be installed and running
- MCP Toolkit must be installed in Docker:
- Firecrawl plugin must be configured in MCP Toolkit:
![MCP Toolkit Firecrawl Configuration](docker-toolkit-firecrawl.png)

### General Notes
- Uses **DeepSeek** model for both user and assistant roles
- Supports async execution and error handling
- Includes retry mechanism for reliability
- Saves results in timestamped Markdown files

---

## 🌟 Docker MCP Toolkit Advantages

### Simplified Management
- **One-Time Setup**: Configure Docker MCP once to access all MCP services in the Docker MCP marketplace
- **Automated Resource Management**:
- On-demand container startup
- Automatic credential injection
- Container termination after task completion
- Efficient resource utilization

### Enhanced Security
- **Runtime Protection**:
- Container isolation protection
- Limited host system access
- Sandboxed environment
- **Credential Management**:
- Built-in OAuth support
- Secure credential storage
- No plaintext environment variables

### Developer Productivity
- **Tool Discovery**: Verified high-quality MCP tools through Docker Hub
- **Simplified Configuration**:
- Automatic dependency handling
- Environment management
- No manual service hosting required
- **Standardized Integration**: Unified interface and management approach

Docker MCP Catalog and Toolkit's core design philosophy is to make MCP tools simple and secure to use, fundamentally changing how developers manage MCP tools by providing better structure, trustworthiness, and scalability.


## 📌 References

- [CAMEL-AI GitHub](https://github.com/camel-ai/camel)
- [OWL Framework](https://github.com/camel-ai/owl)
- [MCP Documentation](https://docs.anthropic.com/claude/docs/model-context-protocol)
- [DeepSeek Models](https://api-docs.deepseek.com/)
- [Docker Toolkit](https://www.docker.com/products/mcp-catalog-and-toolkit/)
- [Docker MCP Toolkit Installation Guide](https://www.cloudesx.com/article/mcp-server-docker)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
177 changes: 177 additions & 0 deletions community_usecase/Docker-Toolkit-MCP/docker_content_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import asyncio
import sys
import datetime
from pathlib import Path
from typing import List

from dotenv import load_dotenv
from camel.models import ModelFactory
from camel.toolkits import FunctionTool, MCPToolkit, SearchToolkit
from camel.types import ModelPlatformType, ModelType
from camel.logger import set_log_level

from owl.utils.enhanced_role_playing import OwlRolePlaying, arun_society

set_log_level(level="DEBUG")
load_dotenv()

async def construct_society(
question: str,
tools: List[FunctionTool],
) -> OwlRolePlaying:
"""Construct OwlRolePlaying instance to enhance content search capabilities"""
models = {
"user": ModelFactory.create(
model_platform=ModelPlatformType.DEEPSEEK,
model_type=ModelType.DEEPSEEK_CHAT,
model_config_dict={"temperature": 0.7},
),
"assistant": ModelFactory.create(
model_platform=ModelPlatformType.DEEPSEEK,
model_type=ModelType.DEEPSEEK_CHAT,
model_config_dict={"temperature": 0.7},
),
}

user_agent_kwargs = {
"model": models["user"],
}

assistant_agent_kwargs = {
"model": models["assistant"],
"tools": tools,
}

task_kwargs = {
"task_prompt": question,
"with_task_specify": False,
}

return OwlRolePlaying(
**task_kwargs,
user_role_name="docker_content_curator",
user_agent_kwargs=user_agent_kwargs,
assistant_role_name="docker_tech_expert",
assistant_agent_kwargs=assistant_agent_kwargs,
)

async def save_search_results(content: str, token_count: int = None) -> Path:
"""Save search results as Markdown file

Args:
content: Search result content
token_count: Number of tokens used

Returns:
Path to saved file
"""
# Create output directory
output_dir = Path(__file__).parent / "search_results"
output_dir.mkdir(exist_ok=True)

# Generate filename
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"docker_toolkit_search_{timestamp}.md"
output_path = output_dir / filename

# Organize file content
file_content = [
"# Docker Toolkit Search Results",
f"\n> Generated at: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
]

if token_count:
file_content.append(f"\n> Tokens used: {token_count}")

file_content.append("\n## Search Content\n")
file_content.append(content)

# Write to file
output_path.write_text("\n".join(file_content), encoding="utf-8")

return output_path

async def main():
# Configure MCP toolkit and search toolkit
config_path = Path(__file__).parent / "mcp_servers_config.json"
mcp_toolkit = MCPToolkit(config_path=str(config_path))
try:
await mcp_toolkit.connect()

default_task = (
"Please help me search for Docker Toolkit related content:\n"
"1. Docker Toolkit technical documentation and official guides\n"
"2. Docker Toolkit video tutorials and practical cases\n"
"3. Docker Toolkit best practices in development and operations\n"
"4. Docker Toolkit performance optimization and troubleshooting guides\n"
"\n"
"Please note:\n"
"- Prioritize recent content\n"
"- Ensure content quality and reliability\n"
"- Include both English and Chinese resources\n"
"- Focus on practical experience and case studies\n"
"\n"
"Please organize in the following format:\n"
"## Documentation and Guides\n"
"- [Title](link)\n"
" Brief description\n"
"\n"
"## Video Tutorials\n"
"- [Title](link)\n"
" Duration | Author | Brief description\n"
"\n"
"## Best Practices\n"
"- [Title](link)\n"
" Brief description\n"
"\n"
"## Troubleshooting and Optimization\n"
"- [Title](link)\n"
" Brief description"
)

task = sys.argv[1] if len(sys.argv) > 1 else default_task

# Combine MCP tools and search tools
tools = [
*mcp_toolkit.get_tools(),
]

society = await construct_society(task, tools)

try:
result = await arun_society(society)

if isinstance(result, tuple) and len(result) == 3:
answer, chat_history, token_count = result
print("\n🔍 Search Results:")
print("=" * 80)
print(answer)
print("=" * 80)
print(f"\n📊 Tokens used: {token_count}")

# Save search results
output_path = await save_search_results(answer, token_count)
print(f"\n💾 Results saved to: {output_path}")

else:
print("\n🔍 Search Results:")
print("=" * 80)
print(str(result))
print("=" * 80)

# Save search results
output_path = await save_search_results(str(result))
print(f"\n💾 Results saved to: {output_path}")

except Exception as e:
print(f"❌ Search execution error: {str(e)}")
raise

finally:
try:
await mcp_toolkit.disconnect()
except:
pass

if __name__ == "__main__":
asyncio.run(main())
17 changes: 17 additions & 0 deletions community_usecase/Docker-Toolkit-MCP/mcp_servers_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mcpServers": {
"MCP_DOCKER": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-l",
"--rm",
"-i",
"alpine/socat",
"STDIO",
"TCP:host.docker.internal:8811"
]
}
}
}