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 ¶
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 ¶
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.