Skip to content

Commit 6d2bbff

Browse files
fix: add implementation description metadata (#981)
## Summary - add the optional `description` field to `mcp.Implementation` - keep the field omitted when empty - cover JSON marshal/unmarshal behavior with a focused regression test Fixes #977. ## To verify - `go test ./mcp -run TestImplementationDescriptionJSON -count=1` - `go test ./mcp -run TestServerRequest_PerRequestAccessors -count=1` - `go test ./mcp -count=1` - `go test ./...` - `git diff --check` Co-authored-by: Guglielmo Colombo <guglielmoc@google.com>
1 parent 8805aa8 commit 6d2bbff

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

mcp/protocol.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,16 +1935,18 @@ type ElicitationCompleteParams struct {
19351935
func (x *ElicitationCompleteParams) isParams() {}
19361936
func (x *ElicitationCompleteParams) isNil() bool { return x == nil }
19371937

1938-
// An Implementation describes the name and version of an MCP implementation, with an optional
1939-
// title for UI representation.
1938+
// An Implementation describes the name and version of an MCP implementation, with
1939+
// optional display metadata.
19401940
type Implementation struct {
19411941
// Intended for programmatic or logical use, but used as a display name in past
19421942
// specs or fallback (if title isn't present).
19431943
Name string `json:"name"`
19441944
// Intended for UI and end-user contexts — optimized to be human-readable and
19451945
// easily understood, even by those unfamiliar with domain-specific terminology.
1946-
Title string `json:"title,omitempty"`
1947-
Version string `json:"version"`
1946+
Title string `json:"title,omitempty"`
1947+
// A human-readable description of the implementation.
1948+
Description string `json:"description,omitempty"`
1949+
Version string `json:"version"`
19481950
// WebsiteURL for the server, if any.
19491951
WebsiteURL string `json:"websiteUrl,omitempty"`
19501952
// Icons for the Server, if any.

mcp/shared_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,39 @@ func TestServerRequest_PerRequestAccessors_Empty(t *testing.T) {
245245
}
246246
}
247247

248+
func TestImplementationDescriptionJSON(t *testing.T) {
249+
impl := &Implementation{
250+
Name: "greeter",
251+
Title: "Greeter",
252+
Description: "Example server for greeting tools",
253+
Version: "v1.0.0",
254+
}
255+
got, err := json.Marshal(impl)
256+
if err != nil {
257+
t.Fatal(err)
258+
}
259+
want := `{"name":"greeter","title":"Greeter","description":"Example server for greeting tools","version":"v1.0.0"}`
260+
if string(got) != want {
261+
t.Fatalf("Implementation JSON = %s, want %s", got, want)
262+
}
263+
264+
var roundTrip Implementation
265+
if err := json.Unmarshal(got, &roundTrip); err != nil {
266+
t.Fatal(err)
267+
}
268+
if diff := cmp.Diff(impl, &roundTrip); diff != "" {
269+
t.Fatalf("Implementation round trip mismatch (-want +got):\n%s", diff)
270+
}
271+
272+
got, err = json.Marshal(&Implementation{Name: "greeter", Version: "v1.0.0"})
273+
if err != nil {
274+
t.Fatal(err)
275+
}
276+
if strings.Contains(string(got), "description") {
277+
t.Fatalf("empty description should be omitted, got %s", got)
278+
}
279+
}
280+
248281
// TODO(v0.3.0): rewrite this test.
249282
// func TestToolValidate(t *testing.T) {
250283
// // Check that the tool returned from NewServerTool properly validates its input schema.

0 commit comments

Comments
 (0)