import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import packageJson from "../package.json" with { type: "json" }; import { createFolderSchema, createNoteSchema, getFolderSchema, getNoteSchema, githubSyncStatusSchema, listFoldersSchema, listNotesSchema, profileSchema, pullGitHubFileToHackMdSchema, syncNoteToGitHubSchema, toolHandlers, updateFolderSchema, updateNoteSchema, } from "./tools/notes.js"; import type { HackMdClient } from "./hackmd/client.js"; export function createServer(client: HackMdClient): McpServer { const server = new McpServer({ name: "hackmd-mcp", version: packageJson.version, }); const handlers = toolHandlers(client); server.registerTool( "hackmd_profile", { title: "HackMD Profile", description: "Get the current HackMD user's profile.", inputSchema: profileSchema.shape, }, handlers.hackmdProfile, ); server.registerTool( "hackmd_list_notes", { title: "List HackMD Notes", description: "List personal HackMD notes, or team notes when teamPath is provided.", inputSchema: listNotesSchema.shape, }, handlers.hackmdListNotes, ); server.registerTool( "hackmd_get_note", { title: "Get HackMD Note", description: "Read one HackMD note by noteId, optionally from a team workspace.", inputSchema: getNoteSchema.shape, }, handlers.hackmdGetNote, ); server.registerTool( "hackmd_create_note", { title: "Create HackMD Note", description: "Create a personal HackMD note, or a team note when teamPath is provided.", inputSchema: createNoteSchema.shape, }, handlers.hackmdCreateNote, ); server.registerTool( "hackmd_update_note", { title: "Update HackMD Note", description: "Update HackMD note content or metadata.", inputSchema: updateNoteSchema, }, handlers.hackmdUpdateNote, ); server.registerTool( "hackmd_list_folders", { title: "List HackMD Folders", description: "List personal HackMD folders, or team folders when teamPath is provided.", inputSchema: listFoldersSchema.shape, }, handlers.hackmdListFolders, ); server.registerTool( "hackmd_get_folder", { title: "Get HackMD Folder", description: "Read one HackMD folder by folderId, optionally from a team workspace.", inputSchema: getFolderSchema.shape, }, handlers.hackmdGetFolder, ); server.registerTool( "hackmd_create_folder", { title: "Create HackMD Folder", description: "Create a personal HackMD folder, or a team folder when teamPath is provided.", inputSchema: createFolderSchema.shape, }, handlers.hackmdCreateFolder, ); server.registerTool( "hackmd_update_folder", { title: "Update HackMD Folder", description: "Update folder name, description, icon, color, or parent folder.", inputSchema: updateFolderSchema, }, handlers.hackmdUpdateFolder, ); server.registerTool( "hackmd_sync_note_to_github", { title: "Sync HackMD Note to GitHub", description: "Sync the current HackMD note content to a non-default GitHub branch and create or reuse a pull request.", inputSchema: syncNoteToGitHubSchema.shape, }, handlers.hackmdSyncNoteToGitHub, ); server.registerTool( "hackmd_pull_github_file_to_hackmd", { title: "Pull GitHub File to HackMD", description: "Create or update a HackMD note from a GitHub Markdown file and start GitHub sync state.", inputSchema: pullGitHubFileToHackMdSchema.shape, }, handlers.hackmdPullGitHubFileToHackMd, ); server.registerTool( "hackmd_github_sync_status", { title: "HackMD GitHub Sync Status", description: "Read locally remembered GitHub sync state for a HackMD note.", inputSchema: githubSyncStatusSchema.shape, }, handlers.hackmdGitHubSyncStatus, ); return server; } export { GitHubClient, GitHubHttpError, GitHubNetworkError } from "./github/client.js"; export { FileGitHubSyncStateStore } from "./github/sync-state.js"; export { HackMdClient, HackMdHttpError, HackMdNetworkError } from "./hackmd/client.js"; export type { CreatePullRequestInput, GitHubClientOptions, GitHubFile, GitHubPullRequest, GitHubRef, GitHubRepository, PutFileInput, } from "./github/client.js"; export type { GitHubSyncResult, PullGitHubFileToHackMdInput, PullGitHubFileToHackMdResult, SyncNoteToGitHubInput, } from "./github/sync.js"; export type { GitHubSyncState, GitHubSyncStateStore } from "./github/sync-state.js"; export type { CommentPermissionType, CreateFolderInput, CreateNoteInput, FolderSelector, HackMdClientOptions, ListFoldersInput, ListNotesInput, NotePermissionRole, NoteSelector, SuggestEditPermissionType, UpdateFolderInput, UpdateNoteInput, } from "./hackmd/client.js";