mcpserver

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package mcpserver implements URI parameter filtering for MCP Resources

Package mcpserver implements MCP Resources functionality for serving feed resources.

Package mcpserver implements the Model Context Protocol server for serving RSS/Atom/JSON feeds.

Index

Constants

View Source
const (
	FeedListURI      = "feeds://all"
	FeedURI          = "feeds://feed/{feedId}"
	FeedItemsURI     = "feeds://feed/{feedId}/items"
	FeedMetaURI      = "feeds://feed/{feedId}/meta"
	ParameterDocsURI = "feeds://parameters"
)

URI template constants for different resource types

View Source
const (
	JSONMIMEType = "application/json"
)

MIME type constants

View Source
const ParameterDocsSummary = "" /* 317-byte string literal not displayed */

ParameterDocsSummary is the concise parameter documentation string used in resource descriptions

Variables

This section is empty.

Functions

func ApplyFilters added in v1.0.0

func ApplyFilters(items []*gofeed.Item, filters *FilterParams) []*gofeed.Item

ApplyFilters applies the filter parameters to a slice of feed items

Types

type AddFeedParams added in v1.1.0

type AddFeedParams struct {
	URL         string `json:"url"`
	Title       string `json:"title,omitempty"`
	Category    string `json:"category,omitempty"`
	Description string `json:"description,omitempty"`
}

AddFeedParams contains parameters for the add_feed tool.

type AllFeedsGetter added in v0.1.12

type AllFeedsGetter interface {
	GetAllFeeds(ctx context.Context) ([]*model.FeedResult, error)
}

AllFeedsGetter provides a method to retrieve all available feeds.

type Config

type Config struct {
	AllFeedsGetter     AllFeedsGetter
	FeedAndItemsGetter FeedAndItemsGetter
	DynamicFeedManager DynamicFeedManager // Optional: for runtime feed management
	Transport          model.Transport
}

Config holds the configuration for creating a new MCP server

type DynamicFeedManager added in v1.1.0

type DynamicFeedManager interface {
	// AddFeed adds a new feed at runtime and returns its information
	AddFeed(ctx context.Context, config FeedConfig) (*ManagedFeedInfo, error)

	// RemoveFeed removes a feed by ID
	RemoveFeed(ctx context.Context, feedID string) (*RemovedFeedInfo, error)

	// RemoveFeedByURL removes a feed by URL
	RemoveFeedByURL(ctx context.Context, url string) (*RemovedFeedInfo, error)

	// ListManagedFeeds returns all managed feeds with their metadata and status
	ListManagedFeeds(ctx context.Context) ([]ManagedFeedInfo, error)

	// RefreshFeed forces a refresh of a specific feed
	RefreshFeed(ctx context.Context, feedID string) (*RefreshFeedInfo, error)

	// UpdateFeedMetadata updates feed metadata (title, category, description)
	UpdateFeedMetadata(ctx context.Context, feedID string, metadata FeedMetadata) error

	// PauseFeed pauses fetching for a specific feed
	PauseFeed(ctx context.Context, feedID string) error

	// ResumeFeed resumes fetching for a paused feed
	ResumeFeed(ctx context.Context, feedID string) error
}

DynamicFeedManager provides methods for runtime feed management

type ExportFeedDataParams added in v1.4.0

type ExportFeedDataParams struct {
	FeedIDs    []string `json:"feedIds,omitempty"`    // Specific feeds to export (empty = all)
	Format     string   `json:"format"`               // json, csv, opml, rss, atom
	Since      string   `json:"since,omitempty"`      // ISO 8601 date
	Until      string   `json:"until,omitempty"`      // ISO 8601 date
	MaxItems   int      `json:"maxItems,omitempty"`   // Limit exported items
	IncludeAll bool     `json:"includeAll,omitempty"` // Include feed metadata
}

ExportFeedDataParams contains parameters for the export_feed_data tool.

type FeedAndItemsGetter added in v0.1.12

type FeedAndItemsGetter interface {
	GetFeedAndItems(ctx context.Context, id string) (*model.FeedAndItemsResult, error)
}

FeedAndItemsGetter provides a method to retrieve a specific feed with its items.

type FeedAndItemsResult

type FeedAndItemsResult = model.FeedAndItemsResult

FeedAndItemsResult represents a feed along with its items

type FeedConfig added in v1.1.0

