mcpserver

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcpserver exposes the deterministic EVE-Cyno tools as a Model Context Protocol server: the same registry (catalog) and the same executor (tools.ExecuteToolResult) as the REST tool endpoint, so a tool answers identically over MCP, REST and the chat brain.

It is a library: cmd/mcp serves it over stdio for local clients (Claude Desktop, Claude Code), and cmd/dataapi mounts the streamable-HTTP handler (HTTPHandler) at /v1/mcp behind the data API's request IDs and rate limiter.

What a client sees:

  • tools/list: one MCP tool per registry tool, with the tool_schemas.json description and argument schema as is. The set follows the tool tiers (catalog.Tier). Over HTTP it is chosen per request: the public tools always (appraise_items among them; its description says the X-Janice-Key header is optional), the keyed tools only when the caller presented a valid API key (HTTPOptions.Keyed) and the disabled tools never; a tool that is not listed is the protocol's own "unknown tool" error. Over stdio the default is the public tools, run without any key of the process (appraise_items then estimates), and Options.All registers every tool, for a local process that spends its owner's keys.
  • tools/call: content[0] is the LLM-oriented text exactly as tools.ExecuteTool returns it; content[1], when the tool has upstreams, is a short "Sources:" line (attribution is a condition of several of the licences, and most clients do not show _meta to the model); structuredContent is the typed result where the tool has one; _meta carries the full attribution (name, url, licence) and the build version.
  • A tool failure (upstream error, timeout, bad arguments) is a normal result with isError set and the message as text, so the model can read it and retry; only a malformed request (arguments that are not a JSON object) or an unregistered tool is a JSON-RPC error.

Arguments are checked against the schema's "required" list only (catalog.Tool.CheckArgs; the REST tool endpoint does the same): a call that lacks a required argument, or sends it blank, is an isError result naming the missing and the unexpected argument names and never reaches the tool. Types are not checked: the tools tolerate mistyped arguments and say so in their text.

Index

Constants

View Source
const (
	// DefaultTimeout bounds one tool execution (the budget of the REST tool endpoint).
	DefaultTimeout = 30 * time.Second

	// MetaPrefix namespaces the keys this server adds to a result's _meta.
	MetaPrefix = "eve-cyno/"

	// ServerName is the implementation name announced in the initialize handshake.
	ServerName = "eve-cyno"
)

Variables

This section is empty.

Functions

func Exposed

func Exposed(opts Options) []catalog.Tool

Exposed returns the tools a stdio-style server built with opts registers, in registry order: everything with All, else the public tier.

func HTTPHandler

func HTTPHandler(deps *tools.Deps, o HTTPOptions) http.Handler

HTTPHandler serves the tools over deps on the MCP streamable-HTTP transport, stateless: no session is kept between requests (every POST is self-contained and answered as one JSON body), so any replica can answer any request and an idle client costs nothing. The handler serves one URL; mount it where the clients are pointed (dataapi: {prefix}/mcp). GET (the server-initiated stream) and DELETE (end session) are 405 in this mode.

The tool set is chosen per request (see the package doc): public tools always, keyed tools when o.Keyed says so, disabled tools never. Each request gets its own server over its own copy of deps (tools.Deps.ForPublic) that carries the caller's X-Janice-Key, or no Janice key at all, never deps' own: the shared deps are not mutated, so concurrent callers cannot see each other's keys, and the key is not logged or kept.

func New

func New(deps *tools.Deps, opts Options) *mcp.Server

New builds a server over deps. deps may be nil (the SDE did not load): the tools are still listed and every call answers an isError result saying the layer is unavailable.

Types

type HTTPOptions

type HTTPOptions struct {
	// DisableLocalhostProtection turns off the SDK's DNS-rebinding guard, which answers
	// 403 to a request that reaches a loopback listener with a non-loopback Host header.
	// A service published through a reverse proxy or tunnel that connects over loopback
	// (cloudflared does) needs it off, or every real request is refused; a server only
	// ever reached directly on loopback should leave it on.
	DisableLocalhostProtection bool
	// Keyed reports whether the request's caller may use the keyed tier (it presented a
	// valid API key). Nil means nobody may: only the public tier is served.
	// Authentication itself is the embedding service's job (dataapi authenticates before
	// this handler runs and refuses an invalid key with 401).
	Keyed func(*http.Request) bool
	// Upstream, when set, is asked before every call that reads a live upstream (a call for
	// which catalog.Tool.SpendsUpstream is true; for plan_jump_route or get_production_chain that means a live
	// option is set) whether the request's caller is within its budget for it
	// (dataapi.UpstreamHook; the same limiter as the REST endpoint, so one budget covers both).
	// A refusal is an isError result: refusal as given when the hook gives one (dataapi's text
	// for a keyless connector caller, the same as its other refusals of such a caller), else the
	// per-caller text, starting "rate_limited", with the wait. Nil: no limit.
	Upstream func(r *http.Request, tool string) (ok bool, retryAfter time.Duration, refusal string)
	// ToolCalled, when set, is called once per tools/call with the HTTP request that carried
	// it and the tool name, before the tool runs (also for a call that is then refused or
	// fails). Nil: off. It must be cheap; the embedding service uses it for usage counting.
	ToolCalled func(r *http.Request, tool string)
	// KeyHint is appended to the server instructions for callers without an API key, after
	// a sentence saying the service is for trying out without one and naming the keyed tools
	// and the free-text fit search they do not get (how to get a key, ideally a URL).
	// Empty: no hint, and the instructions are the same for everyone.
	KeyHint string
	// AnonDailyCap is the requests per UTC day a client without an API key gets (the
	// embedding service's Config.AnonDailyCap); the keyless instructions state it. 0: the
	// instructions do not state a daily number. AnonDailyCapFor, when set, takes its place.
	AnonDailyCap int
	// AnonDailyCapFor, when set, returns the requests per UTC day the keyless caller of the
	// request gets (dataapi.AnonDailyCapsFor: a caller inside dataapi's connector ranges has
	// its own number), and the keyless instructions state that number instead of
	// AnonDailyCap; 0: no daily number. Nil: AnonDailyCap for everyone.
	//
	// inRanges is true for a caller inside Anthropic's connector ranges: its number counts per
	// address and holds for calls from those ranges, and the instructions say so; elsewhere is
	// then the number everyone else has (0: none to state). For other callers daily counts per
	// client and inRanges and elsewhere are false and 0.
	AnonDailyCapFor func(r *http.Request) (daily, elsewhere int, inRanges bool)
	// Timeout bounds one tool execution; zero means DefaultTimeout.
	Timeout time.Duration
	// Logger receives the transport's and the tools' diagnostics. Nil discards.
	Logger *slog.Logger
}

HTTPOptions configures HTTPHandler.

type Options

type Options struct {
	// All registers every tool, whatever its tier (keyed and disabled ones included), and
	// keeps the process's own keys (JANICE_API_KEY makes appraise_items a Janice
	// appraisal). Only for a process that serves its own user (cmd/mcp -all); never for an
	// internet-facing one. Without All the public tools run without any Janice key.
	All bool
	// Timeout bounds one tool execution; zero means DefaultTimeout.
	Timeout time.Duration
	// Logger receives the server's diagnostics (a recovered panic, a failed tool). Nil
	// discards. A stdio server must never log to stdout: that is the protocol channel.
	Logger *slog.Logger
}

Options configures a server.

Jump to

Keyboard shortcuts

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