add
Save web links to the Bookmark Manager MCP by providing a title, URL, and optional category for organized storage and retrieval.
Instructions
Add a new bookmark
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Bookmark title | |
| url | Yes | Bookmark URL | |
| category | No | Bookmark category (default: general) |
Implementation Reference
- src/index.ts:50-61 (handler)The handler function for the 'add' tool. It creates a bookmark object from the input parameters, adds it to the bookmarks array, persists it via saveBookmarks(), and returns a text response confirming the bookmark was added.
async ({ title, url, category = 'general' }) => { const bookmark = { title, url, category } bookmarks.push(bookmark) await saveBookmarks(bookmarks) return { content: [{ type: 'text', text: `Bookmark added: ${title} - ${url} (category: ${category})` }] } } - src/index.ts:44-48 (schema)The input schema for the 'add' tool defined using Zod. It validates that 'title' is a string, 'url' is a valid URL string, and 'category' is an optional string (defaults to 'general').
inputSchema: { title: z.string().describe('Bookmark title'), url: z.string().url().describe('Bookmark URL'), category: z.string().optional().describe('Bookmark category (default: general)') } - src/index.ts:40-62 (registration)Registration of the 'add' tool with the MCP server using server.registerTool(). Includes the tool name, metadata (title, description), input schema, and handler function.
server.registerTool('add', { title: 'Add Bookmark', description: 'Add a new bookmark', inputSchema: { title: z.string().describe('Bookmark title'), url: z.string().url().describe('Bookmark URL'), category: z.string().optional().describe('Bookmark category (default: general)') } }, async ({ title, url, category = 'general' }) => { const bookmark = { title, url, category } bookmarks.push(bookmark) await saveBookmarks(bookmarks) return { content: [{ type: 'text', text: `Bookmark added: ${title} - ${url} (category: ${category})` }] } } ) - src/index.ts:25-37 (helper)Helper function 'saveBookmarks' used by the 'add' tool handler to persist the bookmarks array to a JSON file.
async function saveBookmarks (bookmarksToSave: Bookmark[]): Promise<void> { let fileHandle try { fileHandle = await open(bookMarkFileName, 'w') await fileHandle.writeFile(JSON.stringify(bookmarksToSave, null, 2)) } catch (error) { throw new Error(`Failed to save bookmarks: ${error instanceof Error ? error.message : 'Unknown error'}`) } finally { if (fileHandle) { await fileHandle.close() } } } - src/index.ts:17-21 (schema)TypeScript type definition for Bookmark, defining the structure with title (string), url (string), and category (string) fields.
type Bookmark = { title: string, url: string, category: string }