systemprompt-mcp-gmail
Version:
A specialized Model Context Protocol (MCP) server that enables you to search, read, delete and send emails from your Gmail account, leveraging an AI Agent to help with each operation.
78 lines • 2.49 kB
JavaScript
export class SystemPromptService {
static instance = null;
baseUrl;
constructor() {
this.baseUrl = "https://api.systemprompt.io/v1";
}
static initialize() {
if (!SystemPromptService.instance) {
SystemPromptService.instance = new SystemPromptService();
}
}
static getInstance() {
if (!SystemPromptService.instance) {
throw new Error("SystemPromptService must be initialized first");
}
return SystemPromptService.instance;
}
static cleanup() {
SystemPromptService.instance = null;
}
async request(method, path, body) {
try {
const url = `${this.baseUrl}${path}`;
const response = await fetch(url, {
method,
headers: {
"Content-Type": "application/json",
"api-key": process.env.SYSTEMPROMPT_API_KEY,
},
body: body ? JSON.stringify(body) : undefined,
});
const text = await response.text();
let data;
try {
data = text ? JSON.parse(text) : undefined;
}
catch (error) {
throw new Error("Failed to parse API response");
}
if (!response.ok) {
switch (response.status) {
case 403:
throw new Error("Invalid API key");
case 404:
throw new Error("Resource not found - it may have been deleted");
default:
throw new Error(data?.message || "API request failed");
}
}
return data;
}
catch (error) {
if (error instanceof Error) {
throw error;
}
throw new Error("Failed to make API request");
}
}
async getAllPrompts() {
return this.request("GET", "/prompts");
}
async listBlocks() {
return this.request("GET", "/blocks");
}
async listAgents() {
return this.request("GET", "/agents");
}
async fetchUserStatus() {
return this.request("GET", "/user/status");
}
async deletePrompt(id) {
await this.request("DELETE", `/prompts/${id}`);
}
async deleteBlock(id) {
await this.request("DELETE", `/blocks/${id}`);
}
}
//# sourceMappingURL=systemprompt-service.js.map