| 
1 | 1 | ---  | 
2 |  | -title: "Create an MCP Server using the TypeScript Framework"  | 
 | 2 | +title: "Create an MCP Server using the TypeScript Framework (Gram Functions)"  | 
3 | 3 | description: "Learn how to create and deploy an MCP server using Gram's TypeScript framework."  | 
4 | 4 | ---  | 
5 | 5 | 
 
  | 
6 |  | -## 🚧 Coming Soon! 🚧  | 
 | 6 | +import { Callout } from "@/mdx/components";  | 
7 | 7 | 
 
  | 
8 |  | -Gram's Functions and TypeScript Framework are currently under active  | 
9 |  | -development. Check back in the coming days for a detailed guide on getting  | 
10 |  | -started using these developer tools.  | 
 | 8 | +Welcome! This guide will walk you through the process of creating tools and a MCP server using Gram Functions.  | 
 | 9 | +Gram Functions allows you to deploy completely isolated tool call environments that can then be exposed as MCP servers.  | 
11 | 10 | 
 
  | 
12 |  | -In the meantime, check out the following resources:  | 
 | 11 | +```typescript filename="gram.ts"  | 
 | 12 | +import { Gram } from "@gram-ai/functions";  | 
 | 13 | +import * as z from "zod/mini";  | 
13 | 14 | 
 
  | 
14 |  | -- [GitHub Repository: Gram TypeScript Framework](https://github.com/speakeasy-api/gram/tree/main/ts-framework)  | 
15 |  | -- [Core Concepts: Gram Functions](/docs/gram/concepts/tool-sources#gram-functions)  | 
16 |  | -- [Gram CLI](/docs/gram/command-line/installation)  | 
17 |  | -- [Getting Started: OpenAPI](/docs/gram/getting-started/openapi)  | 
 | 15 | +const gram = new Gram().tool({  | 
 | 16 | +  name: "greet",  | 
 | 17 | +  description: "Greet someone special",  | 
 | 18 | +  inputSchema: { name: z.string() },  | 
 | 19 | +  async execute(ctx, input) {  | 
 | 20 | +    return ctx.text(`Hello, ${input.name}!`);  | 
 | 21 | +  },  | 
 | 22 | +});  | 
 | 23 | + | 
 | 24 | +export default gram;  | 
 | 25 | +```  | 
 | 26 | + | 
 | 27 | +## Step 1: Create a project  | 
 | 28 | + | 
 | 29 | +Gram offers a bootstrapper through `npm/pnpm create` to create a new project.  | 
 | 30 | + | 
 | 31 | +<Callout title="Note" type="info">  | 
 | 32 | +  Gram Functions currently requires a node version >=22.18.0  | 
 | 33 | +</Callout>   | 
 | 34 | + | 
 | 35 | +```bash  | 
 | 36 | +npm create @gram-ai/function  | 
 | 37 | +```  | 
 | 38 | + | 
 | 39 | +This will prompt you to pick a framework.  | 
 | 40 | +```bash  | 
 | 41 | +◆  Pick a framework  | 
 | 42 | +│  ● Gram (Default.  A simple framework to get started quickly)  | 
 | 43 | +│  ○ MCP (Gram also supports the official MCP SDK for more advanced use cases)  | 
 | 44 | +```  | 
 | 45 | + | 
 | 46 | +This will create a new project in the current directory.  | 
 | 47 | +```bash  | 
 | 48 | +cd my-mcp-server  | 
 | 49 | +```  | 
 | 50 | + | 
 | 51 | +Inside your project, you'll find the following files:  | 
 | 52 | +```bash  | 
 | 53 | +└── src  | 
 | 54 | +   ├── gram.ts <- Edit me!  | 
 | 55 | +   └── server.ts  | 
 | 56 | +└── package.json  | 
 | 57 | +└── README.md  | 
 | 58 | +...  | 
 | 59 | +```  | 
 | 60 | + | 
 | 61 | +## Step 2: Write your tools  | 
 | 62 | + | 
 | 63 | +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](/docs/gram/gram-functions/introduction) documentation.  | 
 | 64 | + | 
 | 65 | +```typescript filename="src/gram.ts"  | 
 | 66 | +import { Gram } from "@gram-ai/functions";  | 
 | 67 | +import * as z from "zod/mini";  | 
 | 68 | + | 
 | 69 | +const gram = new Gram().tool({  | 
 | 70 | +  name: "greet",  | 
 | 71 | +  description: "Greet someone special",  | 
 | 72 | +  inputSchema: { name: z.string() },  | 
 | 73 | +  async execute(ctx, input) {  | 
 | 74 | +    return ctx.json({ message: `Hello, ${input.name}!` });  | 
 | 75 | +  },  | 
 | 76 | +});  | 
 | 77 | + | 
 | 78 | +export default gram;  | 
 | 79 | +```  | 
 | 80 | + | 
 | 81 | +<Callout title="Note" type="info">  | 
 | 82 | +  You are not necessarily building an MCP server here. Write whatever tools you want--you will later be able   | 
 | 83 | +  to slice and dice them into MCP servers or combine them with other types of tools into existing MCP servers.  | 
 | 84 | +</Callout>   | 
 | 85 | + | 
 | 86 | +## Step 3: Build and deploy  | 
 | 87 | + | 
 | 88 | +To build and deploy your MCP server, run the following commands:  | 
 | 89 | + | 
 | 90 | +```bash  | 
 | 91 | +npm run build  | 
 | 92 | +npm run push  | 
 | 93 | +```  | 
 | 94 | + | 
 | 95 | +This will build your functions and deploy them to Gram. In the [Gram Dashboard](https://app.getgram.ai), you will see the function source you just uploaded and the tools it created.  | 
 | 96 | + | 
 | 97 | +  | 
 | 98 | + | 
 | 99 | +## Step 4: Create an MCP server  | 
 | 100 | + | 
 | 101 | +You can now add your tools to an existing MCP server or create a new one.  | 
 | 102 | + | 
 | 103 | +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.  | 
 | 104 | +For more information on toolsets, see the [Toolsets](/docs/gram/build-mcp) documentation.  | 
 | 105 | + | 
 | 106 | +  | 
 | 107 | + | 
 | 108 | +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.  | 
 | 109 | + | 
 | 110 | +  | 
 | 111 | + | 
 | 112 | +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](/docs/gram/host-mcp) documentation.  | 
0 commit comments