Skip to content

Commit 2d1fb4c

Browse files
Danny/connect docs mcp 1 (#16732)
* Update openai.mdx * Update pnpm-lock.yaml * Update openai.mdx * Merge branch 'danny/connect-docs-mcp-1' of github.com:PipedreamHQ/pipedream into danny/connect-docs-mcp-1 * Update pnpm-lock.yaml
1 parent 9d78c8b commit 2d1fb4c

File tree

2 files changed

+101
-55
lines changed

2 files changed

+101
-55
lines changed

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

Lines changed: 92 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,142 @@
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 OpenAI using Pipedream Connect. MCP makes it easy to extend the capabilities 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 in order to make authenticated requests on behalf of your users. [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
30+
OPENAI_API_KEY=your_openai_api_key
2731
PIPEDREAM_CLIENT_ID=your_client_id
2832
PIPEDREAM_CLIENT_SECRET=your_client_secret
2933
PIPEDREAM_PROJECT_ID=your_project_id
3034
PIPEDREAM_ENVIRONMENT=development
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 end to end example showing how to:
65+
1. Initialize the Pipedream SDK
66+
2. Find the relevant MCP server
67+
3. Send a prompt to OpenAI with the MCP server as a tool call
68+
69+
<Tabs items={['Node.js', 'cURL']}>
3670
<Tabs.Tab>
3771
```javascript
38-
import OpenAI from "openai";
72+
import OpenAI from 'openai';
3973
import { createBackendClient } from "@pipedream/sdk/server";
4074

41-
const externalUserId = "abc-123" // Unique ID in your system to identify the user
42-
43-
// Initialize the Pipedream SDK
75+
// Initialize the Pipedream client with the SDK
4476
const pd = createBackendClient({
77+
environment: PIPEDREAM_ENVIRONMENT,
4578
credentials: {
4679
clientId: PIPEDREAM_CLIENT_ID,
4780
clientSecret: PIPEDREAM_CLIENT_SECRET,
4881
},
49-
environment: PIPEDREAM_ENVIRONMENT,
50-
projectId: PIPEDREAM_PROJECT_ID,
82+
projectId: PIPEDREAM_PROJECT_ID
5183
});
5284

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

96+
// Initialize OpenAI client
5797
const client = new OpenAI();
5898

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

75118
console.log(response);
76119
```
77120
</Tabs.Tab>
78121
<Tabs.Tab>
79122
```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-
}'
123+
# Complete example from start to finish
88124

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 \
125+
# Step 1: Get access token from Pipedream
126+
ACCESS_TOKEN=$(curl -s -X POST https://api.pipedream.com/v1/oauth/token \
93127
-H "Content-Type: application/json" \
94-
-H "X-PD-Environment: $PIPEDREAM_ENVIRONMENT" \
95-
-H "Authorization: Bearer $ACCESS_TOKEN" \
96128
-d '{
97-
"external_user_id": "abc-123"
98-
}'
129+
"grant_type": "client_credentials",
130+
"client_id": "'$PIPEDREAM_CLIENT_ID'",
131+
"client_secret": "'$PIPEDREAM_CLIENT_SECRET'"
132+
}' | jq -r .access_token)
99133

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

102-
# Step 3: Call OpenAI with the MCP Server
139+
# Step 3: Make request to OpenAI with MCP tool
103140
curl -X POST https://api.openai.com/v1/chat/completions \
104141
-H "Content-Type: application/json" \
105142
-H "Authorization: Bearer $OPENAI_API_KEY" \
@@ -115,9 +152,11 @@ curl -X POST https://api.openai.com/v1/chat/completions \
115152
{
116153
"type": "mcp",
117154
"server_label": "Notion",
118-
"server_url": "https://mcp.pipedream.net/abc-123/notion",
155+
"server_url": "https://mcp.pipedream.net/abc-123/'$APP_SLUG'",
119156
"headers": {
120-
"Authorization": "Bearer $CONNECT_TOKEN"
157+
"Authorization": "Bearer '"$ACCESS_TOKEN"'",
158+
"x-pd-project-id": "$PIPEDREAM_PROJECT_ID",
159+
"x-pd-environment": "$PIPEDREAM_ENVIRONMENT"
121160
},
122161
"require_approval": "never"
123162
}
@@ -126,11 +165,11 @@ curl -X POST https://api.openai.com/v1/chat/completions \
126165
```
127166
</Tabs.Tab>
128167
</Tabs>
129-
168+
</Steps>
130169

131170
## Account Connection
132171

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.
172+
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.
134173

135174
You can handle account connections in one of two ways in your app:
136175

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

141180
### Return a link
142181
- 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
182+
- There is no implementation required for this option since it's already handled in Pipedream's MCP server
144183
- 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:
145184

146185
```

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)