Building a Trading Cards Shopping Agent with Gemini CLI and MCP
Did you know that trading cards, those little pieces of cardboard and ink, are a big business? It is a $10B market annually, and it’s only growing. And that growth is much to my chagrin as a collector, as demand is vastly outpacing supply and scalping has become unfortunately common.
I have been working on my Pokémon card collection, having completed the original Base set after over 25 years. I have been collecting modern cards as well. Sometimes I will buy booster packs, containing 10 random cards of a given set, but often it’s easier and cheaper to buy them as singles online.
The biggest site to do this is TCGPlayer a website designed to make it easy for me, as a buyer, to find the exact card I want with whatever side conditions I want such as quality, language, variant, and more. At the same time, it doesn’t directly connect to my existing collection. It’d be great if, instead of having to jump between two websites, I could connect them together.
Really, I just want to go to a particular set, put all the cards I don’t have into my shopping cart in TCG Player, and then optimize and purchase.
This is what brought me to modern tools such as the Gemini CLI, which can use AI tools including the Model Context Protocol to easily connect websites together.
Browser MCP
When you start up Gemini CLI, you can ask it questions and it can take a few local actions, but cannot do anything beyond that. However, if you want to do more, you can easily install new tools. My first pick was Browser MCP, a server which allows me to easily get Gemini to take actions on a particular tab of my browser.
You can add Browser MCP to your Gemini settings and then it will appear when you run gemini mcp list:
So my first attempt was to just solve everything with a single prompt. I’d go to a set page and then give Gemini a prompt: For each unowned Pokemon card, open the URL and add it to my cart.
What’s really cool is that this happens pretty seamlessly. Because Browser MCP runs locally, in a tab of your choice, you get to see it changing links and moving a cursor around on the page:
Unfortunately, I realized that it got it kinda wrong. The Gemini CLI opened up the tab for Drilbur, a card that I don’t own but is marked as in my wishlist (because I have one coming in the mail already).
I queried Gemini again to see if it knew which cards are not in my wishlist.
Custom MCP Server
It seems like I can’t orchestrate everything just through Gemini and a browser tab. A little more work seems necessary. Rather than just getting Gemini to read through a webpage on TCG Collector, it probably makes sense to be able to pull this data in a structured JSON format. Unfortunately, the website’s API is restricted to select partners and I didn’t want to spend a bunch of time waiting for an API key.
I did the next best thing which is to create my own MCP server and hand-wave the data. Just getting to some demo means hardcoding the data, but I can try to pull the data realistically. Opening up the JS console in TCG Collector, I ran a short script to output a JSON array with names and shopping URLs. I could add more data if I ever feel like it’s necessary in the future. But this is enough to send into Gemini.
I can build a simple MCP server using Python by following this MCP codelab. Once you go through it and get a currency agent, it’s quite easy to add a second tool (or any others). So I built a simple MCP tool which returns my JSON array. Then I add it to my Gemini settings:
"my-mcp-server": {
"httpUrl": "http://127.0.0.1:8080/mcp"
}Once this is setup, Gemini will now know definitively which cards are not owned and it will know definitively the URL to visit. In theory, this makes everything a lot easier.
So I gave it the same prompt: For each unowned Pokemon card, open the URL and add it to my cart.
This time it knows which ones to grab and it begins to operate autonomously. It visits the first few pages. However, it does start struggling for some reason. I copied the URLs and verified that they do load. I can confirm that Gemini is opening the URLs in my browser tab. However, it seems unable to click the Add to Cart button.
That isn’t entirely true. It is able to grab the first few cards and put them in my cart. But then for whatever reason it decides to get spooked and quit. Then it started refusing to do this work as it knew it didn’t work. I had to be a little more strict in my prompt.
I thought about adding in some manual pauses might be necessary, to give things time to load. However, even after telling it please, and having it try again, Gemini was still unable to go beyond a few cards before giving up.
Another problem is that Gemini fits all the webpages into its context. This is great for answering questions and performing actions, but it does mean that every single page in the context can quickly use up tokens. At a certain point, Gemini can run out of tokens. There is a token counter in the corner letting me know.
Clearly, just giving it an entire array and telling it to figure it out was not working. But if I tell it to do a single card, it works fine. If I prompt it each time, telling it to get Serperior, then Simisage, then Lilligant, etc. it isn’t actually faster than doing it manually myself.
However, I don’t need to prompt it manually. Because this is a Gemini CLI, I can take advantage of CLI scripting in order to create a bunch of individual commands to Gemini.
Chaining Gemini prompts
I had to modify my script above to just get a list of the URLs and save them into a urls.txt file separated by newlines. In the future, I could probably do this manually either through Gemini or some other sort of API call. To make it easier, I’ve updated my browser extension to do this in a single button click.
To provide an automated prompt to Gemini, you can add a prompt argument flag. You can add a few different flags. For instance, by using the flag--yoloyou are able to automatically enable all and any tools in your Gemini settings to resolve the prompt. You can also pick the model you want to use. By default, Gemini uses 2.5 Pro. This is fine, except for free users like my personal account means Gemini runs out of quota too soon. So I changed it to always use 2.5 Flash. This is good enough to do simple tasks like what I want.
I also changed my prompt after a little more work. Turns out telling it to Add to Cart isn’t useful because there are more than one of these buttons with that text. I think that is what causes Gemini to get spooked and quit. Rather, by giving it the vaguer prompt of pressing “the button” somehow allows it to do the exact right thing.
#!/bin/bash
# Check if the URL file exists
if [ ! -f "/mnt/c/Users/handn/Development/currency-agent/card-urls.txt" ]; then
echo "Error: card-urls.txt not found!"
exit 1
fi
# Read each URL from the file line by line
while read -r url; do
echo " - - - - - - - - - - - - - - - - - - "
echo "Processing URL: $url"
echo " - - - - - - - - - - - - - - - - - - "
# Send a focused, two-step prompt to the Gemini CLI for the current URL.
# Note the use of double quotes around the whole prompt and single quotes inside.
gemini - yolo - model gemini-2.5-flash - prompt "First, go to the URL $url. Wait a second and then press the button and wait a second."
# Optional: Add a small delay to be respectful to the server
sleep 2
done < "/mnt/c/Users/handn/Development/currency-agent/card-urls.txt"
echo "All URLs have been processed."You can see now that it is able to go to each card URL and press the button. Then the prompt is over. It has done its job. After that, I create an entirely new session with no previous context in order to execute the next action. This means I don’t fill up the context and each session is able to do one task successfully and autonomously.
Cart Optimization
This system isn’t entirely done yet. I want to make sure my cart is optimized. I don’t want to buy 50 cards from 50 different vendors because then I could spend more money on shipping than on the actual cards. TCG Player has a feature that can cut down on the number of individual packages by pooling your order against the smallest number of vendors.
I tried to add this as a capability in my Bash script by adding more instructions at the bottom, after my buying loop.
gemini --yolo --model gemini-2.5-flash --prompt "Go to the shopping cart page https://www.tcgplayer.com/cart. Then, press the Optimize button. Wait until the optimization is done. Then select the option with the fewest packages."
gemini --yolo --model gemini-2.5-flash --prompt "You are on the shopping webpage of TCG Player. Look at the contents of each package. If there is one item in the package from that shop, remove that package. Check the shipping details of that package in the cart. If they do not offer discounted or free shipping, remove that package."
echo "All URLs have been processed."When I checked after the script finished, I didn’t see anything in my cart. Apparently the LLM decided that every package needed to be removed, so that is what it did. I don’t think this is what I envisioned, so it’s clear that I need to think more about precision in my prompts.
Conclusion
This has been working reasonably well in order to save me a lot of time, although there are still some refinements I would like to make.
I might need to implement a budgeting system. While paying seven cents for a Victini is not a problem, I don’t know if I am ready to pay four hundred dollars for a full-art Zekrom. If I could give a limit such as fifty cards or fifty dollars, that might help. Or maybe for these pricey cards I should add a capability to track the market price over time to buy at the right moment.
Another capability that makes sense is to close the loop. Once it is in my cart, I should return to TCG Collector and add these cards to my wishlist. That way the next buying process can be up-to-date.
There are some things that are probably far away from automation such as actually making the transaction. I don’t want to just hand-off my credit card without ensuring that it isn’t going to end up billing me several hundred dollars.
It could be useful if I didn’t need to use Bash to script a bunch of Gemini calls together but I could use Gemini to delegate calls itself. Perhaps to do that I need to build a Shopping agent and Gemini knows how to call the agent multiple times for each card I want to add. That might be future work to look into as well.
Until then, I’m going to walk over to my mailbox and eagerly await my deliveries.
