Connect NMI to ChatGPT: Handle Payments and Recurring Billing
Learn how to connect NMI to ChatGPT using a managed MCP server. Automate payments, recurring billing, and customer vault operations with AI agents.
If you need to connect NMI to ChatGPT to automate payment processing, subscription management, or accounts receivable operations, you need a Model Context Protocol (MCP) server. This server acts as the translation layer between ChatGPT's tool calls and NMI's REST APIs. You can either spend weeks building and maintaining this infrastructure yourself, or use a managed integration platform like Truto to dynamically generate a secure, authenticated MCP server URL.
If your team uses Claude, check out our guide on connecting NMI to Claude or explore our broader architectural overview on connecting NMI to AI Agents.
Giving a Large Language Model (LLM) read and write access to a sprawling financial gateway like Network Merchants Inc (NMI) is a massive engineering challenge. You have to handle payment tokenization securely, map massive JSON schemas to MCP tool definitions, and deal with NMI's specific transaction lifecycles. Every time an endpoint shifts or a new authentication pattern emerges, you have to update your server code, redeploy, and test the integration. This guide breaks down exactly how to use Truto to generate a secure, managed MCP server for NMI, connect it natively to ChatGPT, and execute complex billing workflows using natural language.
The Engineering Reality of the NMI API
A custom MCP server is a self-hosted integration layer. While the open MCP standard provides a predictable way for models to discover tools, the reality of implementing it against NMI's APIs is painful. You aren't just doing generic database operations - you are orchestrating highly sensitive financial transactions that require precise sequencing and strict error handling.
If you decide to build a custom MCP server for NMI, you own the entire API lifecycle. Here are the specific integration challenges that break standard CRUD assumptions when working with NMI:
Transaction State Machines and False Positives
The most dangerous trap in the NMI API is how it handles declines. NMI often returns an HTTP 200 OK for a transaction request, even if the payment failed. The actual result is nested inside the payload under a response field. A 1 means approved, a 2 means declined, and a 3 means error. If your MCP server simply passes the HTTP status code back to ChatGPT, the LLM will assume a declined payment was successful and hallucinate a confirmation message to the user. Your server must strictly define these response schemas so the LLM understands the semantic difference between network success and financial success.
The Customer Vault Triangulation
Recurring billing in NMI is not a single API call. To set up a subscription, you cannot simply pass a credit card to a subscription endpoint. You must first tokenize the payment details via Collect.js or another secure method, pass that token to the Customer Vault to create a stored customer, and then use the resulting customer_vault_id alongside a plan_id to initialize the recurring charge. If your AI agent doesn't understand this exact sequence of operations, it will fail to orchestrate the workflow. Your MCP tools must be designed to chain these IDs together.
Authorization vs Capture
NMI supports distinct API concepts for authorizing funds (nmi_payments_auth) and capturing them (nmi_payments_capture). Unlike basic Stripe charges, many B2B workflows require authorizing a large amount upfront and capturing it later once inventory ships. Your MCP server must expose both methods and provide clear, semantic descriptions to the LLM so it knows when to place a hold versus when to settle the funds.
Rate Limits and Exponential Backoff
NMI enforces strict rate limits to protect their infrastructure. Truto does not retry, throttle, or apply backoff on rate limit errors automatically. When the NMI upstream API returns an HTTP 429 (Too Many Requests), Truto passes that error directly to the caller. Truto normalizes the upstream rate limit info into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) per the IETF specification. The caller - whether that is your application middleware or the LLM framework - is entirely responsible for implementing retry and exponential backoff logic.
Generating a Managed MCP Server for NMI
Instead of building a proxy server from scratch, you can use Truto to generate an MCP server dynamically. Truto translates NMI's OpenAPI specifications and documentation into MCP-compliant JSON-RPC tools instantly.
Each MCP server is scoped to a single integrated NMI account and is secured by a cryptographically hashed token.
Method 1: Via the Truto UI
For teams who prefer visual configuration, you can spin up an MCP server directly from the dashboard.
- Navigate to the Integrated Accounts page in your Truto dashboard and select your connected NMI account.
- Click the MCP Servers tab.
- Click Create MCP Server.
- Select your desired configuration (e.g., restrict to read-only methods, apply specific tool tags, set an expiration date).
- Click Save and copy the generated MCP server URL (e.g.,
https://api.truto.one/mcp/a1b2c3d4...).
Method 2: Via the Truto API
For platform engineers building multi-tenant AI products, you can provision MCP servers programmatically using the Truto API. This creates a dedicated server scoped specifically to that tenant's NMI instance.
// POST https://api.truto.one/integrated-account/{integrated_account_id}/mcp
const response = await fetch(`https://api.truto.one/integrated-account/${accountId}/mcp`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${TRUTO_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "NMI Finance Automation Server",
config: {
methods: ["read", "write"],
tags: ["payments", "vault"]
},
expires_at: "2026-12-31T23:59:59Z"
})
});
const mcpServer = await response.json();
console.log(mcpServer.url); // The URL you pass to ChatGPTConnecting the MCP Server to ChatGPT
Once you have your Truto MCP URL, you need to register it with your ChatGPT environment.
Method 1: Via the ChatGPT UI
If you are using ChatGPT Plus, Team, or Enterprise, you can add custom connectors directly in the interface.
- In ChatGPT, navigate to Settings -> Apps -> Advanced settings.
- Toggle Developer mode to ON.
- Under the MCP servers / Custom connectors section, click Add new server.
- Name the connection "NMI Billing AI".
- Paste the Truto MCP URL into the Server URL field.
- Click Save.
ChatGPT will immediately perform an MCP handshake, calling the initialize and tools/list JSON-RPC endpoints to discover the available NMI operations.
Method 2: Via Manual Configuration File
If you are running ChatGPT desktop clients or building custom agentic workflows via Claude Desktop or Cursor that follow the same spec, you can use the standard MCP configuration file.
Add the following JSON to your mcp.json or claude_desktop_config.json file. Because Truto MCP servers use standard Server-Sent Events (SSE) over HTTP, you invoke them using the official @modelcontextprotocol/server-sse wrapper.
{
"mcpServers": {
"nmi_billing": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sse",
"https://api.truto.one/mcp/a1b2c3d4e5f6..."
]
}
}
}Security and Access Control
Giving an LLM write access to a payment gateway is high stakes. Truto provides four critical security primitives at the MCP server level to prevent catastrophic AI hallucinations:
- Method Filtering (
config.methods): Restrict the AI to specific operation categories. Settingmethods: ["read"]ensures the LLM can only query payment history, preventing it from accidentally issuing refunds or capturing funds. - Tag Filtering (
config.tags): Scope the server to specific functional areas. If you only want the AI to handle subscriptions, you can apply the["recurring"]tag, which hides raw payment tools from the LLM's context window. - Dual Authentication (
require_api_token_auth): When set totrue, possessing the MCP URL is not enough. The client must also pass a valid Truto API token in theAuthorizationheader, verifying that the human interacting with the AI is an authenticated user of your platform. - Ephemeral Servers (
expires_at): Set an ISO 8601 timestamp for the server to self-destruct. This is ideal for granting a temporary AI support agent 24-hour access to investigate a billing dispute.
High-Leverage NMI Tools for AI Agents
Truto automatically translates NMI's endpoints into optimized MCP tools. Do not dump the entire API spec into the LLM context. Instead, focus on these high-leverage operations.
1. Process a Sale (nmi_payments_sale)
This tool processes an authorization and capture in a single step. It is the workhorse of immediate transactions. It accepts raw card details, ACH bank accounts, or a stored customer via customer_vault_id. The response includes the critical response code (1, 2, or 3) and auth_code.
"Process a $500.00 sale for customer vault ID 'vault_9982'. Check the response code to ensure it was approved. If it returns a 2, summarize the decline reason for me."
2. Issue a Refund (nmi_payments_refund)
This tool refunds a previously settled payment back to the customer's payment method. It requires the original payment_id. LLMs excel at matching unstructured customer complaints to past transactions and issuing appropriate refunds.
"Find the transaction for $120.00 that occurred yesterday for John Doe, and issue a full refund using the nmi_payments_refund tool. Confirm the transaction ID of the refund."
3. Create a Vaulted Customer (create_a_nmi_customer)
Directly handling PCI data is risky. This tool creates a customer in the NMI Customer Vault with stored payment methods. It returns the vault ID, which the LLM can store and use for future charges or subscriptions.
"Take the Collect.js payment token provided by the user, and create a new customer in the NMI vault with the email 'sarah@example.com'. Give me back the customer_vault_id."
4. Create a Subscription (create_a_nmi_subscription)
This tool creates a recurring subscription. It can either attach the customer to an existing plan via plan_id or define a custom schedule inline.
"Subscribe customer vault ID 'vault_445' to the Enterprise software plan (plan ID 'plan_ent_monthly'). Confirm the next_charge_date in your response."
5. Create an Invoice (create_a_nmi_invoice)
This tool creates a new invoice record within NMI. It accepts line items, tax details, and customer billing information. It is crucial for B2B workflows that operate on terms rather than immediate capture.
"Draft a new invoice for Acme Corp for 10 hours of consulting at $150 per hour. Set the due date to Net 30."
6. Send an Invoice (nmi_invoices_send)
Once an invoice is created, this tool triggers NMI to email it to the customer. It takes the invoice_id parameter and uses the billing contact address already attached to the invoice.
"Take invoice ID 'inv_88321' and send it to the customer. Let me know when the dispatch is complete."
For a complete list of all available NMI endpoints, schemas, and required parameters, view the NMI integration page.
Workflows in Action
Here is how ChatGPT orchestrates multiple NMI tools to solve complex, multi-step business problems.
Scenario 1: Accounts Receivable Recovery
Persona: Finance Operations Manager
A common issue is dealing with failed subscription renewals. Instead of manually cross-referencing spreadsheets, a finance manager can ask ChatGPT to investigate and resolve the issue.
"Find the failed invoice from yesterday for TechCorp. Check if they have an alternative credit card stored in the customer vault. If they do, process a new sale for the invoice amount against the alternative card, and if successful, close the original invoice."
Execution Steps:
- ChatGPT calls
list_all_nmi_invoicesfiltering for TechCorp and status=past_due. - It identifies the associated
customer_idand callsget_single_nmi_customer_by_id. - It finds an active secondary billing profile in the vault response.
- It calls
nmi_payments_saleusing the invoice amount and the secondarycustomer_vault_id. - Upon receiving
response: 1(approved), it callsnmi_invoices_closeto mark the original invoice as resolved.
sequenceDiagram
participant AI as ChatGPT
participant MCP as Truto MCP
participant NMI as NMI API
AI->>MCP: call: list_all_nmi_invoices
MCP->>NMI: GET /api/v2/invoices
NMI-->>MCP: [TechCorp Invoice (past_due)]
MCP-->>AI: Invoice ID & Customer ID
AI->>MCP: call: get_single_nmi_customer_by_id
MCP->>NMI: GET /api/v2/customers/{id}
NMI-->>MCP: [Vault Profiles]
MCP-->>AI: Secondary Vault ID found
AI->>MCP: call: nmi_payments_sale
MCP->>NMI: POST /api/v2/transactions
NMI-->>MCP: response: 1 (Approved)
MCP-->>AI: Success
AI->>MCP: call: nmi_invoices_close
MCP->>NMI: POST /api/v2/invoices/{id}/close
NMI-->>MCP: Closed
MCP-->>AI: ConfirmedScenario 2: Frictionless SaaS Onboarding
Persona: Customer Success Manager
When a sales rep closes a deal over the phone, they need a seamless way to initialize billing without logging into three different systems.
"I just got off the phone with global logistics. They agreed to the $1000/mo Pro plan. Create a customer vault record for billing@globallogistics.com, send them an invoice for the first month, and set up the recurring subscription for next month."
Execution Steps:
- ChatGPT calls
create_a_nmi_customerwith the provided email to generate acustomer_vault_id. - It calls
create_a_nmi_invoicefor $1000 and immediately follows up withnmi_invoices_sendto dispatch the initial bill. - It calls
create_a_nmi_subscriptionusing thecustomer_vault_idand the existingplan_idfor the Pro tier, scheduling the start date for 30 days out. - The LLM replies to the CSM confirming all three actions are complete, providing the vault ID and subscription ID for their records.
The Strategic Advantage of Managed Infrastructure
Building AI agents that interact with financial gateways requires precision. If you hand-code a custom MCP server for NMI, your engineering team absorbs the operational burden of maintaining schemas, handling edge-case HTTP status codes, and managing complex OAuth token lifecycles.
By leveraging Truto to generate a dynamic, managed MCP server, you eliminate the boilerplate. Your AI applications gain immediate, secure access to the NMI ecosystem, backed by enterprise-grade infrastructure.
FAQ
- How does Truto handle NMI rate limits?
- Truto does not absorb rate limits or apply automatic backoff. When the upstream NMI API returns an HTTP 429 error, Truto passes that error directly to the caller and normalizes the rate limit information into IETF standard headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset). The calling LLM or application must handle the retry logic.
- Can I restrict what my AI agent can do in NMI?
- Yes. Truto's MCP servers support strict method and tag filtering. You can configure a server to only allow read operations, or restrict access to specific resource tags, ensuring the AI cannot execute unauthorized financial transactions.
- How do I create a recurring subscription via the AI?
- The AI orchestrates a multi-step workflow: it uses the create_a_nmi_customer tool to securely vault the payment method, and then passes the resulting customer_vault_id to the create_a_nmi_subscription tool to initialize the recurring schedule.
- How do I know if an NMI payment actually succeeded?
- NMI often returns an HTTP 200 OK even for declined cards. Truto's MCP tools map the response schema so the LLM knows to look for the nested 'response' field, where 1 means approved, 2 means declined, and 3 means error.