feat(tools): implement CRUD operations for thoughts and projects
* Add tools for creating, retrieving, updating, and deleting thoughts. * Implement project management tools for creating and listing projects. * Introduce linking functionality between thoughts. * Add search and recall capabilities for thoughts based on semantic queries. * Implement statistics and summarization tools for thought analysis. * Create database migrations for thoughts, projects, and links. * Add helper functions for UUID parsing and project resolution.
This commit is contained in:
126
internal/mcpserver/server.go
Normal file
126
internal/mcpserver/server.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package mcpserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"git.warky.dev/wdevs/amcs/internal/config"
|
||||
"git.warky.dev/wdevs/amcs/internal/tools"
|
||||
)
|
||||
|
||||
type ToolSet struct {
|
||||
Capture *tools.CaptureTool
|
||||
Search *tools.SearchTool
|
||||
List *tools.ListTool
|
||||
Stats *tools.StatsTool
|
||||
Get *tools.GetTool
|
||||
Update *tools.UpdateTool
|
||||
Delete *tools.DeleteTool
|
||||
Archive *tools.ArchiveTool
|
||||
Projects *tools.ProjectsTool
|
||||
Context *tools.ContextTool
|
||||
Recall *tools.RecallTool
|
||||
Summarize *tools.SummarizeTool
|
||||
Links *tools.LinksTool
|
||||
}
|
||||
|
||||
func New(cfg config.MCPConfig, toolSet ToolSet) http.Handler {
|
||||
server := mcp.NewServer(&mcp.Implementation{
|
||||
Name: cfg.ServerName,
|
||||
Version: cfg.Version,
|
||||
}, nil)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "capture_thought",
|
||||
Description: "Store a thought with generated embeddings and extracted metadata.",
|
||||
}, toolSet.Capture.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "search_thoughts",
|
||||
Description: "Search stored thoughts by semantic similarity.",
|
||||
}, toolSet.Search.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "list_thoughts",
|
||||
Description: "List recent thoughts with optional metadata filters.",
|
||||
}, toolSet.List.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "thought_stats",
|
||||
Description: "Get counts and top metadata buckets across stored thoughts.",
|
||||
}, toolSet.Stats.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "get_thought",
|
||||
Description: "Retrieve a full thought by id.",
|
||||
}, toolSet.Get.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "update_thought",
|
||||
Description: "Update thought content or merge metadata.",
|
||||
}, toolSet.Update.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "delete_thought",
|
||||
Description: "Hard-delete a thought by id.",
|
||||
}, toolSet.Delete.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "archive_thought",
|
||||
Description: "Archive a thought so it is hidden from default search and listing.",
|
||||
}, toolSet.Archive.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "create_project",
|
||||
Description: "Create a named project container for thoughts.",
|
||||
}, toolSet.Projects.Create)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "list_projects",
|
||||
Description: "List projects and their current thought counts.",
|
||||
}, toolSet.Projects.List)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "set_active_project",
|
||||
Description: "Set the active project for the current MCP session.",
|
||||
}, toolSet.Projects.SetActive)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "get_active_project",
|
||||
Description: "Return the active project for the current MCP session.",
|
||||
}, toolSet.Projects.GetActive)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "get_project_context",
|
||||
Description: "Get recent and semantic context for a project.",
|
||||
}, toolSet.Context.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "recall_context",
|
||||
Description: "Recall semantically relevant and recent context.",
|
||||
}, toolSet.Recall.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "summarize_thoughts",
|
||||
Description: "Summarize a filtered or searched set of thoughts.",
|
||||
}, toolSet.Summarize.Handle)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "link_thoughts",
|
||||
Description: "Create a typed relationship between two thoughts.",
|
||||
}, toolSet.Links.Link)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{
|
||||
Name: "related_thoughts",
|
||||
Description: "Retrieve explicit links and semantic neighbors for a thought.",
|
||||
}, toolSet.Links.Related)
|
||||
|
||||
return mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
|
||||
return server
|
||||
}, &mcp.StreamableHTTPOptions{
|
||||
JSONResponse: true,
|
||||
SessionTimeout: 10 * time.Minute,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user