This server provides customer management, Brazilian address lookup, and payment plan retrieval through an MCP-compliant interface with AI chatbot integration.
Core Capabilities:
Customer Registration - Create new customers with required fields (name, email, phone) and optional fields including address details, UTM tracking parameters, identification documents (e.g., CPF), retention flags, company IDs, categorization list IDs, tags, and URLs
Brazilian Address Lookup - Retrieve complete address information using CEP (Brazilian postal code) in formats XXXXX-XXX or XXXXXXXX via ViaCEP service, returning street, neighborhood, city, and state data
Payment Plan Retrieval - Query available payment options including credit card installments (1x to 12x), PIX, and bank slip (boleto) with automatic price calculations and Portuguese summaries
AI-Powered Chatbot - Interact via natural language through REST API endpoints (
/api/chat,/api/chat/reset,/health) powered by OpenAI GPT-4o-mini, supporting Portuguese and English with multi-turn conversation history managementMCP Protocol Compliance - Function as standard MCP server with stdio transport for integration with MCP-compatible clients like Claude Desktop, enabling direct tool access
Automated Validation - Enforce required fields, validate email formats, and handle error scenarios before API submission
Configurable Personality - Customize chatbot tone and style via environment variables (AGENT_TONE or AGENT_STYLE)
Deal Creation - Optionally trigger CRM deal creation during customer registration
Development Tools - Includes TypeScript implementation, logging, and both development and production modes
Powers an AI chatbot using GPT-4o-mini for natural language processing and automated tool invocation based on conversation context.
Retrieves payment plan information including PIX instant payment options for Brazilian e-commerce checkout processes.
Customer Management & Payment Plans MCP Server & Chatbot
This project provides two main components:
MCP Server: A Model Context Protocol server for customer management, address lookup, and payment plan retrieval
AI Chatbot: An OpenAI GPT-4o-mini powered chatbot that integrates with the MCP server via REST API
Features
MCP Server
✅ MCP-compliant server implementation (stdio transport)
✅ Bearer token authentication
✅ Three integrated tools:
createCustomer- Customer registration with validationgetAddressByZipcode- Brazilian CEP address lookuplist_payment_plans- Payment plan retrieval (credit card, PIX, bank slip)
✅ Required field validation
✅ Comprehensive error handling
✅ Development logging
✅ TypeScript implementation
AI Chatbot
✅ OpenAI GPT-4o-mini integration
✅ Configurable tone/style via environment variables
✅ REST API endpoint (
/api/chat)✅ Automatic MCP tool invocation based on conversation
✅ Conversation history management
✅ Express-based HTTP server
Prerequisites
Node.js 18+
Yarn package manager
Installation
Install dependencies:
Configure environment variables:
Copy the example file and edit with your values:
Edit .env:
Note: AGENT_TONE or AGENT_STYLE controls the chatbot's personality.
Usage
Running the MCP Server (standalone)
Development Mode:
Or with watch mode:
Production Mode:
Running the AI Chatbot Server
Development Mode:
Production Mode:
The chatbot server will start on port 3000 (or your configured CHATBOT_PORT).
Chatbot API Endpoints
POST /api/chat
Send a message to the chatbot:
Response:
POST /api/chat/reset
Reset the conversation history:
GET /health
Health check:
MCP Tools
Tool 1: createCustomer
Required Parameters
name(string): Customer full nameemail(string): Customer email address (validated)phone(string): Customer phone number
Optional Parameters
retention(boolean): Retention flagidentification(string): Customer ID document (e.g., CPF)zipcode(string): ZIP/Postal codestate(string): State/Provincestreet(string): Street namenumber(string): Street numberneighborhood(string): Neighborhoodcity(string): Citylist_ids(number): List ID for categorizationcreate_deal(boolean): Whether to create a dealtags(string): Tags for the customerurl(string): URL referenceutm_term(string): UTM term parameterutm_medium(string): UTM medium parameterutm_source(string): UTM source parameterutm_campaign(string): UTM campaign parametercompany_id(string): Company IDutm_content(string): UTM content parameter
Example Request
Example Success Response
Example Error Response
Tool 2: getAddressByZipcode
Lookup Brazilian addresses by CEP (zipcode).
Required Parameters
zipcode(string): Brazilian CEP in format XXXXX-XXX or XXXXXXXX (8 digits)
Example Request
Example Success Response
Tool 3: list_payment_plans
Retrieve available payment plans for checkout offers. Configuration is read from environment variables (CHECKOUT_ID and PRODUCT_ID).
Required Parameters
None - the tool uses configuration from environment variables.
Configuration (Environment Variables)
CHECKOUT_ID(string): Checkout page identifierPRODUCT_ID(string): Comma-separated product IDs (e.g., "36,42")
Example Response
Notes
The API is called once with the full
product_idstring (comma-separated)Backend processes multiple product IDs and returns combined payment conditions
Fine, fine_tax, and late_interest fields are automatically ignored
Payment summary is generated in Portuguese (Brazil)
Example Error Response
Configuring with MCP Clients
To use this server with an MCP-compatible client (like Claude Desktop), add the following to your MCP settings configuration:
How the Chatbot Works
User sends a message to
/api/chatChatbot adds message to conversation history
OpenAI GPT-4o-mini processes the message with configured system prompt
If LLM determines an action is needed (e.g.,
createCustomer,getAddressByZipcode,list_payment_plans), it responds with JSONChatbot extracts the action and calls MCP server via stdio
MCP server executes the appropriate tool:
Customer registration via external API
Address lookup via ViaCEP
Payment plans retrieval via external API
Result is returned to LLM for a friendly follow-up message in Portuguese
Final response sent back to user
Example Chatbot Conversations
Customer Registration:
User: Preciso cadastrar um cliente: João Silva, joao@email.com, (11) 98765-4321
Chatbot: Perfeito! Cadastrei o João Silva com sucesso. O ID do cliente é 67890.
Address Lookup:
User: Qual endereço do CEP 01310-100?
Chatbot: `O CEP 01310-100 corresponde a:
Avenida Paulista
Bairro: Bela Vista
São Paulo - SP`
Payment Plans:
User: Quais são as formas de pagamento?
Chatbot: `Temos as seguintes opções:
Cartão de crédito: até 12x de R$ 91,33
PIX à vista: R$ 1.096,00
Boleto à vista: R$ 1.096,00`
Multi-turn with Address:
User: Quero cadastrar um cliente
Chatbot: `Claro! Preciso de:
Nome completo
E-mail
Telefone`
User: Nome: Maria Santos, Email: maria@email.com, Telefone: (21) 99999-8888, CEP: 20040-020
Chatbot: (looks up CEP) Encontrei o endereço: Avenida Rio Branco, Centro, Rio de Janeiro - RJ. Vou cadastrar a Maria Santos com essas informações.
(creates customer)
Chatbot: Pronto! Maria Santos cadastrada com sucesso. ID: 11223
Project Structure
API Endpoint
POST https://{{host}}/api/v1/customers
Headers:
Authorization: Bearer {{TOKEN}}Content-Type: application/json
Development Logging
When NODE_ENV=development, the server logs:
Request URLs and payloads
Response status and data
API errors with details
Error Handling
The server handles:
Missing or invalid required fields
HTTP errors from the external API
Network connectivity issues
Invalid Bearer tokens
Malformed requests
Security
Environment variables are used for sensitive data (API host and token)
.envfiles are gitignoredBearer token is never logged or exposed
Email validation prevents basic injection attempts
License
MIT