Skip to content

Commit d920654

Browse files
committed
reorganizing
1 parent c61624c commit d920654

File tree

3 files changed

+171
-173
lines changed

3 files changed

+171
-173
lines changed

mcp/prompts.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,103 @@
11
package mcp
22

3+
/* Prompts */
4+
5+
// ListPromptsRequest is sent from the client to request a list of prompts and
6+
// prompt templates the server has.
7+
type ListPromptsRequest struct {
8+
PaginatedRequest
9+
}
10+
11+
// ListPromptsResult is the server's response to a prompts/list request from
12+
// the client.
13+
type ListPromptsResult struct {
14+
PaginatedResult
15+
Prompts []Prompt `json:"prompts"`
16+
}
17+
18+
// GetPromptRequest is used by the client to get a prompt provided by the
19+
// server.
20+
type GetPromptRequest struct {
21+
Request
22+
Params struct {
23+
// The name of the prompt or prompt template.
24+
Name string `json:"name"`
25+
// Arguments to use for templating the prompt.
26+
Arguments map[string]string `json:"arguments,omitempty"`
27+
} `json:"params"`
28+
}
29+
30+
// GetPromptResult is the server's response to a prompts/get request from the
31+
// client.
32+
type GetPromptResult struct {
33+
Result
34+
// An optional description for the prompt.
35+
Description string `json:"description,omitempty"`
36+
Messages []PromptMessage `json:"messages"`
37+
}
38+
39+
// Prompt represents a prompt or prompt template that the server offers.
40+
// If Arguments is non-nil and non-empty, this indicates the prompt is a template
41+
// that requires argument values to be provided when calling prompts/get.
42+
// If Arguments is nil or empty, this is a static prompt that takes no arguments.
43+
type Prompt struct {
44+
// The name of the prompt or prompt template.
45+
Name string `json:"name"`
46+
// An optional description of what this prompt provides
47+
Description string `json:"description,omitempty"`
48+
// A list of arguments to use for templating the prompt.
49+
// The presence of arguments indicates this is a template prompt.
50+
Arguments []PromptArgument `json:"arguments,omitempty"`
51+
}
52+
53+
// PromptArgument describes an argument that a prompt template can accept.
54+
// When a prompt includes arguments, clients must provide values for all
55+
// required arguments when making a prompts/get request.
56+
type PromptArgument struct {
57+
// The name of the argument.
58+
Name string `json:"name"`
59+
// A human-readable description of the argument.
60+
Description string `json:"description,omitempty"`
61+
// Whether this argument must be provided.
62+
// If true, clients must include this argument when calling prompts/get.
63+
Required bool `json:"required,omitempty"`
64+
}
65+
66+
// Role represents the sender or recipient of messages and data in a
67+
// conversation.
68+
type Role string
69+
70+
const (
71+
RoleUser Role = "user"
72+
RoleAssistant Role = "assistant"
73+
)
74+
75+
// PromptMessage describes a message returned as part of a prompt.
76+
//
77+
// This is similar to `SamplingMessage`, but also supports the embedding of
78+
// resources from the MCP server.
79+
type PromptMessage struct {
80+
Role Role `json:"role"`
81+
Content interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
82+
}
83+
84+
// EmbeddedResource represents the contents of a resource, embedded into a prompt or tool call result.
85+
//
86+
// It is up to the client how best to render embedded resources for the
87+
// benefit of the LLM and/or the user.
88+
type EmbeddedResource struct {
89+
Annotated
90+
Type string `json:"type"`
91+
Resource ResourceContents `json:"resource"`
92+
}
93+
94+
// PromptListChangedNotification is an optional notification from the server
95+
// to the client, informing it that the list of prompts it offers has changed. This
96+
// may be issued by servers without any previous subscription from the client.
97+
type PromptListChangedNotification struct {
98+
Notification
99+
}
100+
3101
// PromptOption is a function that configures a Prompt.
4102
// It provides a flexible way to set various properties of a Prompt using the functional options pattern.
5103
type PromptOption func(*Prompt)

mcp/tools.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
11
package mcp
22

