MCP tools are a server-side extension point. Use them when an assistant needs live data, deterministic actions, or integration-specific permissions that cannot be represented by static training content.

Pattern Selection

NeedPreferred patternWhy
Public or organization knowledgeTraining/RAGData is static or broadly visible to the assistant.
End-user account dataCustomer-data OpenAPI connectorIdentity injection and ownership checks are already part of the tool path.
First-party operational actionAuthored MCP serverTypeScript can enforce authorization, side effects, and idempotency.
Third-party read-only lookupOpenAPI connectorTool schemas can be generated from a constrained operation allow-list.
Admin diagnosticsAudit log API and admin UITool traces are already persisted with filters and correlation IDs.

Chat Streaming Pattern

The primary path is streamWithToolCalls. It calls the model with the resolved tools, executes tool calls through mcpRegistry.executeTool, appends tool results to the message history, and asks the model for the final answer.

Use callbacks for UI feedback rather than inventing a parallel tool runner.

Tool-call stream callbacks

Widget Identity Pattern

Customer-data tools should be hidden until Kommander has verified the widget identity. The integrator computes userHash server-side, then the widget sends the signed identity with each conversation request.

Widget identity payload

The tool call path uses the verified identity from server context. Tools must not ask the model or the end user to provide IDs, email addresses, HMAC signatures, or tenant keys.

OpenAPI Connector Pattern

Expose only the operations an assistant should call. Keep each operation narrow and map verified identity into path, query, header, or body parameters.

OpenAPI operation allow-list

Generated tools should return compact JSON. Prefer upstream endpoints that return the exact fields needed by the assistant instead of large generic records.

Authored Server Pattern

Use a custom MCP server when Kommander owns the business logic or when a tool needs complex authorization. The registry caches server instances by userId and server id, so constructors should store config and initialization should open reusable connections.

Server registration pattern

Return tool results as structured JSON with status fields, IDs, timestamps, and ownership markers. Avoid returning prose; the model can turn JSON into a customer-facing answer after Kommander verifies the result.

Admin and Operations Pattern

Use audit logs as the source of truth for what happened during a tool call. Conversation messages can show tool metadata, but tool_audit_logs has the durable filters needed for operations.

Find calls for one conversation

Correlate by correlationId when a model turn produced multiple tool calls. Correlate by connectorId when debugging connector health, rate limits, or circuit-breaker behavior.

Migration Pattern

When converting an existing integration into MCP tools:

  1. List user questions the assistant must answer.
  2. Separate static answers from live data needs.
  3. Create or choose a read-only endpoint for each live data need.
  4. Define the JSON schema that matches the smallest useful argument set.
  5. Add identity injection for customer-owned data.
  6. Add audit redaction for connector-specific sensitive fields.
  7. Test success, missing identity, upstream failure, timeout, and ownership mismatch.