Skip to content

Commit cf6fdea

Browse files
Danny/openai devtok (#16819)
* Updating OpenAI playground info * Update pnpm-lock.yaml
1 parent 630af8d commit cf6fdea

File tree

3 files changed

+150
-97
lines changed

3 files changed

+150
-97
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
import { styles } from "../utils/componentStyles";
5+
6+
export default function TemporaryTokenGenerator() {
7+
const [
8+
token,
9+
setToken,
10+
] = useState("");
11+
const [
12+
copied,
13+
setCopied,
14+
] = useState(false);
15+
16+
// Generate a UUID v4
17+
function generateUUID() {
18+
return crypto.randomUUID();
19+
}
20+
21+
function generateToken() {
22+
const uuid = generateUUID();
23+
const newToken = `devtok_${uuid}`;
24+
setToken(newToken);
25+
setCopied(false);
26+
}
27+
28+
async function copyToClipboard() {
29+
try {
30+
await navigator.clipboard.writeText(token);
31+
setCopied(true);
32+
setTimeout(() => setCopied(false), 2000);
33+
} catch (err) {
34+
console.error("Failed to copy:", err);
35+
}
36+
}
37+
38+
return (
39+
<div className={styles.container}>
40+
<div className={styles.header}>
41+
Generate a temporary access token
42+
</div>
43+
<div className="p-4">
44+
<div className="mb-4">
45+
<button
46+
onClick={generateToken}
47+
className={styles.primaryButton}
48+
>
49+
Generate token
50+
</button>
51+
</div>
52+
53+
{token && (
54+
<div className="mt-4">
55+
<div className="flex items-center gap-2">
56+
<div className={styles.codeDisplay + " flex-1"}>
57+
<code className={styles.codeText}>{token}</code>
58+
</div>
59+
<button
60+
onClick={copyToClipboard}
61+
className={styles.secondaryButton}
62+
>
63+
{copied
64+
? (
65+
<>
66+
<svg className="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20">
67+
<path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
68+
</svg>
69+
Copied!
70+
</>
71+
)
72+
: (
73+
<>
74+
<svg className="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
75+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
76+
</svg>
77+
Copy
78+
</>
79+
)}
80+
</button>
81+
</div>
82+
<div className={`mt-2 ${styles.text.muted}`}>
83+
This is a temporary token. Any linked connected accounts will be regularly deleted.
84+
</div>
85+
</div>
86+
)}
87+
</div>
88+
</div>
89+
);
90+
}

docs-v2/pages/connect/mcp/openai.mdx

Lines changed: 48 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Callout, Tabs, Steps } from 'nextra/components'
2+
import TemporaryTokenGenerator from '@/components/TemporaryTokenGenerator'
23

34
# Using Pipedream MCP with OpenAI
45

@@ -8,7 +9,40 @@ Access {process.env.PUBLIC_APPS}+ APIs and 10,000+ tools in OpenAI using Pipedre
89
Pipedream Connect includes built-in user authentication for [every MCP server](https://mcp.pipedream.com), which means you don't need to build any authorization flows or deal with token storage and refresh in order to make authenticated requests on behalf of your users. [Learn more here](/connect/mcp/developers/#user-account-connections).
910
</Callout>
1011

11-
## Getting started
12+
## Testing in OpenAI's API Playground
13+
14+
OpenAI provides an API playground for developers to test prompts and tool calling, which provides an easy way to test Pipedream MCP. Get started below.
15+
16+
<Steps>
17+
18+
#### Open the playground
19+
20+
Navigate to [OpenAI's playground](https://platform.openai.com/playground/prompts?models=gpt-4.1) and sign in with your OpenAI account.
21+
22+
#### Add Pipedream MCP
23+
24+
Click the **Create** button in the **Tools** section, then select **Pipedream**.
25+
26+
#### Enter your access token
27+
28+
<TemporaryTokenGenerator />
29+
30+
#### Select an app
31+
32+
- Select an app you want to use as an MCP server. For example, `notion`, `google_calendar`, `gmail`, or `slack`.
33+
- Check out all of the available apps here: [mcp.pipedream.com](https://mcp.pipedream.com).
34+
35+
#### Click **Connect**
36+
37+
Enter a prompt and start chatting!
38+
39+
</Steps>
40+
41+
<Callout type="info">
42+
Refer to the instructions below when you're ready to use Pipedream MCP in your app.
43+
</Callout>
44+
45+
## Using Pipedream MCP in your app
1246

1347
<Steps>
1448

@@ -64,7 +98,8 @@ const pd = createBackendClient({
6498
// Find the app to use for the MCP server
6599
// For this example, we'll use Notion
66100
const apps = await pd.getApps({ q: "notion" });
67-
const appSlug = apps.data[0].name_slug; // e.g., "notion"
101+
const appSlug = apps.data[0].name_slug; // e.g., "notion",
102+
const appLabel = apps.data[0].name; // e.g., "Notion"
68103

69104
// Get access token for MCP server auth
70105
const accessToken = await pd.rawAccessToken();
@@ -81,12 +116,14 @@ const response = await client.responses.create({
81116
tools: [
82117
{
83118
type: 'mcp',
84-
server_label: 'Notion',
85-
server_url: `https://remote.mcp.pipedream.net/${externalUserId}/${appSlug}`,
119+
server_label: appLabel,
120+
server_url: `https://remote.mcp.pipedream.net`,
86121
headers: {
87122
Authorization: `Bearer ${accessToken}`,
88123
"x-pd-project-id": PIPEDREAM_PROJECT_ID,
89-
"x-pd-environment": PIPEDREAM_ENVIRONMENT
124+
"x-pd-environment": PIPEDREAM_ENVIRONMENT,
125+
"x-pd-external-user-id": externalUserId,
126+
"x-pd-app-slug": appSlug,
90127
},
91128
require_approval: 'never'
92129
}
@@ -129,11 +166,13 @@ curl -X POST https://api.openai.com/v1/chat/completions \
129166
{
130167
"type": "mcp",
131168
"server_label": "Notion",
132-
"server_url": "https://remote.mcp.pipedream.net/abc-123/'$APP_SLUG'",
169+
"server_url": "https://remote.mcp.pipedream.net",
133170
"headers": {
134171
"Authorization": "Bearer '"$ACCESS_TOKEN"'",
135-
"x-pd-project-id": "$PIPEDREAM_PROJECT_ID",
136-
"x-pd-environment": "$PIPEDREAM_ENVIRONMENT"
172+
"x-pd-project-id": "'"$PIPEDREAM_PROJECT_ID"'",
173+
"x-pd-environment": "'"$PIPEDREAM_ENVIRONMENT"'",
174+
"x-pd-external-user-id": "abc-123",
175+
"x-pd-app-slug": "'"$APP_SLUG"'"
137176
},
138177
"require_approval": "never"
139178
}
@@ -142,84 +181,4 @@ curl -X POST https://api.openai.com/v1/chat/completions \
142181
```
143182
</Tabs.Tab>
144183
</Tabs>
145-
</Steps>
146-
147-
{/* ## Testing in OpenAI's API Playground
148-
149-
OpenAI provides an API playground for developers to test prompts and tool calling:
150-
[https://platform.openai.com/playground/prompts](https://platform.openai.com/playground/prompts?models=gpt-4.1)
151-
152-
1. Navigate to [OpenAI's playground](https://platform.openai.com/playground/prompts?models=gpt-4.1) and sign in with your OpenAI account
153-
2. Click the **Create** button in the **Tools** section, then select **Pipedream**
154-
3. You'll need these inputs to get set up:
155-
156-
- [Pipedream project ID](#copy-your-project-id)
157-
- [Pipedream environment](#define-the-environment)
158-
- [Developer access token](#generate-an-access-token)
159-
160-
<Steps>
161-
162-
### Copy your project ID
163-
164-
1. Open an existing Pipedream project or create a new one at [pipedream.com/projects](https://pipedream.com/projects)
165-
2. Click the **Settings** tab, then copy your **Project ID**
166-
167-
### Define the environment
168-
169-
- Since you're testing for yourself, you should use `development`
170-
- Use `production` when you're ready to ship your app to users
171-
172-
### Generate an access token
173-
174-
**First, create an OAuth client in Pipedream:**
175-
176-
1. Visit the [API settings](https://pipedream.com/settings/api) for your workspace
177-
2. Click the **New OAuth Client** button and give it a name
178-
3. Copy the client ID and secret
179-
180-
**Next, get an access token:**
181-
182-
In the client credentials model, as a developer, you exchange your OAuth client ID and secret for a short-lived access token to make API requests.
183-
184-
<Tabs items={['Node.js', 'cURL']}>
185-
<Tabs.Tab>
186-
```javascript
187-
import { createBackendClient } from "@pipedream/sdk/server";
188-
189-
// Initialize the Pipedream SDK client
190-
const pd = createBackendClient({
191-
environment: PIPEDREAM_ENVIRONMENT,
192-
credentials: {
193-
clientId: PIPEDREAM_CLIENT_ID,
194-
clientSecret: PIPEDREAM_CLIENT_SECRET,
195-
},
196-
projectId: PIPEDREAM_PROJECT_ID
197-
});
198-
199-
const accessToken = await pd.rawAccessToken();
200-
201-
console.log(accessToken);
202-
```
203-
</Tabs.Tab>
204-
<Tabs.Tab>
205-
```bash
206-
curl https://api.pipedream.com/v1/oauth/token \
207-
-H 'Content-Type: application/json' \
208-
-d '{
209-
"grant_type": "client_credentials",
210-
"client_id": "<PIPEDREAM_CLIENT_ID>",
211-
"client_secret": "<PIPEDREAM_CLIENT_SECRET>"
212-
}'
213-
```
214-
</Tabs.Tab>
215-
</Tabs>
216-
217-
</Steps>
218-
219-
### Playground limitations
220-
221-
- The server URL that's defined in OpenAI's playground uses two static fields. In practice, you'll define those dynamically in your app:
222-
- `external_user_id`: `demo-openai-user-123`
223-
- `app_slug`: `google_calendar`
224-
- You'll also define the `PIPEDREAM_PROJECT_ID` and `PIPEDREAM_ENVIRONMENT` in your environment once, then use the Pipedream SDK or REST API to get a fresh access token.
225-
*/}
184+
</Steps>

pnpm-lock.yaml

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)