UNPKG

systemprompt-mcp-core

Version:

A specialized Model Context Protocol (MCP) server that integrates with systemprompt.io to provide powerful prompt management capabilities. This server enables seamless creation, management, and versioning of system prompts and agents through MCP. It works

118 lines 3.89 kB
export class SystemPromptService { static instance = null; apiKey; baseUrl; constructor(apiKey, baseUrl) { if (!apiKey) { throw new Error("API key is required"); } this.apiKey = apiKey; this.baseUrl = baseUrl || "https://api.systemprompt.io/v1"; } static initialize(apiKey, baseUrl) { SystemPromptService.instance = new SystemPromptService(apiKey, baseUrl); } static getInstance() { if (!SystemPromptService.instance) { throw new Error("SystemPromptService must be initialized with an API key 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": this.apiKey, }, 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"); case 409: throw new Error("Resource conflict - it may have been edited"); case 400: throw new Error("Invalid data"); default: throw new Error(data?.message || "API request failed"); } } if (response.status === 204) { return undefined; } return data; } catch (error) { if (error instanceof Error) { if (error.message === "Failed to fetch") { throw new Error("API request failed"); } throw error; } throw new Error("API request failed"); } } async getAllPrompts() { return this.request("GET", "/prompt"); } async createPrompt(data) { return this.request("POST", "/prompt", data); } async editPrompt(uuid, data) { return this.request("PUT", `/prompt/${uuid}`, data); } async deletePrompt(uuid) { return this.request("DELETE", `/prompt/${uuid}`); } async createBlock(data) { return this.request("POST", "/block", data); } async editBlock(uuid, data) { return this.request("PUT", `/block/${uuid}`, data); } async listBlocks() { return this.request("GET", "/block"); } async getBlock(blockId) { return this.request("GET", `/block/${blockId}`); } async getAgent(agentId) { return this.request("GET", `/agent/${agentId}`); } async listAgents() { return this.request("GET", "/agent"); } async createAgent(data) { return this.request("POST", "/agent", data); } async editAgent(uuid, data) { return this.request("PUT", `/agent/${uuid}`, data); } async deleteBlock(uuid) { return this.request("DELETE", `/block/${uuid}`); } async fetchUserStatus() { return this.request("GET", "/user/me"); } async editUser(uuid, data) { return this.request("PATCH", `/user/${uuid}`, data); } } //# sourceMappingURL=systemprompt-service.js.map