@web-interact-mcp/client
Version:
A production-ready TypeScript library that transforms web applications into MCP (Model Context Protocol) servers with robust two-way communication via SignalR
102 lines • 3.58 kB
JavaScript
;
/**
* @fileoverview Core TypeScript type definitions for Web Interact MCP library
* @description This file contains all the type definitions used throughout the library
* @version 1.0.0
* @author Vijay Nirmal
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SuccessfulCallToolResult = exports.TransportType = exports.LogLevel = void 0;
exports.createSuccessResult = createSuccessResult;
exports.createErrorResult = createErrorResult;
exports.createFailedResult = createFailedResult;
/**
* Log levels for the logging system
*/
var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["TRACE"] = 0] = "TRACE";
LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG";
LogLevel[LogLevel["INFO"] = 2] = "INFO";
LogLevel[LogLevel["WARN"] = 3] = "WARN";
LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
LogLevel[LogLevel["FATAL"] = 5] = "FATAL";
LogLevel[LogLevel["OFF"] = 6] = "OFF";
})(LogLevel || (exports.LogLevel = LogLevel = {}));
/**
* Transport types for SignalR connection
*/
var TransportType;
(function (TransportType) {
/** Specifies the WebSockets transport. */
TransportType[TransportType["WebSockets"] = 1] = "WebSockets";
/** Specifies the Server-Sent Events transport. */
TransportType[TransportType["ServerSentEvents"] = 2] = "ServerSentEvents";
/** Specifies the Long Polling transport. */
TransportType[TransportType["LongPolling"] = 4] = "LongPolling";
})(TransportType || (exports.TransportType = TransportType = {}));
/**
* Helper function to create a successful CallToolResult
* @param content - The content for the result (string or ContentBlock array)
* @param structuredContent - Optional structured data
* @returns A successful CallToolResult
*/
function createSuccessResult(content, structuredContent) {
let contentArray;
if (!content) {
contentArray = [{ type: "text", text: "Operation completed successfully" }];
}
else if (typeof content === 'string') {
contentArray = [{ type: "text", text: content }];
}
else {
contentArray = content;
}
const result = {
content: contentArray,
isError: false
};
if (structuredContent !== undefined) {
result.structuredContent = structuredContent;
}
return result;
}
/**
* Helper function to create an error CallToolResult
* @param error - The error (Error object or string)
* @param structuredContent - Optional structured data
* @returns An error CallToolResult
*/
function createErrorResult(error, structuredContent) {
const errorMessage = error instanceof Error ? error.message : error;
const errorDetails = error instanceof Error ? {
name: error.name,
message: error.message,
stack: error.stack
} : { message: errorMessage };
const result = {
content: [{ type: "text", text: `Error: ${errorMessage}` }],
isError: true
};
if (structuredContent !== undefined) {
result.structuredContent = structuredContent;
}
else {
result.structuredContent = { error: errorDetails };
}
return result;
}
/**
* Default successful result constant
*/
exports.SuccessfulCallToolResult = createSuccessResult();
/**
* Helper function to create a failed result
* @param error - The error that occurred
* @returns A failed CallToolResult
*/
function createFailedResult(error) {
const errorObj = error instanceof Error ? error : new Error(String(error || 'Operation failed'));
return createErrorResult(errorObj);
}
//# sourceMappingURL=types.js.map