Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion mcp/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,36 @@ func incTool(_ context.Context, _ *CallToolRequest, args incInput) (*CallToolRes
return nil, incOutput{args.X + 1}, nil
}

var iconObj = Icon{Source: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAQKADAAQAAAABAAAAQAAAAABGUUKwAAAJhElEQVRoBb2adaxUOxDGcXd3d3cLgaDBLbgT3N3dAgkuwSE4BAkQNLgGAsGCu7u7894v75Ayb84u2927y/3jZs7Zr9OZdjr9Oj3h/gn935kzZ8aMGRMlSpRw//3Fjh172rRpFy9eDErP4YKixZuSTZs2lSlTxpjuOOD8jx49etWqVXfv3u2treX7UDnw7NmzJk2aSIs9yhEjRuzcufP79+8tzXXDQuLAnTt3Chcu7NFijy8rVKjw8uVLt3E2b4LvwK1bt/LkyaMMjRQpUq5cuapUqVKpUqVs2bKFDx9eAWrUqPH161cbixUmyA5cv349Z86cyrhmzZqdOHHC2Pfp06dDhw7VqlVLwSZNmqSMs3kMpgNXr15ldKVZLN/58+d7s2PcuHFyKhInTvzo0SNvYG/vg+bApUuXsmTJIq2PGjXq8uXLvXXsvO/WrZtsMmXKlD/j3b8Gx4Hz589nzJhRmkKWXL16terv27dvP378kC+fP3+eMmVK05Cc+/PnTwnwKQfBgbNnz6ZPn94YgRAjRoy1a9eqvhctWpQ3b95ChQqxOcif2rVrZ9omS5bM33QUVgdOnTqVJk0aYwFCzJgxN2zYIE1EJjYMJn78+A8ePDCAefPmmZ+iRYt27do185ONECYHyC2pUqUy3SNAE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QixQpwj2AurREG0dTlsrp06eNZkKRz1bcHMkArAS/3A0Y7P7+gLPRnDlzAlZoGgYYQqa9jeCxJEr13KatT0zIHeD7AziSDAaKh4sXL/ZpmSUgtA5Qigzg+wNL0x1YCB1gt1KVDkrFq1at8ss+n+AQOkDNQkYOOcr9/YFP+3wCQuUArFPeI3E16C6J+jTOBuDhMlAOW8AyhwGqVKY5h3f3F07m17AIoXKAcJcVro0bN8JSw2Kot7ahcoBdVp6zoP5cJuCGNzsCf28TZ4FhKDJzqSMtC8U6DtUidnzmQk2RoqBn0tA6gBsev6Vzf40W2CTTKuQO0IebTfCpDkfKgI2WDf+GA/Sn+Bz3ReraStrkl/yXHMAmGLU57HOtryoUfhktwWE60MgMYyNTv+AOge/qqKb4dbD+g/J/AVf65lqU7WK5AAAAAElFTkSuQmCC",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the actual data does not matter, can we please make this "foobar".

I don't want arbitrary, unreviewable data to be checked into the repo (I don't know what this data represents).

MIMEType: "image/png", Sizes: []string{"48x48", "96x96"}}

