configmcp

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package configmcp provides an in-process MCP server that exposes denkeeper's own configuration as tools callable by the agent. This allows an agent to create skills, list skills, add schedules, and list schedules without relying on text-directive extraction from LLM responses.

The server runs in-process using mcp.NewInMemoryTransports so no subprocess is spawned and latency is negligible. Approval for Config MCP tool calls is handled by the Engine's supervised tool-call flow, not by Config MCP itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySkillCreate added in v0.9.0

func ApplySkillCreate(agentSkillsDir string, appendSkill func(skill.Skill), logger interface {
	Info(string, ...any)
}, payload string) error

ApplySkillCreate writes the skill file to disk and appends it to the in-memory skill list.

func ApplySkillRename added in v0.22.1

func ApplySkillRename(agentSkillsDir string, removeSkill func(string) bool, appendSkill func(skill.Skill), logger interface {
	Info(string, ...any)
}, oldName string, payload string) error

ApplySkillRename writes the skill under its new name, removes the old file, and updates the in-memory skill list (remove old + append new).

func ApplySkillUpdate added in v0.9.0

func ApplySkillUpdate(agentSkillsDir string, updateSkill func(string, skill.Skill) bool, logger interface {
	Info(string, ...any)
}, name string, payload string) error

ApplySkillUpdate writes the updated skill file to disk and replaces it in the in-memory skill list.

func BuildScheduleJob added in v0.9.0

func BuildScheduleJob(cfg scheduler.Config, handleMsg func(context.Context, adapter.IncomingMessage) error, logger *slog.Logger, resolve ChannelResolver, opts BuildScheduleJobOpts) scheduler.JobFunc

BuildScheduleJob returns a JobFunc that dispatches a message when the schedule fires. Used by both schedule_add and schedule_update.

func BuildSchedulePayload added in v0.9.0

func BuildSchedulePayload(name, schedule, skillName, channel, sessionMode, sessionTier string, tags []string, enabled bool) (string, error)

BuildSchedulePayload marshals the schedule config to TOML for storage as approval payload.

func BuildSkillPayload added in v0.9.0

func BuildSkillPayload(name, description, version string, triggers []string, body string) string

BuildSkillPayload constructs the canonical +++ frontmatter + body format.

func EmitBroadcastFailure added in v0.28.0

func EmitBroadcastFailure(ctx context.Context, auditor audit.Emitter, broadcast bool, scheduleName, channel, conversationID string, succeeded, failed int, lastErr string)

EmitBroadcastFailure emits an audit event when broadcast delivery has failures. Safe to call with nil auditor or broadcast=false (no-op).

func MergeScheduleUpdate added in v0.9.0

func MergeScheduleUpdate(existing scheduler.Entry, input ScheduleUpdateInput) (scheduler.Config, string)

MergeScheduleUpdate applies partial updates from input onto an existing entry and returns the merged scheduler.Config plus the channel parts. Returns an error string if validation fails.

func MergeSkillFields added in v0.22.1

func MergeSkillFields(name string, existing skill.Skill, desc, ver *string, triggers []string, body *string) string

MergeSkillFields merges optional update fields with existing skill values and returns the payload built with the given name.

Types

type BuildScheduleJobOpts added in v0.28.0

type BuildScheduleJobOpts struct {
	// Auditor emits audit events for broadcast delivery outcomes. May be nil.
	Auditor audit.Emitter
}

BuildScheduleJobOpts holds parameters for BuildScheduleJob.

type ChannelResolveResult added in v0.28.0

type ChannelResolveResult struct {
	ConversationID string
	Bindings       []agent.AdapterBinding
	Broadcast      bool
}

ChannelResolveResult holds the result of resolving a named channel reference.

type ChannelResolver added in v0.28.0

type ChannelResolver func(name string) *ChannelResolveResult

ChannelResolver looks up a channel by name and returns the resolution result. Returns nil if the channel is not found or has no usable bindings.

type CostSummaryData added in v0.1.0

type CostSummaryData struct {
	GlobalCost    float64            `json:"global_cost"`
	MaxPerSession float64            `json:"max_per_session"`
	SessionCosts  map[string]float64 `json:"session_costs"`
}

CostSummaryData holds the data returned by the get_cost_summary tool.

type Deps

type Deps struct {
	// AgentName is used as the agent label in approval requests.
	AgentName string

	// AgentSkillsDir is the directory where new skill files are written.
	// If empty, skill_create is disabled.
	AgentSkillsDir string

	// GetSkills returns the agent's current in-memory skill list.
	GetSkills func() []skill.Skill

	// AppendSkill adds a skill to the agent's in-memory skill list.
	AppendSkill func(skill.Skill)

	// GetSkill returns a single skill by name and true, or zero value and false.
	// If nil, skill_get is disabled.
	GetSkill func(string) (skill.Skill, bool)

	// UpdateSkill replaces an existing skill by name. Returns false if not found.
	// If nil, skill_update is disabled.
	UpdateSkill func(string, skill.Skill) bool

	// RemoveSkill removes a skill by name. Returns false if not found.
	// Required for skill rename support.
	RemoveSkill func(string) bool

	// Sched is the shared scheduler instance. If nil, schedule_add is disabled.
	Sched *scheduler.Scheduler

	// HandleMessage is invoked by scheduled jobs to dispatch a message to the
	// agent. Typically the engine's HandleMessage method. If nil, schedule_add
	// is disabled.
	HandleMessage func(ctx context.Context, msg adapter.IncomingMessage) error

	// PermissionTier returns the current effective tier for the agent
	// ("autonomous", "supervised", or "restricted").
	PermissionTier func() string

	// LifecycleMgr is the shared tool/plugin lifecycle manager. If nil,
	// tool_add/tool_remove/plugin_add/plugin_remove are disabled.
	LifecycleMgr *tool.LifecycleManager

	// KVStore is the per-agent key-value store. If nil, kv_* tools are disabled.
	KVStore kv.Store

	// CostSummary returns a snapshot of cost tracking data. If nil,
	// get_cost_summary is disabled.
	CostSummary func() CostSummaryData

	// SetFallbacks replaces the LLM router's fallback rule list. If nil,
	// set_fallback is disabled.
	SetFallbacks func(rules []FallbackRuleInput)

	// BrowserProfiles is the shared browser profile service. If nil,
	// browser_profile_* tools are disabled.
	BrowserProfiles *browser.ProfileService

	// GetPersonaSection returns (content, editable, agentMutable, ok) for a
	// persona section. If nil, persona_get is disabled.
	GetPersonaSection func(section string) (string, bool, bool, bool)

	// SavePersonaSection writes content to a persona section. If nil,
	// persona_update is disabled.
	SavePersonaSection func(section, content string) error

	// AppendMemoryEntry adds a new entry to MEMORY.md separated by "---".
	// If nil, persona_memory_manage append is disabled.
	AppendMemoryEntry func(entry string) error

	// RemoveMemoryEntry removes a memory entry by heading from MEMORY.md.
	// If nil, persona_memory_manage remove is disabled.
	RemoveMemoryEntry func(heading string) error

	// ConfigPath is the path to the TOML config file. When non-empty,
	// schedule mutations are persisted to disk so they survive restarts.
	ConfigPath string

	// ChannelResolver resolves @channelname references in schedule channels.
	// If nil, @channelname is not supported for schedules created via Config MCP.
	ChannelResolver ChannelResolver

	// GetChannels returns all configured channels. Nil → channel tools not registered.
	GetChannels func() map[string]*agent.Channel

	// SetActiveChannel switches active channel for an adapter key.
	// Nil → channel_switch not registered.
	SetActiveChannel func(ctx context.Context, adapterKey, channelName string) error

	// ActiveChannelsForChannel returns adapter keys currently active on a channel.
	ActiveChannelsForChannel func(channelName string) []string

	// Auditor emits audit events. If nil, broadcast delivery audit is disabled.
	Auditor audit.Emitter

	Logger *slog.Logger
}

Deps holds the runtime dependencies injected into the Config MCP server. All fields are required unless noted.

type FallbackRuleInput added in v0.1.0

type FallbackRuleInput struct {
	Trigger    string `json:"trigger"`
	Action     string `json:"action"`
	Provider   string `json:"provider,omitempty"`
	Model      string `json:"model,omitempty"`
	Scope      string `json:"scope,omitempty"`
	MaxRetries int    `json:"max_retries,omitempty"`
	Backoff    string `json:"backoff,omitempty"`
}

FallbackRuleInput describes a single fallback rule as provided by the agent.

type ScheduleUpdateInput added in v0.9.0

type ScheduleUpdateInput struct {
	Name        string   `json:"name"`
	Schedule    *string  `json:"schedule"`
	Skill       *string  `json:"skill"`
	Channel     *string  `json:"channel"`
	SessionMode *string  `json:"session_mode"`
	SessionTier *string  `json:"session_tier"`
	Tags        []string `json:"tags"`
	Enabled     *bool    `json:"enabled"`
}

ScheduleUpdateInput holds the parsed arguments for schedule_update. ScheduleUpdateInput holds the parsed arguments for schedule_update. Exported so the REST API can reuse it.

type Server

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

Server is the in-process Config MCP server for a single agent. Construct with New, then call Connect to obtain a *mcp.ClientSession that can be registered into a tool.Manager.

func New

func New(deps Deps) *Server

New constructs and wires the Config MCP server. Tools are registered immediately; the server does not begin serving until Connect is called.

func (*Server) Connect

func (s *Server) Connect(ctx context.Context) (*mcp.ClientSession, error)

Connect starts the in-process server goroutine and returns a *mcp.ClientSession ready to be passed to tool.Manager.RegisterSession. The server runs until ctx is cancelled.

Jump to

Keyboard shortcuts

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