Skip to content

Commit 262fff0

Browse files
committed
Add MCP server instructions to LLM context
Fixes #361
1 parent 040d0bc commit 262fff0

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix native image on Windows not running on older CPUs by enabling `-march=compatibility`. #362
66
- Fix simple summaries in tool calls for ollama.
7+
- Add MCP server instructions to LLM context. #361
78

89
## 0.114.0
910

src/eca/features/prompt.clj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@
105105
{}
106106
all-tools))))
107107

108+
(defn ^:private mcp-instructions-section [db]
109+
(let [servers-with-instructions
110+
(->> (:mcp-clients db)
111+
(keep (fn [[server-name {:keys [status instructions]}]]
112+
(when (and (= :running status)
113+
(not (string/blank? instructions)))
114+
{:name (name server-name)
115+
:instructions instructions})))
116+
seq)]
117+
(when servers-with-instructions
118+
(multi-str
119+
"<mcp-server-instructions description=\"Instructions provided by MCP servers describing their capabilities and usage guidelines.\">"
120+
""
121+
(reduce
122+
(fn [acc {:keys [name instructions]}]
123+
(str acc (format "<mcp-server-instruction name=\"%s\">\n%s\n</mcp-server-instruction>\n\n" name instructions)))
124+
""
125+
servers-with-instructions)
126+
"</mcp-server-instructions>"
127+
""))))
128+
108129
(defn build-chat-instructions [refined-contexts rules skills repo-map* agent-name config chat-id all-tools db]
109130
(let [selmer-ctx (->base-selmer-ctx all-tools chat-id db)]
110131
(multi-str
@@ -135,6 +156,7 @@
135156
["## Contexts"
136157
""
137158
(contexts-str refined-contexts repo-map* (get-in db [:chats chat-id :startup-context]))])
159+
(mcp-instructions-section db)
138160
""
139161
(selmer/render (load-builtin-prompt "additional_system_info.md") selmer-ctx))))
140162

src/eca/features/tools/mcp.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
:tools (get-in db [:mcp-clients mcp-name :tools])
155155
:prompts (get-in db [:mcp-clients mcp-name :prompts])
156156
:resources (get-in db [:mcp-clients mcp-name :resources])
157+
:instructions (get-in db [:mcp-clients mcp-name :instructions])
157158
:has-auth (boolean (get-in db [:mcp-auth mcp-name :access-token]))
158159
:status status})
159160

@@ -314,6 +315,7 @@
314315
:status :starting
315316
:needs-reinit?* needs-reinit?*})
316317
(swap! db* assoc-in [:mcp-clients name :version] version)
318+
(swap! db* assoc-in [:mcp-clients name :instructions] (:instructions init-result))
317319
(swap! db* assoc-in [:mcp-clients name :tools] (list-server-tools client))
318320
(swap! db* assoc-in [:mcp-clients name :prompts] (list-server-prompts client))
319321
(swap! db* assoc-in [:mcp-clients name :resources] (list-server-resources client))

0 commit comments

Comments
 (0)