mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
enhance(cli): graph args+options can be local files or dirs
This affects all cli commands that take graph args. Also tweaked mcp-server host+port defaults to match the app
This commit is contained in:
@@ -168,6 +168,7 @@
|
||||
logseq.cli.common.export.common cli-export-common
|
||||
logseq.cli.common.export.text cli-export-text
|
||||
logseq.cli.common.file common-file
|
||||
logseq.cli.common.mcp.server cli-common-mcp-server
|
||||
logseq.cli.common.mcp.tools cli-common-mcp-tools
|
||||
logseq.cli.text-util cli-text-util
|
||||
logseq.common.config common-config
|
||||
|
||||
1
deps/cli/.clj-kondo/config.edn
vendored
1
deps/cli/.clj-kondo/config.edn
vendored
@@ -12,6 +12,7 @@
|
||||
clojure.string string
|
||||
datascript.core d
|
||||
logseq.cli.commands.graph cli-graph
|
||||
logseq.cli.common.mcp.server cli-common-mcp-server
|
||||
logseq.cli.common.mcp.tools cli-common-mcp-tools
|
||||
logseq.cli.common.graph cli-common-graph
|
||||
logseq.cli.common.export.text cli-export-text
|
||||
|
||||
7
deps/cli/README.md
vendored
7
deps/cli/README.md
vendored
@@ -125,6 +125,13 @@ Exported 16 properties, 16 classes and 36 pages
|
||||
# Append text to current page
|
||||
$ logseq append add this text -a my-token
|
||||
Success!
|
||||
|
||||
# Start mcp-server against a local desktop graph
|
||||
$ logseq mcp-server -g yep
|
||||
MCP Streamable HTTP Server started on 127.0.0.1:12315
|
||||
# Start mcp-server against a local graph file
|
||||
$ logseq mcp-server -g ~/Downloads/logseq_db_yep_1751032977.sqlite
|
||||
MCP Streamable HTTP Server started on 127.0.0.1:12315
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
2
deps/cli/src/logseq/cli/commands/export.cljs
vendored
2
deps/cli/src/logseq/cli/commands/export.cljs
vendored
@@ -74,7 +74,7 @@
|
||||
(println "Exported" (count exported-files) "pages to" file-name)))))
|
||||
|
||||
(defn export [{{:keys [graph] :as opts} :opts}]
|
||||
(if (fs/existsSync (cli-util/get-graph-dir graph))
|
||||
(if (fs/existsSync (cli-util/get-graph-path graph))
|
||||
(let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))]
|
||||
(export-repo-as-markdown! (str common-config/db-version-prefix graph) @conn opts))
|
||||
(cli-util/error "Graph" (pr-str graph) "does not exist")))
|
||||
@@ -8,7 +8,7 @@
|
||||
[logseq.cli.util :as cli-util]))
|
||||
|
||||
(defn export [{{:keys [graph] :as options} :opts}]
|
||||
(if (fs/existsSync (cli-util/get-graph-dir graph))
|
||||
(if (fs/existsSync (cli-util/get-graph-path graph))
|
||||
(let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
|
||||
export-map (sqlite-export/build-export @conn
|
||||
(cond-> {:export-type (:export-type options)}
|
||||
|
||||
2
deps/cli/src/logseq/cli/commands/graph.cljs
vendored
2
deps/cli/src/logseq/cli/commands/graph.cljs
vendored
@@ -19,7 +19,7 @@
|
||||
(defn show-graph
|
||||
[{{:keys [graphs]} :opts}]
|
||||
(doseq [graph graphs]
|
||||
(let [graph-dir (cli-util/get-graph-dir graph)]
|
||||
(let [graph-dir (cli-util/get-graph-path graph)]
|
||||
(if (fs/existsSync graph-dir)
|
||||
(let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
|
||||
kv-value #(:kv/value (d/entity @conn %))]
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
(cli-common-mcp-server/create-mcp-api-server (partial call-api api-server-token))))
|
||||
|
||||
(defn start [{{:keys [debug-tool graph stdio api-server-token] :as opts} :opts :as m}]
|
||||
(when (and graph (not (fs/existsSync (cli-util/get-graph-dir graph))))
|
||||
(when (and graph (not (fs/existsSync (cli-util/get-graph-path graph))))
|
||||
(cli-util/error "Graph" (pr-str graph) "does not exist"))
|
||||
(if debug-tool
|
||||
(if graph
|
||||
|
||||
2
deps/cli/src/logseq/cli/commands/query.cljs
vendored
2
deps/cli/src/logseq/cli/commands/query.cljs
vendored
@@ -74,7 +74,7 @@
|
||||
[{{:keys [graph args graphs properties-readable title-query]} :opts}]
|
||||
(let [graphs' (into [graph] graphs)]
|
||||
(doseq [graph' graphs']
|
||||
(if (fs/existsSync (cli-util/get-graph-dir graph'))
|
||||
(if (fs/existsSync (cli-util/get-graph-path graph'))
|
||||
(let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
|
||||
query* (when (string? (first args)) (common-util/safe-read-string {:log-error? false} (first args)))
|
||||
results (cond
|
||||
|
||||
2
deps/cli/src/logseq/cli/commands/search.cljs
vendored
2
deps/cli/src/logseq/cli/commands/search.cljs
vendored
@@ -51,7 +51,7 @@
|
||||
(p/catch cli-util/command-catch-handler)))
|
||||
|
||||
(defn- local-search [search-term {{:keys [graph raw limit]} :opts}]
|
||||
(if (fs/existsSync (cli-util/get-graph-dir graph))
|
||||
(if (fs/existsSync (cli-util/get-graph-path graph))
|
||||
(let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
|
||||
nodes (->> (d/datoms @conn :aevt :block/title)
|
||||
(filter (fn [datom]
|
||||
|
||||
6
deps/cli/src/logseq/cli/spec.cljs
vendored
6
deps/cli/src/logseq/cli/spec.cljs
vendored
@@ -58,11 +58,11 @@
|
||||
:stdio {:alias :s
|
||||
:desc "Run the MCP server via stdio transport"}
|
||||
:port {:alias :p
|
||||
:default 3000
|
||||
:default 12315
|
||||
:coerce :long
|
||||
:desc "Port for streamable HTTP server"}
|
||||
:host {:default "localhost"
|
||||
:desc "Host for streamable HHP server"}
|
||||
:host {:default "127.0.0.1"
|
||||
:desc "Host for streamable HTTP server"}
|
||||
:debug-tool {:alias :t
|
||||
:coerce :keyword
|
||||
:desc "Debug mcp tool with direct invocation"}})
|
||||
18
deps/cli/src/logseq/cli/util.cljs
vendored
18
deps/cli/src/logseq/cli/util.cljs
vendored
@@ -1,20 +1,28 @@
|
||||
(ns ^:node-only logseq.cli.util
|
||||
"CLI only util fns"
|
||||
(:require ["path" :as node-path]
|
||||
["fs" :as fs]
|
||||
[clojure.string :as string]
|
||||
[logseq.cli.common.graph :as cli-common-graph]
|
||||
[logseq.db.common.sqlite :as common-sqlite]
|
||||
[nbb.error]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn get-graph-dir
|
||||
[graph]
|
||||
(node-path/join (cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)))
|
||||
|
||||
(defn ->open-db-args
|
||||
"Creates args for sqlite-cli/open-db! given a graph. Similar to sqlite-cli/->open-db-args"
|
||||
[graph]
|
||||
[(cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)])
|
||||
(cond
|
||||
(and (fs/existsSync graph) (.isFile (fs/statSync graph)))
|
||||
[graph]
|
||||
(string/includes? graph "/")
|
||||
((juxt node-path/dirname node-path/basename) graph)
|
||||
:else
|
||||
[(cli-common-graph/get-db-graphs-dir) (common-sqlite/sanitize-db-name graph)]))
|
||||
|
||||
(defn get-graph-path
|
||||
"If graph is a file, return its path. Otherwise returns the graph's dir"
|
||||
[graph]
|
||||
(apply node-path/join (->open-db-args graph)))
|
||||
|
||||
(defn api-fetch [token method args]
|
||||
(js/fetch "http://127.0.0.1:12315/api"
|
||||
|
||||
Reference in New Issue
Block a user