feat: Centralize MCP and Agentic type definitions and constants

This commit is contained in:
Aleksander Grygier 2025-12-29 10:35:46 +01:00
parent 94fef3508a
commit abc3764c9f
4 changed files with 64 additions and 67 deletions

View File

@ -0,0 +1,8 @@
import type { AgenticConfig } from '$lib/types/agentic';
export const DEFAULT_AGENTIC_CONFIG: AgenticConfig = {
enabled: true,
maxTurns: 100,
maxToolPreviewLines: 25,
filterReasoningAfterFirstTurn: true
} as const;

View File

@ -0,0 +1,9 @@
import type { ClientCapabilities, Implementation } from '$lib/types/mcp';
export const DEFAULT_MCP_CONFIG = {
protocolVersion: '2025-06-18',
capabilities: { tools: { listChanged: true } } as ClientCapabilities,
clientInfo: { name: 'llama-webui-mcp', version: 'dev' } as Implementation,
requestTimeoutSeconds: 300, // 5 minutes for long-running tools
connectionTimeoutMs: 10_000 // 10 seconds for connection establishment
} as const;

View File

@ -0,0 +1,9 @@
/**
* Agentic orchestration configuration.
*/
export interface AgenticConfig {
enabled: boolean;
maxTurns: number;
maxToolPreviewLines: number;
filterReasoningAfterFirstTurn: boolean;
}

View File

@ -1,32 +1,14 @@
export type JsonRpcId = number | string;
// Re-export SDK types that we use
import type {
ClientCapabilities as SDKClientCapabilities,
Implementation as SDKImplementation,
Tool,
CallToolResult
} from '@modelcontextprotocol/sdk/types.js';
export type JsonRpcRequest = {
jsonrpc: '2.0';
id: JsonRpcId;
method: string;
params?: Record<string, unknown>;
};
export type JsonRpcNotification = {
jsonrpc: '2.0';
method: string;
params?: Record<string, unknown>;
};
export type JsonRpcError = {
code: number;
message: string;
data?: unknown;
};
export type JsonRpcResponse = {
jsonrpc: '2.0';
id: JsonRpcId;
result?: Record<string, unknown>;
error?: JsonRpcError;
};
export type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse | JsonRpcNotification;
export type { Tool, CallToolResult };
export type ClientCapabilities = SDKClientCapabilities;
export type Implementation = SDKImplementation;
export class MCPError extends Error {
code: number;
@ -40,18 +22,6 @@ export class MCPError extends Error {
}
}
export type MCPToolInputSchema = Record<string, unknown>;
export type MCPToolDefinition = {
name: string;
description?: string;
inputSchema?: MCPToolInputSchema;
};
export type MCPServerCapabilities = Record<string, unknown>;
export type MCPClientCapabilities = Record<string, unknown>;
export type MCPTransportType = 'websocket' | 'streamable_http';
export type MCPServerConfig = {
@ -70,24 +40,19 @@ export type MCPServerConfig = {
/** Optional per-server request timeout override (ms). */
requestTimeoutMs?: number;
/** Optional per-server capability overrides. */
capabilities?: MCPClientCapabilities;
capabilities?: ClientCapabilities;
/** Optional pre-negotiated session identifier for Streamable HTTP transport. */
sessionId?: string;
};
export type MCPClientInfo = {
name: string;
version?: string;
};
export type MCPClientConfig = {
servers: Record<string, MCPServerConfig>;
/** Defaults to `2025-06-18`. */
protocolVersion?: string;
/** Default capabilities advertised during initialize. */
capabilities?: MCPClientCapabilities;
capabilities?: ClientCapabilities;
/** Custom client info to advertise. */
clientInfo?: MCPClientInfo;
clientInfo?: Implementation;
/** Request timeout when waiting for MCP responses (ms). Default: 30_000. */
requestTimeoutMs?: number;
};
@ -102,23 +67,29 @@ export type MCPToolCall = {
};
};
export type MCPToolResultContent =
| string
| {
type: 'text';
text: string;
}
| {
type: 'image';
data: string;
mimeType?: string;
}
| {
type: 'resource';
resource: Record<string, unknown>;
};
export type MCPToolsCallResult = {
content?: MCPToolResultContent | MCPToolResultContent[];
result?: unknown;
/**
* Raw MCP server configuration entry stored in settings.
*/
export type MCPServerSettingsEntry = {
id: string;
enabled: boolean;
url: string;
requestTimeoutSeconds: number;
};
/**
* Interface defining the public API for MCP clients.
* Both MCPClient (custom) and MCPClientSDK (official SDK) implement this interface.
*/
export interface IMCPClient {
initialize(): Promise<void>;
shutdown(): Promise<void>;
listTools(): string[];
getToolsDefinition(): Promise<
{
type: 'function';
function: { name: string; description?: string; parameters: Record<string, unknown> };
}[]
>;
execute(toolCall: MCPToolCall, abortSignal?: AbortSignal): Promise<string>;
}