3+
// ListToolsRequest is sent from the client to request a list of tools the
4+
// server has.
5+
type ListToolsRequest struct {
6+
PaginatedRequest
7+
}
8+
9+
// ListToolsResult is the server's response to a tools/list request from the
10+
// client.
11+
type ListToolsResult struct {
12+
PaginatedResult
13+
Tools []Tool `json:"tools"`
14+
}
15+
16+
// CallToolResult is the server's response to a tool call.
17+
//
18+
// Any errors that originate from the tool SHOULD be reported inside the result
19+
// object, with `isError` set to true, _not_ as an MCP protocol-level error
20+
// response. Otherwise, the LLM would not be able to see that an error occurred
21+
// and self-correct.
22+
//
23+
// However, any errors in _finding_ the tool, an error indicating that the
24+
// server does not support tool calls, or any other exceptional conditions,
25+
// should be reported as an MCP error response.
26+
type CallToolResult struct {
27+
Result
28+
Content []interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
29+
// Whether the tool call ended in an error.
30+
//
31+
// If not set, this is assumed to be false (the call was successful).
32+
IsError bool `json:"isError,omitempty"`
33+
}
34+
35+
// CallToolRequest is used by the client to invoke a tool provided by the server.
36+
type CallToolRequest struct {
37+
Request
38+
Params struct {
39+
Name string `json:"name"`
40+
Arguments map[string]interface{} `json:"arguments,omitempty"`
41+
Meta *struct {
42+
// If specified, the caller is requesting out-of-band progress
43+
// notifications for this request (as represented by
44+
// notifications/progress). The value of this parameter is an
45+
// opaque token that will be attached to any subsequent
46+
// notifications. The receiver is not obligated to provide these
47+
// notifications.
48+
ProgressToken ProgressToken `json:"progressToken,omitempty"`
49+
} `json:"_meta,omitempty"`
50+
} `json:"params"`
51+
}
52+
53+
// ToolListChangedNotification is an optional notification from the server to
54+
// the client, informing it that the list of tools it offers has changed. This may
55+
// be issued by servers without any previous subscription from the client.
56+
type ToolListChangedNotification struct {
57+
Notification
58+
}
59+
60+
// Tool represents the definition for a tool the client can call.
61+
type Tool struct {
62+
// The name of the tool.
63+
Name string `json:"name"`
64+
// A human-readable description of the tool.
65+
Description string `json:"description,omitempty"`
66+
// A JSON Schema object defining the expected parameters for the tool.
67+
InputSchema ToolInputSchema `json:"inputSchema"`
68+
}
69+
70+
type ToolInputSchema struct {
71+
Type string `json:"type"`
72+
Properties map[string]interface{} `json:"properties,omitempty"`
73+
Required []string `json:"required,omitempty"`
74+
}
75+
376
// ToolOption is a function that configures a Tool.
477
// It provides a flexible way to set various properties of a Tool using the functional options pattern.
578
type ToolOption func(*Tool)

mcp/types.go

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -478,179 +478,6 @@ type BlobResourceContents struct {
478478
Blob string `json:"blob"`
479479
}
480480

