133 lines
3.8 KiB
Go
133 lines
3.8 KiB
Go
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
|
|
Backfill *tools.BackfillTool
|
|
}
|
|
|
|
func New(cfg config.MCPConfig, toolSet ToolSet) http.Handler {
|
|
server := mcp.NewServer(&mcp.Implementation{
|
|
Name: cfg.ServerName,
|
|
Version: cfg.Version,
|
|
}, nil)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "capture_thought",
|
|
Description: "Store a thought with generated embeddings and extracted metadata.",
|
|
}, toolSet.Capture.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "search_thoughts",
|
|
Description: "Search stored thoughts by semantic similarity.",
|
|
}, toolSet.Search.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "list_thoughts",
|
|
Description: "List recent thoughts with optional metadata filters.",
|
|
}, toolSet.List.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "thought_stats",
|
|
Description: "Get counts and top metadata buckets across stored thoughts.",
|
|
}, toolSet.Stats.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "get_thought",
|
|
Description: "Retrieve a full thought by id.",
|
|
}, toolSet.Get.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "update_thought",
|
|
Description: "Update thought content or merge metadata.",
|
|
}, toolSet.Update.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "delete_thought",
|
|
Description: "Hard-delete a thought by id.",
|
|
}, toolSet.Delete.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "archive_thought",
|
|
Description: "Archive a thought so it is hidden from default search and listing.",
|
|
}, toolSet.Archive.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "create_project",
|
|
Description: "Create a named project container for thoughts.",
|
|
}, toolSet.Projects.Create)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "list_projects",
|
|
Description: "List projects and their current thought counts.",
|
|
}, toolSet.Projects.List)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "set_active_project",
|
|
Description: "Set the active project for the current MCP session.",
|
|
}, toolSet.Projects.SetActive)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "get_active_project",
|
|
Description: "Return the active project for the current MCP session.",
|
|
}, toolSet.Projects.GetActive)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "get_project_context",
|
|
Description: "Get recent and semantic context for a project.",
|
|
}, toolSet.Context.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "recall_context",
|
|
Description: "Recall semantically relevant and recent context.",
|
|
}, toolSet.Recall.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "summarize_thoughts",
|
|
Description: "Summarize a filtered or searched set of thoughts.",
|
|
}, toolSet.Summarize.Handle)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "link_thoughts",
|
|
Description: "Create a typed relationship between two thoughts.",
|
|
}, toolSet.Links.Link)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "related_thoughts",
|
|
Description: "Retrieve explicit links and semantic neighbors for a thought.",
|
|
}, toolSet.Links.Related)
|
|
|
|
addTool(server, &mcp.Tool{
|
|
Name: "backfill_embeddings",
|
|
Description: "Generate missing embeddings for stored thoughts using the active embedding model.",
|
|
}, toolSet.Backfill.Handle)
|
|
|
|
return mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
|
|
return server
|
|
}, &mcp.StreamableHTTPOptions{
|
|
JSONResponse: true,
|
|
SessionTimeout: 10 * time.Minute,
|
|
})
|
|
}
|