type FeedConfig struct {
	URL         string `json:"url" description:"RSS/Atom/JSON feed URL"`
	Title       string `json:"title,omitempty" description:"Optional human-readable title"`
	Category    string `json:"category,omitempty" description:"Optional category for organization"`
	Description string `json:"description,omitempty" description:"Optional description"`
}

FeedConfig holds configuration for a new feed

type FeedMetadata added in v1.1.0

type FeedMetadata struct {
	Title       string `json:"title,omitempty" description:"Feed title"`
	Category    string `json:"category,omitempty" description:"Feed category"`
	Description string `json:"description,omitempty" description:"Feed description"`
}

FeedMetadata holds updatable metadata for a feed

type FeedSource added in v1.1.0

type FeedSource string

FeedSource indicates how a feed was added to the system

const (
	FeedSourceStartup FeedSource = "startup" // From CLI args
	FeedSourceOPML    FeedSource = "opml"    // From OPML file
	FeedSourceRuntime FeedSource = "runtime" // Added via tools
)

Feed source constants indicate how a feed was added to the system

type FetchLinkParams added in v0.3.0

type FetchLinkParams struct {
	URL string
}

FetchLinkParams contains parameters for the fetch_link tool.

type FilterParams added in v1.0.0

type FilterParams struct {
	// Existing filters
	Since    *time.Time // Filter items since this date
	Until    *time.Time // Filter items until this date
	Limit    *int       // Maximum number of items to return
	Offset   *int       // Number of items to skip (for pagination)
	Category string     // Filter by category/tag
	Author   string     // Filter by author
	Search   string     // Search in title/description

	// Enhanced filters (Phase 2)
	Language   string // Filter by language (en, es, fr, etc.)
	MinLength  *int   // Minimum content length
	MaxLength  *int   // Maximum content length
	HasMedia   *bool  // Only items with images/video
	Sentiment  string // positive, negative, neutral
	Duplicates *bool  // Include/exclude duplicate content
	SortBy     string // date, relevance, popularity
	Format     string // json, xml, html, markdown
}

FilterParams represents parsed URI parameters for filtering

func ParseURIParameters added in v1.0.0

func ParseURIParameters(resourceURI string) (*FilterParams, error)

ParseURIParameters extracts and validates filter parameters from a resource URI

type FilterSummary added in v1.0.0

type FilterSummary struct {
	TotalItems     int            `json:"total_items"`
	FilteredItems  int            `json:"filtered_items"`
	AppliedFilters map[string]any `json:"applied_filters,omitempty"`
}

FilterSummary provides information about applied filters and results

func CreateFilterSummary added in v1.0.0

func CreateFilterSummary(originalCount, filteredCount int, filters *FilterParams) *FilterSummary

CreateFilterSummary creates a summary of the filtering operation

type GetSyndicationFeedParams added in v0.3.0

type GetSyndicationFeedParams struct {
	ID string
}

GetSyndicationFeedParams contains parameters for the get_syndication_feed_items tool.

type ManagedFeedInfo added in v1.1.0

type ManagedFeedInfo struct {
	FeedID      string    `json:"feedId" description:"Unique feed identifier"`
	URL         string    `json:"url" description:"Feed URL"`
	Title       string    `json:"title" description:"Feed title"`
	Category    string    `json:"category,omitempty" description:"Feed category"`
	Description string    `json:"description,omitempty" description:"Feed description"`
	Status      string    `json:"status" description:"'active', 'error', 'paused'"`
	LastFetched time.Time `json:"lastFetched" description:"Last successful fetch time"`
	LastError   string    `json:"lastError,omitempty" description:"Most recent error message"`
	ItemCount   int       `json:"itemCount" description:"Current number of cached items"`
	AddedAt     time.Time `json:"addedAt" description:"When feed was added"`
	Source      string    `json:"source" description:"'runtime', 'startup', 'opml'"`
}

ManagedFeedInfo contains comprehensive information about a managed feed

type MergeFeedsParams added in v1.4.0

type MergeFeedsParams struct {
	FeedIDs     []string `json:"feedIds"`
	Title       string   `json:"title,omitempty"`
	MaxItems    int      `json:"maxItems,omitempty"`
	SortBy      string   `json:"sortBy,omitempty"`      // date, title, source
	Deduplicate bool     `json:"deduplicate,omitempty"` // Remove duplicate items
}

MergeFeedsParams contains parameters for the merge_feeds tool.

type MergedFeedResult added in v1.4.0

type MergedFeedResult struct {
	ID          string         `json:"id"`
	Title       string         `json:"title"`
	Description string         `json:"description"`
	Items       []*gofeed.Item `json:"items"`
	SourceFeeds []string       `json:"source_feeds"`
	TotalItems  int            `json:"total_items"`
	CreatedAt   time.Time      `json:"created_at"`
}

MergedFeedResult represents the result of merging multiple feeds.

type PromptResult added in v1.4.0

type PromptResult struct {
	Success   bool                   `json:"success"`
	Message   string                 `json:"message,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
	Error     string                 `json:"error,omitempty"`
	Generated time.Time              `json:"generated"`
}

PromptResult represents the structured result of a prompt execution

type RefreshFeedInfo added in v1.1.0

type RefreshFeedInfo struct {
	FeedID      string    `json:"feedId" description:"Feed ID that was refreshed"`
	Status      string    `json:"status" description:"'refreshed', 'error', 'not_found'"`
	ItemsAdded  int       `json:"itemsAdded" description:"Number of new items fetched"`
	LastFetched time.Time `json:"lastFetched" description:"Timestamp of refresh"`
	Error       string    `json:"error,omitempty" description:"Error message if refresh failed"`
}

RefreshFeedInfo contains information about a feed refresh operation

type RefreshFeedParams added in v1.4.0

type RefreshFeedParams struct {
	FeedID string `json:"feedId"`
}

RefreshFeedParams contains parameters for the refresh_feed tool.

type RemoveFeedParams added in v1.1.0

type RemoveFeedParams struct {
	FeedID string `json:"feedId,omitempty"`
	URL    string `json:"url,omitempty"`
}

RemoveFeedParams contains parameters for the remove_feed tool.

type RemovedFeedInfo added in v1.1.0

type RemovedFeedInfo struct {
	FeedID       string `json:"feedId" description:"ID of removed feed"`
	URL          string `json:"url" description:"URL of removed feed"`
	Title        string `json:"title" description:"Title of removed feed"`
	ItemsRemoved int    `json:"itemsRemoved" description:"Number of cached items removed"`
}

RemovedFeedInfo contains information about a removed feed

type ResourceCacheConfig added in v1.0.0

type ResourceCacheConfig struct {
	DefaultTTL      time.Duration // Default TTL for resource content
	FeedListTTL     time.Duration // TTL for feed list resources
	FeedItemsTTL    time.Duration // TTL for feed items resources
	FeedMetadataTTL time.Duration // TTL for feed metadata resources
	MaxCost         int64         // Maximum cache size in bytes
	NumCounters     int64         // Number of keys to track frequency
	BufferItems     int64         // Number of keys per Get buffer
}

ResourceCacheConfig holds resource-specific cache configuration

type ResourceCacheMetrics added in v1.0.0

type ResourceCacheMetrics struct {
	Hits             uint64
	Misses           uint64
	Evictions        uint64
	InvalidationHits uint64 // Cache invalidations triggered
	// contains filtered or unexported fields
}

ResourceCacheMetrics tracks cache performance metrics

type ResourceManager added in v1.0.0

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

ResourceManager handles MCP resource operations for feeds

func NewResourceManager added in v1.0.0

func NewResourceManager(feedStore AllFeedsGetter, feedAndItemsGetter FeedAndItemsGetter) *ResourceManager

NewResourceManager creates a new ResourceManager with configurable cache settings

func NewResourceManagerWithConfig added in v1.0.0

func NewResourceManagerWithConfig(feedStore AllFeedsGetter, feedAndItemsGetter FeedAndItemsGetter, config *ResourceCacheConfig) *ResourceManager

NewResourceManagerWithConfig creates a ResourceManager with custom cache configuration

func (*ResourceManager) AddCacheInvalidationHook added in v1.0.0

func (rm *ResourceManager) AddCacheInvalidationHook(hook func(uri string))

AddCacheInvalidationHook adds a hook function that gets called when cache is invalidated

func (*ResourceManager) CreateSession added in v1.0.0

func (rm *ResourceManager) CreateSession(sessionID string) *ResourceSession

CreateSession creates a new resource session

func (*ResourceManager) DetectResourceChanges added in v1.0.0

func (rm *ResourceManager) DetectResourceChanges(ctx context.Context) ([]string, error)

DetectResourceChanges checks for changes in feed content and returns URIs that have changed This is a placeholder implementation - in a production system, this would use timestamps, content hashes, or other change detection mechanisms

func (*ResourceManager) GetAllSubscribedURIs added in v1.0.0

func (rm *ResourceManager) GetAllSubscribedURIs() []string

GetAllSubscribedURIs returns all URIs that have at least one subscription

func (*ResourceManager) GetCacheMetrics added in v1.0.0

func (rm *ResourceManager) GetCacheMetrics() ResourceCacheMetrics

GetCacheMetrics returns current cache metrics

func (*ResourceManager) GetPendingNotifications added in v1.0.0

func (rm *ResourceManager) GetPendingNotifications() []string

GetPendingNotifications returns and clears all pending notification URIs

func (*ResourceManager) GetSession added in v1.0.0

func (rm *ResourceManager) GetSession(sessionID string) (*ResourceSession, bool)

GetSession retrieves a resource session

func (*ResourceManager) GetSubscribedSessions added in v1.0.0

func (rm *ResourceManager) GetSubscribedSessions(uri string) []string

GetSubscribedSessions returns all sessions subscribed to a given resource URI

func (*ResourceManager) InvalidateCache added in v1.0.0

func (rm *ResourceManager) InvalidateCache(ctx context.Context) error

InvalidateCache invalidates all cached resources and triggers notification hooks

func (*ResourceManager) InvalidateFeedCache added in v1.0.0

func (rm *ResourceManager) InvalidateFeedCache(ctx context.Context, feedID string) error

InvalidateFeedCache invalidates all cache entries for a specific feed

func (*ResourceManager) InvalidateResourceCache added in v1.0.0

func (rm *ResourceManager) InvalidateResourceCache(ctx context.Context, uri string) error

InvalidateResourceCache invalidates cache for a specific resource URI

func (*ResourceManager) ListResources added in v1.0.0

func (rm *ResourceManager) ListResources(ctx context.Context) ([]*mcp.Resource, error)

ListResources returns all available resources

func (*ResourceManager) MarkPendingNotification added in v1.0.0

func (rm *ResourceManager) MarkPendingNotification(uri string)

MarkPendingNotification marks a resource URI as needing notification

func (*ResourceManager) ReadResource added in v1.0.0

func (rm *ResourceManager) ReadResource(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)

ReadResource reads content for a specific resource

func (*ResourceManager) RemoveSession added in v1.0.0

func (rm *ResourceManager) RemoveSession(sessionID string)

RemoveSession removes a resource session

func (*ResourceManager) Subscribe added in v1.0.0

func (rm *ResourceManager) Subscribe(sessionID, uri string) error

Subscribe adds a subscription for the given session and resource URI

func (*ResourceManager) Unsubscribe added in v1.0.0

func (rm *ResourceManager) Unsubscribe(sessionID, uri string) error

Unsubscribe removes a subscription for the given session and resource URI

type ResourceSession added in v1.0.0

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

ResourceSession tracks subscription state for a client session

func (*ResourceSession) GetSubscriptionCount added in v1.0.0

func (rs *ResourceSession) GetSubscriptionCount() int

GetSubscriptionCount returns the number of active subscriptions for this session

func (*ResourceSession) GetSubscriptions added in v1.0.0

func (rs *ResourceSession) GetSubscriptions() []string

GetSubscriptions returns all active subscriptions

func (*ResourceSession) IsSubscribed added in v1.0.0

func (rs *ResourceSession) IsSubscribed(uri string) bool

IsSubscribed checks if a session is subscribed to a resource

func (*ResourceSession) Subscribe added in v1.0.0

func (rs *ResourceSession) Subscribe(uri string)

Subscribe adds a resource subscription for a session

func (*ResourceSession) Unsubscribe added in v1.0.0

func (rs *ResourceSession) Unsubscribe(uri string)

Unsubscribe removes a resource subscription for a session

type Server

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

Server implements an MCP server for serving syndication feeds

func NewServer

func NewServer(config Config) (*Server, error)

NewServer creates a new MCP server with the given configuration

func (*Server) CheckForResourceChanges added in v1.0.0

func (s *Server) CheckForResourceChanges(ctx context.Context, interval time.Duration, mcpServer *mcp.Server)

CheckForResourceChanges periodically checks for resource changes and sends notifications This is a background process that should be started when the server runs

func (*Server) NotifyResourceUpdated added in v1.0.0

func (s *Server) NotifyResourceUpdated(ctx context.Context, uri string, mcpServer *mcp.Server) error

NotifyResourceUpdated sends resource update notifications to subscribed clients using v0.3.0 SDK This method would be called when resource content changes are detected

func (*Server) Run

func (s *Server) Run(ctx context.Context) (err error)

Run starts the MCP server and handles client connections until context is canceled

Jump to

Keyboard shortcuts

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