// runServerTest runs the server conformance test.
// It must be executed in a synctest bubble.
func runServerTest(t *testing.T, test *conformanceTest) {
ctx := t.Context()
// Construct the server based on features listed in the test.
s := NewServer(&Implementation{Name: "testServer", Version: "v1.0.0"}, nil)
impl := &Implementation{Name: "testServer", Version: "v1.0.0"}

// TODO(IAmSurajBobade): Remove this hack once we have a client protocol specific handling.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove your self assignment here. We'll probably clean up by adding a more general "settings" file to the test archive.

if test.name == "version-draft.txtar" {
impl.Icons = []Icon{iconObj}
impl.WebsiteURL = "https://modelcontextprotocol.io"
}

s := NewServer(impl, nil)
for _, tn := range test.tools {
switch tn {
case "greet":
AddTool(s, &Tool{
Name: "greet",
Description: "say hi",
}, sayHi)
case "greetWithIcon":
AddTool(s, &Tool{
Name: "greetWithIcon",
Description: "say hi",
Icons: []Icon{iconObj},
}, sayHi)
case "structured":
AddTool(s, &Tool{Name: "structured"}, structuredTool)
case "tomorrow":
Expand All @@ -167,6 +184,13 @@ func runServerTest(t *testing.T, test *conformanceTest) {
switch pn {
case "code_review":
s.AddPrompt(codeReviewPrompt, codReviewPromptHandler)
case "code_reviewWithIcon":
s.AddPrompt(&Prompt{
Name: "code_review",
Description: "do a code review",
Arguments: []*PromptArgument{{Name: "Code", Required: true}},
Icons: []Icon{iconObj},
}, codReviewPromptHandler)
default:
t.Fatalf("unknown prompt %q", pn)
}
Expand All @@ -177,6 +201,13 @@ func runServerTest(t *testing.T, test *conformanceTest) {
s.AddResource(resource1, readHandler)
case "info":
s.AddResource(resource3, handleEmbeddedResource)
case "infoWithIcon":
s.AddResource(&Resource{
Name: "info",
MIMEType: "text/plain",
URI: "embedded:info",
Icons: []Icon{iconObj},
}, handleEmbeddedResource)
default:
t.Fatalf("unknown resource %q", rn)
}
Expand Down
25 changes: 25 additions & 0 deletions mcp/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,21 @@ type ProgressNotificationParams struct {

func (*ProgressNotificationParams) isParams() {}

// Icon provides visual identifiers for their resources, tools, prompts, and implementations
// See [/specification/draft/basic/index#icons] for notes on icons

// TODO(iamsurajbobade): update specification url from draft.
type Icon struct {
// Source is A URI pointing to the icon resource (required). This can be:
// - An HTTP/HTTPS URL pointing to an image file
// - A data URI with base64-encoded image data
Source string `json:"src"`
// Optional MIME type if the server's type is missing or generic
MIMEType string `json:"mimeType,omitempty"`
// Optional size specification (e.g., ["48x48"], ["any"] for scalable formats like SVG, or ["48x48", "96x96"] for multiple sizes)
Sizes []string `json:"sizes,omitempty"`
}

// A prompt or prompt template that the server offers.
type Prompt struct {
// See [specification/2025-06-18/basic/index#general-fields] for notes on _meta
Expand All @@ -673,6 +688,8 @@ type Prompt struct {
// Intended for UI and end-user contexts — optimized to be human-readable and
// easily understood, even by those unfamiliar with domain-specific terminology.
Title string `json:"title,omitempty"`
// Icons for the prompt, if any.
Icons []Icon `json:"icons,omitempty"`
}

// Describes an argument that a prompt can accept.
Expand Down Expand Up @@ -782,6 +799,8 @@ type Resource struct {
Title string `json:"title,omitempty"`
// The URI of this resource.
URI string `json:"uri"`
// Icons for the resource, if any.
Icons []Icon `json:"icons,omitempty"`
}

type ResourceListChangedParams struct {
Expand Down Expand Up @@ -948,6 +967,8 @@ type Tool struct {
// If not provided, Annotations.Title should be used for display if present,
// otherwise Name.
Title string `json:"title,omitempty"`
// Icons for the tool, if any.
Icons []Icon `json:"icons,omitempty"`
}

// Additional properties describing a Tool to clients.
Expand Down Expand Up @@ -1090,6 +1111,10 @@ type Implementation struct {
// easily understood, even by those unfamiliar with domain-specific terminology.
Title string `json:"title,omitempty"`
Version string `json:"version"`
// WebsiteURL for the server, if any.
WebsiteURL string `json:"websiteUrl,omitempty"`
// Icons for the Server, if any.
Icons []Icon `json:"icons,omitempty"`
}

// Present if the server supports argument autocompletion suggestions.
Expand Down
12 changes: 10 additions & 2 deletions mcp/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ const (
//
// It is the version that the client sends in the initialization request, and
// the default version used by the server.
latestProtocolVersion = protocolVersion20250618
protocolVersion20250618 = "2025-06-18"
latestProtocolVersion = protocolVersion20250618

protocolVersionDraft = "draft" // draft protocol version with experimental features for testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove this now, if we're not attempting to gate this functionality on the latest spec.

protocolVersion20250618 = "2025-06-18" // latest stable version
protocolVersion20250326 = "2025-03-26"
protocolVersion20241105 = "2024-11-05"
)
Expand All @@ -48,6 +50,12 @@ var supportedProtocolVersions = []string{
// negotiatedVersion returns the effective protocol version to use, given a
// client version.
func negotiatedVersion(clientVersion string) string {
// If client sends protocol version draft, enable draft features.
if clientVersion == protocolVersionDraft {
log.Printf("Using draft protocol version features")
return protocolVersionDraft
}

// In general, prefer to use the clientVersion, but if we don't support the
// client's version, use the latest version.
//
Expand Down
Loading