Skip to content

Commit e581ab8

Browse files
committed
[feat] change other request params
1 parent 64cea69 commit e581ab8

File tree

2 files changed

+127
-100
lines changed

2 files changed

+127
-100
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/types.go

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

147147
type Request struct {
148-
Method string `json:"method"`
149-
Params struct {
150-
Meta *Meta `json:"_meta,omitempty"`
151-
} `json:"params,omitempty"`
148+
Method string `json:"method"`
149+
Params RequestParams `json:"params,omitempty"`
150+
}
151+
152+
type RequestParams struct {
153+
Meta *Meta `json:"_meta,omitempty"`
152154
}
153155

154156
type Params map[string]any
@@ -369,17 +371,19 @@ type EmptyResult Result
369371
// A client MUST NOT attempt to cancel its `initialize` request.
370372
type CancelledNotification struct {
371373
Notification
372-
Params struct {
373-
// The ID of the request to cancel.
374-
//
375-
// This MUST correspond to the ID of a request previously issued
376-
// in the same direction.
377-
RequestId RequestId `json:"requestId"`
374+
Params CancelledNotificationParams `json:"params"`
375+
}
376+
377+
type CancelledNotificationParams struct {
378+
// The ID of the request to cancel.
379+
//
380+
// This MUST correspond to the ID of a request previously issued
381+
// in the same direction.
382+
RequestId RequestId `json:"requestId"`
378383

379-
// An optional string describing the reason for the cancellation. This MAY
380-
// be logged or presented to the user.
381-
Reason string `json:"reason,omitempty"`
382-
} `json:"params"`
384+
// An optional string describing the reason for the cancellation. This MAY
385+
// be logged or presented to the user.
386+
Reason string `json:"reason,omitempty"`
383387
}
384388

