Gram Functions
Gram Functions are compact code units that represent LLM tools. They allow you to create tools from TypeScript code that can be deployed to Gram and exposed to language models via MCP servers. 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.
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, scaffold a new project using the Gram template:
pnpm create @gram-ai/function@latest --template gramInstall the required package:
pnpm add @gram-ai/functionsFor a complete walkthrough, follow the Getting Started guide.
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.
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 pushFunctions vs. MCP servers
Gram Functions are a way to create individual tools that can be used in MCP servers. However, creating tools in Gram 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 Gram 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 Gram dashboard. Tools can also be created directly from OpenAPI documents.
Local development
With that said, Gram Functions can be run as a local MCP server with MCP Inspector
pnpm run devLast updated on