Documentation
¶
Overview ¶
Package mcphttp provides an HTTP-based MCP server for tool execution. This package is kept separate to avoid import cycles with internal/llm.
Index ¶
- func ParseMCPToolName(mcpName string) string
- func ToolCallIDFromContext(ctx context.Context) string
- type ContentPart
- type ContentPartType
- type Server
- func (s *Server) SetDebug(debug bool)
- func (s *Server) Start(ctx context.Context, tools []ToolSpec) (url, token string, err error)
- func (s *Server) StartOnAddress(host string, port int, token string, tools []ToolSpec) (url, actualToken string, err error)
- func (s *Server) Stop(ctx context.Context) error
- func (s *Server) Token() string
- func (s *Server) URL() string
- type ToolExecutor
- type ToolResult
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseMCPToolName ¶
ParseMCPToolName extracts the original tool name from an MCP-namespaced name. MCP tools from term-llm are namespaced as "mcp__term-llm__<tool>".
func ToolCallIDFromContext ¶ added in v0.9.40
ToolCallIDFromContext returns the model-authored tool-use ID supplied by a local CLI client, when available.
Types ¶
type ContentPart ¶ added in v0.9.16
type ContentPart struct {
Type ContentPartType
Text string
MIMEType string
Data []byte
}
ContentPart is one MCP content block. Image Data holds raw (decoded) bytes; the go-sdk base64-encodes it on the wire.
type ContentPartType ¶ added in v0.9.16
type ContentPartType string
ContentPartType identifies an MCP tool-result content block.
const ( ContentPartText ContentPartType = "text" ContentPartImage ContentPartType = "image" )
type Server ¶
type Server struct {
// HandlerMiddleware is installed before serving. Set only before Start.
// Tool descendants must retain request ownership if they outlive the handler.
HandlerMiddleware func(http.Handler) http.Handler
// ConnState observes transport completion, after response buffers flush.
ConnState func(net.Conn, http.ConnState)
// contains filtered or unexported fields
}
Server runs an MCP server over HTTP with token-based authentication. It exposes tools to local CLI transports and executes them using the provided executor.
func NewServer ¶
func NewServer(executor ToolExecutor) *Server
NewServer creates a new HTTP MCP server. The executor function is called to execute tool calls.
func (*Server) Start ¶
Start starts the HTTP server on a random available port on localhost. Returns the server URL and auth token for connecting.
func (*Server) StartOnAddress ¶ added in v0.0.128
func (s *Server) StartOnAddress(host string, port int, token string, tools []ToolSpec) (url, actualToken string, err error)
StartOnAddress starts the HTTP server on a specific host:port. If token is empty, a crypto-random token is generated. Returns the server URL and the auth token used.
type ToolExecutor ¶
type ToolExecutor func(ctx context.Context, name string, args json.RawMessage) (ToolResult, error)
ToolExecutor is a function that executes a tool and returns the result.
type ToolResult ¶ added in v0.0.406
type ToolResult struct {
Content string // text-only result; used when Parts is empty
Parts []ContentPart // optional structured blocks (text + images); takes precedence over Content
IsError bool
}
ToolResult is the result exposed to an MCP client and its semantic status.
type ToolSpec ¶
type ToolSpec struct {
Name string
Description string
Schema map[string]interface{}
// Parallelizable is a private loopback-bridge scheduling hint used for
// execution parity with native/API providers. Claude Code currently overlaps
// MCP calls only when readOnlyHint is true; this does not alter term-llm's
// permissions, approvals, or execution policy.
Parallelizable bool
}
ToolSpec describes a tool to expose via MCP.