
Building a YouTube Analytics Agent with Amazon Bedrock and MCP
How I Built an AI Agent That Fetches, Ranks, and Emails YouTube Stats
If you work with data, you probably spend a lot of time pulling numbers from different APIs, formatting them, and sharing them with your team. What if an AI agent could do all of that for you in a single conversation?
That is exactly what I built. A command-line AI agent that connects to the YouTube Data API, retrieves channel and video statistics, ranks them, exports them to CSV, and even sends a styled email report with key insights. All powered by Amazon Bedrock and the Model Context Protocol (MCP).
In this article, I want to share how I built it, what I learned, and why I think this is a great project for anyone who wants to start building AI agents.
The Idea
I wanted to build something practical. Not just a chatbot, but an agent that actually does real work. As someone who creates content and analyzes YouTube channels, I was tired of manually checking stats across multiple channels and videos.
So I asked myself: what if I could just tell an AI agent "get me the stats for these 5 channels" and it would fetch everything, rank them by subscribers, save a CSV, show me a nice table, and then ask me if I want the results in my inbox?
That became YouTube Agent - Get Stats.
What the Agent Does
The agent has three tools:
get_channel_stats - You give it one or more YouTube channel IDs and it returns: channel name, subscribers, total views, video count, country, custom URL, keywords, and creation date. All ranked by subscriber count and saved to CSV.
get_video_stats - You give it one or more video IDs and it returns: title, views, likes, comments, duration in minutes, tags, category, and engagement rate. All ranked by views and saved to CSV.
send_email_stats - After showing you the results, the agent asks if you want them by email. It sends a styled HTML report with the stats table, AI-generated key insights, and the CSV file attached.
How It Looks
When you start the agent, you see a welcome screen with the available tools:

You type your request in natural language. The agent confirms what you need and calls the right tool:


After presenting the results, the agent proactively asks if you want to take a follow-up action like sending the report by email:

The report is sended succesfully to the email provided to the Agent


The Tech Stack
Here is what powers this agent:
- Amazon Bedrock with Claude as the AI model for natural language understanding and tool orchestration
- Model Context Protocol (MCP) as the communication layer between the AI model and the tools
- YouTube Data API v3 for fetching real channel and video statistics
- Resend for sending styled HTML email reports with CSV attachments
- Python with libraries like boto3, google-api-python-client, and prompt-toolkit for the interactive CLI
How It Works (The Architecture)
The architecture follows the MCP pattern:

The flow is simple:
- You type a natural language request in the CLI
- Amazon Bedrock (Claude) reads the system prompt and decides which tool to call
- The MCP Client sends the request to the MCP Server
- The MCP Server executes the tool (YouTube API, CSV export, or Resend)
- The result comes back through the MCP Client to Bedrock
- Bedrock formats the response with insights and presents it to you
The key files are:
-
main.py- Entry point with the system prompt and app bootstrap
-
mcp_server.py- The MCP server with all three YouTube tools
-
mcp_client.py- The MCP client that handles communication between Bedrock and the server
The
core/ module handles the Bedrock client, chat loop, CLI interface, and tool execution. I built it following the MCP module from the Anthropic Academy course (more on that below).What I Learned
System prompts are everything. The behavior of the agent depends heavily on how you write the system prompt. I spent time making the agent proactive: after showing stats, it always suggests sending an email or doing a deeper analysis. But it never executes a tool without asking first. That balance comes from the system prompt.
MCP makes tool integration clean. Instead of writing custom function-calling logic, MCP gives you a standard way to define tools, expose them to the model, and handle the results. It is like building an API for your AI agent.
Small details matter. Things like parsing ISO 8601 duration formats, handling missing fields from the YouTube API, ranking results, and building proper HTML emails. These are the kinds of things that separate a demo from something you actually use.
Want to Build This Yourself?
I built this project after completing the Claude with Amazon Bedrock course on Anthropic Academy. The course covers everything from API basics to tool use, RAG, and MCP. The MCP module specifically gives you the foundation to build agents like this one.
I highly recommend the course if you want to understand the full architecture. It is free and very well structured.
The public repo with the main scripts (mcp_server.py, mcp_client.py, main.py) is available here:
You will need the
core/ module from the course to run it. Take the course, build the foundation, and then customize the agent for your own use case. Maybe you want to track Instagram stats, monitor stock prices, or analyze Spotify playlists. The pattern is the same.Summary
Building this agent showed me that the gap between "AI chatbot" and "AI tool that does real work" is smaller than you think. With Amazon Bedrock, MCP, and a few well-defined tools, you can build agents that fetch data, analyze it, and deliver results where you need them.
The best part? You can extend it. Add more tools, connect more APIs, and customize the system prompt. The foundation is there.
A little bit about myself, I came from the Data Engineering field with 6+ years of experience, but due to my AI-first mindset, I've become passionate about the world of AI after winning a couple of hackathons, and now I'm transitioning into the AI Engineering roadmap.
Let's Connect
I would love to hear from you. Whether you have questions about this project, want to collaborate, or just want to talk about AI and data.
- LinkedIn: alexanderbolano
- Website: Datexland
- Medium: @datexland
- AWS Community Builder: @datexland
- GitHub: @alexbonella
Built with Amazon Bedrock, MCP, and a lot of curiosity.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article