Speakeasy Logo
Skip to Content
Gram DocumentationGram FunctionsIntroduction

Gram Functions

Gram Functions allow you to create tools from TypeScript code. Once deployed, they can be used just like any other tool in the Gram platform, allowing you to create and host MCP servers, combine them with other tools into toolsets, build multi-tool workflows, and more.

gram.ts
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;

Getting started

To get started with Gram Functions, follow the Getting Started guide.

npm create @gram-ai/function

Writing tools

Gram Functions can be written using the Gram 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.

gram-framework.ts
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;

Deploying to Gram

Gram allows you to easily deploy and host your tools. Beyond hosting and running code for you, Gram 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.

npm run build npm run push

Functions vs. MCP Servers

Gram Functions are a great way to create tools that can be used in MCP servers. However, creating tools in Gram is not the same as creating MCP servers. Once you have created a tool (via Functions or OpenAPI), you can combine it with other tools into one (or many) MCP servers. You can therefore split your Gram functions into multiple projects for convenience, or keep every tool in one file. MCP servers will be created from toolsets later in the Gram dashboard. However, they are not the only way to create tools. You can also directly from OpenAPI documents.

Local development

With that said, Gram Functions can be run as a local MCP server with MCP Inspector  for testing and development purposes. Simply run:

pnpm run dev

Last updated on