Skip to content

Commit 40c1a00

Browse files
committed
Sync open source content 🐝 (from 9cff8d127dfec54c7ac42e2f349cd7f09c7ad581)
1 parent bc8b95e commit 40c1a00

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Add OAuth
3+
description: Learn how to implement OAuth authentication in Gram Functions for secure third-party integrations.
4+
---
5+
6+
Integrating OAuth into Gram Functions is a simple process.
7+
8+
## Accessing the token
9+
10+
```typescript filename="src/gram.ts"
11+
const gram = new Gram({
12+
envSchema: {
13+
GOOGLE_ACCESS_TOKEN: z.string().describe("Google OAuth2 access token"),
14+
},
15+
authInput: {
16+
oauthVariable: "GOOGLE_ACCESS_TOKEN",
17+
},
18+
})
19+
.tool({
20+
name: "search_files",
21+
description:
22+
"Search for PDF files in Google Drive. Takes a search query and returns matching files based on their filename.",
23+
},
24+
async execute(ctx, input) {
25+
const token = ctx.env.GOOGLE_ACCESS_TOKEN;
26+
return fetch(`https://www.googleapis.com/drive/v3/files`, {
27+
headers: { Authorization: `Bearer ${token}` },
28+
});
29+
},
30+
});
31+
```
32+
33+
The `authInput` object is used to specify which environment varibale should be populated with the OAuth token.
34+
Gram will then handle the OAuth exchange and automatically supply the token to your function.
35+
36+
Note that this will only work if you follow the steps below to enable OAuth for your MCP server.
37+
38+
## Adding OAuth to your MCP server
39+
40+
Configuring OAuth for a toolset containing Gram Functions is the same as configuring OAuth for any other toolset.
41+
You can follow the steps in our [guide](/docs/gram/host-mcp/adding-oauth) to get started.
42+
43+
## Caveats
44+
45+
MCP servers can only have one authentication method. This means that toolsets cannot contain tools that require different forms of OAuth (though they can contain any number of tools that DO NOT require OAuth alongside tools of a single OAuth type).

0 commit comments

Comments
 (0)