Skip to main content
Glama
jasonkneen

Simple TypeScript MCP Server

by jasonkneen

createNote

Create and store notes with titles and content using a TypeScript MCP server for note-taking operations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesThe title of the note
contentYesThe content of the note

Implementation Reference

  • The handler function for the 'createNote' MCP tool. It takes title and content, calls notesStore.createNote, and returns a JSON response with the new note or an error.
      async ({ title, content }) => {
        try {
          const newNote = notesStore.createNote(title, content);
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  success: true,
                  note: newNote
                }, null, 2)
              }
            ]
          };
        } catch (err) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  success: false,
                  error: "Failed to create note"
                }, null, 2)
              }
            ]
          };
        }
      },
    );
  • Input schema for the createNote tool using Zod, defining required string parameters for title and content.
    {
      title: z.string().describe("The title of the note"),
      content: z.string().describe("The content of the note")
    },
  • src/server.ts:101-136 (registration)
    Registration of the 'createNote' tool on the MCP server, including name, input schema, and handler function.
    server.tool(
      "createNote",
      {
        title: z.string().describe("The title of the note"),
        content: z.string().describe("The content of the note")
      },
      async ({ title, content }) => {
        try {
          const newNote = notesStore.createNote(title, content);
          
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  success: true,
                  note: newNote
                }, null, 2)
              }
            ]
          };
        } catch (err) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  success: false,
                  error: "Failed to create note"
                }, null, 2)
              }
            ]
          };
        }
      },
    );
  • Helper method in NotesStore class that creates a new Note object with generated ID and stores it in memory.
    createNote(title: string, content: string): Note {
      const id = `note${Date.now()}`;
      const newNote = {
        id,
        title,
        content,
        createdAt: new Date().toISOString()
      };
      
      this.notes[id] = newNote;
      return newNote;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jasonkneen/mcp-server-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server