CREATE TABLE IF NOT EXISTS tools (
    space_id TEXT NOT NULL,
    tool_name TEXT NOT NULL,
    description TEXT,
    input_schema TEXT,  -- JSON schema
    output_type TEXT,
    endpoint_type TEXT DEFAULT 'schema',
    FOREIGN KEY(space_id) REFERENCES spaces(space_id) ON DELETE CASCADE,
    PRIMARY KEY (space_id, tool_name)
);

CREATE INDEX IF NOT EXISTS idx_tool_name ON tools(tool_name);