MCP Now
Stripe

Stripe

by stripe
GitHub

Interact with Stripe API

stripe
agent
context
import
stripeagenttoolkit

Stripe Agent Toolkit

The Stripe Agent Toolkit enables popular agent frameworks including OpenAI's Agent SDK, LangChain, CrewAI, Vercel's AI SDK, and Model Context Protocol (MCP) to integrate with Stripe APIs through function calling. The library is not exhaustive of the entire Stripe API. It includes support for both Python and TypeScript and is built directly on top of the Stripe Python and Node SDKs.

Included below are basic instructions, but refer to the Python and TypeScript packages for more information.

Python

Installation

You don't need this source code unless you want to modify the package. If you just want to use the package run:

1pip install stripe-agent-toolkit

Requirements

  • Python 3.11+

Usage

The library needs to be configured with your account's secret key which is available in your Stripe Dashboard.

1from stripe_agent_toolkit.openai.toolkit import StripeAgentToolkit 2 3stripe_agent_toolkit = StripeAgentToolkit( 4 secret_key="sk_test_...", 5 configuration={ 6 "actions": { 7 "payment_links": { 8 "create": True, 9 }, 10 } 11 }, 12)

The toolkit works with OpenAI's Agent SDK, LangChain, and CrewAI and can be passed as a list of tools. For example:

1from agents import Agent 2 3stripe_agent = Agent( 4 name="Stripe Agent", 5 instructions="You are an expert at integrating with Stripe", 6 tools=stripe_agent_toolkit.get_tools() 7)

Examples for OpenAI's Agent SDK,LangChain, and CrewAI are included in /examples.

Context

In some cases you will want to provide values that serve as defaults when making requests. Currently, the account context value enables you to make API calls for your connected accounts.

1stripe_agent_toolkit = StripeAgentToolkit( 2 secret_key="sk_test_...", 3 configuration={ 4 "context": { 5 "account": "acct_123" 6 } 7 } 8)

TypeScript

Installation

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 @stripe/agent-toolkit

Requirements

  • Node 18+

Usage

The library needs to be configured with your account's secret key which is available in your Stripe Dashboard. Additionally, configuration enables you to specify the types of actions that can be taken using the toolkit.

1import { StripeAgentToolkit } from "@stripe/agent-toolkit/langchain"; 2 3const stripeAgentToolkit = new StripeAgentToolkit({ 4 secretKey: process.env.STRIPE_SECRET_KEY!, 5 configuration: { 6 actions: { 7 paymentLinks: { 8 create: true, 9 }, 10 }, 11 }, 12});

Tools

The toolkit works with LangChain and Vercel's AI SDK and can be passed as a list of tools. For example:

1import { AgentExecutor, createStructuredChatAgent } from "langchain/agents"; 2 3const tools = stripeAgentToolkit.getTools(); 4 5const agent = await createStructuredChatAgent({ 6 llm, 7 tools, 8 prompt, 9}); 10 11const agentExecutor = new AgentExecutor({ 12 agent, 13 tools, 14});

Context

In some cases you will want to provide values that serve as defaults when making requests. Currently, the account context value enables you to make API calls for your connected accounts.

1const stripeAgentToolkit = new StripeAgentToolkit({ 2 secretKey: process.env.STRIPE_SECRET_KEY!, 3 configuration: { 4 context: { 5 account: "acct_123", 6 }, 7 }, 8});

Metered billing

For Vercel's AI SDK, you can use middleware to submit billing events for usage. All that is required is the customer ID and the input/output meters to bill.

1import { StripeAgentToolkit } from "@stripe/agent-toolkit/ai-sdk"; 2import { openai } from "@ai-sdk/openai"; 3import { 4 generateText, 5 experimental_wrapLanguageModel as wrapLanguageModel, 6} from "ai"; 7 8const stripeAgentToolkit = new StripeAgentToolkit({ 9 secretKey: process.env.STRIPE_SECRET_KEY!, 10 configuration: { 11 actions: { 12 paymentLinks: { 13 create: true, 14 }, 15 }, 16 }, 17}); 18 19const model = wrapLanguageModel({ 20 model: openai("gpt-4o"), 21 middleware: stripeAgentToolkit.middleware({ 22 billing: { 23 customer: "cus_123", 24 meters: { 25 input: "input_tokens", 26 output: "output_tokens", 27 }, 28 }, 29 }), 30});

Model Context Protocol

The Stripe Agent Toolkit also supports the Model Context Protocol (MCP).

To run the Stripe MCP server using npx, use the following command:

1npx -y @stripe/mcp --tools=all --api-key=YOUR_STRIPE_SECRET_KEY

Replace YOUR_STRIPE_SECRET_KEY with your actual Stripe secret key. Or, you could set the STRIPE_SECRET_KEY in your environment variables.

Alternatively, you can set up your own MCP server. For example:

1import { StripeAgentToolkit } from "@stripe/agent-toolkit/modelcontextprotocol"; 2import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; 3 4const server = new StripeAgentToolkit({ 5 secretKey: process.env.STRIPE_SECRET_KEY!, 6 configuration: { 7 actions: { 8 paymentLinks: { 9 create: true, 10 }, 11 products: { 12 create: true, 13 }, 14 prices: { 15 create: true, 16 }, 17 }, 18 }, 19}); 20 21async function main() { 22 const transport = new StdioServerTransport(); 23 await server.connect(transport); 24 console.error("Stripe MCP Server running on stdio"); 25} 26 27main().catch((error) => { 28 console.error("Fatal error in main():", error); 29 process.exit(1); 30});

Supported API methods