package main
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"github.com/modelcontextprotocol/go-sdk/mcp"
"skraak_mcp/prompts"
"skraak_mcp/resources"
"skraak_mcp/tools"
)
var dbPath string
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <path-to-duckdb-database>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Example: %s ./data/mydb.duckdb\n", os.Args[0])
os.Exit(1)
}
dbPath = os.Args[1]
tools.SetDBPath(dbPath)
schemaPath := filepath.Join(filepath.Dir(os.Args[0]), "db", "schema.sql")
resources.SetSchemaPath(schemaPath)
server := mcp.NewServer(&mcp.Implementation{
Name: "skraak_mcp",
Version: "v1.0.0",
}, nil)
mcp.AddTool(server, &mcp.Tool{
Name: "get_current_time",
Description: "Get the current system time with timezone information",
}, tools.GetCurrentTime)
mcp.AddTool(server, &mcp.Tool{
Name: "execute_sql",
Description: "Execute arbitrary SQL SELECT queries against the database. Supports parameterized queries with ? placeholders. Database is read-only. Results limited to 1000 rows by default (max 10000). Use with schema resources to construct queries.",
}, tools.ExecuteSQL)
mcp.AddTool(server, &mcp.Tool{
Name: "create_dataset",
Description: "Create a new dataset. Returns the created dataset with generated ID and timestamps.",
}, tools.CreateDataset)
mcp.AddTool(server, &mcp.Tool{
Name: "create_location",
Description: "Create a new location within a dataset. Requires valid dataset_id, GPS coordinates, and IANA timezone.",
}, tools.CreateLocation)
mcp.AddTool(server, &mcp.Tool{
Name: "create_cluster",
Description: "Create a new cluster within a location. Location must belong to the specified dataset.",
}, tools.CreateCluster)
mcp.AddTool(server, &mcp.Tool{
Name: "create_cyclic_recording_pattern",
Description: "Create a reusable recording pattern with record/sleep cycle in seconds.",
}, tools.CreateCyclicRecordingPattern)
mcp.AddTool(server, &mcp.Tool{
Name: "import_audio_files",
Description: "Batch import WAV files from a folder into the database. Automatically parses AudioMoth and filename timestamps, calculates hashes, extracts metadata, and computes astronomical data. Files are imported in a single transaction. Duplicate files (by hash) are skipped.",
}, tools.ImportAudioFiles)
schemaResource, schemaTemplate := resources.GetSchemaResources()
server.AddResource(schemaResource, resources.SchemaResourceHandler)
server.AddResourceTemplate(schemaTemplate, resources.SchemaResourceHandler)
server.AddPrompt(prompts.GetQueryDatasetsPrompt(), prompts.QueryDatasetsPromptHandler)
server.AddPrompt(prompts.GetExploreSchemaPrompt(), prompts.ExploreSchemaPromptHandler)
server.AddPrompt(prompts.GetExploreLocationHierarchyPrompt(), prompts.ExploreLocationHierarchyPromptHandler)
server.AddPrompt(prompts.GetQueryLocationDataPrompt(), prompts.QueryLocationDataPromptHandler)
server.AddPrompt(prompts.GetAnalyzeClusterFilesPrompt(), prompts.AnalyzeClusterFilesPromptHandler)
server.AddPrompt(prompts.GetSystemStatusPrompt(), prompts.SystemStatusPromptHandler)
if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatalf("Server error: %v", err)
}
}