481-
/* Prompts */
482-
483-
// ListPromptsRequest is sent from the client to request a list of prompts and
484-
// prompt templates the server has.
485-
type ListPromptsRequest struct {
486-
PaginatedRequest
487-
}
488-
489-
// ListPromptsResult is the server's response to a prompts/list request from
490-
// the client.
491-
type ListPromptsResult struct {
492-
PaginatedResult
493-
Prompts []Prompt `json:"prompts"`
494-
}
495-
496-
// GetPromptRequest is used by the client to get a prompt provided by the
497-
// server.
498-
type GetPromptRequest struct {
499-
Request
500-
Params struct {
501-
// The name of the prompt or prompt template.
502-
Name string `json:"name"`
503-
// Arguments to use for templating the prompt.
504-
Arguments map[string]string `json:"arguments,omitempty"`
505-
} `json:"params"`
506-
}
507-
508-
// GetPromptResult is the server's response to a prompts/get request from the
509-
// client.
510-
type GetPromptResult struct {
511-
Result
512-
// An optional description for the prompt.
513-
Description string `json:"description,omitempty"`
514-
Messages []PromptMessage `json:"messages"`
515-
}
516-
517-
// Prompt represents a prompt or prompt template that the server offers.
518-
// If Arguments is non-nil and non-empty, this indicates the prompt is a template
519-
// that requires argument values to be provided when calling prompts/get.
520-
// If Arguments is nil or empty, this is a static prompt that takes no arguments.
521-
type Prompt struct {
522-
// The name of the prompt or prompt template.
523-
Name string `json:"name"`
524-
// An optional description of what this prompt provides
525-
Description string `json:"description,omitempty"`
526-
// A list of arguments to use for templating the prompt.
527-
// The presence of arguments indicates this is a template prompt.
528-
Arguments []PromptArgument `json:"arguments,omitempty"`
529-
}
530-
531-
// PromptArgument describes an argument that a prompt template can accept.
532-
// When a prompt includes arguments, clients must provide values for all
533-
// required arguments when making a prompts/get request.
534-
type PromptArgument struct {
535-
// The name of the argument.
536-
Name string `json:"name"`
537-
// A human-readable description of the argument.
538-
Description string `json:"description,omitempty"`
539-
// Whether this argument must be provided.
540-
// If true, clients must include this argument when calling prompts/get.
541-
Required bool `json:"required,omitempty"`
542-
}
543-
544-
// Role represents the sender or recipient of messages and data in a
545-
// conversation.
546-
type Role string
547-
548-
const (
549-
RoleUser Role = "user"
550-
RoleAssistant Role = "assistant"
551-
)
552-
553-
// PromptMessage describes a message returned as part of a prompt.
554-
//
555-
// This is similar to `SamplingMessage`, but also supports the embedding of
556-
// resources from the MCP server.
557-
type PromptMessage struct {
558-
Role Role `json:"role"`
559-
Content interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
560-
}
561-
562-
// EmbeddedResource represents the contents of a resource, embedded into a prompt or tool call result.
563-
//
564-
// It is up to the client how best to render embedded resources for the
565-
// benefit of the LLM and/or the user.
566-
type EmbeddedResource struct {
567-
Annotated
568-
Type string `json:"type"`
569-
Resource ResourceContents `json:"resource"`
570-
}
571-
572-
// PromptListChangedNotification is an optional notification from the server
573-
// to the client, informing it that the list of prompts it offers has changed. This
574-
// may be issued by servers without any previous subscription from the client.
575-
type PromptListChangedNotification struct {
576-
Notification
577-
}
578-
579-
/* Tools */
580-
581-
// ListToolsRequest is sent from the client to request a list of tools the
582-
// server has.
583-
type ListToolsRequest struct {
584-
PaginatedRequest
585-
}
586-
587-
// ListToolsResult is the server's response to a tools/list request from the
588-
// client.
589-
type ListToolsResult struct {
590-
PaginatedResult
591-
Tools []Tool `json:"tools"`
592-
}
593-
594-
// CallToolResult is the server's response to a tool call.
595-
//
596-
// Any errors that originate from the tool SHOULD be reported inside the result
597-
// object, with `isError` set to true, _not_ as an MCP protocol-level error
598-
// response. Otherwise, the LLM would not be able to see that an error occurred
599-
// and self-correct.
600-
//
601-
// However, any errors in _finding_ the tool, an error indicating that the
602-
// server does not support tool calls, or any other exceptional conditions,
603-
// should be reported as an MCP error response.
604-
type CallToolResult struct {
605-
Result
606-
Content []interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
607-
// Whether the tool call ended in an error.
608-
//
609-
// If not set, this is assumed to be false (the call was successful).
610-
IsError bool `json:"isError,omitempty"`
611-
}
612-
613-
// CallToolRequest is used by the client to invoke a tool provided by the server.
614-
type CallToolRequest struct {
615-
Request
616-
Params struct {
617-
Name string `json:"name"`
618-
Arguments map[string]interface{} `json:"arguments,omitempty"`
619-
Meta *struct {
620-
// If specified, the caller is requesting out-of-band progress
621-
// notifications for this request (as represented by
622-
// notifications/progress). The value of this parameter is an
623-
// opaque token that will be attached to any subsequent
624-
// notifications. The receiver is not obligated to provide these
625-
// notifications.
626-
ProgressToken ProgressToken `json:"progressToken,omitempty"`
627-
} `json:"_meta,omitempty"`
628-
} `json:"params"`
629-
}
630-
631-
// ToolListChangedNotification is an optional notification from the server to
632-
// the client, informing it that the list of tools it offers has changed. This may
633-
// be issued by servers without any previous subscription from the client.
634-
type ToolListChangedNotification struct {
635-
Notification
636-
}
637-
638-
// Tool represents the definition for a tool the client can call.
639-
type Tool struct {
640-
// The name of the tool.
641-
Name string `json:"name"`
642-
// A human-readable description of the tool.
643-
Description string `json:"description,omitempty"`
644-
// A JSON Schema object defining the expected parameters for the tool.
645-
InputSchema ToolInputSchema `json:"inputSchema"`
646-
}
647-
648-
type ToolInputSchema struct {
649-
Type string `json:"type"`
650-
Properties map[string]interface{} `json:"properties,omitempty"`
651-
Required []string `json:"required,omitempty"`
652-
}
653-
654481
/* Logging */
655482

656483
// SetLevelRequest is a request from the client to the server, to enable or

0 commit comments

Comments
 (0)