winston-ai-mcp
Version:
Model Context Protocol (MCP) Server for Winston AI - the most accurate AI Detector. Detect AI-generated content, plagiarism, and compare texts with ease.
120 lines • 5.74 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WinstonAiClient = void 0;
const axios_1 = __importDefault(require("axios"));
const WINSTONAI_BASE_API_URL = "https://api.gowinston.ai";
class WinstonAiClient {
constructor(apiKey) {
this.apiKey = apiKey;
}
isApiKeyInvalid() {
return !this.apiKey || this.apiKey.length === 0 || this.apiKey.toLowerCase().includes("api");
}
request(route, body) {
return __awaiter(this, void 0, void 0, function* () {
const config = {
method: "post",
maxBodyLength: Infinity,
url: `${WINSTONAI_BASE_API_URL}${route}`,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`,
},
data: body,
};
const request = yield axios_1.default.request(config);
return request.data;
});
}
assembleTextCompareResponse(result) {
if ('error' in result || !result.similarity_score) {
return JSON.stringify(result, null, 2);
}
const global_similarity_score = result.similarity_score;
const first_text_similarity_score = result.first_text.similarity_percentage;
const second_text_similarity_score = result.second_text.similarity_percentage;
let response = `The similarity score between the two texts is ${global_similarity_score}%. The first text is ${first_text_similarity_score}% similar to the second text. The second text is ${second_text_similarity_score}% similar to the first text.`;
response += "\n\n Full API Response : \n\n" + JSON.stringify(result, null, 2);
return response;
}
assemblePlagiarismResponse(r) {
if ('error' in r || !r.result) {
return JSON.stringify(r, null, 2);
}
const result = r.result;
const globalScore = result.score;
let response = `The plagiarism detection tool Winston AI has detected the text as ${globalScore}% plagiarism.`;
let sources = r.sources
.filter((source) => source.canAccess)
.slice(0, 2)
.map((source) => {
return `"""${source.url}""" with a plagiarism score of ${source.score}% plagiarism`;
});
if (sources.length > 0) {
response += ` The main plagiarized sources are ${sources.join(", ")}`;
}
// Return all the sources in the customResponse, but dont return the plagiarismFound object
const sourcesWithoutPlagiarism = r.sources.map((source) => {
const customSource = source;
delete customSource.plagiarismFound;
return customSource;
});
const customResponse = {
status: r.status,
scanInformation: r.scanInformation,
result: r.result,
sources: sourcesWithoutPlagiarism,
citations: r.citations,
credits_used: r.credits_used,
credits_remaining: r.credits_remaining,
};
response += "\n\n API Response : \n\n" + JSON.stringify(customResponse, null, 2);
return response;
}
assembleAiTextDetectorResponse(result) {
if ('error' in result || !result.score) {
return JSON.stringify(result, null, 2);
}
const humanScore = result.score;
const aiScore = 100 - humanScore;
let response = `The AI detector Winston AI has detected the text as ${humanScore}% human-written. Which means that the text is ${aiScore}% likely to be written by an AI.`;
// Return the 2 most AI sentences
const ss = result.sentences
.sort((a, b) => b.score - a.score)
.slice(0, 2)
.map((s) => {
return `"""${s.text}""" with a score of ${s.score}%`;
});
if (ss.length > 0) {
response += `The most AI sentences are ${ss.join(", ")}.`;
}
response += "\n\n Full API Response : \n\n" + JSON.stringify(result, null, 2);
return response;
}
assembleAiImageDetectorResponse(result) {
if ('error' in result || !result.human_probability) {
return JSON.stringify(result, null, 2);
}
let response = "";
// Keep only 2 decimals
const humanPercentage = Number((result.human_probability * 100).toFixed(2));
const aiPercentage = Number((result.ai_probability * 100).toFixed(2));
response += `The AI detector Winston AI has detected the image as ${humanPercentage}% human. Which means that the image is ${aiPercentage}% likely to be AI generated.`;
response += "\n\n Full API Response : \n\n" + JSON.stringify(result, null, 2);
return response;
}
}
exports.WinstonAiClient = WinstonAiClient;
//# sourceMappingURL=WinstonAIClient.js.map