# 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.

```typescript filename="gram.ts"

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}!`);
  },
});

```

## Getting started

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

```bash
pnpm create @gram-ai/function@latest --template gram
```

Install the required package:

```bash
pnpm add @gram-ai/functions
```

For a complete walkthrough, follow the [Getting Started](/docs/ai-control-plane/connect/sources/typescript) guide.

## Writing tools

You can write Functions using the [Functions Framework](/docs/ai-control-plane/connect/sources/functions/functions-framework) or the official [MCP SDK](/docs/ai-control-plane/connect/sources/functions/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.

```typescript filename="gram-framework.ts"

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}!`);
  },
});

```

## Deploying to Speakeasy

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](/docs/ai-control-plane/connect/sources/functions/build-deploy) guide to learn more.

```bash
npm run build
npm run push
```

## Functions vs MCP servers

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](/docs/ai-control-plane/reference/concepts/toolsets) later in the Speakeasy dashboard. Tools can also be created directly from OpenAPI documents.

### Local development

That said, you can run Functions as a local MCP server with the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) for testing and development purposes. Use the following command:

```bash
pnpm run dev
```
