PayPal Agent
The PayPal Agent Toolkit enables popular agent frameworks including OpenAI's Agent SDK, LangChain, Vercel's AI SDK, and Model Context Protocol (MCP) to integrate with PayPal APIs through function calling. It includes support for TypeScript and is built on top of PayPal APIs and the PayPal SDKs.
You don't need this source code unless you want to modify the package. If you just want to use the package run:
npm install @paypal/agent-toolkit
The library needs to be configured with your account's client id and secret which is available in your PayPal Developer Dashboard.
The toolkit works with Vercel's AI SDK and can be passed as a list of tools. For more details, refer our examples
import {PayPalAgentToolkit} from '@paypal/agent-toolkit/ai-sdk';
const paypalToolkit = new PayPalAgentToolkit({
clientId: process.env.PAYPAL_CLIENT_ID,
clientSecret: process.env.PAYPAL_CLIENT_SECRET
});
const llm: LanguageModelV1 = getModel(); // The model to be used with ai-sdk
const {text: response}= await generateText({
model: llm,
tools: await paypalToolkit.getTools(),
prompt: `Create an invoice for 3 hours of labor at $120/hr and text a link to John Doe.`,
});
The PayPal Model Context Protocol server allows you to integrate with PayPal APIs through function calling. This protocol supports various tools to interact with different PayPal services.
To run the PayPal MCP server using npx, use the following command:
npx -y @paypal/mcp --tools=all PAYPAL_ACCESS_TOKEN="YOUR_ACCESS_TOKEN" PAYPAL_ENVIRONMENT="SANDBOX"
Replace YOUR_ACCESS_TOKEN
with active access token generated using these steps: PayPal access token. Alternatively, you could set the PAYPAL_ACCESS_TOKEN in your environment variables.
You can set up your own MCP server. For example:
import { PayPalAgentToolkit } from “@paypal/agent-toolkit/modelcontextprotocol";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const tools = payPalAgentToolkit.getTools();
const server = new PayPalAgentToolkit({
accessToken: process.env.PAYPAL_ACCESS_TOKEN
});
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("PayPal MCP Server running on stdio");
}
main().catch((error) => {
console.error("Fatal error in main():", error);
process.exit(1);
});
This guide explains how to integrate the PayPal connector with Claude Desktop.
Node.js is required for the PayPal connector to function:
We will show the integration with Claude desktop. You can use your favorite MCP host.
{
"mcpServers": {
"paypal": {
"command": "npx",
"args": [
"-y",
"@paypal/mcp",
"--tools=all"
],
"env": {
"PAYPAL_ACCESS_TOKEN": "YOUR_PAYPAL_ACCESS_TOKEN",
"PAYPAL_ENVIRONMENT": "SANDBOX"
}
}
}
}
Make sure to replace YOUR_PAYPAL_ACCESS_TOKEN
with your actual PayPal Access Token. Alternatively, you could set the PAYPAL_ACCESS_TOKEN as an environment variable. You can also pass it as an argument using --access-token in "args"
Set PAYPAL_ENVIRONMENT
value as either SANDBOX
for stage testing and PRODUCTION
for production environment.
Tool | Description | Availability |
---|---|---|
invoices.create | Create a new invoice | MCP Server |
invoices.list | List invoices | MCP Server |
createOrder | Create an Order | ai-sdk |
getOrder | Get Order details | ai-sdk |
The following environment variables can be used:
PAYPAL_ACCESS_TOKEN
: Your PayPal Access TokenPAYPAL_ENVIRONMENT
: Set to SANDBOX
for sandbox mode, PRODUCTION
for production (defaults to SANDBOX
mode)This guide explains how to generate an access token for PayPal API integration, including how to find your client ID and client secret.
Create a PayPal Developer Account:
Access Your Credentials:
Create or View an App:
Retrieve Credentials:
curl -v https://api-m.sandbox.paypal.com/v1/oauth2/token \\
-H \"Accept: application/json\" \\
-H \"Accept-Language: en_US\" \\
-u \"CLIENT_ID:CLIENT_SECRET\" \\
-d \"grant_type=client_credentials\"
Replace CLIENT_ID
and CLIENT_SECRET
with your actual credentials. For production, use https://api-m.paypal.com
instead of the sandbox URL.
https://api-m.sandbox.paypal.com/v1/oauth2/token
grant_type
with value client_credentials
A successful response will look like:
{
"scope": "...",
"access_token": "Your Access Token",
"token_type": "Bearer",
"app_id": "APP-80W284485P519543T",
"expires_in": 32400,
"nonce": "..."
}
Copy the access_token
value for use in your Claude Desktop integration.
Once you have your access token, update the PAYPAL_ACCESS_TOKEN
value in your Claude Desktop connector configuration:
{
"env": {
"PAYPAL_ACCESS_TOKEN": "YOUR_NEW_ACCESS_TOKEN",
"PAYPAL_ENVIRONMENT": "SANDBOX"
}
}
AI-generated content may be inaccurate or incomplete. Users are responsible for independently verifying any information before relying on it. PayPal makes no guarantees regarding output accuracy and is not liable for any decisions, actions, or consequences resulting from its use.