Skip to content
Closed
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
287 changes: 287 additions & 0 deletions mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
# MCP Tools

This directory contains Model Context Protocol (MCP) tools that can be used by AI assistants and agents.

## Available Tools

### 1. Weather Tool (`weather_tool/`)

Get weather information for any city.

**Features**:
- Current weather data
- Temperature, wind speed, conditions
- Uses Open-Meteo API (no API key required)

**Tools**:
- `get_weather(city: str)` - Get weather info for a city

### 2. Movie Tool (`movie_tool/`)

Get movie information and reviews from OMDb.

**Features**:
- Movie details (plot, ratings, actors, awards)
- Full plot summaries
- Uses OMDb API

**Tools**:
- `get_full_plot(movie_title: str)` - Get full plot summary
- `get_movie_details(movie_title: str)` - Get full movie details

**Requirements**:
- OMDB_API_KEY environment variable

### 3. Slack Tool (`slack_tool/`)

Interact with Slack workspaces.

**Features**:
- List channels
- Get channel history
- Optional fine-grained authorization

**Tools**:
- `get_channels()` - Lists all public and private channels
- `get_channel_history(channel_id: str, limit: int)` - Fetches recent messages

**Requirements**:
- SLACK_BOT_TOKEN environment variable
- Optional: ADMIN_SLACK_BOT_TOKEN for fine-grained auth

### 4. GitHub Tool (`github_tool/`)

Interact with GitHub repositories (written in Go).

**Features**:
- Repository management
- Issue tracking
- Pull request operations

**Requirements**:
- GitHub authentication token

### 5. Shopping Agent (`shopping_agent/`) ⭐ NEW

AI-powered shopping recommendations using LangChain, LangGraph, OpenAI, and SerpAPI.

**Features**:
- Natural language query understanding
- Real-time product search across retailers
- AI-curated recommendations with reasoning
- Budget-aware suggestions
- Multi-step LangGraph workflow

**Tools**:
- `recommend_products(query: str, maxResults: int)` - Get AI-powered product recommendations
- `search_products(query: str, maxResults: int)` - Raw product search

**Requirements**:
- OPENAI_API_KEY environment variable
Comment on lines +66 to +80
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main mcp/README.md incorrectly describes the shopping agent as using "LangChain, LangGraph, OpenAI" when the actual implementation only uses SerpAPI. The description claims "AI-curated recommendations with reasoning" and "Multi-step LangGraph workflow", but the code shows it only returns raw search results without any AI reasoning.

Suggested change
AI-powered shopping recommendations using LangChain, LangGraph, OpenAI, and SerpAPI.
**Features**:
- Natural language query understanding
- Real-time product search across retailers
- AI-curated recommendations with reasoning
- Budget-aware suggestions
- Multi-step LangGraph workflow
**Tools**:
- `recommend_products(query: str, maxResults: int)` - Get AI-powered product recommendations
- `search_products(query: str, maxResults: int)` - Raw product search
**Requirements**:
- OPENAI_API_KEY environment variable
Product search and recommendations using SerpAPI.
**Features**:
- Real-time product search across retailers
- Simple keyword-based search
- Budget-aware suggestions (if supported by query and SerpAPI)
**Tools**:
- `recommend_products(query: str, maxResults: int)` - Get product recommendations (returns raw search results)
- `search_products(query: str, maxResults: int)` - Raw product search
**Requirements**:

Copilot uses AI. Check for mistakes.
- SERPAPI_API_KEY environment variable

Comment on lines +80 to +82
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect requirements list: OPENAI_API_KEY is listed as required but is never used in the actual implementation. Only SERPAPI_API_KEY is needed.

Suggested change
- OPENAI_API_KEY environment variable
- SERPAPI_API_KEY environment variable
- SERPAPI_API_KEY environment variable

Copilot uses AI. Check for mistakes.
**Example Usage**:
```bash
curl -X POST http://localhost:8000/tools/recommend_products \
-H "Content-Type: application/json" \
-d '{
"query": "I want to buy a scarf for 40 dollars",
"maxResults": 5
}'
```

**Technologies**:
- FastMCP - MCP server framework
- LangChain - LLM application framework
- LangGraph - Agent workflow orchestration
- OpenAI GPT-4o-mini - Natural language understanding/generation
Comment on lines +95 to +97
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Technologies" section incorrectly lists "LangChain - LLM application framework", "LangGraph - Agent workflow orchestration", and "OpenAI GPT-4o-mini - Natural language understanding/generation" as technologies used by the shopping agent. The actual implementation only uses FastMCP and SerpAPI.

Suggested change
- LangChain - LLM application framework
- LangGraph - Agent workflow orchestration
- OpenAI GPT-4o-mini - Natural language understanding/generation

Copilot uses AI. Check for mistakes.
- SerpAPI - Product search across retailers

**Documentation**:
- [README.md](shopping_agent/README.md) - Full documentation
- [QUICKSTART.md](shopping_agent/QUICKSTART.md) - Quick start guide
- [ARCHITECTURE.md](shopping_agent/ARCHITECTURE.md) - Architecture details
- [VERIFICATION.md](shopping_agent/VERIFICATION.md) - Requirements verification
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference to non-existent "VERIFICATION.md" file in the documentation list. This file is not included in the PR.

Suggested change
- [VERIFICATION.md](shopping_agent/VERIFICATION.md) - Requirements verification

Copilot uses AI. Check for mistakes.

## Getting Started

### General Setup

All MCP tools follow a similar pattern:

1. **Install dependencies**:
```bash
cd <tool_directory>
uv pip install -e .
```

2. **Configure environment variables**:
```bash
export API_KEY="your-api-key-here"
```

3. **Run the server**:
```bash
python <tool_name>.py
```

4. **Test the server**:
```bash
curl http://localhost:8000/health
```

### Docker Deployment

Each tool includes a Dockerfile for containerized deployment:

```bash
cd <tool_directory>
docker build -t <tool-name>-mcp .
docker run -p 8000:8000 -e API_KEY="your-key" <tool-name>-mcp
```

## MCP Protocol

All tools expose functionality via the Model Context Protocol (MCP), which allows AI assistants to discover and use these tools programmatically.

### Key Features

- **Tool Discovery**: Tools are self-describing with metadata
- **Type Safety**: Strong typing for parameters and returns
- **Documentation**: Built-in documentation for each tool
- **Error Handling**: Standardized error responses
- **Transport**: HTTP transport support (streamable HTTP optional)

### Tool Annotations

Tools use annotations to describe their behavior:
- `readOnlyHint`: Indicates if the tool only reads data
- `destructiveHint`: Warns if the tool modifies or deletes data
- `idempotentHint`: Indicates if repeated calls have the same effect

## Framework Comparison

| Tool | Language | Framework | Key Library |
|------|----------|-----------|-------------|
| Weather | Python | FastMCP | requests |
| Movie | Python | FastMCP | requests + OMDb |
| Slack | Python | FastMCP | slack_sdk |
| GitHub | Go | Custom | GitHub API |
| Shopping Agent | Python | FastMCP | LangChain + LangGraph |

## Advanced Example: Shopping Agent Architecture

The Shopping Agent demonstrates an advanced MCP tool with:

```
User Query
Parse Query Node (OpenAI)
Search Products Node (SerpAPI)
Generate Recommendations Node (OpenAI)
Structured Response
```

**Key Technologies**:
- **LangGraph**: Multi-node agent workflow with state management
- **LangChain**: LLM framework for tool integration
- **OpenAI**: Natural language understanding and generation
- **SerpAPI**: Real-time search across retailers

See [shopping_agent/ARCHITECTURE.md](shopping_agent/ARCHITECTURE.md) for detailed architecture.
Comment on lines +174 to +194
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Advanced Example: Shopping Agent Architecture" section describes a multi-node workflow with "Parse Query Node (OpenAI)", "Search Products Node (SerpAPI)", and "Generate Recommendations Node (OpenAI)" using LangGraph and LangChain. This is completely inaccurate - the actual implementation is a simple function that calls SerpAPI and returns results.

