mcp

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mcp implements the Model Context Protocol (MCP) server for TokMan. This allows AI assistants to use TokMan's filtering capabilities as MCP tools.

Index

Constants

View Source
const (
	MessageTypeInitialize  = "initialize"
	MessageTypeInitialized = "initialized"
	MessageTypeToolsList   = "tools/list"
	MessageTypeToolsCall   = "tools/call"
	MessageTypePing        = "ping"
	MessageTypePong        = "pong"
	MessageTypeError       = "error"
)

Message types

View Source
const (
	ErrorCodeParseError     = -32700
	ErrorCodeInvalidRequest = -32600
	ErrorCodeMethodNotFound = -32601
	ErrorCodeInvalidParams  = -32602
	ErrorCodeInternalError  = -32603
)

Error codes

View Source
const ProtocolVersion = "2024-11-05"

ProtocolVersion is the MCP protocol version we support

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzeParams added in v0.28.0

type AnalyzeParams struct {
	Text string `json:"text"`
}

AnalyzeParams for tokman_analyze_output tool

type ClientCapabilities added in v0.28.0

type ClientCapabilities struct {
	Roots    *RootsCapability    `json:"roots,omitempty"`
	Sampling *SamplingCapability `json:"sampling,omitempty"`
}

ClientCapabilities describes client capabilities

type CompressFileParams added in v0.28.0

type CompressFileParams struct {
	Path     string `json:"path"`
	Mode     string `json:"mode,omitempty"`
	MaxLines int    `json:"max_lines,omitempty"`
}

CompressFileParams for tokman_compress_file tool

type Content added in v0.28.0

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

Content represents a content item in a response

func NewTextContent added in v0.28.0

func NewTextContent(text string) Content

NewTextContent creates text content

type FilterParams added in v0.28.0

type FilterParams struct {
	Text   string `json:"text"`
	Mode   string `json:"mode,omitempty"`
	Budget int    `json:"budget,omitempty"`
	Query  string `json:"query,omitempty"`
}

FilterParams for tokman_filter tool

type FilterResult added in v0.28.0

type FilterResult struct {
	FilteredText   string   `json:"filtered_text"`
	OriginalTokens int      `json:"original_tokens"`
	FilteredTokens int      `json:"filtered_tokens"`
	TokensSaved    int      `json:"tokens_saved"`
	SavingsPercent float64  `json:"savings_percent"`
	LayersApplied  []string `json:"layers_applied"`
}

FilterResult for filter tool response

type Implementation added in v0.28.0

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

Implementation identifies the implementation

type InitializeParams added in v0.28.0

type InitializeParams struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ClientCapabilities `json:"capabilities"`
	ClientInfo      Implementation     `json:"clientInfo"`
}

InitializeParams contains initialization parameters

type InitializeResult

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

InitializeResult is the response to initialize

type JSONRPCError added in v0.28.0

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

JSONRPCError is a JSON-RPC 2.0 error

type JSONRPCRequest added in v0.28.0

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

JSONRPCRequest is a JSON-RPC 2.0 request

type JSONRPCResponse added in v0.28.0

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

JSONRPCResponse is a JSON-RPC 2.0 response

type RootsCapability added in v0.28.0

type RootsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

RootsCapability indicates client supports roots

type SamplingCapability added in v0.28.0

type SamplingCapability struct{}

SamplingCapability indicates client supports sampling

type Server added in v0.28.0

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

Server implements an MCP server

func NewServer added in v0.28.0

func NewServer(name, version string, pipeline *filter.PipelineCoordinator) *Server

NewServer creates a new MCP server

func (*Server) RegisterTool added in v0.28.0

func (s *Server) RegisterTool(tool Tool, handler ToolHandler) error

RegisterTool registers a tool with the server

func (*Server) RunStdio added in v0.28.0

func (s *Server) RunStdio() error

RunStdio runs the server with stdio transport

type ServerCapabilities

type ServerCapabilities struct {
	Tools *ToolsCapability `json:"tools,omitempty"`
}

ServerCapabilities describes server capabilities

type Tool

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

Tool represents an available tool

type ToolHandler

type ToolHandler func(arguments json.RawMessage) (*ToolsCallResult, error)

ToolHandler is a function that handles a tool call

type ToolsCallParams added in v0.28.0

type ToolsCallParams struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

ToolsCallParams contains tool call parameters

type ToolsCallResult added in v0.28.0

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

ToolsCallResult is the response to tools/call

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

ToolsCapability describes tool support

type ToolsListResult added in v0.28.0

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

ToolsListResult is the response to tools/list

Jump to

Keyboard shortcuts

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