@@ -15,6 +15,7 @@ import (
1515 "path/filepath"
1616 "strings"
1717
18+ "github.com/modelcontextprotocol/go-sdk/internal/mcpgodebug"
1819 "github.com/modelcontextprotocol/go-sdk/internal/util"
1920 "github.com/modelcontextprotocol/go-sdk/jsonrpc"
2021 "github.com/yosida95/uritemplate/v3"
@@ -37,8 +38,25 @@ type serverResourceTemplate struct {
3738// If it cannot find the resource, it should return the result of calling [ResourceNotFoundError].
3839type ResourceHandler func (context.Context , * ReadResourceRequest ) (* ReadResourceResult , error )
3940
41+ // customresnotfounderrcode is a compatibility parameter that restores the
42+ // pre-1.7.0 behavior of [ResourceNotFoundError] and [CodeResourceNotFound],
43+ // where the error code was a custom -32002. See the documentation for the mcpgodebug
44+ // package for instructions on how to enable it.
45+ // The option will be removed in the future version of the SDK.
46+ var customresnotfounderrcode = mcpgodebug .Value ("customresnotfounderrcode" )
47+
48+ func init () {
49+ if customresnotfounderrcode == "1" {
50+ CodeResourceNotFound = - 32002
51+ }
52+ }
53+
4054// ResourceNotFoundError returns an error indicating that a resource being read could
4155// not be found.
56+ //
57+ // By default, the error code is -32602 (Invalid Params), as specified in the
58+ // MCP specification (SEP-2164). To restore the pre-1.7.0 release behavior where the
59+ // error code was -32002, set MCPGODEBUG=customresnotfounderrcode=1.
4260func ResourceNotFoundError (uri string ) error {
4361 return & jsonrpc.Error {
4462 Code : CodeResourceNotFound ,
0 commit comments