gomcp/internal/application/resources/provider.go
DmitrL-dev 694e32be26 refactor: rename identity to syntrex, add root orchestration and CI/CD
- Rename Go module: sentinel-community/gomcp -> syntrex/gomcp (50+ files)
- Rename npm package: sentinel-dashboard -> syntrex-dashboard
- Update Cargo.toml repository URL to syntrex/syntrex
- Update all doc references from DmitrL-dev/AISecurity to syntrex
- Add root Makefile (build-all, test-all, lint-all, clean-all)
- Add MIT LICENSE
- Add .editorconfig (Go/Rust/TS/C cross-language)
- Add .github/workflows/ci.yml (Go + Rust + Dashboard)
- Add dashboard next.config.ts and .env.example
- Clean ARCHITECTURE.md: remove brain/immune/strike/micro-swarm, fix 61->67 engines
2026-03-11 15:30:49 +10:00

64 lines
1.7 KiB
Go

// Package resources provides MCP resource implementations.
package resources
import (
"context"
"encoding/json"
"fmt"
"github.com/syntrex/gomcp/internal/domain/memory"
"github.com/syntrex/gomcp/internal/domain/session"
)
// Provider serves MCP resources (rlm://state, rlm://facts, rlm://stats).
type Provider struct {
factStore memory.FactStore
stateStore session.StateStore
}
// NewProvider creates a new resource Provider.
func NewProvider(factStore memory.FactStore, stateStore session.StateStore) *Provider {
return &Provider{
factStore: factStore,
stateStore: stateStore,
}
}
// GetState returns the current cognitive state for a session as JSON.
func (p *Provider) GetState(ctx context.Context, sessionID string) (string, error) {
state, _, err := p.stateStore.Load(ctx, sessionID, nil)
if err != nil {
return "", fmt.Errorf("load state: %w", err)
}
data, err := json.MarshalIndent(state, "", " ")
if err != nil {
return "", fmt.Errorf("marshal state: %w", err)
}
return string(data), nil
}
// GetFacts returns L0 facts as JSON.
func (p *Provider) GetFacts(ctx context.Context) (string, error) {
facts, err := p.factStore.ListByLevel(ctx, memory.LevelProject)
if err != nil {
return "", fmt.Errorf("list L0 facts: %w", err)
}
data, err := json.MarshalIndent(facts, "", " ")
if err != nil {
return "", fmt.Errorf("marshal facts: %w", err)
}
return string(data), nil
}
// GetStats returns fact store statistics as JSON.
func (p *Provider) GetStats(ctx context.Context) (string, error) {
stats, err := p.factStore.Stats(ctx)
if err != nil {
return "", fmt.Errorf("get stats: %w", err)
}
data, err := json.MarshalIndent(stats, "", " ")
if err != nil {
return "", fmt.Errorf("marshal stats: %w", err)
}
return string(data), nil
}