Speakeasy Logo
Skip to Content

Create an MCP Server using the TypeScript Framework (Gram Functions)

When you need to build tools with custom business logic, data transformations, or multi-step workflows, Gram Functions provides a TypeScript framework for creating serverless functions that can be exposed as MCP server tools. Unlike OpenAPI-sourced tools which simply wrap existing API endpoints, Gram Functions allow you to write custom code that executes in isolated environments.

Gram Functions-sourced MCP tools are ideal for the following use cases:

  • Custom business logic: Implement complex calculations, data processing, or decision-making logic that goes beyond simple API calls. For example, aggregating data from multiple sources or applying custom validation rules.
  • Data transformations: Transform, filter, or enrich data before returning it to LLM clients. For example, parsing and summarizing large datasets or converting between data formats.
  • Multi-step workflows: Orchestrate multiple API calls or operations in a single tool. For example, creating a tool that searches for data, processes it, and then stores the results.

This guide walks through the steps of building an MCP server with Gram Functions. This includes:

  • Creating a new Gram Functions project,
  • Writing custom tools with TypeScript,
  • Deploying your functions to Gram, and
  • Creating an MCP server from your tools.

Before you start

This guide assumes that you have already done the following:

  • Created a Gram account ,
  • Created a Gram project (accomplished during onboarding), and
  • Installed Node.js version >=22.18.0.

Step 1: Create a project

Gram offers a bootstrapper through npm/pnpm create to create a new project.

npm create @gram-ai/function

This will prompt you to pick a framework.

Pick a framework Gram (Default. A simple framework to get started quickly) MCP (Gram also supports the official MCP SDK for more advanced use cases)

This will create a new project in the current directory.

cd my-mcp-server

Inside your project, you’ll find the following files:

└── src ├── gram.ts <- Edit me! └── server.ts └── package.json └── README.md ...

Step 2: Write your tools

Open src/gram.ts and write your tools. You can add as many tools as you want, or leave it as-is to use the default tool. For more information on writing tools, see the Gram Functions documentation.

src/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.json({ message: `Hello, ${input.name}!` }); }, }); export default gram;

Step 3: Build and deploy

To build and deploy your MCP server, run the following commands:

npm run build npm run push

This will build your functions and deploy them to Gram. In the Gram Dashboard , you will see the function source you just uploaded and the tools it created.

Gram Dashboard, showing the function source you just uploaded

Step 4: Create an MCP server

You can now add your tools to an existing MCP server or create a new one.

To create a new MCP server, go to the Toolsets page and click Create A Toolset (or + Add Toolset). Name it whatever you want. A toolset is a group of tools that can be exposed as an MCP server. For more information on toolsets, see the Toolsets documentation.

Gram Dashboard, showing the create toolset dialog

Now, click Add Tools to add your tools to the toolset. You’ll see the tools you defined in your src/gram.ts file listed here.

Gram Dashboard, showing the add tools dialog

Finally, head to the MCP tab on the toolset page and click Enable. Check out the Install Page linked therein for help installing the MCP server in your favorite client. For more information on MCP servers, see the MCP Servers documentation.

What’s next?

The following resources will help you get the most out of your Gram MCP server:

Last updated on