{"id":24404,"date":"2025-09-15T20:23:12","date_gmt":"2025-09-15T20:23:12","guid":{"rendered":"https:\/\/www.newsbeep.com\/nz\/24404\/"},"modified":"2025-09-15T20:23:12","modified_gmt":"2025-09-15T20:23:12","slug":"heres-how-i-built-an-mcp-to-automate-my-data-science-job","status":"publish","type":"post","link":"https:\/\/www.newsbeep.com\/nz\/24404\/","title":{"rendered":"Here\u2019s How I Built an MCP to Automate My Data Science Job"},"content":{"rendered":"<p>    <img decoding=\"async\" alt=\"How I Built an MCP to Automate My Data Science Job\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.newsbeep.com\/nz\/wp-content\/uploads\/2025\/09\/MCP-for-Data-Science-V1.jpeg\"\/><br \/>Image by Ideogram<br \/>\n\u00a0<\/p>\n<p>Most of my days as a data scientist look like this:<\/p>\n<p>Stakeholder: &#8220;Can you tell us how much we made in advertising revenue in the last month and what percentage of that came from search ads?&#8221;<br \/>\nMe: &#8220;Run an SQL query to extract the data and hand it to them.&#8221;<br \/>\nStakeholder: &#8220;I see. What is our revenue forecast for the next 3 years?&#8221;<br \/>\nMe: &#8220;Consolidate data from multiple sources, speak to the finance team, and build a model that forecasts revenue.&#8221;<\/p>\n<p>Tasks like the above are ad hoc requests from business stakeholders. They take around 3\u20135 hours to complete and are usually unrelated to the core project I&#8217;m working on.<\/p>\n<p>When data-related questions like these come in, they often require me to push the deadlines of current projects or work extra hours to get the job done. And this is where AI comes in.<\/p>\n<p>Once AI models like <a href=\"https:\/\/openai.com\/chatgpt\" target=\"_blank\" rel=\"nofollow noopener\">ChatGPT<\/a> and <a href=\"https:\/\/claude.ai\/\" target=\"_blank\" rel=\"nofollow noopener\">Claude<\/a> were made available, the team&#8217;s efficiency improved, as did my ability to respond to ad hoc stakeholder requests. AI dramatically reduced the time I spent writing code, generating SQL queries, and even collaborating with different teams for required information. Additionally, after AI code assistants like <a href=\"https:\/\/www.cursor.com\/\" target=\"_blank\" rel=\"nofollow noopener\">Cursor<\/a> were integrated with our codebases, efficiency gains improved even further. Tasks like the one I just explained above could now be completed twice as fast as before.<\/p>\n<p>Recently, when MCP servers started gaining popularity, I thought to myself:<\/p>\n<p>\u00a0<\/p>\n<p>\nCan I build an MCP that automates these data science workflows further?\n<\/p>\n<p>\u00a0<\/p>\n<p>I spent two days building this MCP server, and in this article, I will break down:<\/p>\n<p>The results and how much time I&#8217;ve saved with my data science MCP<br \/>\nResources and reference materials used to create the MCP<br \/>\nThe basic setup, APIs, and services I integrated into my workflow<\/p>\n<p>\u00a0<\/p>\n<p>#\u00a0Building a Data Science MCP<\/p>\n<p>\u00a0<br \/>If you don&#8217;t already know what an MCP is, it stands for Model Context Protocol and is a framework that allows you to connect a large language model to external services.<br \/><a href=\"https:\/\/youtu.be\/bC3mIQWHZMQ?si=GQfqAfVDJiBocsPZ\" target=\"_blank\" rel=\"nofollow noopener\">This video<\/a> is a great introduction to MCPs.<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0The Core Problem<\/p>\n<p>The problem I wanted to solve with my new data science MCP was:<\/p>\n<p>\nHow do I consolidate information that is scattered across various sources and generate results that can directly be used by stakeholders and team members?\n<\/p>\n<p>\u00a0<\/p>\n<p>To accomplish this, I built an MCP with three components, as shown in the flowchart below:<\/p>\n<p>\u00a0<\/p>\n<p><img decoding=\"async\" alt=\"Data Science MCP Flowchart\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.newsbeep.com\/nz\/wp-content\/uploads\/2025\/09\/Data-Science-MCP-Flowchart.png\"\/><br \/>Image by Author | Mermaid<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Component 1: Query Bank Integration<\/p>\n<p>As a knowledge base for my MCP, I used my team&#8217;s query bank (which contained questions, a sample query to answer the question, and some context about the tables).<\/p>\n<p>When a stakeholder asks me a question like this:<\/p>\n<p>What percentage of advertising revenue came from search ads?<\/p>\n<p>I no longer have to look through multiple tables and column names to generate a query. The MCP instead searches the query bank for a similar question. It then gains context about the relevant tables it should query and adapts these queries to my specific question. All I need to do is call the MCP server, paste in my stakeholder&#8217;s request, and I get a relevant query in a few minutes.<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Component 2: Google Drive Integration<\/p>\n<p>Product documentation is usually stored in Google Drive\u2014whether it&#8217;s a slide deck, document, or spreadsheet.<\/p>\n<p>I connected my MCP server to the team&#8217;s Google Drive so it had access to all our documentation across dozens of projects. This helps quickly extract data and answer questions like:<\/p>\n<p>Can you tell us how much we made in advertising revenue in the last month?<\/p>\n<p>I also indexed these documents to extract specific keywords and titles, so the MCP simply has to go through the keyword list based on the query rather than accessing hundreds of pages at once.<\/p>\n<p>For example, if someone asks a question related to &#8220;mobile video ads,&#8221; the MCP will first search through the document index to identify the most relevant files before looking through them.<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Component 3: Local Document Access<\/p>\n<p>This is the simplest component of the MCP, where I have a local folder that the MCP searches through. I add or remove files as needed, allowing me to add my own context, information, and instructions on top of my team&#8217;s projects.<\/p>\n<p>\u00a0<\/p>\n<p>#\u00a0Summary: How My Data Science MCP Works<\/p>\n<p>\u00a0<br \/>Here&#8217;s an example of how my MCP currently works to answer ad hoc data requests:<\/p>\n<p>A question comes in:\u200a&#8221;How many video ad impressions did we serve in Q3, and how much ad demand do we have relative to supply?&#8221;<br \/>\nThe document retrieval MCP searches our project folder for &#8220;Q3,&#8221; &#8220;video,&#8221; &#8220;ad,&#8221; &#8220;demand,&#8221; and &#8220;supply,&#8221; and finds relevant project documents<br \/>\nIt then retrieves specific details about the Q3 video ad campaign, its supply, and demand from team documents<br \/>\nIt searches the query bank for similar questions about ad serves<br \/>\nIt uses the context obtained from the documents and query bank to generate an SQL query about Q3&#8217;s video campaign<br \/>\nFinally, the query is passed to a separate MCP that is connected to Presto SQL, which is automatically executed<br \/>\nI then gather the results, review them, and send them to my stakeholders<\/p>\n<p>\u00a0<\/p>\n<p>#\u00a0Implementation Details<\/p>\n<p>\u00a0<br \/>Here is how I implemented this MCP:<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Step 1: Cursor Installation<\/p>\n<p>I used Cursor as my MCP client. You can install Cursor from <a href=\"https:\/\/cursor.com\/\" target=\"_blank\" rel=\"nofollow noopener\">this link<\/a>. It is essentially an AI code editor that can access your codebase and use it to generate or modify code.<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Step 2: Google Drive Credentials<\/p>\n<p>Almost all the documents used by this MCP (including the query bank) were stored in Google Drive.<\/p>\n<p>To give your MCP access to Google Drive, Sheets, and Docs, you&#8217;ll need to set up API access:<\/p>\n<p>Go to the Google Cloud Console and create a new project.<br \/>\nEnable the following APIs: Google Drive, Google Sheets, Google Docs.<br \/>\nCreate credentials (OAuth 2.0 client ID) and save them in a file called credentials.json.<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Step 3: Set Up FastMCP<\/p>\n<p><a href=\"https:\/\/github.com\/jxnl\/fastmcp\" target=\"_blank\" rel=\"nofollow noopener\">FastMCP<\/a> is an open-source Python framework used to build MCP servers. I followed <a href=\"https:\/\/youtu.be\/rnljvmHorQw?si=_OmIlhq567Mwmng5\" target=\"_blank\" rel=\"nofollow noopener\">this tutorial<\/a> to build my first MCP server using FastMCP.<\/p>\n<p>(Note: This tutorial uses Claude Desktop as the MCP client, but the steps are applicable to Cursor or any AI code editor of your choice.)<\/p>\n<p>With FastMCP, you can create the MCP server with Google integration (sample code snippet below):<\/p>\n<p>@mcp.tool()&#13;<br \/>\ndef search_team_docs(query: str) -&gt; str:&#13;<br \/>\n    &#8220;&#8221;&#8221;Search team documents in Google Drive&#8221;&#8221;&#8221;&#13;<br \/>\n    drive_service, _ = get_google_services()&#13;<br \/>\n    # Your search logic here&#13;<br \/>\n    return f&#8221;Searching for: {query}&#8221;<\/p>\n<p>\u00a0<\/p>\n<p>\/\/\u00a0Step 4: Configure the MCP<\/p>\n<p>Once your MCP is built, you can configure it in Cursor. This can be done by navigating to Cursor&#8217;s Settings window \u2192 Features \u2192 Model Context Protocol. Here, you&#8217;ll see a section where you can add an MCP server. When you click on it, a file called mcp.json will open, where you can include the configuration for your new MCP server.<\/p>\n<p>This is an example of what your configuration should look like:<\/p>\n<p>{&#13;<br \/>\n  &#8220;mcpServers&#8221;: {&#13;<br \/>\n    &#8220;team-data-assistant&#8221;: {&#13;<br \/>\n      &#8220;command&#8221;: &#8220;python&#8221;,&#13;<br \/>\n      &#8220;args&#8221;: [&#8220;path\/to\/team_data_server.py&#8221;],&#13;<br \/>\n      &#8220;env&#8221;: {&#13;<br \/>\n        &#8220;GOOGLE_APPLICATION_CREDENTIALS&#8221;: &#8220;path\/to\/credentials.json&#8221;&#13;<br \/>\n      }&#13;<br \/>\n    }&#13;<br \/>\n  }&#13;<br \/>\n}<\/p>\n<p>\u00a0<\/p>\n<p>After saving your changes to the JSON file, you can enable this MCP and start using it within Cursor.<\/p>\n<p>\u00a0<\/p>\n<p>#\u00a0Final Thoughts<\/p>\n<p>\u00a0<br \/>This MCP server was a simple side project I decided to build to save time on my personal data science workflows. It isn&#8217;t groundbreaking, but this tool solves my immediate pain point: spending hours answering ad hoc data requests that take away from the core projects I&#8217;m working on. I believe that a tool like this simply scratches the surface of what&#8217;s possible with generative AI and represents a broader shift in how data science work gets done.<\/p>\n<p>The traditional data science workflow is moving away from:<\/p>\n<p>Spending hours finding data<br \/>\nWriting code<br \/>\nBuilding models<\/p>\n<p>The focus is shifting away from hands-on technical work, and data scientists are now expected to look at the bigger picture and solve business problems. In some cases, we are expected to oversee product decisions and step in as a product or project manager.<\/p>\n<p>As AI continues to evolve, I believe that the lines between technical roles will become blurred. What will remain relevant is the skill of understanding business context, asking the right questions, interpreting results, and communicating insights. If you are a data scientist (or an aspiring one), there is no question that AI will change the way you work.<\/p>\n<p>You have two choices: you can either adopt AI tools and build solutions that shape this change for your team, or let others build them for you.<br \/>\u00a0<br \/>\u00a0<\/p>\n<p><a href=\"https:\/\/linktr.ee\/natasshaselvaraj\" rel=\"noopener nofollow\" target=\"_blank\"><a href=\"https:\/\/linktr.ee\/natasshaselvaraj\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Natassha Selvaraj<\/a><\/a> is a self-taught data scientist with a passion for writing. Natassha writes on everything data science-related, a true master of all data topics. You can connect with her on <a href=\"https:\/\/www.linkedin.com\/in\/natassha-selvaraj-33430717a\/\" rel=\"noopener nofollow\" target=\"_blank\">LinkedIn<\/a> or check out her <a href=\"https:\/\/www.youtube.com\/@natassha_ds\" rel=\"nofollow noopener\" target=\"_blank\">YouTube channel<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"Image by Ideogram \u00a0 Most of my days as a data scientist look like this: Stakeholder: &#8220;Can you&hellip;\n","protected":false},"author":2,"featured_media":24405,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[365,363,364,111,139,69,145],"class_list":["post-24404","post","type-post","status-publish","format-standard","has-post-thumbnail","category-artificial-intelligence","tag-ai","tag-artificial-intelligence","tag-artificialintelligence","tag-new-zealand","tag-newzealand","tag-nz","tag-technology"],"_links":{"self":[{"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/posts\/24404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/comments?post=24404"}],"version-history":[{"count":0,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/posts\/24404\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/media\/24405"}],"wp:attachment":[{"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/media?parent=24404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/categories?post=24404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.newsbeep.com\/nz\/wp-json\/wp\/v2\/tags?post=24404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}