Spaces:
Sleeping
Sleeping
| """ | |
| FastMCP quickstart example. | |
| cd to the `examples/snippets/clients` directory and run: | |
| uv run server fastmcp_quickstart stdio | |
| """ | |
| from mcp.server.fastmcp import FastMCP # pyright: ignore[reportMissingImports] | |
| from googleapiclient.discovery import build # pyright: ignore[reportMissingImports] | |
| import os | |
| # Instance MCP server | |
| mcp = FastMCP("xctopus-getting-loot") | |
| # Add an addition tool | |
| def search_youtube_videos(query: str, max_results: int = 5) -> list: | |
| """Searches YouTube for videos based on a query.""" | |
| # Initialize YouTube client with API key from environment | |
| api_key = os.getenv('YOUTUBE_API_KEY') | |
| if not api_key: | |
| raise ValueError("YOUTUBE_API_KEY environment variable is not set") | |
| youtube = build('youtube', 'v3', developerKey=api_key) | |
| request = youtube.search().list( | |
| q=query, | |
| part='snippet', | |
| type='video', | |
| maxResults=max_results | |
| ) | |
| response = request.execute() | |
| results = [] | |
| for item in response.get('items', []): | |
| results.append({ | |
| 'title': item['snippet']['title'], | |
| 'video_id': item['id']['videoId'], | |
| 'description': item['snippet']['description'] | |
| }) | |
| return results | |
| if __name__ == "__main__": | |
| mcp.run() |