385389
/* Initialization */
@@ -388,13 +392,15 @@ type CancelledNotification struct {
388392
// connects, asking it to begin initialization.
389393
type InitializeRequest struct {
390394
Request
391-
Params struct {
392-
// The latest version of the Model Context Protocol that the client supports.
393-
// The client MAY decide to support older versions as well.
394-
ProtocolVersion string `json:"protocolVersion"`
395-
Capabilities ClientCapabilities `json:"capabilities"`
396-
ClientInfo Implementation `json:"clientInfo"`
397-
} `json:"params"`
395+
Params InitializeRequestParams `json:"params"`
396+
}
397+
398+
type InitializeRequestParams struct {
399+
// The latest version of the Model Context Protocol that the client supports.
400+
// The client MAY decide to support older versions as well.
401+
ProtocolVersion string `json:"protocolVersion"`
402+
Capabilities ClientCapabilities `json:"capabilities"`
403+
ClientInfo Implementation `json:"clientInfo"`
398404
}
399405

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

503511
/* Pagination */
504512

505513
type PaginatedRequest struct {
506514
Request
507-
Params struct {
508-
// An opaque token representing the current pagination position.
509-
// If provided, the server should return results starting after this cursor.
510-
Cursor Cursor `json:"cursor,omitempty"`
511-
} `json:"params,omitempty"`
515+
Params PaginatedRequestParams `json:"params,omitempty"`
516+
}
517+
518+
type PaginatedRequestParams struct {
519+
// An opaque token representing the current pagination position.
520+
// If provided, the server should return results starting after this cursor.
521+
Cursor Cursor `json:"cursor,omitempty"`
512522
}
513523

514524
type PaginatedResult struct {
@@ -551,13 +561,15 @@ type ListResourceTemplatesResult struct {
551561
// specific resource URI.
552562
type ReadResourceRequest struct {
553563
Request
554-
Params struct {
555-
// The URI of the resource to read. The URI can use any protocol; it is up
556-
// to the server how to interpret it.
557-
URI string `json:"uri"`
558-
// Arguments to pass to the resource handler
559-
Arguments map[string]any `json:"arguments,omitempty"`
560-
} `json:"params"`
564+
Params ReadResourceRequestParams `json:"params"`
565+
}
566+
567+
type ReadResourceRequestParams struct {
568+
// The URI of the resource to read. The URI can use any protocol; it is up
569+
// to the server how to interpret it.
570+
URI string `json:"uri"`
571+
// Arguments to pass to the resource handler
572+
Arguments map[string]any `json:"arguments,omitempty"`
561573
}
562574

563575
// ReadResourceResult is the server's response to a resources/read request
@@ -579,34 +591,39 @@ type ResourceListChangedNotification struct {
579591
// notifications from the server whenever a particular resource changes.
580592
type SubscribeRequest struct {
581593
Request
582-
Params struct {
583-
// The URI of the resource to subscribe to. The URI can use any protocol; it
584-
// is up to the server how to interpret it.
585-
URI string `json:"uri"`
586-
} `json:"params"`
594+
Params SubscribeRequestParams `json:"params"`
595+
}
596+
597+
type SubscribeRequestParams struct {
598+
// The URI of the resource to subscribe to. The URI can use any protocol; it
599+
// is up to the server how to interpret it.
600+
URI string `json:"uri"`
587601
}
588602

589603
// UnsubscribeRequest is sent from the client to request cancellation of
590604
// resources/updated notifications from the server. This should follow a previous
591605
// resources/subscribe request.
592606
type UnsubscribeRequest struct {
593607
Request
594-
Params struct {
595-
// The URI of the resource to unsubscribe from.
596-
URI string `json:"uri"`
597-
} `json:"params"`
608+
Params UnsubscribeRequestParams `json:"params"`
609+
}
610+
611+
type UnsubscribeRequestParams struct {
612+
// The URI of the resource to unsubscribe from.
613+
URI string `json:"uri"`
598614
}
599615

600616
// ResourceUpdatedNotification is a notification from the server to the client,
601617
// informing it that a resource has changed and may need to be read again. This
602618
// should only be sent if the client previously sent a resources/subscribe request.
603619
type ResourceUpdatedNotification struct {
604620
Notification
605-
Params struct {
606-
// The URI of the resource that has been updated. This might be a sub-
607-
// resource of the one that the client actually subscribed to.
608-
URI string `json:"uri"`
609-
} `json:"params"`
621+
Params ResourceUpdatedNotificationParams `json:"params"`
622+
}
623+
type ResourceUpdatedNotificationParams struct {
624+
// The URI of the resource that has been updated. This might be a sub-
625+
// resource of the one that the client actually subscribed to.
626+
URI string `json:"uri"`
610627
}
611628

612629
// Resource represents a known resource that the server is capable of reading.
@@ -693,28 +710,32 @@ func (BlobResourceContents) isResourceContents() {}
693710
// adjust logging.
694711
type SetLevelRequest struct {
695712
Request
696-
Params struct {
697-
// The level of logging that the client wants to receive from the server.
698-
// The server should send all logs at this level and higher (i.e., more severe) to
699-
// the client as notifications/logging/message.
700-
Level LoggingLevel `json:"level"`
701-
} `json:"params"`
713+
Params SetLevelRequestParams `json:"params"`
714+
}
715+
716+
type SetLevelRequestParams struct {
717+
// The level of logging that the client wants to receive from the server.
718+
// The server should send all logs at this level and higher (i.e., more severe) to
719+
// the client as notifications/logging/message.
720+
Level LoggingLevel `json:"level"`
702721
}
703722

704723
// LoggingMessageNotification is a notification of a log message passed from
705724
// server to client. If no logging/setLevel request has been sent from the client,
706725
// the server MAY decide which messages to send automatically.
707726
type LoggingMessageNotification struct {
708727
Notification
709-
Params struct {
710-
// The severity of this log message.
711-
Level LoggingLevel `json:"level"`
712-
// An optional name of the logger issuing this message.
713-
Logger string `json:"logger,omitempty"`
714-
// The data to be logged, such as a string message or an object. Any JSON
715-
// serializable type is allowed here.
716-
Data any `json:"data"`
717-
} `json:"params"`
728+
Params LoggingMessageNotificationParams `json:"params"`
729+
}
730+
731+
type LoggingMessageNotificationParams struct {
732+
// The severity of this log message.
733+
Level LoggingLevel `json:"level"`
734+
// An optional name of the logger issuing this message.
735+
Logger string `json:"logger,omitempty"`
736+
// The data to be logged, such as a string message or an object. Any JSON
737+
// serializable type is allowed here.
738+
Data any `json:"data"`
718739
}
719740

720741
// LoggingLevel represents the severity of a log message.
@@ -742,16 +763,18 @@ const (
742763
// the request (human in the loop) and decide whether to approve it.
743764
type CreateMessageRequest struct {
744765
Request
745-
Params struct {
746-
Messages []SamplingMessage `json:"messages"`
747-
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
748-
SystemPrompt string `json:"systemPrompt,omitempty"`
749-
IncludeContext string `json:"includeContext,omitempty"`
750-
Temperature float64 `json:"temperature,omitempty"`
751-
MaxTokens int `json:"maxTokens"`
752-
StopSequences []string `json:"stopSequences,omitempty"`
753-
Metadata any `json:"metadata,omitempty"`
754-
} `json:"params"`
766+
CreateMessageRequestParams `json:"params"`
767+
}
768+
769+
type CreateMessageRequestParams struct {
770+
Messages []SamplingMessage `json:"messages"`
771+
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
772+
SystemPrompt string `json:"systemPrompt,omitempty"`
773+
IncludeContext string `json:"includeContext,omitempty"`
774+
Temperature float64 `json:"temperature,omitempty"`
775+
MaxTokens int `json:"maxTokens"`
776+
StopSequences []string `json:"stopSequences,omitempty"`
777+
Metadata any `json:"metadata,omitempty"`
755778
}
756779

757780
// CreateMessageResult is the client's response to a sampling/create_message
@@ -909,15 +932,17 @@ type ModelHint struct {
909932
// CompleteRequest is a request from the client to the server, to ask for completion options.
910933
type CompleteRequest struct {
911934
Request
912-
Params struct {
913-
Ref any `json:"ref"` // Can be PromptReference or ResourceReference
914-
Argument struct {
915-
// The name of the argument
916-
Name string `json:"name"`
917-
// The value of the argument to use for completion matching.
918-
Value string `json:"value"`
919-
} `json:"argument"`
920-
} `json:"params"`
935+
Params CompleteRequestParams `json:"params"`
936+
}
937+
938+
type CompleteRequestParams struct {
939+
Ref any `json:"ref"` // Can be PromptReference or ResourceReference
940+
Argument struct {
941+
// The name of the argument
942+
Name string `json:"name"`
943+
// The value of the argument to use for completion matching.
944+
Value string `json:"value"`
945+
} `json:"argument"`
921946
}
922947

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

0 commit comments

Comments
 (0)