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
| Need | Preferred pattern | Why |
|---|---|---|
| Public or organization knowledge | Training/RAG | Data is static or broadly visible to the assistant. |
| End-user account data | Customer-data OpenAPI connector | Identity injection and ownership checks are already part of the tool path. |
| First-party operational action | Authored MCP server | TypeScript can enforce authorization, side effects, and idempotency. |
| Third-party read-only lookup | OpenAPI connector | Tool schemas can be generated from a constrained operation allow-list. |
| Admin diagnostics | Audit log API and admin UI | Tool 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.
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.
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.
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.
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.
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:
- List user questions the assistant must answer.
- Separate static answers from live data needs.
- Create or choose a read-only endpoint for each live data need.
- Define the JSON schema that matches the smallest useful argument set.
- Add identity injection for customer-owned data.
- Add audit redaction for connector-specific sensitive fields.
- Test success, missing identity, upstream failure, timeout, and ownership mismatch.