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
707 lines (706 loc) • 21.9 kB
JavaScript
export const NOTION_CALLBACKS = {
CREATE_PAGE: "systemprompt_create_notion_page_complex",
EDIT_PAGE: "systemprompt_edit_notion_page_complex",
};
export const ERROR_MESSAGES = {
INVALID_REQUEST: {
MISSING_MESSAGES: "Invalid request: missing messages",
MISSING_PARAMS: "Request must have params",
EMPTY_MESSAGES: "Request must have at least one message",
},
VALIDATION: {
INVALID_ROLE: 'Message role must be either "user" or "assistant"',
MISSING_CONTENT: "Message must have a content object",
INVALID_CONTENT_TYPE: 'Content type must be either "text" or "image"',
INVALID_TEXT_CONTENT: "Text content must have a string text field",
INVALID_IMAGE_DATA: "Image content must have a base64 data field",
INVALID_IMAGE_MIME: "Image content must have a mimeType field",
INVALID_MAX_TOKENS: "maxTokens must be a positive number",
INVALID_TEMPERATURE: "temperature must be a number between 0 and 1",
INVALID_INCLUDE_CONTEXT: 'includeContext must be "none", "thisServer", or "allServers"',
INVALID_MODEL_PRIORITY: "Model preference priorities must be numbers between 0 and 1",
},
SAMPLING: {
EXPECTED_TEXT: "Expected text response from LLM",
UNKNOWN_CALLBACK: "Unknown callback type: ",
REQUEST_FAILED: "Sampling request failed: ",
},
};
export const VALID_ROLES = ["user", "assistant"];
export const VALID_CONTENT_TYPES = ["text", "image", "resource"];
export const VALID_INCLUDE_CONTEXT = [
"none",
"thisServer",
"allServers",
];
export const XML_TAGS = {
REQUEST_PARAMS_CLOSE: "</requestParams>",
EXISTING_CONTENT_TEMPLATE: (content) => `</requestParams>
<existingContent>
${content}
</existingContent>`,
};
// Base schema for rich text content
export const richTextSchema = {
type: "array",
items: {
type: "object",
properties: {
type: { type: "string", enum: ["text"] },
text: {
type: "object",
properties: {
content: { type: "string" },
link: {
type: ["object", "null"],
properties: {
url: { type: "string" },
},
},
},
required: ["content"],
},
annotations: {
type: "object",
properties: {
bold: { type: "boolean" },
italic: { type: "boolean" },
strikethrough: { type: "boolean" },
underline: { type: "boolean" },
code: { type: "boolean" },
color: { type: "string" },
},
},
plain_text: { type: "string" },
href: { type: ["string", "null"] },
},
required: ["type", "text"],
},
};
// Title property schema
export const titlePropertySchema = {
type: "object",
properties: {
title: richTextSchema,
},
required: ["title"],
};
// Text property schema
export const textPropertySchema = {
type: "object",
properties: {
rich_text: richTextSchema,
},
required: ["rich_text"],
};
// Number property schema
export const numberPropertySchema = {
type: "object",
properties: {
number: { type: ["number", "null"] },
},
required: ["number"],
};
// Select property schema
export const selectPropertySchema = {
type: "object",
properties: {
select: {
type: ["object", "null"],
properties: {
id: { type: "string" },
name: { type: "string" },
color: { type: "string" },
},
},
},
required: ["select"],
};
// Multi-select property schema
export const multiSelectPropertySchema = {
type: "object",
properties: {
multi_select: {
type: "array",
items: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
color: { type: "string" },
},
required: ["id", "name"],
},
},
},
required: ["multi_select"],
};
// Date property schema
export const datePropertySchema = {
type: "object",
properties: {
date: {
type: ["object", "null"],
properties: {
start: { type: "string", format: "date-time" },
end: { type: ["string", "null"], format: "date-time" },
time_zone: { type: ["string", "null"] },
},
required: ["start"],
},
},
required: ["date"],
};
// People property schema
export const peoplePropertySchema = {
type: "object",
properties: {
people: {
type: "array",
items: {
type: "object",
properties: {
id: { type: "string" },
object: { type: "string", enum: ["user"] },
},
required: ["id", "object"],
},
},
},
required: ["people"],
};
// Files property schema
export const filesPropertySchema = {
type: "object",
properties: {
files: {
type: "array",
items: {
type: "object",
properties: {
name: { type: "string" },
type: { type: "string", enum: ["file", "external"] },
file: {
type: "object",
properties: {
url: { type: "string" },
expiry_time: { type: "string", format: "date-time" },
},
},
external: {
type: "object",
properties: {
url: { type: "string" },
},
},
},
required: ["name", "type"],
},
},
},
required: ["files"],
};
// Checkbox property schema
export const checkboxPropertySchema = {
type: "object",
properties: {
checkbox: { type: "boolean" },
},
required: ["checkbox"],
};
// URL property schema
export const urlPropertySchema = {
type: "object",
properties: {
url: { type: ["string", "null"] },
},
required: ["url"],
};
// Email property schema
export const emailPropertySchema = {
type: "object",
properties: {
email: { type: ["string", "null"] },
},
required: ["email"],
};
// Phone number property schema
export const phoneNumberPropertySchema = {
type: "object",
properties: {
phone_number: { type: ["string", "null"] },
},
required: ["phone_number"],
};
// Formula property schema
export const formulaPropertySchema = {
type: "object",
properties: {
formula: {
type: "object",
properties: {
type: { type: "string", enum: ["string", "number", "boolean", "date"] },
string: { type: "string" },
number: { type: "number" },
boolean: { type: "boolean" },
date: {
type: "object",
properties: {
start: { type: "string", format: "date-time" },
end: { type: ["string", "null"], format: "date-time" },
},
},
},
required: ["type"],
},
},
required: ["formula"],
};
// Relation property schema
export const relationPropertySchema = {
type: "object",
properties: {
relation: {
type: "array",
items: {
type: "object",
properties: {
id: { type: "string" },
},
required: ["id"],
},
},
},
required: ["relation"],
};
// Rollup property schema
export const rollupPropertySchema = {
type: "object",
properties: {
rollup: {
type: "object",
properties: {
type: { type: "string", enum: ["number", "date", "array"] },
number: { type: "number" },
date: {
type: "object",
properties: {
start: { type: "string", format: "date-time" },
end: { type: ["string", "null"], format: "date-time" },
},
},
array: {
type: "array",
items: {
type: "object",
// The items can be of any property type
additionalProperties: true,
},
},
},
required: ["type"],
},
},
required: ["rollup"],
};
// Created time property schema
export const createdTimePropertySchema = {
type: "object",
properties: {
created_time: { type: "string", format: "date-time" },
},
required: ["created_time"],
};
// Created by property schema
export const createdByPropertySchema = {
type: "object",
properties: {
created_by: {
type: "object",
properties: {
id: { type: "string" },
object: { type: "string", enum: ["user"] },
},
required: ["id", "object"],
},
},
required: ["created_by"],
};
// Last edited time property schema
export const lastEditedTimePropertySchema = {
type: "object",
properties: {
last_edited_time: { type: "string", format: "date-time" },
},
required: ["last_edited_time"],
};
// Last edited by property schema
export const lastEditedByPropertySchema = {
type: "object",
properties: {
last_edited_by: {
type: "object",
properties: {
id: { type: "string" },
object: { type: "string", enum: ["user"] },
},
required: ["id", "object"],
},
},
required: ["last_edited_by"],
};
// Combined property schemas map
export const notionPropertySchemas = {
title: titlePropertySchema,
rich_text: textPropertySchema,
number: numberPropertySchema,
select: selectPropertySchema,
multi_select: multiSelectPropertySchema,
date: datePropertySchema,
people: peoplePropertySchema,
files: filesPropertySchema,
checkbox: checkboxPropertySchema,
url: urlPropertySchema,
email: emailPropertySchema,
phone_number: phoneNumberPropertySchema,
formula: formulaPropertySchema,
relation: relationPropertySchema,
rollup: rollupPropertySchema,
created_time: createdTimePropertySchema,
created_by: createdByPropertySchema,
last_edited_time: lastEditedTimePropertySchema,
last_edited_by: lastEditedByPropertySchema,
};
// Common schema definitions for rich text blocks
const richTextBlockDef = {
type: "object",
required: ["rich_text"],
additionalProperties: false,
properties: {
rich_text: { $ref: "#/definitions/richTextArray" },
},
};
const richTextArrayDef = {
type: "array",
items: {
type: "object",
required: ["text"],
additionalProperties: false,
properties: {
text: {
type: "object",
required: ["content"],
additionalProperties: false,
properties: {
content: {
type: "string",
description: "The text content",
},
},
},
},
},
};
// Base schema for page content blocks
const pageBlocksSchema = {
type: "array",
items: {
type: "object",
required: ["object", "type"],
properties: {
object: {
type: "string",
const: "block",
},
type: {
type: "string",
enum: [
"paragraph",
"heading_1",
"heading_2",
"heading_3",
"bulleted_list_item",
"numbered_list_item",
"to_do",
"toggle",
"code",
"quote",
],
},
},
allOf: [
{
if: {
type: "object",
properties: {
type: { const: "paragraph" },
},
},
then: {
type: "object",
required: ["paragraph"],
properties: {
paragraph: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "heading_1" },
},
},
then: {
type: "object",
required: ["heading_1"],
properties: {
heading_1: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "heading_2" },
},
},
then: {
type: "object",
required: ["heading_2"],
properties: {
heading_2: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "heading_3" },
},
},
then: {
type: "object",
required: ["heading_3"],
properties: {
heading_3: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "bulleted_list_item" },
},
},
then: {
type: "object",
required: ["bulleted_list_item"],
properties: {
bulleted_list_item: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "numbered_list_item" },
},
},
then: {
type: "object",
required: ["numbered_list_item"],
properties: {
numbered_list_item: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "to_do" },
},
},
then: {
type: "object",
required: ["to_do"],
properties: {
to_do: {
type: "object",
required: ["rich_text", "checked"],
additionalProperties: false,
properties: {
rich_text: { $ref: "#/definitions/richTextArray" },
checked: {
type: "boolean",
description: "Whether the to-do is checked",
},
},
},
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "toggle" },
},
},
then: {
type: "object",
required: ["toggle"],
properties: {
toggle: { $ref: "#/definitions/richTextBlock" },
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "code" },
},
},
then: {
type: "object",
required: ["code"],
properties: {
code: {
type: "object",
required: ["rich_text", "language"],
additionalProperties: false,
properties: {
rich_text: { $ref: "#/definitions/richTextArray" },
language: {
type: "string",
description: "The programming language of the code block",
},
},
},
},
},
},
{
if: {
type: "object",
properties: {
type: { const: "quote" },
},
},
then: {
type: "object",
required: ["quote"],
properties: {
quote: { $ref: "#/definitions/richTextBlock" },
},
},
},
],
},
};
// Schema for creating new pages
export const NOTION_PAGE_CREATOR_SCHEMA = {
type: "object",
required: ["parent", "properties"],
additionalProperties: false,
properties: {
parent: {
type: "object",
properties: {
database_id: {
type: "string",
description: "The ID of the database to create the page in",
},
},
required: ["database_id"],
additionalProperties: false,
},
properties: {
type: "object",
required: ["title"],
additionalProperties: false,
properties: {
title: {
type: "array",
items: {
type: "object",
required: ["text"],
additionalProperties: false,
properties: {
text: {
type: "object",
required: ["content"],
additionalProperties: false,
properties: {
content: {
type: "string",
description: "The title text of the page",
},
},
},
},
},
},
},
},
children: pageBlocksSchema,
},
definitions: {
richTextBlock: richTextBlockDef,
richTextArray: richTextArrayDef,
},
};
// Schema for editing existing pages
export const NOTION_PAGE_EDITOR_SCHEMA = {
type: "object",
required: ["pageId"],
additionalProperties: false,
properties: {
pageId: {
type: "string",
description: "The ID of the page to edit",
pattern: "^[a-f0-9-]+$",
},
archived: {
type: "boolean",
description: "Whether to archive the page",
},
properties: {
type: "object",
properties: {
title: {
type: "array",
items: {
type: "object",
required: ["text"],
additionalProperties: false,
properties: {
text: {
type: "object",
required: ["content"],
additionalProperties: false,
properties: {
content: {
type: "string",
description: "The title text of the page",
},
},
},
},
},
},
},
},
children: pageBlocksSchema,
},
definitions: {
richTextBlock: richTextBlockDef,
richTextArray: richTextArrayDef,
},
};