mirror of
https://github.com/coder/coder.git
synced 2026-10-31 19:36:41 +08:00
## Stack Context PR 5 of 6 in a stack that migrates every Coder MCP surface from the archived `github.com/mark3labs/mcp-go` library to the official `github.com/modelcontextprotocol/go-sdk` v1.7.0. Stack: #28056 -> #28057 -> #28058 -> #28059 -> #28060 -> #28061 ## Why The aibridge injected-MCP proxy now owns an official `*mcp.Client`, `*mcp.StreamableClientTransport`, and `*mcp.ClientSession`. - The proxy constructor accepts an optional `*http.Client` instead of mark3labs options; the header-injecting wrapper shallow-copies a supplied client so its Timeout, Jar, and redirect policy survive. - Manual protocol version negotiation and the mark3labs five-second close workaround are removed; the SDK negotiates during `Connect` and fails when no mutually supported version exists. - Repeated `Init` closes the previous session, and a failed tool fetch closes the just-created session so transports do not leak. - Tool and intercept types use the official pointer content types; embedded resource blobs are re-encoded to base64 for model-facing text because the SDK decodes them into raw bytes. - `aibridge/mcpmock` is regenerated, and its stale `go:generate` source path is corrected. > Mux created this PR on Mike's behalf.
27 lines
1014 B
Go
27 lines
1014 B
Go
package mcp
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// ServerProxier provides an abstraction to communicate with MCP Servers regardless of their transport.
|
|
// The ServerProxier is expected to, at least, fetch any available MCP tools.
|
|
type ServerProxier interface {
|
|
// Init initializes the proxier, establishing a connection with the upstream server and fetching resources.
|
|
Init(context.Context) error
|
|
// Gracefully shut down connections to the MCP server. Session management will vary per transport.
|
|
// See https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management.
|
|
Shutdown(ctx context.Context) error
|
|
|
|
// ListTools lists all known tools. These MUST be sorted in a stable order.
|
|
ListTools() []*Tool
|
|
// GetTool returns a given tool, if known, or returns nil.
|
|
GetTool(id string) *Tool
|
|
// CallTool invokes an injected MCP tool
|
|
CallTool(ctx context.Context, name string, input any) (*mcp.CallToolResult, error)
|
|
}
|
|
|
|
// TODO: support HTTP+SSE.
|