mcp

package
v1.18.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mcp implements a Model Context Protocol server that exposes DevClaw tools, resources, and prompts to MCP-compatible clients (Cursor, VSCode, etc.) via stdio and SSE transports.

Package mcp – sse.go implements the SSE (Server-Sent Events) transport for the MCP server, allowing HTTP-based clients to connect.

Index

Constants

View Source
const (
	ProtocolVersion = "2024-11-05"
	ServerName      = "devclaw"
	ServerVersion   = "1.0.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

ContentBlock is a single content item in a tool result.

type HandlerFunc

type HandlerFunc func(ctx context.Context, params json.RawMessage) (any, error)

HandlerFunc handles an MCP JSON-RPC request.

type Prompt

type Prompt struct {
	Name        string      `json:"name"`
	Description string      `json:"description,omitempty"`
	Arguments   []PromptArg `json:"arguments,omitempty"`
}

Prompt describes an MCP prompt template.

type PromptArg

type PromptArg struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

PromptArg describes an argument to a prompt template.

type Resource

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

Resource describes an MCP resource.

type SSETransport

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

SSETransport serves MCP over HTTP with SSE for responses.

func NewSSETransport

func NewSSETransport(server *Server, logger *slog.Logger) *SSETransport

NewSSETransport creates a new SSE transport wrapping the MCP server.

func (*SSETransport) Handler

func (t *SSETransport) Handler() http.Handler

Handler returns an http.Handler that serves the MCP SSE endpoints. GET /sse — establishes SSE connection POST /message?sessionId=X — sends JSON-RPC messages

type Server

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

Server implements the MCP JSON-RPC 2.0 protocol.

func New

func New(logger *slog.Logger) *Server

New creates a new MCP server.

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(method string, handler HandlerFunc)

RegisterHandler adds a custom method handler.

func (*Server) RegisterTool

func (s *Server) RegisterTool(def ToolDef, handler HandlerFunc)

RegisterTool adds a tool to the server.

func (*Server) ServeStdio

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

ServeStdio runs the MCP server over stdin/stdout (JSON-RPC over stdio).

type ToolCallResult

type ToolCallResult struct {
	Content []ContentBlock `json:"content"`
	IsError bool           `json:"isError,omitempty"`
}

ToolCallResult is the result of executing an MCP tool.

type ToolDef

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

ToolDef describes a tool exposed via MCP.

Jump to

Keyboard shortcuts

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