Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit ed0305d

Browse files
mcp-sqlite as prompts
1 parent 42748b9 commit ed0305d

File tree

8 files changed

+72
-18
lines changed

8 files changed

+72
-18
lines changed

prompts/examples/curl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
model: claude-3-5-sonnet-20241022
23
tools:
34
- name: curl
45
---

prompts/examples/explain_dockerfile.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description: |
77
Synonyms: explain my Dockerfile, annotate this Dockerfile...
88
99
This tool can explain a pre-provided Dockerfile but it can also fetch the Dockerfile from the user's workspace.
10+
model: claude-3-5-sonnet-20241022
1011
tools:
1112
- name: cat_file
1213
description: fetch a file

prompts/examples/hello_world.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
name: hello-docker
33
description: run the hello-docker
4+
model: claude-3-5-sonnet-20241022
45
tools:
56
- name: hello-docker
67
description: print a secret message

prompts/examples/mcp-sqlite.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,70 @@
11
---
22
description: |
33
A prompt to seed the database with initial data and demonstrate what you can do with an SQLite MCP Server + Claude
4+
model: claude-3-5-sonnet-20241022
45
tools:
56
- name: read-query
67
description: Execute a SELECT query on the SQLite database
7-
container:
8+
parameters: &query
9+
type: object
10+
properties:
11+
query:
12+
type: string
13+
description: SELECT SQL query to execute
14+
container: &sqlite
815
image: vonwig/sqlite:latest
916
command:
10-
- "{{database}}"
11-
- "{{sql}}"
17+
- "/mcp/test1.db"
18+
- "{{query|safe}}"
19+
mounts: &mounts
20+
- "mcp-test:/mcp"
1221
- name: write-query
1322
description: Execute an INSERT, UPDATE, or DELETE query on the SQLite database
23+
parameters: *query
24+
container: *sqlite
1425
- name: create-table
1526
description: Create a new table in the SQLite database
27+
parameters: *query
28+
container: *sqlite
1629
- name: list-tables
1730
description: List all tables in the SQLite database
31+
container:
32+
image: vonwig/sqlite:latest
33+
command:
34+
- "/mcp/test1.db"
35+
- "SELECT name from sqlite_master WHERE type='table'"
36+
mounts: *mounts
1837
- name: describe-table
1938
description: Get the schema information for a specific table
39+
parameters:
40+
type: object
41+
properties:
42+
table_name:
43+
type: string
44+
description: Name of the table to describe
45+
container:
46+
image: vonwig/sqlite:latest
47+
command:
48+
- "/mcp/test1.db"
49+
- "PRAGMA table_info({{table_name}})"
50+
mounts: *mounts
2051
- name: append-insight
2152
description: Add a business insight to the memo
53+
parameters:
54+
type: object
55+
properties:
56+
insight:
57+
type: string
58+
description: Business insight discovered from data analysis
59+
container:
60+
image: vonwig/bash_alpine
61+
command:
62+
- "-c"
63+
- "echo '{{insight|safe}}' >> /mcp/insights.txt"
64+
mounts: *mounts
65+
prompt-format: django
66+
parameter-values:
67+
topic: Ocean Conservation
2268
---
2369

2470
# prompt user

src/claude.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
(try
1515
(string/trim (slurp (io/file (or (System/getenv "CLAUDE_API_KEY_LOCATION") (System/getenv "HOME")) ".claude-api-key")))
1616
(catch Throwable _
17-
(throw (ex-info "Unable to read claude-api-key secret" {})))))
17+
(throw (ex-info "Unable to read claude api-key secret" {})))))
1818

1919
(defn parse-sse [s]
2020
(when (string/starts-with? s "data:")
@@ -52,7 +52,7 @@
5252
(if tool_calls
5353
{:role (:role message)
5454
:content (concat
55-
(when (:content message) [{:type "text" :text (:content message)}])
55+
(when (and (:content message) (not (= "" (:content message)))) [{:type "text" :text (:content message)}])
5656
(->> tool_calls
5757
(map (fn [{:keys [id function]}]
5858
{:type "tool_use"

src/graph.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
(let [[chunk-handler sample] (providers (llm-provider (or (:model metadata) model)))
4949
[c h] (chunk-handler)
5050
request (merge
51-
(dissoc metadata :agent :host-dir :workdir :prompt-format :description :name) ; TODO should we just select relevant keys instead of removing bad ones
51+
(dissoc metadata :agent :host-dir :workdir :prompt-format :description :name :parameter-values) ; TODO should we just select relevant keys instead of removing bad ones
5252
{:messages messages
5353
:level level}
5454
(when (seq functions) {:tools functions})

src/prompts.clj

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@
132132
(fn [content]
133133
(if prompts-file
134134
(stache/render-string
135-
content
136-
m
137-
{:partials (partials/file-partials
138-
[(if (fs/directory? prompts-file) prompts-file (fs/parent prompts-file))]
139-
".md")})
135+
content
136+
m
137+
{:partials (partials/file-partials
138+
[(if (fs/directory? prompts-file) prompts-file (fs/parent prompts-file))]
139+
".md")})
140140
(stache/render-string content m)))))
141141

142142
(defn selmer-render [m message]
@@ -145,9 +145,9 @@
145145
(fn [content]
146146
(selmer/render content m))))
147147

148-
(selmer/add-tag! :tip (fn [args context-map]
149-
(format
150-
"At the very end of the response, add this sentence: \"ℹ️ You can also ask: '%s'\", in the language used by the user, with the question in italic." (first args))))
148+
(selmer/add-tag! :tip (fn [args context-map]
149+
(format
150+
"At the very end of the response, add this sentence: \"ℹ️ You can also ask: '%s'\", in the language used by the user, with the question in italic." (first args))))
151151

152152
(comment
153153
(stache/render-string "yo {{a.0.content}}" {:a [{:content "blah"}]}))
@@ -159,7 +159,7 @@
159159
returns map of messages, functions, metadata and optionally error"
160160
[{:keys [parameters prompts user platform host-dir prompt-content] :as opts}]
161161
(let [{:keys [metadata] :as prompt-data}
162-
(cond
162+
(cond
163163
;; prompt content is already in opts
164164
prompt-content
165165
(markdown-parser/parse-prompts prompt-content)
@@ -179,8 +179,11 @@
179179
:else
180180
(markdown-parser/parse-prompts (slurp prompts)))
181181

182-
m (merge (run-extractors (:extractors metadata) opts) parameters)
183-
renderer (if (= "django" (:prompt-format metadata))
182+
m (merge
183+
(run-extractors (:extractors metadata) opts)
184+
parameters
185+
(-> metadata :parameter-values))
186+
renderer (if (= "django" (:prompt-format metadata))
184187
(partial selmer-render (facts m user platform host-dir))
185188
(partial moustache-render prompts (facts m user platform host-dir)))]
186189
((schema/validate :schema/prompts-file)

src/tools.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@
9090
false
9191
(not= 0 exit-code))]
9292
(cond
93-
(and (= :exited done) (not exit-code-fail?))
93+
(and (= :exited done) (not exit-code-fail?) pty-output (not (= "" pty-output)))
9494
(resolve pty-output)
95+
(and (= :exited done) (not exit-code-fail?))
96+
(resolve "success")
9597
(and (= :exited done) exit-code-fail?)
9698
(fail (format "call exited with non-zero code (%d): %s" exit-code pty-output))
9799
(= :timeout done)

0 commit comments

Comments
 (0)