mcp: lock down Params and Result
Add unexported methods to the Params and Result interface, so that they're harder to implement outside the mcp package. It looks like these are the only two interfaces we need to lock down: others are either intentionally open (Transport, Connection), or already closed (Session). Fixes #263
This commit is contained in:
parent
e9e0da8dac
commit
8186bf39c7
1 changed files with 53 additions and 0 deletions
|
|
@ -335,6 +335,9 @@ func setProgressToken(p Params, pt any) {
|
|||
|
||||
// Params is a parameter (input) type for an MCP call or notification.
|
||||
type Params interface {
|
||||
// mcpParams discourages implementation of Params outside of this package.
|
||||
mcpParams()
|
||||
|
||||
// GetMeta returns metadata from a value.
|
||||
GetMeta() map[string]any
|
||||
// SetMeta sets the metadata on a value.
|
||||
|
|
@ -356,6 +359,9 @@ type RequestParams interface {
|
|||
|
||||
// Result is a result of an MCP call.
|
||||
type Result interface {
|
||||
// mcpResult discourages implementation of Result outside of this package.
|
||||
mcpResult()
|
||||
|
||||
// GetMeta returns metadata from a value.
|
||||
GetMeta() map[string]any
|
||||
// SetMeta sets the metadata on a value.
|
||||
|
|
@ -366,6 +372,7 @@ type Result interface {
|
|||
// Those methods cannot return nil, because jsonrpc2 cannot handle nils.
|
||||
type emptyResult struct{}
|
||||
|
||||
func (*emptyResult) mcpResult() {}
|
||||
func (*emptyResult) GetMeta() map[string]any { panic("should never be called") }
|
||||
func (*emptyResult) SetMeta(map[string]any) { panic("should never be called") }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue