-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp_local_server.clj
More file actions
71 lines (63 loc) · 3.25 KB
/
mcp_local_server.clj
File metadata and controls
71 lines (63 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(ns mcp-local-server
(:require [github.copilot-sdk :as copilot]
[github.copilot-sdk.helpers :as h]))
;; See examples/README.md for usage
;; See doc/mcp/overview.md for full MCP documentation
;; This example demonstrates using MCP (Model Context Protocol) servers
;; to extend the assistant's capabilities with external tools.
;; NOTE: This example requires npx (Node.js) to be installed,
;; as it uses the @modelcontextprotocol/server-filesystem MCP server.
(def defaults
{:allowed-dir "/tmp"})
(defn run
"Run a query with the filesystem MCP server.
Usage:
clojure -A:examples -X mcp-local-server/run
clojure -A:examples -X mcp-local-server/run :allowed-dir '\"/home/user/docs\"'"
[{:keys [allowed-dir] :or {allowed-dir (:allowed-dir defaults)}}]
(println (str "MCP Filesystem Server — allowed directory: " allowed-dir))
(println)
(let [session-config {:model "claude-haiku-4.5"
:on-permission-request copilot/approve-all
:mcp-servers
{"filesystem"
{:mcp-command "npx"
:mcp-args ["-y" "@modelcontextprotocol/server-filesystem"
allowed-dir]
:mcp-tools ["*"]}}}]
(copilot/with-client [client {}]
(copilot/with-session [session client session-config]
(println "Q: List the files in the allowed directory")
(println "🤖:" (h/query (str "List the files in " allowed-dir ". Just list the filenames, nothing more.")
:session session))))))
(defn run-with-custom-tools
"Run with MCP server and custom tools combined.
Usage:
clojure -A:examples -X mcp-local-server/run-with-custom-tools
clojure -A:examples -X mcp-local-server/run-with-custom-tools :allowed-dir '\"/home/user/docs\"'"
[{:keys [allowed-dir] :or {allowed-dir (:allowed-dir defaults)}}]
(let [summary-tool
(copilot/define-tool "summarize_text"
{:description "Summarize a piece of text into a single sentence."
:parameters {:type "object"
:properties {:text {:type "string"
:description "The text to summarize"}}
:required ["text"]}
:handler (fn [{:keys [text]} _]
(copilot/result-success
(str "Summary: " (subs text 0 (min 100 (count text))) "...")))})
session-config {:model "claude-haiku-4.5"
:tools [summary-tool]
:on-permission-request copilot/approve-all
:mcp-servers
{"filesystem"
{:mcp-command "npx"
:mcp-args ["-y" "@modelcontextprotocol/server-filesystem" allowed-dir]
:mcp-tools ["*"]}}}]
(println "MCP + Custom Tools Example")
(println (str " Allowed directory: " allowed-dir))
(println)
(copilot/with-client [client {}]
(copilot/with-session [session client session-config]
(println "🤖:" (h/query (str "List the files in " allowed-dir " and summarize the result briefly using the summarize_text tool.")
:session session))))))