SseMcpTransport
Namespace: Vercel.AI.Mcp
public sealed class SseMcpTransport : IMcpTransport, IDisposableMCP over the legacy HTTP+SSE transport. StartAsync(CancellationToken) opens a GET event stream, waits for the
endpoint event, then CancellationToken) posts JSON-RPC messages to that endpoint. Responses arrive on the stream.
Inheritance: object
Implements: IMcpTransport, IDisposable
Constructors
Section titled “Constructors”SseMcpTransport(HttpClient, Uri, IReadOnlyDictionary<string, string>?)
Section titled “SseMcpTransport(HttpClient, Uri, IReadOnlyDictionary<string, string>?)”public SseMcpTransport(HttpClient httpClient, Uri url, IReadOnlyDictionary<string, string>? headers = null)Creates a transport for the SSE endpoint at <code class=“paramref”>url</code>.
Parameters
| Name | Type | Description |
|---|---|---|
httpClient |
HttpClient | |
url |
Uri | |
headers |
IReadOnlyDictionary<string, string> |
Fields
Section titled “Fields”LatestLegacyProtocolVersion
Section titled “LatestLegacyProtocolVersion”public const string LatestLegacyProtocolVersion = "2024-11-05"Protocol version sent in mcp-protocol-version until ProtocolVersion is set.
Value: string
Properties
Section titled “Properties”OnClose
Section titled “OnClose”public Action? OnClose { get; set; }Called when the stream closes after CloseAsync().
Value: Action
OnError
Section titled “OnError”public Action<Exception>? OnError { get; set; }Called with each transport error, such as a failed connection or an unparsable message.
Value: Action<Exception>
OnMessage
Section titled “OnMessage”public Action<JsonElement>? OnMessage { get; set; }Called with each JSON-RPC message the server sends.
Value: Action<JsonElement>
ProtocolVersion
Section titled “ProtocolVersion”public string? ProtocolVersion { get; set; }Negotiated protocol version. Defaults to LatestLegacyProtocolVersion when unset.
Value: string
Methods
Section titled “Methods”CallAsync(string, JsonElement, CancellationToken)
Section titled “CallAsync(string, JsonElement, CancellationToken)”public Task<JsonElement> CallAsync(string method, JsonElement parameters, CancellationToken cancellationToken)Calls <code class=“paramref”>method</code> and returns the JSON-RPC result.
Parameters
| Name | Type | Description |
|---|---|---|
method |
string | |
parameters |
JsonElement | |
cancellationToken |
CancellationToken |
Returns: Task<JsonElement>
CloseAsync()
Section titled “CloseAsync()”public Task CloseAsync()Closes the event stream and fails pending calls.
Returns: Task
DeserializeMessage(string)
Section titled “DeserializeMessage(string)”public static JsonElement DeserializeMessage(string line)Parses one JSON-RPC message. Prototype-pollution keys are rejected.
Parameters
| Name | Type | Description |
|---|---|---|
line |
string |
Returns: JsonElement
Dispose()
Section titled “Dispose()”public void Dispose()Closes the transport.
SendAsync(JsonElement, CancellationToken)
Section titled “SendAsync(JsonElement, CancellationToken)”public Task SendAsync(JsonElement message, CancellationToken cancellationToken = default)Posts one JSON-RPC message to the endpoint the server announced.
Parameters
| Name | Type | Description |
|---|---|---|
message |
JsonElement | |
cancellationToken |
CancellationToken |
Returns: Task
StartAsync(CancellationToken)
Section titled “StartAsync(CancellationToken)”public Task StartAsync(CancellationToken cancellationToken = default)Opens the event stream and completes once the server has sent its endpoint event.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product