internal/mcp: implement roots

Add support for roots.

Change-Id: Ia50abc88f0047238272d698f30ce615b1a8fd486
Reviewed-on: https://go-review.googlesource.com/c/tools/+/671360
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Jonathan Amsterdam 2025-05-09 22:04:50 -04:00
commit 5004d3e1bb

View file

@ -70,14 +70,16 @@ type CancelledParams struct {
// additional capabilities.
type ClientCapabilities struct {
// Experimental, non-standard capabilities that the client supports.
Experimental map[string]map[string]json.RawMessage `json:"experimental,omitempty"`
Experimental map[string]struct {
} `json:"experimental,omitempty"`
// Present if the client supports listing roots.
Roots *struct {
// Whether the client supports notifications for changes to the roots list.
ListChanged bool `json:"listChanged,omitempty"`
} `json:"roots,omitempty"`
// Present if the client supports sampling from an LLM.
Sampling map[string]json.RawMessage `json:"sampling,omitempty"`
Sampling struct {
} `json:"sampling,omitempty"`
}
type GetPromptParams struct {
@ -131,7 +133,11 @@ type InitializeResult struct {
ServerInfo Implementation `json:"serverInfo"`
}
type InitializedParams map[string]json.RawMessage
type InitializedParams struct {
// This parameter name is reserved by MCP to allow clients and servers to attach
// additional metadata to their notifications.
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
type ListPromptsParams struct {
// An opaque token representing the current pagination position. If provided,
@ -150,6 +156,26 @@ type ListPromptsResult struct {
Prompts []Prompt `json:"prompts"`
}
type ListRootsParams struct {
Meta *struct {
// If specified, the caller is requesting out-of-band progress notifications for
// this request (as represented by notifications/progress). The value of this
// parameter is an opaque token that will be attached to any subsequent
// notifications. The receiver is not obligated to provide these notifications.
ProgressToken *any `json:"progressToken,omitempty"`
} `json:"_meta,omitempty"`
}
// The client's response to a roots/list request from the server. This result
// contains an array of Root objects, each representing a root directory or file
// that the server can operate on.
type ListRootsResult struct {
// This result property is reserved by the protocol to allow clients and servers
// to attach additional metadata to their responses.
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
Roots []Root `json:"roots"`
}
type ListToolsParams struct {
// An opaque token representing the current pagination position. If provided,
// the server should return results starting after this cursor.
@ -213,16 +239,31 @@ type ResourceCapabilities struct {
// The sender or recipient of messages and data in a conversation.
type Role string
// Represents a root directory or file that the server can operate on.
type Root struct {
// An optional name for the root. This can be used to provide a human-readable
// identifier for the root, which may be useful for display purposes or for
// referencing the root in other parts of the application.
Name string `json:"name,omitempty"`
// The URI identifying the root. This *must* start with file:// for now. This
// restriction may be relaxed in future versions of the protocol to allow other
// URI schemes.
URI string `json:"uri"`
}
// Capabilities that a server may support. Known capabilities are defined here,
// in this schema, but this is not a closed set: any server can define its own,
// additional capabilities.
type ServerCapabilities struct {
// Present if the server supports argument autocompletion suggestions.
Completions map[string]json.RawMessage `json:"completions,omitempty"`
Completions struct {
} `json:"completions,omitempty"`
// Experimental, non-standard capabilities that the server supports.
Experimental map[string]map[string]json.RawMessage `json:"experimental,omitempty"`
Experimental map[string]struct {
} `json:"experimental,omitempty"`
// Present if the server supports sending log messages to the client.
Logging map[string]json.RawMessage `json:"logging,omitempty"`
Logging struct {
} `json:"logging,omitempty"`
// Present if the server offers any prompt templates.
Prompts *PromptCapabilities `json:"prompts,omitempty"`
// Present if the server offers any resources to read.