mcp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDefaultTools added in v0.2.0

func RegisterDefaultTools(server *MCPServer, executor ToolExecutor)

RegisterDefaultTools registers hawk's standard capabilities as MCP tools. If executor is non-nil, tools that delegate to hawk's tool registry will use it for execution; otherwise those tools return a not-configured error.

func SetClientVersion added in v0.2.0

func SetClientVersion(v string)

SetClientVersion lets main.go propagate the canonical hawk version into this package without creating an import cycle with cmd.

Types

type HTTPServer

type HTTPServer struct {
	Name    string
	URL     string
	Headers map[string]string
	Type    string // "http" or "sse"
	// contains filtered or unexported fields
}

HTTPServer represents an MCP server connected via HTTP or SSE transport.

func ConnectHTTP

func ConnectHTTP(ctx context.Context, name, url string, headers map[string]string) (*HTTPServer, error)

ConnectHTTP connects to an MCP server via HTTP streamable transport.

func ConnectSSE

func ConnectSSE(ctx context.Context, name, url string, headers map[string]string) (*HTTPServer, error)

ConnectSSE connects to an MCP server via Server-Sent Events transport.

func (*HTTPServer) Call

func (s *HTTPServer) Call(ctx context.Context, method string, params interface{}) (json.RawMessage, error)

Call sends a JSON-RPC request and returns the result.

func (*HTTPServer) CallTool

func (s *HTTPServer) CallTool(ctx context.Context, name string, args map[string]interface{}) (string, error)

CallTool invokes a tool on the HTTP/SSE MCP server.

func (*HTTPServer) Close

func (s *HTTPServer) Close() error

Close is a no-op for HTTP/SSE servers (no persistent connection).

func (*HTTPServer) ListTools

func (s *HTTPServer) ListTools(ctx context.Context) ([]Tool, error)

ListTools returns tools from the HTTP/SSE MCP server.

type JSONRPCRequest added in v0.2.0

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

JSON-RPC 2.0 request from a client.

type JSONRPCResponse added in v0.2.0

type JSONRPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id"`
	Result  interface{} `json:"result,omitempty"`
	Error   *RPCError   `json:"error,omitempty"`
}

JSON-RPC 2.0 response to a client.

type MCPServer added in v0.2.0

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

MCPServer exposes hawk's capabilities as an MCP server that external clients (IDEs, agents, CLI tools) can connect to via JSON-RPC 2.0 over stdio.

func NewMCPServer added in v0.2.0

func NewMCPServer(info ServerInfo) *MCPServer

NewMCPServer creates a new MCP server with the given identity.

func (*MCPServer) RegisterTool added in v0.2.0

func (s *MCPServer) RegisterTool(handler MCPToolHandler)

RegisterTool adds a tool to the server. If a tool with the same name already exists, it is replaced.

func (*MCPServer) Serve added in v0.2.0

func (s *MCPServer) Serve(ctx context.Context, r io.Reader, w io.Writer) error

Serve runs the MCP server reading from r and writing responses to w. This is the testable core of ServeStdio.

func (*MCPServer) ServeStdio added in v0.2.0

func (s *MCPServer) ServeStdio(ctx context.Context) error

ServeStdio runs the MCP server on stdin/stdout, reading JSON-RPC requests line-by-line and writing responses. It blocks until ctx is cancelled or stdin reaches EOF.

type MCPToolHandler added in v0.2.0

type MCPToolHandler struct {
	Name        string
	Description string
	InputSchema map[string]interface{}
	Handler     func(ctx context.Context, params json.RawMessage) (string, error)
}

MCPToolHandler defines a tool exposed by the MCP server.

type RPCError added in v0.2.0

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

RPCError is a JSON-RPC 2.0 error object.

type Resource

type Resource struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	MimeType    string `json:"mimeType,omitempty"`
	Description string `json:"description,omitempty"`
}

Resource is a resource exposed by an MCP server.

type Server

type Server struct {
	Name    string
	Command string
	Args    []string
	// contains filtered or unexported fields
}

Server represents a connected MCP server.

func Connect

func Connect(ctx context.Context, name, command string, args ...string) (*Server, error)

Connect starts an MCP server process via stdio transport.

func (*Server) CallTool

func (s *Server) CallTool(name string, args map[string]interface{}) (string, error)

CallTool invokes a tool on the MCP server.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the MCP server.

func (*Server) ListResources

func (s *Server) ListResources() ([]Resource, error)

ListResources returns resources available on this MCP server.

func (*Server) ListTools

func (s *Server) ListTools() ([]Tool, error)

ListTools returns tools available on this MCP server.

func (*Server) ReadResource

func (s *Server) ReadResource(uri string) (string, error)

ReadResource reads a resource from this MCP server.

type ServerInfo added in v0.2.0

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

ServerInfo identifies the MCP server to connecting clients.

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"inputSchema"`
}

Tool is a tool exposed by an MCP server.

type ToolExecutor added in v0.2.0

type ToolExecutor func(ctx context.Context, name string, input json.RawMessage) (string, error)

ToolExecutor is a function that executes a named tool with JSON input. This avoids importing the tool package (which already imports mcp).

Jump to

Keyboard shortcuts

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