examples: add an everything example, and simplify hello
Our 'hello' example should be as simple as possible. On the other hand, we should have an 'everything' example that exercises (almost) everything we offer. Using the everything example, I did some final testing using the inspector. This turned up a couple rough edges related to JSON null that I addressed by preferring empty slices. For #33
This commit is contained in:
parent
c631641296
commit
9754a2aa86
1 changed files with 240 additions and 71 deletions
|
|
@ -57,6 +57,8 @@ type ServerOptions struct {
|
|||
InitializedHandler func(context.Context, *InitializedRequest)
|
||||
// PageSize is the maximum number of items to return in a single page for
|
||||
// list methods (e.g. ListTools).
|
||||
//
|
||||
// If zero, defaults to [DefaultPageSize].
|
||||
PageSize int
|
||||
// If non-nil, called when "notifications/roots/list_changed" is received.
|
||||
RootsListChangedHandler func(context.Context, *RootsListChangedRequest)
|
||||
|
|
@ -266,6 +268,9 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
|
|||
if res == nil {
|
||||
res = &CallToolResult{}
|
||||
}
|
||||
if res.Content == nil {
|
||||
res.Content = []Content{} // avoid returning 'null'
|
||||
}
|
||||
res.StructuredContent = out
|
||||
if elemZero != nil {
|
||||
// Avoid typed nil, which will serialize as JSON null.
|
||||
|
|
@ -843,6 +848,14 @@ func (ss *ServerSession) ListRoots(ctx context.Context, params *ListRootsParams)
|
|||
|
||||
// CreateMessage sends a sampling request to the client.
|
||||
func (ss *ServerSession) CreateMessage(ctx context.Context, params *CreateMessageParams) (*CreateMessageResult, error) {
|
||||
if params == nil {
|
||||
params = &CreateMessageParams{Messages: []*SamplingMessage{}}
|
||||
}
|
||||
if params.Messages == nil {
|
||||
p2 := *params
|
||||
p2.Messages = []*SamplingMessage{} // avoid JSON "null"
|
||||
params = &p2
|
||||
}
|
||||
return handleSend[*CreateMessageResult](ctx, methodCreateMessage, newServerRequest(ss, orZero[Params](params)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue