Skip to content

Commit bfc3773

Browse files
authored
Merge pull request #333 from OswinWu/feat/separate-CallToolRequstParams
2 parents c7c0e13 + a283d23 commit bfc3773

File tree

3 files changed

+134
-105
lines changed

3 files changed

+134
-105
lines changed

mcp/prompts.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ type ListPromptsResult struct {
1919
// server.
2020
type GetPromptRequest struct {
2121
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"`
22+
Params GetPromptParams `json:"params"`
23+
}
24+
25+
type GetPromptParams struct {
26+
// The name of the prompt or prompt template.
27+
Name string `json:"name"`
28+
// Arguments to use for templating the prompt.
29+
Arguments map[string]string `json:"arguments,omitempty"`
2830
}
2931

3032
// GetPromptResult is the server's response to a prompts/get request from the

mcp/tools.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ type CallToolResult struct {
4545
// CallToolRequest is used by the client to invoke a tool provided by the server.
4646
type CallToolRequest struct {
4747
Request
48-
Params struct {
49-
Name string `json:"name"`
50-
Arguments any `json:"arguments,omitempty"`
51-
Meta *Meta `json:"_meta,omitempty"`
52-
} `json:"params"`
48+
Params CallToolParams `json:"params"`
49+
}
50+
51+
type CallToolParams struct {
52+
Name string `json:"name"`
53+
Arguments any `json:"arguments,omitempty"`
54+
Meta *Meta `json:"_meta,omitempty"`
5355
}
5456

5557
// GetArguments returns the Arguments as map[string]any for backward compatibility

mcp/types.go

Lines changed: 119 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ func (m *Meta) UnmarshalJSON(data []byte) error {
151151
}
152152

153153
type Request struct {
154-
Method string `json:"method"`
155-
Params struct {
156-
Meta *Meta `json:"_meta,omitempty"`
157-
} `json:"params,omitempty"`
154+
Method string `json:"method"`
155+
Params RequestParams `json:"params,omitempty"`
156+
}
157+
158+
type RequestParams struct {
159+
Meta *Meta `json:"_meta,omitempty"`
158160
}
159161

160162
type Params map[string]any
@@ -375,17 +377,19 @@ type EmptyResult Result
375377
// A client MUST NOT attempt to cancel its `initialize` request.
376378
type CancelledNotification struct {
377379
Notification
378-
Params struct {
379-
// The ID of the request to cancel.
380-
//
381-
// This MUST correspond to the ID of a request previously issued
382-
// in the same direction.
383-
RequestId RequestId `json:"requestId"`
380+
Params CancelledNotificationParams `json:"params"`
381+
}
382+
383+
type CancelledNotificationParams struct {
384+
// The ID of the request to cancel.
385+
//
386+
// This MUST correspond to the ID of a request previously issued
387+
// in the same direction.
388+
RequestId RequestId `json:"requestId"`
384389

385-
// An optional string describing the reason for the cancellation. This MAY
386-
// be logged or presented to the user.
387-
Reason string `json:"reason,omitempty"`
388-
} `json:"params"`
390+
// An optional string describing the reason for the cancellation. This MAY
391+
// be logged or presented to the user.
392+
Reason string `json:"reason,omitempty"`
389393
}
390394

391395
/* Initialization */
@@ -394,13 +398,15 @@ type CancelledNotification struct {
394398
// connects, asking it to begin initialization.
395399
type InitializeRequest struct {
396400
Request
397-
Params struct {
398-
// The latest version of the Model Context Protocol that the client supports.
399-
// The client MAY decide to support older versions as well.
400-
ProtocolVersion string `json:"protocolVersion"`
401-
Capabilities ClientCapabilities `json:"capabilities"`
402-
ClientInfo Implementation `json:"clientInfo"`
403-
} `json:"params"`
401+
Params InitializeParams `json:"params"`
402+
}
403+
404+
type InitializeParams struct {
405+
// The latest version of the Model Context Protocol that the client supports.
406+
// The client MAY decide to support older versions as well.
407+
ProtocolVersion string `json:"protocolVersion"`
408+
Capabilities ClientCapabilities `json:"capabilities"`
409+
ClientInfo Implementation `json:"clientInfo"`
404410
}
405411

406412
// InitializeResult is sent after receiving an initialize request from the
@@ -491,30 +497,34 @@ type PingRequest struct {
491497
// receiver of a progress update for a long-running request.
492498
type ProgressNotification struct {
493499
Notification
494-
Params struct {
495-
// The progress token which was given in the initial request, used to
496-
// associate this notification with the request that is proceeding.
497-
ProgressToken ProgressToken `json:"progressToken"`
498-
// The progress thus far. This should increase every time progress is made,
499-
// even if the total is unknown.
500-
Progress float64 `json:"progress"`
501-
// Total number of items to process (or total progress required), if known.
502-
Total float64 `json:"total,omitempty"`
503-
// Message related to progress. This should provide relevant human-readable
504-
// progress information.
505-
Message string `json:"message,omitempty"`
506-
} `json:"params"`
500+
Params ProgressNotificationParams `json:"params"`
501+
}
502+
503+
type ProgressNotificationParams struct {
504+
// The progress token which was given in the initial request, used to
505+
// associate this notification with the request that is proceeding.
506+
ProgressToken ProgressToken `json:"progressToken"`
507+
// The progress thus far. This should increase every time progress is made,
508+
// even if the total is unknown.
509+
Progress float64 `json:"progress"`
510+
// Total number of items to process (or total progress required), if known.
511+
Total float64 `json:"total,omitempty"`
512+
// Message related to progress. This should provide relevant human-readable
513+
// progress information.
514+
Message string `json:"message,omitempty"`
507515
}
508516

509517
/* Pagination */
510518

511519
type PaginatedRequest struct {
512520
Request
513-
Params struct {
514-
// An opaque token representing the current pagination position.
515-
// If provided, the server should return results starting after this cursor.
516-
Cursor Cursor `json:"cursor,omitempty"`
517-
} `json:"params,omitempty"`
521+
Params PaginatedParams `json:"params,omitempty"`
522+
}
523+
524+
type PaginatedParams struct {
525+
// An opaque token representing the current pagination position.
526+
// If provided, the server should return results starting after this cursor.
527+
Cursor Cursor `json:"cursor,omitempty"`
518528
}
519529

520530
type PaginatedResult struct {
@@ -557,13 +567,15 @@ type ListResourceTemplatesResult struct {
557567
// specific resource URI.
558568
type ReadResourceRequest struct {
559569
Request
560-
Params struct {
561-
// The URI of the resource to read. The URI can use any protocol; it is up
562-
// to the server how to interpret it.
563-
URI string `json:"uri"`
564-
// Arguments to pass to the resource handler
565-
Arguments map[string]any `json:"arguments,omitempty"`
566-
} `json:"params"`
570+
Params ReadResourceParams `json:"params"`
571+
}
572+
573+
type ReadResourceParams struct {
574+
// The URI of the resource to read. The URI can use any protocol; it is up
575+
// to the server how to interpret it.
576+
URI string `json:"uri"`
577+
// Arguments to pass to the resource handler
578+
Arguments map[string]any `json:"arguments,omitempty"`
567579
}
568580

569581
// ReadResourceResult is the server's response to a resources/read request
@@ -585,34 +597,39 @@ type ResourceListChangedNotification struct {
585597
// notifications from the server whenever a particular resource changes.
586598
type SubscribeRequest struct {
587599
Request
588-
Params struct {
589-
// The URI of the resource to subscribe to. The URI can use any protocol; it
590-
// is up to the server how to interpret it.
591-
URI string `json:"uri"`
592-
} `json:"params"`
600+
Params SubscribeParams `json:"params"`
601+
}
602+
603+
type SubscribeParams struct {
604+
// The URI of the resource to subscribe to. The URI can use any protocol; it
605+
// is up to the server how to interpret it.
606+
URI string `json:"uri"`
593607
}
594608

595609
// UnsubscribeRequest is sent from the client to request cancellation of
596610
// resources/updated notifications from the server. This should follow a previous
597611
// resources/subscribe request.
598612
type UnsubscribeRequest struct {
599613
Request
600-
Params struct {
601-
// The URI of the resource to unsubscribe from.
602-
URI string `json:"uri"`
603-
} `json:"params"`
614+
Params UnsubscribeParams `json:"params"`
615+
}
616+
617+
type UnsubscribeParams struct {
618+
// The URI of the resource to unsubscribe from.
619+
URI string `json:"uri"`
604620
}
605621

606622
// ResourceUpdatedNotification is a notification from the server to the client,
607623
// informing it that a resource has changed and may need to be read again. This
608624
// should only be sent if the client previously sent a resources/subscribe request.
609625
type ResourceUpdatedNotification struct {
610626
Notification
611-
Params struct {
612-
// The URI of the resource that has been updated. This might be a sub-
613-
// resource of the one that the client actually subscribed to.
614-
URI string `json:"uri"`
615-
} `json:"params"`
627+
Params ResourceUpdatedNotificationParams `json:"params"`
628+
}
629+
type ResourceUpdatedNotificationParams struct {
630+
// The URI of the resource that has been updated. This might be a sub-
631+
// resource of the one that the client actually subscribed to.
632+
URI string `json:"uri"`
616633
}
617634

618635
// Resource represents a known resource that the server is capable of reading.
@@ -699,28 +716,32 @@ func (BlobResourceContents) isResourceContents() {}
699716
// adjust logging.
700717
type SetLevelRequest struct {
701718
Request
702-
Params struct {
703-
// The level of logging that the client wants to receive from the server.
704-
// The server should send all logs at this level and higher (i.e., more severe) to
705-
// the client as notifications/logging/message.
706-
Level LoggingLevel `json:"level"`
707-
} `json:"params"`
719+
Params SetLevelParams `json:"params"`
720+
}
721+
722+
type SetLevelParams struct {
723+
// The level of logging that the client wants to receive from the server.
724+
// The server should send all logs at this level and higher (i.e., more severe) to
725+
// the client as notifications/logging/message.
726+
Level LoggingLevel `json:"level"`
708727
}
709728

710729
// LoggingMessageNotification is a notification of a log message passed from
711730
// server to client. If no logging/setLevel request has been sent from the client,
712731
// the server MAY decide which messages to send automatically.
713732
type LoggingMessageNotification struct {
714733
Notification
715-
Params struct {
716-
// The severity of this log message.
717-
Level LoggingLevel `json:"level"`
718-
// An optional name of the logger issuing this message.
719-
Logger string `json:"logger,omitempty"`
720-
// The data to be logged, such as a string message or an object. Any JSON
721-
// serializable type is allowed here.
722-
Data any `json:"data"`
723-
} `json:"params"`
734+
Params LoggingMessageNotificationParams `json:"params"`
735+
}
736+
737+
type LoggingMessageNotificationParams struct {
738+
// The severity of this log message.
739+
Level LoggingLevel `json:"level"`
740+
// An optional name of the logger issuing this message.
741+
Logger string `json:"logger,omitempty"`
742+
// The data to be logged, such as a string message or an object. Any JSON
743+
// serializable type is allowed here.
744+
Data any `json:"data"`
724745
}
725746

726747
// LoggingLevel represents the severity of a log message.
@@ -748,16 +769,18 @@ const (
748769
// the request (human in the loop) and decide whether to approve it.
749770
type CreateMessageRequest struct {
750771
Request
751-
Params struct {
752-
Messages []SamplingMessage `json:"messages"`
753-
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
754-
SystemPrompt string `json:"systemPrompt,omitempty"`
755-
IncludeContext string `json:"includeContext,omitempty"`
756-
Temperature float64 `json:"temperature,omitempty"`
757-
MaxTokens int `json:"maxTokens"`
758-
StopSequences []string `json:"stopSequences,omitempty"`
759-
Metadata any `json:"metadata,omitempty"`
760-
} `json:"params"`
772+
CreateMessageParams `json:"params"`
773+
}
774+
775+
type CreateMessageParams struct {
776+
Messages []SamplingMessage `json:"messages"`
777+
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
778+
SystemPrompt string `json:"systemPrompt,omitempty"`
779+
IncludeContext string `json:"includeContext,omitempty"`
780+
Temperature float64 `json:"temperature,omitempty"`
781+
MaxTokens int `json:"maxTokens"`
782+
StopSequences []string `json:"stopSequences,omitempty"`
783+
Metadata any `json:"metadata,omitempty"`
761784
}
762785

763786
// CreateMessageResult is the client's response to a sampling/create_message
@@ -915,15 +938,17 @@ type ModelHint struct {
915938
// CompleteRequest is a request from the client to the server, to ask for completion options.
916939
type CompleteRequest struct {
917940
Request
918-
Params struct {
919-
Ref any `json:"ref"` // Can be PromptReference or ResourceReference
920-
Argument struct {
921-
// The name of the argument
922-
Name string `json:"name"`
923-
// The value of the argument to use for completion matching.
924-
Value string `json:"value"`
925-
} `json:"argument"`
926-
} `json:"params"`
941+
Params CompleteParams `json:"params"`
942+
}
943+
944+
type CompleteParams struct {
945+
Ref any `json:"ref"` // Can be PromptReference or ResourceReference
946+
Argument struct {
947+
// The name of the argument
948+
Name string `json:"name"`
949+
// The value of the argument to use for completion matching.
950+
Value string `json:"value"`
951+
} `json:"argument"`
927952
}
928953

929954
// CompleteResult is the server's response to a completion/complete request

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy