Skip to content

Commit 513c2f1

Browse files
Update openai.mdx
1 parent b89161c commit 513c2f1

File tree

1 file changed

+93
-53
lines changed

1 file changed

+93
-53
lines changed

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

Lines changed: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,143 @@
1-
import { Callout, Tabs } from 'nextra/components'
1+
import { Callout, Tabs, Steps } from 'nextra/components'
22

33
# Using Pipedream MCP with OpenAI
44

5-
Access {process.env.PUBLIC_APPS}+ APIs and 10,000+ tools in OpenAI using Pipedream MCP with the [OpenAI Responses API](https://platform.openai.com/docs/guides/tools?api-mode=responses). MCP makes it easy to extend the capabilties of any LLM or agent, and Pipedream offers drop-in support for OpenAI.
5+
Access {process.env.PUBLIC_APPS}+ APIs and 10,000+ tools in the OpenAI using Pipedream Connect. MCP makes it easy to extend the capabilties of any LLM or agent, and Pipedream offers drop-in support for [calling tools in OpenAI](https://platform.openai.com/docs/guides/tools?api-mode=responses) .
66

77
<Callout type="info">
8-
Pipedream MCP includes built-in user authentication for [every integrated API](https://pipedream.com/apps/), which means you don't need to build any authorization flows or think about token storage or refresh. [Learn more here](#account-connection).
8+
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. [Learn more below](#account-connection).
99
</Callout>
1010

11-
## Getting Started
11+
### Getting started
12+
13+
<Steps>
14+
15+
### Set up your environment
16+
1217
To use Pipedream MCP with your own users, you need the following:
1318

1419
1. A [Pipedream account](https://pipedream.com/auth/signup)
15-
2. A [Pipedream project](/projects/#creating-projects). Accounts connected via MCP will be stored here.
20+
2. A [Pipedream project](/projects/#creating-projects) (accounts connected via MCP will be stored here)
1621
3. [Pipedream OAuth credentials](/rest-api/auth/#oauth)
1722

1823
<Callout type="info">
19-
These are requiremnents for you, the developer. Your users do **not** need to sign up for Pipedream in order to connect their accounts in your app or agent.
24+
These are requirements for you, the developer. Your users do **not** need to sign up for Pipedream in order to connect their accounts in your app or agent.
2025
</Callout>
2126

22-
#### Set up environment variables
23-
24-
Set the following environment variables (learn more about environments in Pipedream Connect [here](/connect/managed-auth/environments/)):
27+
Now set the following environment variables (learn more about environments in Pipedream Connect [here](/connect/managed-auth/environments/)):
2528

2629
```bash
2730
PIPEDREAM_CLIENT_ID=your_client_id
2831
PIPEDREAM_CLIENT_SECRET=your_client_secret
2932
PIPEDREAM_PROJECT_ID=your_project_id
3033
PIPEDREAM_ENVIRONMENT=development
34+
OPENAI_API_KEY=your_openai_api_key
3135
```
3236

33-
### Examples
37+
### Discover available MCP servers
38+
39+
Pipedream provides [{process.env.PUBLIC_APPS}+ APIs as MCP servers](https://mcp.pipedream.com) that can be used with OpenAI's tool calls. Each server corresponds to an app integration (like Notion, Gmail, or Slack) and has its own specific set of tools that you can expose to OpenAI.
40+
41+
<Tabs items={['List all apps', 'Search for a specific app']}>
42+
<Tabs.Tab>
43+
```javascript
44+
// Get all available apps (paginated)
45+
const apps = await pd.getApps();
46+
47+
// Each app has these key properties:
48+
// - name_slug: Used in the MCP server URL (e.g., "notion", "gmail", "slack")
49+
// - name: Display name (e.g., "Notion", "Gmail", "Slack")
50+
```
51+
</Tabs.Tab>
52+
<Tabs.Tab>
53+
```javascript
54+
// Search by app name
55+
const notionApps = await pd.getApps({ q: "notion" });
56+
const gmailApps = await pd.getApps({ q: "gmail" });
57+
const slackApps = await pd.getApps({ q: "slack" });
58+
```
59+
</Tabs.Tab>
60+
</Tabs>
3461

35-
<Tabs items={['JavaScript', 'cURL']}>
62+
### Generate a model response in OpenAI with Pipedream MCP
63+
64+
Below is an example showing how to:
65+
1. Initialize the Pipedream SDK
66+
2. Identify the right MCP server based on the user's query
67+
3. Get an access token for authorization to Pipedream MCP
68+
4. Send a prompt to OpenAI with the MCP server as a tool call
69+
70+
<Tabs items={['Node.js', 'cURL']}>
3671
<Tabs.Tab>
3772
```javascript
38-
import OpenAI from "openai";
73+
import OpenAI from 'openai';
3974
import { createBackendClient } from "@pipedream/sdk/server";
4075

41-
const externalUserId = "abc-123" // Unique ID in your system to identify the user
42-
43-
// Initialize the Pipedream SDK
76+
// Initialize the Pipedream client with the SDK
4477
const pd = createBackendClient({
78+
environment: PIPEDREAM_ENVIRONMENT,
4579
credentials: {
4680
clientId: PIPEDREAM_CLIENT_ID,
4781
clientSecret: PIPEDREAM_CLIENT_SECRET,
4882
},
49-
environment: PIPEDREAM_ENVIRONMENT,
50-
projectId: PIPEDREAM_PROJECT_ID,
83+
projectId: PIPEDREAM_PROJECT_ID
5184
});
5285

53-
const { token } = await pd.createConnectToken({
54-
external_user_id: externalUserId,
55-
})
86+
// Find the app to use for the MCP server
87+
// For this example, we'll use Notion
88+
const apps = await pd.getApps({ q: "notion" });
89+
const appSlug = apps.data[0].name_slug; // e.g., "notion"
90+
91+
// Get access token for MCP server auth
92+
const accessToken = await pd.rawAccessToken();
93+
94+
// Send the unique ID that you use to identify this user in your system
95+
const externalUserId = 'abc-123'; // Used in MCP URL to identify the user
5696

97+
// Initialize OpenAI client
5798
const client = new OpenAI();
5899

100+
// Make the OpenAI request with the MCP server
59101
const response = await client.responses.create({
60-
model: "gpt-4.1",
102+
model: 'gpt-4.1',
61103
tools: [
62104
{
63-
"type": "mcp",
64-
"server_label": "Notion",
65-
"server_url": `https://mcp.pipedream.net/${externalUserId}/notion`,
66-
"headers": {
67-
"Authorization": `Bearer ${token}`
105+
type: 'mcp',
106+
server_label: 'Notion',
107+
server_url: `https://mcp.pipedream.net/${externalUserId}/${appSlug}`,
108+
headers: {
109+
Authorization: `Bearer ${accessToken}`,
110+
"x-pd-project-id": PIPEDREAM_PROJECT_ID,
111+
"x-pd-environment": PIPEDREAM_ENVIRONMENT
68112
},
69-
"require_approval": "never"
70-
},
113+
require_approval: 'never'
114+
}
71115
],
72-
input: "Summarize my most recently created Notion doc for me and help draft an email to our customers"
73-
})
116+
input: 'Summarize my most recently created Notion doc for me and help draft an email to our customers'
117+
});
74118

75119
console.log(response);
76120
```
77121
</Tabs.Tab>
78122
<Tabs.Tab>
79123
```bash
80-
# Step 1: Authenticate to the Pipedream API
81-
curl -X POST https://api.pipedream.com/v1/oauth/token \
82-
-H "Content-Type: application/json" \
83-
-d '{
84-
"grant_type": "client_credentials",
85-
"client_id": "$PIPEDREAM_CLIENT_ID",
86-
"client_secret": "$PIPEDREAM_CLIENT_SECRET"
87-
}'
124+
# Complete example from start to finish
88125

89-
# Store the access_token from the response
90-
91-
# Step 2: Get a short-lived Connect Token
92-
curl -X POST https://api.pipedream.com/v1/connect/$PIPEDREAM_PROJECT_ID/tokens \
126+
# Step 1: Get access token from Pipedream
127+
ACCESS_TOKEN=$(curl -s -X POST https://api.pipedream.com/v1/oauth/token \
93128
-H "Content-Type: application/json" \
94-
-H "X-PD-Environment: $PIPEDREAM_ENVIRONMENT" \
95-
-H "Authorization: Bearer $ACCESS_TOKEN" \
96129
-d '{
97-
"external_user_id": "abc-123"
98-
}'
130+
"grant_type": "client_credentials",
131+
"client_id": "'$PIPEDREAM_CLIENT_ID'",
132+
"client_secret": "'$PIPEDREAM_CLIENT_SECRET'"
133+
}' | jq -r .access_token)
99134

100-
# Store the token from the response
135+
# Step 2: Find the app to use for MCP server
136+
# Search for the Notion app
137+
APP_SLUG=$(curl -s -X GET "https://api.pipedream.com/v1/apps?q=notion" \
138+
-H "Authorization: Bearer $ACCESS_TOKEN" | jq -r '.data[0].name_slug')
101139

102-
# Step 3: Call OpenAI with the MCP Server
140+
# Step 3: Make request to OpenAI with MCP tool
103141
curl -X POST https://api.openai.com/v1/chat/completions \
104142
-H "Content-Type: application/json" \
105143
-H "Authorization: Bearer $OPENAI_API_KEY" \
@@ -115,9 +153,11 @@ curl -X POST https://api.openai.com/v1/chat/completions \
115153
{
116154
"type": "mcp",
117155
"server_label": "Notion",
118-
"server_url": "https://mcp.pipedream.net/abc-123/notion",
156+
"server_url": "https://mcp.pipedream.net/abc-123/'$APP_SLUG'",
119157
"headers": {
120-
"Authorization": "Bearer $CONNECT_TOKEN"
158+
"Authorization": "Bearer '"$ACCESS_TOKEN"'",
159+
"x-pd-project-id": "$PIPEDREAM_PROJECT_ID",
160+
"x-pd-environment": "$PIPEDREAM_ENVIRONMENT"
121161
},
122162
"require_approval": "never"
123163
}
@@ -126,11 +166,11 @@ curl -X POST https://api.openai.com/v1/chat/completions \
126166
```
127167
</Tabs.Tab>
128168
</Tabs>
129-
169+
</Steps>
130170

131171
## Account Connection
132172

133-
One of the core features of Pipedream Connect and our MCP product is the ability for your users to easily connect their accounts without having to build any of the authorization flow or handle token storage, etc.
173+
One of the core features of Pipedream Connect and our MCP product is the ability for your users to easily connect their accounts without having to build any of the authorization flow or handle token storage.
134174

135175
You can handle account connections in one of two ways in your app:
136176

@@ -140,7 +180,7 @@ You can handle account connections in one of two ways in your app:
140180

141181
### Return a link
142182
- Use [Connect Link ](/connect/managed-auth/quickstart/#or-use-connect-link) to let your users open a Pipedream hosted page to connect their account
143-
- There isn't any implementation required for this option since it's already handled in Pipedream's MCP server
183+
- There is no implementation required for this option since it's already handled in Pipedream's MCP server
144184
- If a user doesn't have a connected account that's required for a given tool call, we'll return a URL in the tool call response. For example:
145185

146186
```

0 commit comments

Comments
 (0)