Suggested change
The Shopping Agent demonstrates an advanced MCP tool with:
```
User Query
Parse Query Node (OpenAI)
Search Products Node (SerpAPI)
Generate Recommendations Node (OpenAI)
Structured Response
```
**Key Technologies**:
- **LangGraph**: Multi-node agent workflow with state management
- **LangChain**: LLM framework for tool integration
- **OpenAI**: Natural language understanding and generation
- **SerpAPI**: Real-time search across retailers
See [shopping_agent/ARCHITECTURE.md](shopping_agent/ARCHITECTURE.md) for detailed architecture.
The Shopping Agent is a simple MCP tool that provides product search results using SerpAPI.
**How it works:**
- Accepts a user query (e.g., "Find me the best noise-cancelling headphones under $200").
- Calls SerpAPI to search for relevant products.
- Returns the search results in a structured format.
**Key Technologies**:
- **SerpAPI**: Real-time product search across retailers
The implementation is a straightforward function wrapper around SerpAPI. There is no multi-node workflow or use of LangGraph/LangChain in the current version.

Copilot uses AI. Check for mistakes.

## Creating Your Own MCP Tool

### Basic Template

```python
import os
from fastmcp import FastMCP

mcp = FastMCP("My Tool")

@mcp.tool(annotations={"readOnlyHint": True})
def my_function(param: str) -> str:
"""Tool description"""
# Your logic here
return result

def run_server():
transport = os.getenv("MCP_TRANSPORT", "http")
host = os.getenv("HOST", "0.0.0.0")
port = int(os.getenv("PORT", "8000"))
mcp.run(transport=transport, host=host, port=port)

if __name__ == "__main__":
run_server()
```

### Best Practices

1. **Environment Variables**: Use env vars for API keys and configuration
2. **Error Handling**: Return structured error responses
3. **Logging**: Use appropriate log levels
4. **Documentation**: Include docstrings for all tools
5. **Type Hints**: Use type hints for parameters and returns
6. **Testing**: Provide test clients or scripts
7. **Docker**: Include Dockerfile for deployment
8. **README**: Comprehensive documentation

## Common Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| HOST | Server host address | 0.0.0.0 |
| PORT | Server port | 8000 |
| MCP_TRANSPORT | Transport protocol | http |
| LOG_LEVEL | Logging level | INFO |

## Troubleshooting

### Server Won't Start

1. Check API keys are set
2. Verify port 8000 is available
3. Check Python version (3.10+)
4. Review logs for errors

### Tool Returns Errors

1. Verify API keys are valid
2. Check API quota limits
3. Review request parameters
4. Check network connectivity

### Import Errors

1. Install dependencies: `uv pip install -e .`
2. Verify Python version
3. Check for conflicting packages

## Contributing

When adding new MCP tools:

1. Follow the existing structure
2. Use FastMCP framework (or document why not)
3. Include comprehensive README
4. Add Dockerfile
5. Provide test client
6. Document all tools and parameters
7. Use environment variables for secrets
8. Add logging and error handling

## Resources

- [FastMCP Documentation](https://github.com/jlowin/fastmcp)
- [Model Context Protocol Spec](https://modelcontextprotocol.io/)
- [LangChain Documentation](https://python.langchain.com/)
- [LangGraph Documentation](https://langchain-ai.github.io/langgraph/)

## License

See the repository's LICENSE file for details.

58 changes: 58 additions & 0 deletions mcp/shopping_agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# API Keys and Secrets - NEVER COMMIT THESE!
.env
.env.local
.env.*.local
config.sh
*.key
*.pem

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual Environments
venv/
ENV/
env/
.venv

# IDE
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store

# Logs
*.log

# Testing
.pytest_cache/
.coverage
htmlcov/

# uv
uv.lock

Loading