How tiflux/tiflux-mcp works
Purpose and Entry Points
This is a Node.js MCP server/SDK that exposes Tiflux service-management operations as AI-callable tools: tickets, chats/WhatsApp, clients, requestors, assets, knowledge, billing, and reporting. It supports local stdio execution via npx @tiflux/mcp; the hosted HTTP/OAuth service described in the README is an external deployment mode.
• SDK/bootstrap entry: server-sdk.js
• MCP API assembly: src/api/tiflux-api.js
• Package/runtime contract: package.json
Composition Root and Dependency Boundaries
The application uses a lightweight dependency container. Startup loads environment/configuration, creates shared infrastructure, then registers tool handlers. Tool code should depend on container-provided services rather than directly constructing HTTP, cache, or logging clients.
• Configuration and environment defaults: src/core/Config.js, config/default.json
• Dependency composition: src/core/Container.js
• Infrastructure initialization: src/infrastructure/InfrastructureBootstrap.js
MCP Tool Registration and Dispatch
The registry is the control boundary between an MCP client invocation and a domain handler. Domain folders export tool definitions/handlers, while the central registry aggregates them for the MCP API layer.
• Registry: src/registry/HandlerRegistry.js, src/registry/index.js
• API-facing MCP server logic: src/api/tiflux-api.js
• Representative domain entry points: src/tools/tickets/index.js, src/tools/chats/index.js, src/tools/clients/index.js
Domain Tool Layer
Tools are organized by Tiflux business capability, generally mapping an MCP schema and response formatter to one or more Tiflux API v2 calls. The ticket domain is the largest workflow surface: lifecycle changes, answers, files, histories, SLA, appointments, entity fields, aggregation, and feedback reports.
• Ticket workflows: src/tools/tickets/createTicket.js, src/tools/tickets/updateTicket.js, src/tools/tickets/listTickets.js
• Chat and WhatsApp operations: src/tools/chats/sendMessage.js, src/tools/chats/updateChat.js
• Other major bounded domains: src/tools/equipments/, src/tools/pre_tickets/, src/tools/billings/
Resolution, Validation, and Presentation Pipeline
Handlers normalize/validate MCP arguments, resolve human names to Tiflux IDs when needed, make API calls, and render Markdown-oriented responses. Shared logic encapsulates cross-domain business behaviors such as fuzzy matching, desk/client/requestor/user lookup, custom-field handling, file validation, pagination, comparisons, and diagnostics.
• Name and entity resolution: src/tools/_shared/deskResolver.js, src/tools/_shared/clientResolver.js, src/tools/_shared/entityFieldResolver.js
• Validation and errors: src/tools/_shared/validators.js, src/tools/_shared/errors.js
• Response/rendering and Markdown conversion: src/tools/_shared/response.js, src/tools/_shared/markdownToHtml.js
External Integration and Resilience
The primary external dependency is the Tiflux API v2. Requests are made through a centralized HTTP client, with retry policy and cache abstractions available for reusable API access patterns. API credentials are supplied through environment configuration (TIFLUX_API_KEY for local execution); permissions and licenses are enforced by Tiflux API responses.
• HTTP boundary: src/infrastructure/http/HttpClient.js, src/infrastructure/http/RetryPolicy.js
• Cache abstraction: src/infrastructure/cache/CacheManager.js, src/infrastructure/cache/CacheStrategy.js
• Error normalization: src/utils/errors.js
Runtime Observability and Request Context
Node.js 18+ is the material local runtime. Logging and client fingerprinting provide operational context without being part of business-domain handlers. Output verbosity is configurable for token-sensitive MCP clients.
• Logging: src/core/Logger.js
• Client identification: src/telemetry/ClientFingerprint.js
• Environment template: .env.example
Main entry points: HttpClient.js HTTP client & retries · HandlerRegistry.js Handler registry · index.js Ticket workflows · server-sdk.js SDK bootstrap
Components 19
Runtime & Composition
- Package & runtime · Defines the Node.js 18+ package and npx entrypoint.
package.json - SDK bootstrap
server-sdk.js - Config & environment
src/core/Config.js - Dependency container
src/core/Container.js - Infrastructure bootstrap
src/infrastructure/InfrastructureBootstrap.js - Logger
src/core/Logger.js
MCP Boundary
- Tiflux MCP API · Assembles MCP-facing tool execution.
src/api/tiflux-api.js - Handler registry · Aggregates domain tool definitions and handlers.
src/registry/HandlerRegistry.js
Domain Tools
- Ticket workflows · Largest workflow surface for ticket lifecycle and reporting.
src/tools/tickets/index.js - Chat & WhatsApp tools
src/tools/chats/index.js - Client tools
src/tools/clients/index.js - Assets, pre-tickets & billing
Shared Pipeline
- Entity resolution · Resolves human names and custom fields to Tiflux IDs.
src/tools/_shared/deskResolver.js - Validation & tool errors
src/tools/_shared/validators.js - Response rendering · Formats Markdown-oriented MCP responses.
src/tools/_shared/response.js
Infrastructure & External API
- HTTP client & retries · Centralizes Tiflux API v2 requests and retry policy.
src/infrastructure/http/HttpClient.js - Cache manager
src/infrastructure/cache/CacheManager.js - Tiflux API v2 · Credentials, permissions, and licenses are enforced here.
- Client fingerprint
src/telemetry/ClientFingerprint.js
Connections 27
- Package & runtime → SDK bootstrap: declares entrypoint
- SDK bootstrap → Config & environment: loads
- SDK bootstrap → Dependency container: creates
- Dependency container → Infrastructure bootstrap: initializes
- Infrastructure bootstrap → HTTP client & retries: provisions
- Infrastructure bootstrap → Cache manager: provisions
- Dependency container → Logger: provides
- SDK bootstrap → Tiflux MCP API: starts
- Tiflux MCP API → Handler registry: dispatches tools through
- Handler registry → Ticket workflows: registers
- Handler registry → Chat & WhatsApp tools: registers
- Handler registry → Client tools: registers
- Handler registry → Assets, pre-tickets & billing: registers
- Ticket workflows → Validation & tool errors: validates arguments
- Chat & WhatsApp tools → Validation & tool errors: validates arguments
- Ticket workflows → Entity resolution: resolves entities
- Client tools → Entity resolution: resolves entities
- Ticket workflows → Response rendering: renders response
- Chat & WhatsApp tools → Response rendering: renders response
- Entity resolution → HTTP client & retries: looks up IDs via
- Ticket workflows → HTTP client & retries: calls through
- Chat & WhatsApp tools → HTTP client & retries: calls through
- Client tools → HTTP client & retries: calls through
- Assets, pre-tickets & billing → HTTP client & retries: calls through
- HTTP client & retries → Cache manager: may use
- HTTP client & retries → Tiflux API v2: API v2 requests
- Tiflux MCP API → Client fingerprint: identifies client