UNPKG

systemprompt-mcp-notion

Version:

A specialized Model Context Protocol (MCP) server that integrates Notion into your AI workflows. This server enables seamless access to Notion through MCP, allowing AI agents to interact with pages, databases, and comments.

77 lines (76 loc) 2.62 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(endpoint, method, data) { try { const response = await fetch(`${this.baseUrl}${endpoint}`, { method, headers: { "Content-Type": "application/json", "api-key": this.apiKey, }, body: data ? JSON.stringify(data) : undefined, }); let responseData; if (response.status !== 204) { try { responseData = await response.json(); } catch (e) { 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(responseData.message || "Invalid request parameters"); default: throw new Error(responseData?.message || `API request failed with status ${response.status}`); } } return responseData; } catch (error) { if (error.message) { throw error; } throw new Error("API request failed"); } } async getAllPrompts() { return this.request("/prompt", "GET"); } async listBlocks() { return this.request("/block", "GET"); } async getBlock(blockId) { return this.request(`/block/${blockId}`, "GET"); } }