Skip to content

Connect

Speakeasy Functions

Speakeasy Functions are compact code units that represent LLM tools. They allow you to create tools from TypeScript code, deploy them to Speakeasy, and expose them to language models via MCP servers. Once deployed, Functions can be used just like any other tool on the platform, allowing you to create and host MCP servers, combine them with other tools into toolsets, build multi-tool workflows, and more.

import { Gram } from "@gram-ai/functions";
import * as z from "zod/mini";
const gram = new Gram().tool({
name: "greet",
description: "Greet someone special",
inputSchema: { name: z.string() },
async execute(ctx, input) {
return ctx.text(`Hello, ${input.name}!`);
},
});
export default gram;

To get started with Functions, scaffold a new project using the gram template:

Terminal window
pnpm create @gram-ai/function@latest --template gram

Install the required package:

Terminal window
pnpm add @gram-ai/functions

For a complete walkthrough, follow the Getting Started guide.

You can write Functions using the Functions Framework or the official MCP SDK. The Functions Framework is a more lightweight way to write tools, while MCP SDK support is available if you prefer to use the official SDK.

import { Gram } from "@gram-ai/functions";
import * as z from "zod/mini";
const gram = new Gram().tool({
name: "greet",
description: "Greet someone special",
inputSchema: { name: z.string() },
async execute(ctx, input) {
return ctx.text(`Hello, ${input.name}!`);
},
});
export default gram;

Speakeasy allows you to easily deploy and host your tools. Beyond hosting and running code for you, the platform offers a comprehensive set of features to help you build on top of your tools and deliver a powerful AI-native experience to your users. Follow the Build and deploy guide to learn more.

Terminal window
npm run build
npm run push

Functions provide a way to create individual tools for use in MCP servers. However, creating tools is not the same as creating MCP servers.

The key distinction:

  • Functions: Individual tools that represent specific capabilities or operations
  • MCP Servers: Collections of tools combined into a single server that can be accessed by LLM clients

Once you have created a tool (via Functions or OpenAPI), combine it with other tools into one or many MCP servers. This means you can:

  • Split your Functions into multiple projects for convenience
  • Keep every tool in one file
  • Organize tools however makes sense for your workflow

MCP servers are created from toolsets later in the Speakeasy dashboard. Tools can also be created directly from OpenAPI documents.

That said, you can run Functions as a local MCP server with the MCP Inspector for testing and development purposes. Use the following command:

Terminal window
pnpm run dev