@sassoftware/vi-api
Version:
Types used in the SAS Visual Investigator API
115 lines (114 loc) • 4.86 kB
TypeScript
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
export interface PromptPlaceholderDefinition {
title: string;
type: "string" | "number" | "boolean" | "date" | "date-time";
enumNames?: string[];
required?: boolean;
}
export interface SimpleContextMenuPrompt {
name: string;
label: string;
parentLabel: string;
prompt: string;
placeholders?: Record<string, PromptPlaceholderDefinition>;
}
export interface ToolCategory {
id: string;
name: string;
description: string;
tools: string[];
}
export interface ToolCategoryApi {
getAll(): ToolCategory[];
get(id: string): ToolCategory | undefined;
create(category: ToolCategory): void;
update(id: string, category: ToolCategory): void;
delete(id: string): void;
}
export interface RemoteMCPServerConfig {
url: string;
}
export interface BaseMCPServerConfig {
name: string;
title?: string;
version: string;
}
export interface StreamableMCPServerConfig extends BaseMCPServerConfig, RemoteMCPServerConfig {
url: string;
name: string;
transport: "streamable";
headers?: Record<string, string>;
}
export interface LocalTransportConfig extends BaseMCPServerConfig {
name: string;
version: string;
transport: "local";
connect: (transport: Transport) => void;
}
/**
* This API provides functionality related to extension of MCP (Model Context Protocol) on the VI platform.
*
* Accessed from the window at `window.sas.vi.mcp`.
*
* @example window.sas.vi.mcp.registerMCPServer(newMcpConfig);
* @category API
*/
export interface McpApi {
/**
* @method
* @description Registers an MCP server with the VI platform using the provided configuration.
* @param config The configuration object for the MCP server to register.
* @returns A Promise that resolves when the server has been successfully registered.
*/
registerServer(config: StreamableMCPServerConfig | LocalTransportConfig): Promise<void>;
/**
* @method
* @description Deregisters an MCP server from the VI platform using the provided configuration.
* @param config The configuration object for the MCP server to deregister.
* @returns A Promise that resolves when the server has been successfully deregistered.
*/
deregisterServer(config: StreamableMCPServerConfig | LocalTransportConfig): Promise<void>;
/**
* @description Provides CRUD operations for managing tool categories.
* @example window.sas.vi.mcp.toolCategories.getAll();
* @example window.sas.vi.mcp.toolCategories.create({ id: "my_category", name: "My Category", description: "Custom tools", tools: ["my.tool"] });
*/
toolCategories: ToolCategoryApi;
/**
* @method
* @description Registers prompts with the VI platform that can be used in MCP interactions.
* @param prompts The array of prompts to add to the existing prompts on the system. If a prompt with the same label and parentLabel already exists, it will be ignored.
* @see SimpleContextMenuPrompt for more detail on prompt definitions.
* @example window.sas.vi.mcpApi.registerPrompts([{name: "my_prompt", label: "Example Prompt", parentLabel: "Example Prompts", prompt: "Tell me more about Visual Investigator."}]);
*/
registerPrompts(prompts: SimpleContextMenuPrompt[]): void;
/**
* @method
* @description Maps prompt names (previously registered via `registerPrompts`) to a route prefix.
* When the user navigates to a matching route the chat welcome screen will display those prompts.
* Uses longest-prefix matching, so `/search/advanced` will prefer a `/search/advanced` registration over `/search`.
* @param routePrefix The route URL prefix to match against (e.g. `"/home"`, `"/search"`).
* @param promptNames Names of prompts previously registered via `registerPrompts`.
* @example window.sas.vi.mcpApi.registerWelcomePrompts("/home", ["my_prompt", "another_prompt"]);
*/
registerWelcomePrompts(routePrefix: string, promptNames: string[]): void;
/**
* @method
* @description Sets the prompts shown on the chat welcome screen when no route-specific prompts match.
* Replaces any previously registered defaults.
* @param promptNames Names of prompts previously registered via `registerPrompts`.
* @example window.sas.vi.mcpApi.registerDefaultWelcomePrompts(["my_prompt", "another_prompt"]);
*/
registerDefaultWelcomePrompts(promptNames: string[]): void;
}
export type ValidElicitationDataTypes = number | string | boolean | undefined;
export type ElicitationDialogResponse = {
action: "accept";
data: {
values: Record<string, ValidElicitationDataTypes>;
promptResult?: string;
};
} | {
action: "decline" | "cancel";
data: undefined;
};