feat: add chat history MCP tools

Adds save/get/list/delete tools for persisting and retrieving agent
chat histories in AMCS.

Changes:
- migrations/018_chat_histories.sql: new chat_histories table with
  indexes on session_id, project_id, channel, agent_id, created_at,
  and FTS over title+summary
- internal/types/extensions.go: ChatMessage and ChatHistory types
- internal/store/chat_histories.go: SaveChatHistory, GetChatHistory,
  GetChatHistoryBySessionID, ListChatHistories, DeleteChatHistory
- internal/tools/chat_history.go: ChatHistoryTool with four handlers
  (save_chat_history, get_chat_history, list_chat_histories,
  delete_chat_history)
- internal/mcpserver/server.go: ChatHistory field in ToolSet,
  registerChatHistoryTools registration function
- internal/app/app.go: wire ChatHistoryTool into ToolSet
This commit is contained in:
sam
2026-04-01 16:06:56 +02:00
parent bb759f4683
commit 741a09017b
6 changed files with 445 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ type ToolSet struct {
Meals *tools.MealsTool
CRM *tools.CRMTool
Skills *tools.SkillsTool
ChatHistory *tools.ChatHistoryTool
}
func New(cfg config.MCPConfig, logger *slog.Logger, toolSet ToolSet, onSessionClosed func(string)) (http.Handler, error) {
@@ -54,6 +55,7 @@ func New(cfg config.MCPConfig, logger *slog.Logger, toolSet ToolSet, onSessionCl
registerMealTools,
registerCRMTools,
registerSkillTools,
registerChatHistoryTools,
} {
if err := register(server, logger, toolSet); err != nil {
return nil, err
@@ -514,3 +516,31 @@ func registerSkillTools(server *mcp.Server, logger *slog.Logger, toolSet ToolSet
}
return nil
}
func registerChatHistoryTools(server *mcp.Server, logger *slog.Logger, toolSet ToolSet) error {
if err := addTool(server, logger, &mcp.Tool{
Name: "save_chat_history",
Description: "Save a chat session's message history for later retrieval. Stores messages with optional title, summary, channel, agent, and project metadata.",
}, toolSet.ChatHistory.SaveChatHistory); err != nil {
return err
}
if err := addTool(server, logger, &mcp.Tool{
Name: "get_chat_history",
Description: "Retrieve a saved chat history by its UUID or session_id. Returns the full message list.",
}, toolSet.ChatHistory.GetChatHistory); err != nil {
return err
}
if err := addTool(server, logger, &mcp.Tool{
Name: "list_chat_histories",
Description: "List saved chat histories with optional filters: project, channel, agent_id, session_id, or recent days.",
}, toolSet.ChatHistory.ListChatHistories); err != nil {
return err
}
if err := addTool(server, logger, &mcp.Tool{
Name: "delete_chat_history",
Description: "Permanently delete a saved chat history by id.",
}, toolSet.ChatHistory.DeleteChatHistory); err != nil {
return err
}
return nil
}