Spaces:
Sleeping
Sleeping
File size: 1,308 Bytes
1ba381f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """
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
@mcp.tool("search_youtube_videos")
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() |