Introduction

LLMs have a cutoff date and relies on web search to get the most current data. It often hallucinates by using a unreliable source or outdated training data. In this tutorial, we’ll build a simple Tako MCP Server that clients can use to search Tako for real-time data and ground their answer based on authoritative sources.

Prerequisites

Building Tako MCP

Starting your project

Let’s start by creating a new project directory using uv and install necessary packages

uv init tako-mcp
cd tako-mcp
uv venv
source .venv/bin/activate
uv add tako-sdk "mcp[cli]"

Initialize MCP Server and Tako client

We will need to import all the necessary modules and initialize MCP Server and Tako client.

from tako.client import TakoClient, KnowledgeSearchSourceIndex
from mcp.server.fastmcp import FastMCP

TAKO_API_KEY = os.getenv("TAKO_API_KEY")

# Initialize MCP Server and Tako Client
mcp = FastMCP("tako")
tako_client = TakoClient(api_key=TAKO_API_KEY)

We initialize the client with TAKO_API_KEY which is passed from an environment variable. We will configure the environment variable when we connect our server to a client.

Write Search Tako tool

We will write a tool that takes in client’s input as a string and search Tako by calling knowledge_search from the Tako client.

Also add a docstring description so the client can understand the functionality of the tool.

@mcp.tool()
async def search_tako(text: str) -> str:
    """Search Tako for any knowledge you want and get data and visualizations."""
    try:
        response = tako_client.knowledge_search(text=text)
    except Exception:
        return "No card found"
    return response.model_dump()

Add a prompt to optimize your query

Although Tako can take any natural language queries, we can add a prompt for the client to use to fine-tune their queries to Tako. Check out this guide for more information!

@mcp.prompt()
async def generate_search_tako_prompt(text: str) -> str:
    """Generate a prompt to search Tako for given user input text."""
    return f"""
    You are a data analyst agent that generates a Tako search query from a user input text to search Tako and retrieve real-time data and visualizations. 
    
    Generate queries and search Tako following the instructions below:
    
    Step 1. Generate search queries following the instructions below and call `search_tako(query)` for each query.
    * If the text includes a cohort such as "G7", "African Countries", "Magnificent 7 stocks", generate search queries for each individual countries, stocks, or companies within the cohort. For example, if user input includes "G7", generate queries for "United States", "Canada", "France", "Germany", "Italy", "Japan", and "United Kingdom".
    * If the text is about a broad topic, generate specific search queries related to the topic.
    * If the text can be answered by categorizing the data, generate search queries using semantic functions such as "Top 10", or "Bottom 10".
    * If the text is about a timeline, generate a search query starting with "Timeline of".
    * Search for a single metric per query. For example if user wants to know about a company, you may generate query like "Market Cap of Tesla" or "Revenue of Tesla" but not "Tesla's Market Cap and Revenue".
    
    Step 2. Ground your answer based on the results from Tako.
    * Using the data provided by Tako, ground your answer.
    
    Step 3. Add visualizations from Step 1 to your answer.
    * Use the embed or image link provided by Tako to add visualizations to your answer.
    
    <UserInputText>
    {text}
    </UserInputText>
    """

Server Initialization

Now add a line to start your server when the code runs.

if __name__ == "__main__":
    mcp.run(transport="stdio")

Add Tako MCP Server to Claude Desktop

Add the following to your .cursor/mcp.json or claude_desktop_config.json (MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json)

Python
{
    "mcpServers": {
        "takoApi": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/tako/mcp",
                "run",
                "main.py"
            ],
            "env": {
                "TAKO_API_KEY": "<TAKO_API_KEY>"
            }
        }
    }
}

Query Tako MCP using Claude Desktop

Try using the prompt we created above and query Tako.

  • Query Input: “Compare Magnificent 7 stock companies on relevant metrics.”

  • Chat Input: Write me a research report on the magnificent 7 companies. Embed the result in an iframe whenever necessary

Result: