httpconn

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package httpconn is the session wrapper this module's two network transports share: a protocol.Conn that delegates to an SDK-backed session and classifies everything that can go wrong underneath it.

It exists for the reason internal/httpsec does. Streamable HTTP and legacy SSE carry the same protocol over the same HTTP layer, so a failure means the same thing on both, and the taxonomy that says so should be written once. The alternative is two copies of a hierarchy of causes that is subtle in exactly the places it matters — which cause outranks which, and which of them may safely be rendered into a message — and a second copy of that is a second place for a credential to end up in a log.

Only the transport's display name differs, which is why it is a field.

Index

Constants

View Source
const (
	OpNew        = "new"
	OpConnect    = "connect"
	OpInitialize = "initialize"
	OpClose      = "close"
	// The catalog list operations, named as they appear in an error.
	OpListTools             = "list_tools"
	OpListPrompts           = "list_prompts"
	OpListResources         = "list_resources"
	OpListResourceTemplates = "list_resource_templates"
	// The request operations.
	OpCallTool     = "call_tool"
	OpGetPrompt    = "get_prompt"
	OpReadResource = "read_resource"
	OpSubscribe    = "subscribe"
	OpUnsubscribe  = "unsubscribe"
	OpSetLogLevel  = "set_log_level"
)

Operation names carried by the errors these transports return. They are the shared vocabulary of the taxonomy: a caller branches on an Error's Op, so two transports naming the same operation differently would be two things to learn.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is one MCP session over an HTTP transport.

It is thin, and it is thin on purpose: the SDK's transport owns the wire, so there is nothing here to hold but the session and the record of what went wrong underneath it.

What it adds to protocol.Session — which already implements protocol.Conn — is classification. Only this layer can tell "the server spoke badly" from "the remote server is gone" from "a credential was refused", because only it holds the Diagnostics that recorded the cause at the point the cause was still a value. A transport that returned the session directly would report every one of those as the same opaque failure.

func New

func New(session *protocol.Session, diags *httpsec.Diagnostics, name, endpoint, origin string) *Conn

New returns the Conn for one session. name is the transport's display name; endpoint and origin are its validated URL and canonical origin, held so that a failure can be described without quoting the request URL.

func (*Conn) CallTool

func (c *Conn) CallTool(ctx context.Context, rawName string, args json.RawMessage, opts protocol.CallOptions) (protocol.ToolResult, error)

CallTool invokes a tool by its raw server name.

func (*Conn) Close

func (c *Conn) Close(ctx context.Context) error

Close ends the session. The SDK's close drains the conversation and then issues the DELETE that releases the server's session state.

It is idempotent, via Session. A server that has already forgotten the session is not a close failure: there is nothing left to release, which is what Close is for.

func (*Conn) GetPrompt

func (c *Conn) GetPrompt(ctx context.Context, name string, args map[string]string) (protocol.PromptResult, error)

GetPrompt fetches a prompt's messages.

func (*Conn) Initialize

func (c *Conn) Initialize(ctx context.Context) (protocol.InitializeResult, error)

Initialize performs the MCP handshake.

func (*Conn) ListPrompts

func (c *Conn) ListPrompts(ctx context.Context, cursor string) (protocol.PromptPage, error)

ListPrompts fetches one page of prompts.

func (*Conn) ListResourceTemplates

func (c *Conn) ListResourceTemplates(ctx context.Context, cursor string) (protocol.ResourceTemplatePage, error)

ListResourceTemplates fetches one page of resource templates.

func (*Conn) ListResources

func (c *Conn) ListResources(ctx context.Context, cursor string) (protocol.ResourcePage, error)

ListResources fetches one page of resources.

func (*Conn) ListTools

func (c *Conn) ListTools(ctx context.Context, cursor string) (protocol.ToolPage, error)

ListTools fetches one page of tools.

func (*Conn) ReadResource

func (c *Conn) ReadResource(ctx context.Context, uri string) (protocol.ResourceResult, error)

ReadResource reads a resource by URI.

func (*Conn) SetLogLevel

func (c *Conn) SetLogLevel(ctx context.Context, level string) error

SetLogLevel asks the server to send logs at or above level.

func (*Conn) Subscribe

func (c *Conn) Subscribe(ctx context.Context, uri string) error

Subscribe asks the server to report changes to a resource.

func (*Conn) Unsubscribe

func (c *Conn) Unsubscribe(ctx context.Context, uri string) error

Unsubscribe asks the server to stop reporting changes to a resource.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL