mcp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package mcp provides functionality for managing Model Context Protocol (MCP) clients within the Seshat application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(ctx context.Context) error

Close closes all MCP clients. This should be called during application shutdown.

func DisableSingle

func DisableSingle(cfg *config.ConfigStore, name string) error

DisableSingle disables and closes a single MCP client by name.

func GetPromptMessages

func GetPromptMessages(ctx context.Context, cfg *config.ConfigStore, clientName, promptName string, args map[string]string) ([]string, error)

GetPromptMessages retrieves the content of an MCP prompt with the given arguments.

func GetStates

func GetStates() map[string]ClientInfo

GetStates returns the current state of all MCP clients

func Initialize

func Initialize(ctx context.Context, permissions permission.Service, cfg *config.ConfigStore)

Initialize initializes MCP clients based on the provided configuration.

func InitializeSingle

func InitializeSingle(ctx context.Context, name string, cfg *config.ConfigStore) error

InitializeSingle initializes a single MCP client by name.

func Prompts

func Prompts() iter.Seq2[string, []*Prompt]

Prompts returns all available MCP prompts.

func RefreshPrompts

func RefreshPrompts(ctx context.Context, name string)

RefreshPrompts gets the updated list of prompts from the MCP and updates the global state.

func RefreshResources

func RefreshResources(ctx context.Context, name string)

RefreshResources gets the updated list of resources from the MCP and updates the global state.

func RefreshTools

func RefreshTools(ctx context.Context, cfg *config.ConfigStore, name string)

RefreshTools gets the updated list of tools from the MCP and updates the global state.

func Resources

func Resources() iter.Seq2[string, []*Resource]

Resources returns all available MCP resources.

func SubscribeEvents

func SubscribeEvents(ctx context.Context) <-chan pubsub.Event[Event]

SubscribeEvents returns a channel for MCP events

func Tools

func Tools() iter.Seq2[string, []*Tool]

Tools returns all available MCP tools.

func WaitForInit

func WaitForInit(ctx context.Context) error

WaitForInit blocks until MCP initialization is complete. If Initialize was never called, this returns immediately.

Types

type ClientInfo

type ClientInfo struct {
	Name        string
	State       State
	Error       error
	Client      *ClientSession
	Counts      Counts
	ConnectedAt time.Time
}

ClientInfo holds information about an MCP client's state

func GetState

func GetState(name string) (ClientInfo, bool)

GetState returns the state of a specific MCP client

type ClientSession

type ClientSession struct {
	*mcp.ClientSession
	// contains filtered or unexported fields
}

ClientSession wraps an mcp.ClientSession with a context cancel function so that the context created during session establishment is properly cleaned up on close.

func (*ClientSession) Close

func (s *ClientSession) Close() error

Close cancels the session context and then closes the underlying session.

type Counts

type Counts struct {
	Tools     int
	Prompts   int
	Resources int
}

Counts number of available tools, prompts, etc.

type Event

type Event struct {
	Type   EventType
	Name   string
	State  State
	Error  error
	Counts Counts
}

Event represents an event in the MCP system

type EventType

type EventType uint

EventType represents the type of MCP event

const (
	EventStateChanged EventType = iota
	EventToolsListChanged
	EventPromptsListChanged
	EventResourcesListChanged
)

type Prompt

type Prompt = mcp.Prompt

type Resource

type Resource = mcp.Resource

func ListResources

func ListResources(ctx context.Context, cfg *config.ConfigStore, name string) ([]*Resource, error)

ListResources returns the current resources for an MCP server.

type ResourceContents

type ResourceContents = mcp.ResourceContents

func ReadResource

func ReadResource(ctx context.Context, cfg *config.ConfigStore, name, uri string) ([]*ResourceContents, error)

ReadResource reads the contents of a resource from an MCP server.

type State

type State int

State represents the current state of an MCP client

const (
	StateDisabled State = iota
	StateStarting
	StateConnected
	StateError
)

func (State) String

func (s State) String() string

type Tool

type Tool = mcp.Tool

type ToolResult

type ToolResult struct {
	Type      string
	Content   string
	Data      []byte
	MediaType string
}

ToolResult represents the result of running an MCP tool.

func RunTool

func RunTool(ctx context.Context, cfg *config.ConfigStore, name, toolName string, input string) (ToolResult, error)

RunTool runs an MCP tool with the given input parameters.

Jump to

Keyboard shortcuts

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