You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The framework validates inputs against the provided Zod schema by default. For strict validation, inputs that don't match the schema will be rejected.
94
+
95
+
### Lax mode
96
+
97
+
To allow unvalidated inputs, enable lax mode:
98
+
99
+
```typescript
100
+
const gram =newGram({ lax: true }).tool({
101
+
name: "flexible_tool",
102
+
inputSchema: { required: z.string() },
103
+
async execute(ctx, input) {
104
+
// input may contain additional properties not in the schema
105
+
returnctx.json({ received: input });
106
+
},
107
+
});
108
+
```
109
+
110
+
## Environment variables
111
+
112
+
Specify credentials or environment variable values that need to be provided to the tool runner. These can be provided either by end user set MCP headers or with stored Gram environments.
36
113
37
114
```typescript
38
115
const gram =newGram({
39
116
envSchema: {
40
-
BASE_URL: z.string().check(z.url()),
117
+
API_KEY: z.string().describe("API key for authentication"),
118
+
BASE_URL: z.string().url().describe("Base URL for API requests"),
Copy file name to clipboardExpand all lines: docs/gram/gram-functions/introduction.mdx
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,7 @@ title: "Gram Functions"
3
3
description: "Build custom tools with TypeScript functions for complete control over logic and dependencies."
4
4
---
5
5
6
-
Gram Functions allow you to create tools from TypeScript code.
7
-
Once deployed, they can be used just like any other tool in the Gram platform, allowing you to create and host MCP servers,
8
-
combine them with other tools into toolsets, build multi-tool workflows, and more.
6
+
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.
9
7
10
8
```typescript filename="gram.ts"
11
9
import { Gram } from"@gram-ai/functions";
@@ -25,12 +23,20 @@ export default gram;
25
23
26
24
## Getting started
27
25
28
-
To get started with Gram Functions, follow the [Getting Started](/docs/gram/getting-started/typescript) guide.
26
+
To get started with Gram Functions, scaffold a new project using the Gram template:
For a complete walkthrough, follow the [Getting Started](/docs/gram/getting-started/typescript) guide.
39
+
34
40
## Writing tools
35
41
36
42
Gram Functions can be written using the [Gram Functions Framework](/docs/gram/gram-functions/functions-framework) or the official [MCP SDK](/docs/gram/gram-functions/mcp-sdk).
@@ -63,12 +69,22 @@ npm run build
63
69
npm run push
64
70
```
65
71
66
-
## Functions vs. MCP Servers
72
+
## Functions vs. MCP servers
73
+
74
+
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.
75
+
76
+
The key distinction:
77
+
78
+
-**Functions**: Individual tools that represent specific capabilities or operations
79
+
-**MCP Servers**: Collections of tools combined into a single server that can be accessed by LLM clients
80
+
81
+
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:
82
+
83
+
- Split your Gram functions into multiple projects for convenience
84
+
- Keep every tool in one file
85
+
- Organize tools however makes sense for your workflow
67
86
68
-
Gram Functions are a great way to create tools that can be used in MCP servers.
69
-
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.
70
-
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](/docs/gram/concepts/toolsets) later in the Gram dashboard.
71
-
However, they are not the only way to create tools. You can also directly from OpenAPI documents.
87
+
MCP servers are created from [toolsets](/docs/gram/concepts/toolsets) later in the Gram dashboard. Tools can also be created directly from OpenAPI documents.
Copy file name to clipboardExpand all lines: docs/gram/gram-functions/mcp-sdk.mdx
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,10 +85,9 @@ server.registerResource(
85
85
After running `push` simply select that resource to add it to a toolset.
86
86

87
87
88
-
## Environment Variables
88
+
## Environment variables
89
89
90
-
You can specify credentials or envrionment variable values that will need to be made available in your tool runner envrionment.
91
-
These can be provided either by end user set MCP headers or with stored Gram environments.
90
+
Specify credentials or environment variable values that need to be made available in your tool runner environment. These can be provided either by end user set MCP headers or with stored Gram environments.
0 commit comments