Improvements and fixes (#223)
Some checks failed
CI / Test (macos-latest, Swift 6.1.0) (push) Has been cancelled
CI / Test (ubuntu-latest, Swift 6.1.0) (push) Has been cancelled
CI / MCP Conformance Tests (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Linux Static SDK Build (6.1.2 - ubuntu-latest) (push) Has been cancelled

* feat: added http transport context to the task local execution

* fix: added refresh_token to the grantTypes for DCR

* chore: updated documentation
This commit is contained in:
yehorsobko 2026-04-29 13:34:21 +02:00 • committed by GitHub
commit a0ae212ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,6 +41,7 @@ of the MCP specification.
- [Logging](#logging-1)
- [Progress Tracking](#progress-tracking-1)
- [Initialize Hook](#initialize-hook)
- [HTTP Request Context in Handlers](#http-request-context-in-handlers)
- [Graceful Shutdown](#graceful-shutdown)
- [Transports](#transports)
- [Authentication](#authentication)
@ -1184,6 +1185,35 @@ try await server.start(transport: transport) { clientInfo, clientCapabilities in
}
```
### HTTP Request Context in Handlers
When a server is connected over `StatefulHTTPServerTransport` or `StatelessHTTPServerTransport`,
method handlers can observe the originating HTTP request (headers, body, path, method) via
`Server.currentHandlerContext` — a task-local set automatically before each handler runs:
```swift
await server.withMethodHandler(CallTool.self) { params in
let httpRequest = Server.currentHandlerContext?.httpContext
let authHeader = httpRequest?.headers["Authorization"]
// …use the header to scope the response, audit, etc.
return .init(content: [.text("ok")], isError: false)
}
```
`httpContext` is `nil` for transports that don't carry HTTP context (e.g. `StdioTransport`,
`InMemoryTransport`) and for handlers reached off the dispatch path.
Task-locals are not inherited by `Task.detached`. If you spawn a detached task from a handler,
capture the context up front:
```swift
let ctx = Server.currentHandlerContext
Task.detached { await doWork(with: ctx?.httpContext) }
```
Custom HTTP transports can opt in by conforming to `HTTPContextProviding` and returning the
`HTTPRequest` for a given JSON-RPC id while it is in flight.
### Graceful Shutdown
We recommend using