The Magpie AI Toolkit makes it easy to connect your AI projects with Magpie payment services. It works with popular AI tools like LangChain and Vercel's AI SDK.
npm install @magpieim/ai-toolkitThe Magpie AI Toolkit makes it easy to connect your AI projects with Magpie payment services. It works with popular AI tools like LangChain and Vercel's AI SDK.
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 @magpieim/ai-toolkit
- Node 18+
The library needs to be configured with your account's secret key which is available in your [Magpie Dashboard][developers]. Additionally, configuration enables you to specify the types of actions that can be taken using the toolkit.
`typescript
import {MagpieAgentToolkit} from '@magpieim/ai-toolkit/langchain';
const magpieAgentToolkit = new MagpieAgentToolkit({
secretKey: process.env.MAGPIE_SECRET_KEY!,
configuration: {
actions: {
customers: {
create: true,
},
},
},
});
`
The toolkit works with LangChain and Vercel's AI SDK and can be passed as a list of tools. For example:
`typescript
import {AgentExecutor, createStructuredChatAgent} from 'langchain/agents';
const tools = magpieAgentToolkit.getTools();
const agent = await createStructuredChatAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
`
The Magpie 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.
`typescript
import {MagpieAgentToolkit} from '@magpieim/ai-toolkit/modelcontextprotocol';
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new MagpieAgentToolkit({
secretKey: process.env.MAGPIE_SECRET_KEY!,
configuration: {
actions: {
customers: {
create: true,
},
charges: {
create: true,
},
checkout_sessions: {
create: true,
},
},
},
});
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('Magpie MCP Server running on stdio');
}
main().catch((error) => {
console.error('Fatal error in main():', error);
process.exit(1);
});
``