Skip to content

Commit 8d68d57

Browse files
Merge branch 'main' into guglielmoc/SEP-2243_http_standardization_2
2 parents 2faa9a9 + 9604499 commit 8d68d57

14 files changed

Lines changed: 141 additions & 21 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ jobs:
3838
- name: Checkout repository
3939
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4040
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
41+
uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
4242
with:
4343
languages: ${{ matrix.language }}
4444
build-mode: ${{ matrix.build-mode }}
4545
- name: Perform CodeQL Analysis
46-
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
46+
uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
4747
with:
4848
category: "/language:${{matrix.language}}"

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
go-version: "^1.26"
3131
- name: Set up Node.js
32-
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
32+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
3333
with:
3434
node-version: "22"
3535
- name: Run server conformance tests

.github/workflows/publish-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
python-version: 3.x
2424
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
25-
- uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
25+
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
2626
with:
2727
key: mkdocs-material-${{ env.cache_id }}
2828
path: .cache

.github/workflows/scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6565
# format to the repository Actions tab.
6666
- name: "Upload artifact"
67-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
67+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
6868
with:
6969
name: SARIF file
7070
path: results.sarif
@@ -73,6 +73,6 @@ jobs:
7373
# Upload the results to GitHub's code scanning dashboard (optional).
7474
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
7575
- name: "Upload to code-scanning"
76-
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
76+
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
7777
with:
7878
sarif_file: results.sarif

docs/mcpgodebug.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818

1919
## `MCPGODEBUG` history
2020

21+
### 1.7.0
22+
23+
Options listed below were added and will be removed in the 1.9.0 version of the SDK.
24+
25+
- `customresnotfounderrcode` added. If set to `1`, `ResourceNotFoundError` will
26+
use the custom error code `-32002` instead of the standard `-32602` (Invalid
27+
Params), restoring the previous behavior. The default behavior was changed to
28+
align with SEP-2164 and the JSON-RPC specification.
29+
2130
### 1.6.0
2231

2332
Options listed below were added and will be removed in the 1.8.0 version of the SDK.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/segmentio/encoding v0.5.4
1010
github.com/yosida95/uritemplate/v3 v3.0.2
1111
golang.org/x/oauth2 v0.35.0
12+
golang.org/x/time v0.15.0
1213
golang.org/x/tools v0.42.0
1314
)
1415

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
1414
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
1515
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
1616
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
17+
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
18+
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
1719
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
1820
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=

internal/docs/mcpgodebug.src.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
## `MCPGODEBUG` history
1919

20+
### 1.7.0
21+
22+
Options listed below were added and will be removed in the 1.9.0 version of the SDK.
23+
24+
- `customresnotfounderrcode` added. If set to `1`, `ResourceNotFoundError` will
25+
use the custom error code `-32002` instead of the standard `-32602` (Invalid
26+
Params), restoring the previous behavior. The default behavior was changed to
27+
align with SEP-2164 and the JSON-RPC specification.
28+
2029
### 1.6.0
2130

2231
Options listed below were added and will be removed in the 1.8.0 version of the SDK.

mcp/error_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ func TestServerErrors(t *testing.T) {
111111
}
112112
}
113113

114+
// TestResourceNotFoundErrorCode verifies ResourceNotFoundError code and
115+
// CodeResourceNotFound are -32602 (InvalidParams) per SEP-2164.
116+
func TestResourceNotFoundErrorCode(t *testing.T) {
117+
err := ResourceNotFoundError("file:///test.txt")
118+
var rpcErr *jsonrpc.Error
119+
if !errors.As(err, &rpcErr) {
120+
t.Fatalf("got error type %T, want *jsonrpc.Error", err)
121+
}
122+
if rpcErr.Code != jsonrpc.CodeInvalidParams {
123+
t.Errorf("got error code %d, want %d (InvalidParams)", rpcErr.Code, jsonrpc.CodeInvalidParams)
124+
}
125+
if CodeResourceNotFound != jsonrpc.CodeInvalidParams {
126+
t.Errorf("CodeResourceNotFound = %d, want %d", CodeResourceNotFound, jsonrpc.CodeInvalidParams)
127+
}
128+
}
129+
114130
// TestInputValidationToolError validates that input validation errors (missing
115131
// required params, wrong types) are returned as tool results with IsError=true,
116132
// not as JSON-RPC errors. This allows LLMs to see the error and self-correct.

mcp/logging.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"slices"
1414
"sync"
1515
"time"
16+
17+
"golang.org/x/time/rate"
1618
)
1719

1820
// Logging levels.
@@ -83,10 +85,10 @@ type LoggingHandler struct {
8385
// Ensures that the buffer reset is atomic with the write (see Handle).
8486
// A pointer so that clones share the mutex. See
8587
// https://github.com/golang/example/blob/master/slog-handler-guide/README.md#getting-the-mutex-right.
86-
mu *sync.Mutex
87-
lastMessageSent time.Time // for rate-limiting
88-
buf *bytes.Buffer
89-
handler slog.Handler
88+
mu *sync.Mutex
89+
limiter *rate.Limiter // for rate-limiting
90+
buf *bytes.Buffer
91+
handler slog.Handler
9092
}
9193

9294
// ensureLogger returns l if non-nil, otherwise a discard logger.
@@ -118,6 +120,9 @@ func NewLoggingHandler(ss *ServerSession, opts *LoggingHandlerOptions) *LoggingH
118120
}
119121
if opts != nil {
120122
lh.opts = *opts
123+
if opts.MinInterval > 0 {
124+
lh.limiter = rate.NewLimiter(rate.Every(opts.MinInterval), 1)
125+
}
121126
}
122127
return lh
123128
}
@@ -157,11 +162,7 @@ func (h *LoggingHandler) Handle(ctx context.Context, r slog.Record) error {
157162

158163
func (h *LoggingHandler) handle(ctx context.Context, r slog.Record) error {
159164
// Observe the rate limit.
160-
// TODO(jba): use golang.org/x/time/rate.
161-
h.mu.Lock()
162-
skip := time.Since(h.lastMessageSent) < h.opts.MinInterval
163-
h.mu.Unlock()
164-
if skip {
165+
if h.limiter != nil && !h.limiter.Allow() {
165166
return nil
166167
}
167168

@@ -184,10 +185,6 @@ func (h *LoggingHandler) handle(ctx context.Context, r slog.Record) error {
184185
return err
185186
}
186187

187-
h.mu.Lock()
188-
h.lastMessageSent = time.Now()
189-
h.mu.Unlock()
190-
191188
params := &LoggingMessageParams{
192189
Logger: h.opts.LoggerName,
193190
Level: slogLevelToMCP(r.Level),

0 commit comments

Comments
 (0)