mcp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mcp implements the LLMSafeSpaces MCP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(client APIClient, defaultTimeout time.Duration) *server.MCPServer

NewServer creates a configured MCP server with all LLMSafeSpaces tools registered. Tools are workspace-centric — the sandbox layer is hidden from callers.

Types

type APIClient

type APIClient interface {
	CreateWorkspace(ctx context.Context, req CreateWorkspaceReq) (*WorkspaceResp, error)
	ActivateWorkspace(ctx context.Context, workspaceID string) (*ActivateResp, error)
	SuspendWorkspace(ctx context.Context, workspaceID string) error
	RefreshWorkspace(ctx context.Context, workspaceID string) (*RefreshWorkspaceResp, error)
	CreateSession(ctx context.Context, workspaceID string) (*SessionResp, error)
	GetHistory(ctx context.Context, workspaceID, sessionID string) ([]Message, error)
	SendMessage(ctx context.Context, workspaceID, sessionID, message string, timeout time.Duration) (string, error)

	// Agent input — question & permission replies (Epic 16 US-16.6)
	QuestionReply(ctx context.Context, workspaceID, requestID string, answers [][]string) error
	QuestionReject(ctx context.Context, workspaceID, requestID string) error
	PermissionReply(ctx context.Context, workspaceID, requestID, reply, message string) error

	// Credential management
	CreateCredential(ctx context.Context, req CreateCredentialReq) (*CredentialResp, error)
	ListCredentials(ctx context.Context) ([]CredentialResp, error)
	DeleteCredential(ctx context.Context, credentialID string) error
	BindCredential(ctx context.Context, workspaceID string, credentialIDs []string) error

	// Model management
	ListModels(ctx context.Context, workspaceID string) (json.RawMessage, error)
	SetModel(ctx context.Context, workspaceID, model string) error
}

APIClient defines the interface for calling the LLMSafeSpaces REST API. All operations are workspace-centric — the sandbox layer is internal.

type ActivateResp

type ActivateResp struct {
	Resumed   string `json:"resumed"`
	Suspended string `json:"suspended,omitempty"`
}

ActivateResp is the response from workspace activation.

type CreateCredentialReq

type CreateCredentialReq struct {
	Name        string `json:"name"`
	Kind        string `json:"kind"`
	Slug        string `json:"slug"`
	APIKey      string `json:"apiKey"`
	BaseURL     string `json:"baseURL,omitempty"`
	Default     string `json:"default,omitempty"`
	WorkspaceID string `json:"workspaceID,omitempty"` // if set, auto-binds after creation
}

CreateCredentialReq is the request for creating an LLM provider credential.

Epic 55 identity model: Kind is the SDK-class enum (openai, anthropic, openai_compatible, ...) that selects the adapter the agent loads; Slug is the per-owner unique identity that becomes the agent-config.json provider key. Both are required — the API's llm-provider value validator rejects a credential missing either.

type CreateWorkspaceReq

type CreateWorkspaceReq struct {
	Name    string `json:"name,omitempty"`
	Runtime string `json:"runtime"`
}

CreateWorkspaceReq is the request body for workspace creation.

type CredentialResp

type CredentialResp struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
}

CredentialResp is the response from credential operations.

type HTTPClient

type HTTPClient struct {
	BaseURL    string
	HTTPClient *http.Client
	APIKey     string
}

HTTPClient implements APIClient using HTTP calls to the LLMSafeSpaces API. It resolves workspace → sandbox internally for session/message operations.

func (*HTTPClient) ActivateWorkspace

func (c *HTTPClient) ActivateWorkspace(ctx context.Context, workspaceID string) (*ActivateResp, error)

func (*HTTPClient) BindCredential

func (c *HTTPClient) BindCredential(ctx context.Context, workspaceID string, credentialIDs []string) error

func (*HTTPClient) CreateCredential

func (c *HTTPClient) CreateCredential(ctx context.Context, req CreateCredentialReq) (*CredentialResp, error)

func (*HTTPClient) CreateSession

func (c *HTTPClient) CreateSession(ctx context.Context, workspaceID string) (*SessionResp, error)

CreateSession resolves workspace → sandbox, then creates a session via the proxy.

func (*HTTPClient) CreateWorkspace

func (c *HTTPClient) CreateWorkspace(ctx context.Context, req CreateWorkspaceReq) (*WorkspaceResp, error)

func (*HTTPClient) DeleteCredential

func (c *HTTPClient) DeleteCredential(ctx context.Context, credentialID string) error

func (*HTTPClient) GetHistory

func (c *HTTPClient) GetHistory(ctx context.Context, workspaceID, sessionID string) ([]Message, error)

func (*HTTPClient) ListCredentials

func (c *HTTPClient) ListCredentials(ctx context.Context) ([]CredentialResp, error)

func (*HTTPClient) ListModels

func (c *HTTPClient) ListModels(ctx context.Context, workspaceID string) (json.RawMessage, error)

func (*HTTPClient) PermissionReply

func (c *HTTPClient) PermissionReply(ctx context.Context, workspaceID, requestID, reply, message string) error

func (*HTTPClient) QuestionReject

func (c *HTTPClient) QuestionReject(ctx context.Context, workspaceID, requestID string) error

func (*HTTPClient) QuestionReply

func (c *HTTPClient) QuestionReply(ctx context.Context, workspaceID, requestID string, answers [][]string) error

func (*HTTPClient) RefreshWorkspace

func (c *HTTPClient) RefreshWorkspace(ctx context.Context, workspaceID string) (*RefreshWorkspaceResp, error)

func (*HTTPClient) SendMessage

func (c *HTTPClient) SendMessage(ctx context.Context, workspaceID, sessionID, message string, timeout time.Duration) (string, error)

SendMessage sends a prompt via prompt_async, then subscribes to SSE events until session.idle is received or timeout expires.

func (*HTTPClient) SetModel

func (c *HTTPClient) SetModel(ctx context.Context, workspaceID, model string) error

func (*HTTPClient) SuspendWorkspace

func (c *HTTPClient) SuspendWorkspace(ctx context.Context, workspaceID string) error

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a chat message in session history.

type RefreshWorkspaceResp

type RefreshWorkspaceResp struct {
	RestartGeneration int64 `json:"restartGeneration"`
}

RefreshWorkspaceResp is the response from workspace compute refresh.

type SessionResp

type SessionResp struct {
	ID string `json:"id"`
}

SessionResp is the response from session creation.

type WorkspaceResp

type WorkspaceResp struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Runtime string `json:"runtime"`
	Phase   string `json:"phase"`
}

WorkspaceResp is the response from workspace creation.

Jump to

Keyboard shortcuts

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