mcpserver

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package mcpserver implements a Model Context Protocol server that exposes the redmine-cli API surface to MCP-compatible hosts (Claude Desktop, Claude Code, Cursor, etc.).

Code generated by go generate ./...; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHTTPHandler added in v2.5.0

func BuildHTTPHandler(client *api.Client, opts Options) http.Handler

BuildHTTPHandler constructs a streamable HTTP handler backed by the same MCP server definition used for stdio. It does not apply any auth or timeouts on its own — wrap it with WrapAuthToken and host it on a configured http.Server, or use BuildHTTPServer to get both in one call.

func BuildHTTPServer added in v2.5.0

func BuildHTTPServer(client *api.Client, opts Options, httpOpts HTTPOptions) *http.Server

BuildHTTPServer returns a fully configured *http.Server that exposes the MCP transport with hardened timeouts and an optional bearer-token gate. Caller is responsible for calling ListenAndServe / Shutdown.

func BuildServer

func BuildServer(client *api.Client, opts Options) *mcp.Server

BuildServer constructs an MCP server wired to the given Redmine API client. Tools that mutate remote state are only registered when opts.EnableWrites is true.

func IsKnownGroup added in v2.5.0

func IsKnownGroup(name string) bool

IsKnownGroup reports whether name matches one of the canonical groups.

func IsKnownTool added in v2.5.0

func IsKnownTool(name string) bool

IsKnownTool reports whether name matches a generated MCP tool name.

func NormalizeBindAddr added in v2.5.0

func NormalizeBindAddr(addr string) (normalized string, isLoopback bool)

NormalizeBindAddr applies the convenience defaults used by `redmine mcp serve --http <addr>`:

  • An empty string returns "" with isLoopback=false (caller skips HTTP).
  • An address starting with ":" (no host) is rewritten to bind on 127.0.0.1 only. Listening on all interfaces is opt-in, never the default.
  • Explicit hosts are returned unchanged. The boolean reports whether the resolved host is a loopback address; callers use it to decide whether to warn about exposing the server without an auth token.

Unparsable addresses are returned as-is with isLoopback=false; the bind will fail downstream with a clearer error.

func ParseTools added in v2.5.0

func ParseTools(names []string) ([]string, error)

ParseTools validates a list of tool names and returns the trimmed values. Empty entries are skipped so callers can pass values like "list_issues,,get_issue" without failing.

func ToolsByGroup added in v2.5.0

func ToolsByGroup() map[Group][]ToolDescriptor

ToolsByGroup buckets AllTools by group. Groups that are valid but have no tools are still included with an empty slice so callers can render every group.

func WrapAuthToken added in v2.5.0

func WrapAuthToken(h http.Handler, token string) http.Handler

WrapAuthToken gates h behind a constant-time bearer-token check. An empty token disables the gate (the handler is returned untouched). Failed checks respond 401 with a WWW-Authenticate header so MCP clients can retry with credentials.

Types

type FilterSpec added in v2.5.0

type FilterSpec struct {
	EnableGroups  []Group
	DisableGroups []Group
	EnableTools   []string
	DisableTools  []string
}

FilterSpec is the user-facing filter input collected from flags, env, and config. ResolveOptions merges it into the runtime maps used by Options.

type Group added in v2.5.0

type Group string

Group is the public identifier of a tool group exposed by the MCP server. Group names are part of the configuration surface (CLI flags, env vars, config file). Renaming a value is a breaking change.

Values mirror the //mcpgen:category directives in internal/ops so the generator can stamp each tool with its group at code-generation time.

const (
	GroupIssues      Group = "issues"
	GroupProjects    Group = "projects"
	GroupTime        Group = "time"
	GroupUsers       Group = "users"
	GroupGroups      Group = "groups"
	GroupSearch      Group = "search"
	GroupMeta        Group = "meta"
	GroupWiki        Group = "wiki"
	GroupMemberships Group = "memberships"
)

func AllGroups added in v2.5.0

func AllGroups() []Group

AllGroups returns the canonical list of groups in the order used by `redmine mcp list-groups` and the documentation.

func ParseGroup added in v2.5.0

func ParseGroup(name string) (Group, error)

ParseGroup validates a textual group name and returns the matching Group. Names are matched case-insensitively to be friendly to CLI input.

func ParseGroups added in v2.5.0

func ParseGroups(names []string) ([]Group, error)

ParseGroups parses a list of group names. Empty entries are skipped so callers can pass values like "issues,,wiki" without failing.

type HTTPOptions added in v2.5.0

type HTTPOptions struct {
	// Addr is the listen address passed to http.Server. Required.
	Addr string

	// AuthToken, when non-empty, requires every request to carry an
	// `Authorization: Bearer <token>` header that matches it. Compared in
	// constant time.
	AuthToken string

	// ReadHeaderTimeout, ReadTimeout, WriteTimeout, IdleTimeout override the
	// http.Server timeouts when non-zero. Defaults are applied when left as
	// the zero value.
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
}

HTTPOptions controls how BuildHTTPServer assembles the streamable HTTP transport. Zero values yield safe defaults suitable for a localhost bind.

type Options

type Options struct {
	// EnableWrites gates registration of mutating tools (create/update/delete
	// and similar). When false, those tools are not registered and therefore
	// never appear in tools/list.
	EnableWrites bool

	// Name is the server name advertised in the MCP initialize response.
	Name string

	// Version is the server version advertised in the MCP initialize response.
	Version string

	// EnabledGroups, if non-nil, restricts tool and resource registration to
	// the listed groups. A nil map means "all groups enabled" (the default).
	// An empty non-nil map means "no groups enabled".
	EnabledGroups map[Group]bool

	// EnabledTools, if non-nil, restricts tool registration to the listed
	// tool names within the enabled groups. A nil map means "no allow-list".
	EnabledTools map[string]bool

	// DisabledTools is a deny-list applied after the group and allow-list
	// filters. Names listed here are never registered.
	DisabledTools map[string]bool
}

Options controls how the MCP server is built.

func ResolveOptions added in v2.5.0

func ResolveOptions(opts Options, spec FilterSpec) Options

ResolveOptions builds the runtime Options filter maps from a FilterSpec.

Precedence rules:

  • EnableGroups, when non-empty, narrows the set to only those groups; when empty, all groups start enabled.
  • DisableGroups subtracts from whatever EnableGroups produced.
  • EnableTools, when non-empty, becomes the tool allow-list.
  • DisableTools is the tool deny-list, applied last.

Passing an empty FilterSpec is a no-op, preserving the default behavior of "all groups enabled, no per-tool filter".

type ToolDescriptor added in v2.5.0

type ToolDescriptor struct {
	Name        string
	Description string
	Group       Group
	Writes      bool
}

ToolDescriptor is a static description of an MCP tool. It is emitted by the code generator (zz_generated_tools.go) and consumed by the `mcp list-groups` discovery command.

func AllTools added in v2.5.0

func AllTools() []ToolDescriptor

AllTools returns the static catalog of every tool registered by the code generator, sorted by group and then name. The result reflects the contents of internal/ops/, not the current Options filter.

Jump to

Keyboard shortcuts

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