mcp

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mcp provides a minimal in-memory MCP (Model Context Protocol) server pre-loaded with tok tools.

The implementation is deliberately small: it is an in-process registry + dispatcher with no stdio/HTTP/SSE transport. Host applications that need transport wire this package's *MCPServer into their own MCP daemon (for example, hawk's internal/mcp package exposes it to MCP-compatible agents).

The three default tools wired up by NewTokServer call the real tok package APIs rather than stub implementations:

  • count_tokens → tok.EstimateTokensForModel (BPE) or tok.EstimateTokens
  • estimate_cost → tok.GetModelPricing × (inputTokens + outputTokens)
  • compress_text → tok.Compress with the caller-supplied options

Tool authors can also use the bare NewServer + RegisterTool for custom surfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCPServer

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

func NewServer

func NewServer(name string) *MCPServer

NewServer creates an empty MCP server with the given name. Tools must be registered with RegisterTool before the server is useful.

func NewTokServer

func NewTokServer() *MCPServer

NewTokServer creates an MCP server pre-registered with the standard tok tool surface. The registered tools call the real tok package APIs:

  • count_tokens(text, model) → real BPE-backed token count
  • estimate_cost(model, inputTokens, outputTokens) → real pricing-table cost
  • compress_text(text, mode) → real 31-layer compression pipeline
  • redact_secrets(text) → real 33-pattern secret detector

func (*MCPServer) HandleRequest

func (s *MCPServer) HandleRequest(ctx context.Context, method string, params map[string]interface{}) (interface{}, error)

HandleRequest dispatches a JSON-RPC-style request to the registered tool. Supported methods: "tools/list" (no params) and "tools/call" (params must include "name" and optional "arguments" map).

func (*MCPServer) ListTools

func (s *MCPServer) ListTools() []ToolDef

ListTools returns the registered tool definitions. Order is not stable.

func (*MCPServer) RegisterTool

func (s *MCPServer) RegisterTool(name, description string, schema map[string]interface{}, handler ToolHandler)

RegisterTool adds a tool to the server. Re-registering an existing name overwrites the previous definition and handler.

type ToolDef

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

type ToolHandler

type ToolHandler func(ctx context.Context, params map[string]interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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