Finizi B4B MCP Server
Overview
The Finizi B4B MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with the Finizi B4B (Business-to-Business) API platform. This server exposes 15 comprehensive MCP tools that enable AI assistants to interact with business entities, invoices, vendors, and products through natural language commands.
Built with modern Python async/await patterns and featuring robust error handling, automatic retries, and token-based authentication, this MCP server provides a reliable bridge between AI assistants and the Finizi B4B platform.
Key Features
15 Comprehensive MCP Tools
The server implements 15 specialized tools across 5 categories:
Authentication Tools (3)
login: Authenticate users with phone and password
logout: Clear authentication session
whoami: Get current user information
Entity Management Tools (4)
list_entities: List business entities with pagination and search
get_entity: Retrieve detailed entity information
create_entity: Create new business entities
update_entity: Update existing entity details
Invoice Management Tools (4)
list_invoices: List invoices with advanced filtering
get_invoice: Retrieve detailed invoice information
import_invoice_xml: Import invoices from XML format
get_invoice_statistics: Get invoice analytics and statistics
Vendor Management Tools (2)
list_vendors: List vendors with pagination and search
get_vendor: Retrieve detailed vendor information
Product Management Tools (2)
list_products: List products with category filtering
search_similar_products: Find similar products using AI matching
Architecture Highlights
Token Pass-Through Architecture: Secure JWT token management with automatic token extraction and injection
Singleton API Client: Efficient connection reuse with pooling and keep-alive
Automatic Retry Logic: Exponential backoff for transient failures (3 attempts)
Structured Logging: Comprehensive logging with structlog for debugging
Type Safety: Full type hints and Pydantic models for validation
Error Handling: Custom exception hierarchy with proper HTTP status mapping
Requirements
Python 3.11 or higher
UV package manager (recommended) or pip
Access to Finizi B4B API server
Valid B4B API credentials
Quick Start Guide
Installation with UV (Recommended)
Clone the repository:
Install UV package manager (if not already installed):
Create virtual environment and install dependencies:
Installation with pip (Alternative)
Configuration
Copy the environment template:
Configure your environment variables:
Running the Server
Standalone Mode
With MCP Client (Claude Desktop)
Configure Claude Desktop (
claude_desktop_config.json
):
Restart Claude Desktop to load the MCP server
Testing the Connection
Example Usage
Authentication Flow
Entity Management
Invoice Management
Vendor Management
Product Management
Development Guide
Running Tests
Code Quality
Project Structure
Architecture Overview
Token Pass-Through Model
The server implements a secure token pass-through architecture:
Authentication: User credentials are sent to B4B API via
login
toolToken Storage: JWT tokens are stored in MCP session metadata
Automatic Injection: Tokens are automatically added to all API requests
Session Isolation: Each MCP session maintains its own authentication state
Error Handling
The server implements a comprehensive error handling strategy:
MCPAuthenticationError: 401 Unauthorized - Token invalid/expired
MCPAuthorizationError: 403 Forbidden - Insufficient permissions
MCPValidationError: 400 Bad Request - Invalid input parameters
MCPNotFoundError: 404 Not Found - Resource doesn't exist
MCPServerError: 500+ Server Error - B4B API issues
Performance Optimizations
Connection Pooling: Reuse HTTP connections (100 connections, 10 per host)
Keep-Alive: Maintain persistent connections for reduced latency
Retry Logic: Automatic retry with exponential backoff (3 attempts)
Request Timeouts: Configurable timeouts to prevent hanging
Async Operations: Full async/await support for concurrent operations
Security Considerations
Authentication Security
JWT tokens are stored only in memory (session metadata)
Tokens are never logged or persisted to disk
Each session maintains isolated authentication state
Automatic token cleanup on logout
API Security
All API calls use HTTPS in production
Input validation on all user-provided data
SQL injection prevention through parameterized queries
XSS prevention through proper output encoding
Best Practices
Use strong passwords for B4B accounts
Rotate API credentials regularly
Monitor access logs for suspicious activity
Keep dependencies updated for security patches
Use environment variables for sensitive configuration
Troubleshooting
Common Issues
Connection Refused
Solution: Ensure B4B API server is running and accessible at configured URL
Authentication Failed
Solution: Verify phone number format (+84...) and password
Token Expired
Solution: Call login
again to obtain a new token
Rate Limiting
Solution: Implement request throttling or increase rate limits
Debug Mode
Enable debug logging for troubleshooting:
View detailed request/response logs:
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
Code style and standards
Testing requirements
Pull request process
Issue reporting
License
This project is licensed under the MIT License - see LICENSE file for details.
Support
Documentation: https://docs.finizi.com/mcp
Issues: GitHub Issues
Email: dev@finizi.ai
Discord: Finizi Community
Acknowledgments
Built with MCP SDK by Anthropic
HTTP client powered by httpx
Logging with structlog
Configuration with Pydantic
Version: 1.0.0 Last Updated: October 2024 Maintained by: Finizi Team
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables AI assistants to interact with the Finizi B4B platform through 15 comprehensive tools for managing business entities, invoices, vendors, and products. Features secure JWT authentication, automatic retries, and comprehensive business data operations through natural language commands.