mcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JSON-RPC 2.0 well-known error codes.
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603

	// Application error codes live in the JSON-RPC server error range.
	CodeForbidden = -32003
	CodeNotFound  = -32004
)

Variables

View Source
var AgentTools = []Tool{
	{
		Name:        "get_bundle",
		Description: "Fetch the incident triage bundle for this agent session.",
		InputSchema: objectSchema(nil, nil),
	},
	{
		Name:        "get_context",
		Description: "Fetch scoped incident context: failing logs, run history, or why output.",
		InputSchema: objectSchema(map[string]any{
			"kind": map[string]any{
				"type":        "string",
				"description": "Context kind to fetch.",
				"enum":        []string{"logs", "history", "why"},
			},
			"job": map[string]any{
				"type":        "string",
				"description": "Optional job alias for history; must be in the incident allowlist unless it is the incident job.",
			},
			"task": map[string]any{
				"type":        "string",
				"description": "Task name for why context.",
			},
		}, []string{"kind"}),
	},
	{
		Name:        "propose_action",
		Description: "Propose or execute a typed remediation action through Caesium's server-side executor.",
		InputSchema: objectSchema(map[string]any{
			"type": map[string]any{
				"type":        "string",
				"description": "Typed remediation action name.",
			},
			"params": map[string]any{
				"type":        "object",
				"description": "Action-specific parameters.",
			},
		}, []string{"type"}),
	},
	{
		Name:        "add_note",
		Description: "Append a free-text finding to the incident timeline.",
		InputSchema: objectSchema(map[string]any{
			"text": map[string]any{
				"type":        "string",
				"description": "Timeline note text.",
			},
		}, []string{"text"}),
	},
}

AgentTools are the four Caesium agent tools exposed over MCP. The incident id is intentionally absent: it comes only from /v1/agent/incidents/:id/mcp.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	Tools map[string]any `json:"tools"`
}

Capabilities advertises supported MCP server capabilities.

type Dispatcher

type Dispatcher struct {
	Tools               []Tool
	CallTool            ToolHandler
	ReservedParamFields []string
}

Dispatcher handles MCP's JSON-RPC methods over one synchronous HTTP POST.

func (Dispatcher) Dispatch

func (d Dispatcher) Dispatch(req Request) Response

Dispatch handles initialize, tools/list, and tools/call.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is the JSON-RPC 2.0 error object.

func Forbidden

func Forbidden(message string) *Error

Forbidden returns a JSON-RPC forbidden application error.

func InternalError

func InternalError() *Error

InternalError returns a JSON-RPC internal-error response with a stable message.

func InvalidParams

func InvalidParams(message string) *Error

InvalidParams returns a JSON-RPC invalid-params error.

func NotFound

func NotFound(message string) *Error

NotFound returns a JSON-RPC not-found application error.

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string       `json:"protocolVersion"`
	Capabilities    Capabilities `json:"capabilities"`
	ServerInfo      ServerInfo   `json:"serverInfo"`
}

InitializeResult is the MCP initialize response payload.

type ListToolsResult

type ListToolsResult struct {
	Tools []Tool `json:"tools"`
}

ListToolsResult is the tools/list response payload.

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is the JSON-RPC 2.0 envelope accepted by the MCP endpoint.

func (Request) IsNotification

func (r Request) IsNotification() bool

IsNotification reports whether the request is a JSON-RPC 2.0 notification: a request with no "id" member. Notifications MUST NOT receive a response.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Result  any             `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Response is the JSON-RPC 2.0 envelope returned by the MCP endpoint.

func ErrorResponse

func ErrorResponse(id json.RawMessage, err *Error) Response

ErrorResponse builds a JSON-RPC error envelope.

func Handle

func Handle(r io.Reader, d Dispatcher) (Response, bool)

Handle decodes one JSON-RPC request from r and dispatches it. The returned bool reports whether a response should be written back to the client: JSON-RPC notifications (requests without an "id") MUST NOT receive a response, so callers must suppress the response body when it is false.

func SuccessResponse

func SuccessResponse(id json.RawMessage, result any) Response

SuccessResponse builds a JSON-RPC success envelope.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ServerInfo identifies this MCP server surface.

type Tool

type Tool struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	InputSchema any    `json:"inputSchema"`
}

Tool is an MCP tool descriptor.

type ToolCallParams

type ToolCallParams struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

ToolCallParams is the tools/call params payload.

type ToolCallResult

type ToolCallResult struct {
	Content           []ToolContent `json:"content"`
	StructuredContent any           `json:"structuredContent,omitempty"`
}

ToolCallResult is the MCP tools/call result payload.

func NewToolCallResult

func NewToolCallResult(payload any) (ToolCallResult, error)

NewToolCallResult returns both structured JSON and a text JSON representation for MCP clients that only consume content[].

type ToolContent

type ToolContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

ToolContent is one MCP content item.

type ToolHandler

type ToolHandler func(name string, arguments json.RawMessage) (any, *Error)

ToolHandler executes one named MCP tool and returns the structured payload for the MCP tools/call result.

Jump to

Keyboard shortcuts

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