@magpieim/ai-toolkit v0.1.9
Magpie AI Toolkit - TypeScript
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.
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 @magpieim/ai-toolkitRequirements
- Node 18+
Usage
The library needs to be configured with your account's secret key which is available in your Magpie Dashboard. Additionally, configuration enables you to specify the types of actions that can be taken using the toolkit.
import {MagpieAgentToolkit} from '@magpieim/ai-toolkit/langchain';
const magpieAgentToolkit = new MagpieAgentToolkit({
secretKey: process.env.MAGPIE_SECRET_KEY!,
configuration: {
actions: {
customers: {
create: true,
},
},
},
});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 = magpieAgentToolkit.getTools();
const agent = await createStructuredChatAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});Model Context Protocol
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.
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);
});