Skip to content

New Official SDKs for TypeScript, Python and Go

SerpKite
Get API key

TypeScript · @mastra/core

Mastra + SerpKite

Build a Google search tool with Mastra's createTool and a zod schema, attach it to an Agent and call generate. SerpKite returns Markdown the agent can read directly.

Overview

What Mastra is, and where SerpKite fits

Mastra is a TypeScript framework for agents, workflows and RAG. Tools are created with createTool from @mastra/core/tools, with a zod inputSchema and an execute function.

The example targets Mastra 1.x, where execute receives the validated input as its first argument, and calls SerpKite through the official serpkite TypeScript SDK.

Setup

Set it up in 4 steps

  1. 1

    Get an API key

    Sign up (no card), create a key in the dashboard and export it as SERPKITE_API_KEY. New accounts get 2,500 free credits, then 1,000 every month.

    export SERPKITE_API_KEY=skt_live_…
  2. 2

    Install

    Add Mastra to an existing project (or start with npm create mastra@latest).

    npm install serpkite @mastra/core zod
  3. 3

    Create the tool

    Define an input and output schema and call SerpKite in execute.

  4. 4

    Register it on an agent

    Tools are passed as an object keyed by name.

Code

Complete example

src/mastra/agents/researcher.ts
import { Agent } from "@mastra/core/agent";
import { createTool } from "@mastra/core/tools";
import { SerpKite, SerpKiteError } from "serpkite";
import { z } from "zod";

const sk = new SerpKite(); // reads SERPKITE_API_KEY

export const googleSearch = createTool({
  id: "google-search",
  description: "Search Google for current information. Returns the top results with links, People Also Ask and related searches as Markdown. Use for recent events, facts and anything after your training cutoff.",
  inputSchema: z.object({
    query: z.string().describe("The search query"),
    country: z.string().default("us").describe("Two-letter country code"),
  }),
  outputSchema: z.object({ markdown: z.string() }),
  execute: async ({ query, country }) => {
    try {
      return { markdown: await sk.search({ q: query, country, format: "markdown" }) };
    } catch (err) {
      if (err instanceof SerpKiteError) return { markdown: `Search failed: ${err.message}` };
      throw err;
    }
  },
});

export const researcher = new Agent({
  id: "researcher",
  name: "Researcher",
  instructions: "Search the web before answering. Cite the URLs you used.",
  model: "openai/gpt-5-mini",
  tools: { googleSearch },
});

const result = await researcher.generate("What are the best-rated coffee roasters in Berlin?");
console.log(result.text);

FAQ

Mastra and SerpKite: common questions

Start building

Give your Mastra project Google search

2,500 free credits, then 1,000 every month. No credit card.