# Testing the Skraak MCP Server

## Quick Testing with Shell Scripts

The easiest way to test the server is using the provided shell scripts:

### Comprehensive Test (All Tools)
```bash
./test_mcp.sh [path-to-database]
```

Tests all functionality:
1. Server initialization
2. Tool listing
3. `get_current_time` tool
4. `query_datasets` tool

Default database path: `./db/skraak.duckdb`

### Quick Tool Tests

**Get Current Time:**
```bash
./get_time.sh [path-to-database]
```

**Query Datasets:**
```bash
./query_datasets.sh [path-to-database]
```

Both scripts output clean JSON using `jq`.

## Manual JSON-RPC Testing

You can send messages manually via stdin:

```bash
./skraak_mcp ./db/skraak.duckdb
```

Then type these JSON-RPC messages (one per line):

### 1. Initialize
```json
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}
```

### 2. List Tools
```json
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
```

### 3. Call get_current_time
```json
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_current_time","arguments":{}}}
```

### 4. Call query_datasets
```json
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"query_datasets","arguments":{}}}
```

## Expected Responses

### Initialize Response
```json
{
  "jsonrpc":"2.0",
  "id":1,
  "result":{
    "capabilities":{"logging":{},"tools":{"listChanged":true}},
    "protocolVersion":"2024-11-05",
    "serverInfo":{"name":"skraak_mcp","version":"v1.0.0"}
  }
}
```

### List Tools Response
```json
{
  "jsonrpc":"2.0",
  "id":2,
  "result":{
    "tools":[
      {
        "name":"get_current_time",
        "description":"Get the current system time with timezone information",
        "inputSchema":{"type":"object","additionalProperties":false},
        "outputSchema":{
          "type":"object",
          "required":["time","timezone","unix"],
          "properties":{
            "time":{"type":"string","description":"Current system time in RFC3339 format"},
            "timezone":{"type":"string","description":"System timezone"},
            "unix":{"type":"integer","description":"Unix timestamp in seconds"}
          }
        }
      },
      {
        "name":"query_datasets",
        "description":"Query all datasets from the database. Returns dataset information including ID, name, description, timestamps, active status, and type (organise/test/train).",
        "inputSchema":{"type":"object","additionalProperties":false},
        "outputSchema":{
          "type":"object",
          "required":["datasets","count"],
          "properties":{
            "datasets":{"type":"array","description":"Array of dataset records from the database"},
            "count":{"type":"integer","description":"Total number of datasets returned"}
          }
        }
      }
    ]
  }
}
```

### Get Current Time Response
```json
{
  "jsonrpc":"2.0",
  "id":3,
  "result":{
    "structuredContent":{
      "time":"2026-01-25T16:30:00+13:00",
      "timezone":"Local",
      "unix":1769311800
    }
  }
}
```

### Query Datasets Response
```json
{
  "jsonrpc":"2.0",
  "id":4,
  "result":{
    "structuredContent":{
      "count":10,
      "datasets":[
        {
          "id":"U1khPsIN_r9-",
          "name":"sorted data test",
          "description":null,
          "created_at":"2025-08-26T09:01:04Z",
          "last_modified":"2025-08-26T09:03:05Z",
          "active":false,
          "type":"organise"
        }
      ]
    }
  }
}
```

## Testing with Claude Desktop

Configure the server in Claude Desktop:

1. Edit your MCP config file:
   - **Linux**: `~/.config/Claude/claude_desktop_config.json`
   - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
   - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`

2. Add this configuration:
```json
{
  "mcpServers": {
    "skraak_mcp": {
      "command": "/home/david/go/src/skraak_mcp/skraak_mcp",
      "args": ["/home/david/go/src/skraak_mcp/db/skraak.duckdb"]
    }
  }
}
```

3. Restart Claude Desktop

4. Test by asking:
   - "What time is it?"
   - "Query all datasets"
   - "List the available datasets"

## Troubleshooting

- **Server immediately exits**: Normal - it waits for stdin input
- **"Usage: ./skraak_mcp <path>"**: You must provide database path argument
- **JSON parsing errors**: Each JSON message must be on a single line
- **No response**: Server outputs to stdout; notifications may appear between responses
- **Tool not found**: Initialize the connection first before calling tools
- **Database connection failed**: Check the database path exists and is readable