withMethodHandler resources/read
I maintainer di solito rispondono entro 7 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start at the withMethodHandler API and the resources/read dispatch path, especially where handlers currently receive only decoded MCP parameters. Compare the proposed RequestContext properties with the SDK’s framework integrations, including Vapor.Request. Done means a framework-agnostic context can reach handlers without coupling the SDK to one HTTP framework, with integration coverage for supported backends.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature Request: Framework-Agnostic Request Context Injection for MCP Handlers
Problem
Currently, the MCP Swift SDK registers all method handlers (tools, resources, etc.) using:
@discardableResult
public func withMethodHandler<M: Method>(
_ type: M.Type,
handler: @escaping @Sendable (M.Parameters) async throws -> M.Result
) -> Self
This closure only receives the decoded MCP parameters (M.Parameters). There is no way to access the underlying HTTP request or any HTTP context (headers, authentication, route-local state, etc.).
Why This Is a Problem
-
Many real-world handlers (especially for resources/read, but also for tools) need access to HTTP request context to:
- Reuse existing route logic
- Access authentication/session data
- Read headers, cookies, or other request-scoped information
- Share logic/state between HTTP routes and MCP handlers
-
For tools, we can work around this by intercepting the HTTP request in our own route, enriching the MCP request, and passing both the MCP and HTTP request to our handler.
-
For resources, this is not possible: the SDK directly invokes the handler with only the MCP parameters, and there is no extension point to inject the HTTP request.
Current Workarounds
- For resources, we are forced to use an HTTP client (e.g.,
URLSession) to call our own local endpoint from inside the handler, just to get the same data as the HTTP route. This is inefficient and not production-grade. - For tools, we must maintain a custom bridge layer, which is complex and fragile.
Proposed Solution
Add support for injecting a framework-agnostic HTTP request context into MCP handler closures.
Example API
Define a protocol in the SDK, e.g.:
public protocol RequestContext {
var headers: [String: String] { get }
var method: String { get }
var path: String { get }
var query: [String: String] { get }
var body: Data? { get }
// ...other common properties
}
Handler registration would then look like:
@discardableResult
public func withMethodHandler<M: Method>(
_ type: M.Type,
handler: @escaping @Sendable (M.Parameters, RequestContext) async throws -> M.Result
) -> Self
- The SDK would provide a default implementation for each supported backend.
- Vapor integration would wrap
Vapor.Requestas aRequestContext. - Other frameworks (Hummingbird, Kitura, etc.) would provide their own adapters.
Benefits
- Keeps the SDK decoupled from any specific HTTP framework.
- Enables code sharing between HTTP routes and MCP handlers.
- Allows access to authentication, headers, and other request-scoped data.
- Removes the need for inefficient HTTP self-calls and custom bridges.
- Makes the SDK more flexible and production-ready for stateless HTTP deployments.
Summary
Please add a way to inject a framework-agnostic HTTP request context into MCP handler closures. This will enable robust, efficient, and maintainable MCP server implementations in Swift, and eliminate the need for current workarounds.
- Lingua principale
- Swift
- Stelle
- 1.5k
- Fork
- 252
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di modelcontextprotocol/swift-sdk
-
NetworkTransport leaks the underlying socket (CLOSE_WAIT) when reconnection is disabled and the receive loop terminatesForse già presa @skirrellyjones l’ha presa 37 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
modelcontextprotocol/swift-sdk#282 ·
I maintainer di solito rispondono entro 7 giorni
-
Value decoding changes data-URL-looking JSON strings into Value.dataForse già presa @bitbemol l’ha presa 48 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/swift-sdk#277 ·
I maintainer di solito rispondono entro 7 giorni
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
modelcontextprotocol/swift-sdk#274 ·
I maintainer di solito rispondono entro 7 giorni
-
`HTTPClientTransport` fails to build on Windows: `#if !os(Linux)` guards no longer match the `EventSource` platform conditionForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
modelcontextprotocol/swift-sdk#261 ·
I maintainer di solito rispondono entro 7 giorni
-
Value: add numberValue (Double?) that coerces .int and .doubleForse già presa @gsdali l’ha presa 159 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/swift-sdk#225 ·
I maintainer di solito rispondono entro 7 giorni
Tutte le issue di modelcontextprotocol/swift-sdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] File transcription skips audio chunks shorter than one secondForse già presa @sabbah13 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
altic-dev/FluidVoice#1161 ·
I maintainer di solito rispondono entro 1 giorno
-
swift.md: `Date(myString, strategy: .iso8601)` example omits `try` — the initializer is throwingAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
core: RAC_LLM_OPTIONS_DEFAULT.min_p disagrees with the IDL's annotated defaultForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug core p3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
RunanywhereAI/runanywhere-sdks#1083 ·
I maintainer di solito rispondono entro 5 giorni
-
bug/fix needs: triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
capawesome-team/capacitor-firebase#1054 ·
I maintainer di solito rispondono entro 1 giorno