Commit8ab4b424Recorded31 Aug 2026Repositorysigil-mcp

sigil-mcp: retain decoded initialize metadata

Changed
 package.sgl              |  2 +-
 src/sigil/mcp/client.sgl | 12 +++++++++---
 test/test-client.sgl     | 20 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 4 deletions(-)
Diff
package.sglmodified
@@ -7,7 +7,7 @@
7
8
(package
9
name: "sigil-mcp"
−10
version: "0.17.2"
+10
version: "0.17.3"
11
sigil: "^0.19"
12
description: "Library for building MCP clients and servers in Sigil"
13
url: "https://codeberg.org/sigil/sigil-mcp"
src/sigil/mcp/client.sglmodified
@@ -2,6 +2,7 @@
2
3
(define-library (sigil mcp client)
4
(import (sigil core)
+5
(sigil dict)
6
(sigil struct)
7
(sigil mcp protocol))
8
(export mcp-client
@@ -85,6 +86,11 @@
86
(mcp-client-notify! client "notifications/cancelled"
87
`((requestId . ,id))))
88
+89
(define (wire-ref value alist-key dict-key)
+90
(cond ((dict? value) (dict-ref value dict-key #f))
+91
((list? value) (assoc-ref alist-key value))
+92
(else #f)))
+93
94
(define (mcp-client-initialize! client protocol-version client-info capabilities callback)
95
(set-mcp-client-state! client 'initializing)
96
(mcp-client-request!
@@ -96,11 +102,11 @@
102
(if (jsonrpc-response? outcome)
103
(let ((result (jsonrpc-response-result outcome)))
104
(set-mcp-client-protocol-version!
−99
client (and (list? result) (assoc-ref 'protocolVersion result)))
+105
client (wire-ref result 'protocolVersion protocolVersion:))
106
(set-mcp-client-server-info!
−101
client (and (list? result) (assoc-ref 'serverInfo result)))
+107
client (wire-ref result 'serverInfo serverInfo:))
108
(set-mcp-client-server-capabilities!
−103
client (and (list? result) (assoc-ref 'capabilities result)))
+109
client (wire-ref result 'capabilities capabilities:))
110
(set-mcp-client-state! client 'ready)
111
(mcp-client-notify! client "notifications/initialized")
112
(emit! client `((type . initialized)
test/test-client.sglmodified
@@ -52,6 +52,26 @@
52
(assert-equal "notifications/initialized"
53
(dict-ref (json-decode (car (reverse sent))) method:))))
54
+55
(test "initialize records metadata decoded from a JSON frame"
+56
(let* ((json-client
+57
(mcp-client send: (lambda (_) #t)))
+58
(id (mcp-client-initialize!
+59
json-client "2025-06-18"
+60
'((name . "test") (version . "1")) '() (lambda (_) #t))))
+61
(mcp-client-handle-line!
+62
json-client
+63
(json-encode
+64
#{ jsonrpc: "2.0" id: id
+65
result: #{ protocolVersion: "2025-06-18"
+66
capabilities: #{ resources: #{} }
+67
serverInfo: #{ name: "fixture" version: "1" } } }))
+68
(assert-equal "2025-06-18" (mcp-client-protocol-version json-client))
+69
(assert-true
+70
(dict? (mcp-client-server-capabilities json-client)))
+71
(assert-true
+72
(dict? (dict-ref (mcp-client-server-capabilities json-client)
+73
resources: #f)))))
+74
75
(test "server notification is typed and observable"
76
(mcp-client-handle-message!
77
client (make-notification "notifications/claude/channel" '((content . "hi"))))