{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "import asyncio\n", "from fastmcp import Client\n", "from fastmcp.client.transports import StreamableHttpTransport\n", "import nest_asyncio\n", "from dotenv import load_dotenv\n", "from IPython.display import Markdown, display\n", "\n", "nest_asyncio.apply()\n", "\n", "load_dotenv()\n", "\n", "ZAPIER_URL = os.getenv(\"ZAPIER_URL_FASTMCP\") # \"https://mcp.zapier.com/api/mcp/s/your-secret-key/mcp\"\n", "\n", "transport = StreamableHttpTransport(ZAPIER_URL)\n", "\n", "client = Client(transport=transport)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Available tools: [\n", " \"add_tools\",\n", " \"edit_tools\",\n", " \"gmail_find_email\"\n", "]" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Tool Used: gmail_find_email" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Subject: Meralco Bill for May 2025 for Customer Account Number (CAN) 1811346XXX" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Body: Welcome to Meralco Online\r\n", "\r\n", "\r\n", " \r\n", " \r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "Hi Stephen,\r\n", "\r\n", "\r\n", "\r\n", "Your Meralco bill for May 2025 bill is now available online. Below is the summary of your monthly billing.\r\n", "\r\n", "\r\n", "\r\n", "Customer Account Number (CAN): 1811346XXX\r\n", "\r\n", "SIN: XXXXX3130102\r\n", "\r\n", "Billing Period: 18 April 2025 to 18 May 2025\r\n", "\r\n", "kWh Consumption: 471\r\n", "\r\n", "Current Amount Due: PHP 6,464.10\r\n", "\r\n", "Due Date: 30 May 2025\r\n", "\r\n", "\r\n", "\r\n", "To access your bill and pay online, log on to your My Meralco Account or pay through our authorized payment partners using your 10-digit CAN. \r\n", "\r\n", "\r\n", "\r\n", "For further assistance, you may reach us via:\r\n", "\r\n", "FB Messenger: Fb.com/Meralco\r\n", "\r\n", "DM on X: @Meralco\r\n", "\r\n", "Email: \r\n", "mailto:customercare@meralco.com.ph \r\n", "customercare@meralco.com.ph \r\n", "\r\n", "\r\n", " \r\n", "Thanks for letting us serve you better!\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "**Disclaimer: The information contained in this email message is intended only for the individual or entity to which it is addressed, and such information may be privileged or confidential and protected under applicable laws. If you are not the intended recipient, you must not disseminate, distribute, store, print, copy or deliver this message. Email transmission cannot be guaranteed to be error-free owing to the nature of the internet. Therefore, you fully understand that MERALCO shall not be liable for any omission or error in this message which may arise as a result of email transmission. Further MERALCO does not warrant against, and will not be liable and/or responsible for, any loss or damage that the receipt, use or other disposition of this e-mail and/or its attachments may cause\r\n", " to the recipient’s computer or network.\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "https://click.email.meralco.com.ph/?qs=0ca8f807c32d824bad193d7e42080b3c9a4abbf7fcbe47d070fcae99d89f3e47c1cb767868c510cf260fa9fe15973f839bd81441d02f5d20 \r\n", "Meralco Terms of Use \r\n", "https://click.email.meralco.com.ph/?qs=81572b8dae599b7068de9f89a92dda1db20a12bc46d927e37281ec7954a98367a83afca0384cfab114199287dd69c1e7162ea47b8407b17e \r\n", "Privacy Policy\r\n", "This is a system-generated message and does not require a signature. Please do not reply to this email. Copyright (c) 2019. Meralco. All rights reserved\r\n", "\r\n", "https://click.email.meralco.com.ph/?qs=7d06fb219a628260bc24b5f9efab0670db31161ee470281eea3577ba031545bcc06c142a710eb074650dfc9fb4831eaf44cbd86564d6540e \r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "__PRESENT\r\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "async def main(): \n", " async with client: \n", " \n", " # Tool Discovery i.e. query the available tools from the MCP server and print them\n", " tools = await client.list_tools()\n", "\n", " display(Markdown(f\"Available tools: {json.dumps([t.name for t in tools], indent=2)}\"))\n", "\n", " display(Markdown(f\"\"\"Tool Used: {tools[-1].name}\"\"\"))\n", "\n", " # Tool Invocation i.e. call the tool and print the results \n", " result = await client.call_tool(\n", " tools[-1].name,\n", " {\n", " \"instructions\": \"Execute the Gmail: Find Email tool with the following parameters\",\n", " \"query\": \"Meralco\", # the search term\n", " },\n", " )\n", "\n", " # Parse the JSON string\n", " json_result = json.loads(result[0].text)\n", " subject = json_result[\"results\"][0][\"raw\"][\"payload\"]['headers']['Subject']\n", " body = json_result[\"results\"][0][\"body_plain\"]\n", " \n", " # Print the 'Subject' and 'Body' of the requested email (Meralco)\n", " display(Markdown(f'Subject: {subject}'))\n", " display(Markdown('Body: ' + body))\n", "\n", "\n", "if __name__ == \"__main__\":\n", " asyncio.run(main())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv-mcp", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }