Files

Stripe Agent Toolkit - TypeScript

The Stripe Agent Toolkit enables popular agent frameworks including LangChain and Vercel's AI SDK to integrate with Stripe APIs through function calling.

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. We strongly recommend using a Restricted API Key (rk_*) for better security and granular permissions. Tool availability is determined by the permissions you configure on the restricted key.

import {StripeAgentToolkit} from '@stripe/agent-toolkit/langchain';

const stripeAgentToolkit = new StripeAgentToolkit({
  secretKey: process.env.STRIPE_SECRET_KEY!,
  configuration: {},
});

Tools

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

import {AgentExecutor, createStructuredChatAgent} from 'langchain/agents';

const tools = stripeAgentToolkit.getTools();

const agent = await createStructuredChatAgent({
  llm,
  tools,
  prompt,
});

const agentExecutor = new AgentExecutor({
  agent,
  tools,
});

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.

const stripeAgentToolkit = new StripeAgentToolkit({
  secretKey: process.env.STRIPE_SECRET_KEY!,
  configuration: {
    context: {
      account: 'acct_123',
    },
  },
});

Model Context Protocol

The Stripe Agent Toolkit also supports the Model Context Protocol (MCP). See /examples/modelcontextprotocol for an example. The same configuration options are available, and the server can be run with all supported transports.

import {StripeAgentToolkit} from '@stripe/agent-toolkit/modelcontextprotocol';
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new StripeAgentToolkit({
  secretKey: process.env.STRIPE_SECRET_KEY!,
  configuration: {},
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.error('Stripe MCP Server running on stdio');
}

main().catch((error) => {
  console.error('Fatal error in main():', error);
  process.exit(1);
});