@aiquants/html-to-markdown 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { J as JSONRPCMessageSchema, i as isInitializeRequest, d as isJSONRPCRequest, D as DEFAULT_NEGOTIATED_PROTOCOL_VERSION, e as SUPPORTED_PROTOCOL_VERSIONS, f as isJSONRPCResponse, h as isJSONRPCError, g as getPackageVersion, S as Server, I as InitializeRequestSchema, L as ListToolsRequestSchema, C as CallToolRequestSchema, p as parseHtmlToMarkdownArgs, b as parseSaveContentArgs, s as saveContentToFile } from "./version-BF9-U8Ef.js";
1
+ import { J as JSONRPCMessageSchema, i as isInitializeRequest, e as isJSONRPCRequest, D as DEFAULT_NEGOTIATED_PROTOCOL_VERSION, f as SUPPORTED_PROTOCOL_VERSIONS, h as isJSONRPCResponse, j as isJSONRPCError, g as getPackageVersion, S as Server, I as InitializeRequestSchema, L as ListToolsRequestSchema, C as CallToolRequestSchema, p as parseHtmlToMarkdownArgs, b as parseSaveContentArgs, s as saveContentToFile, d as parseUrlToMarkdownFileArgs } from "./version-BSh9aXhF.js";
2
2
  import { a as getAugmentedNamespace, c as commonjsGlobal, b as getDefaultExportFromCjs, h as htmlToMarkdown } from "./core-CouDTni-.js";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import cors from "cors";
@@ -7229,6 +7229,43 @@ class StreamableHtmlToMarkdownMcpServer {
7229
7229
  anyOf: [{ required: ["save_path"] }, { required: ["save_directory"] }]
7230
7230
  },
7231
7231
  handler: (args, context) => this.handleSaveContentToFile(args, context)
7232
+ },
7233
+ {
7234
+ name: "url_to_markdown_file_streamable",
7235
+ description: "Streamable URL to Markdown file converter with real-time progress updates. Combines HTML-to-Markdown conversion and file saving in one step. Ideal for large pages with JavaScript dynamic content support.",
7236
+ inputSchema: {
7237
+ type: "object",
7238
+ properties: {
7239
+ url: {
7240
+ type: "string",
7241
+ description: "URL of the web page to convert and save as Markdown file (e.g., https://example.com). Handles JavaScript-rendered dynamic content effectively."
7242
+ },
7243
+ html_content: {
7244
+ type: "string",
7245
+ description: "HTML string to convert directly and save as Markdown file. Use instead of URL for local files or API response HTML content."
7246
+ },
7247
+ locale: {
7248
+ type: "string",
7249
+ description: "Browser locale setting. Use 'ja-JP' for Japanese sites, 'en-US' for English sites. Affects content rendering and language detection.",
7250
+ enum: ["en-US", "ja-JP"],
7251
+ default: "en-US"
7252
+ },
7253
+ save_path: {
7254
+ type: "string",
7255
+ description: "Complete file path including filename to save the converted Markdown content (e.g., '/home/user/output.md'). Cannot be used with save_directory."
7256
+ },
7257
+ save_directory: {
7258
+ type: "string",
7259
+ description: "Directory path to save the converted Markdown content with auto-generated filename (e.g., '/home/user/downloads'). Cannot be used with save_path."
7260
+ },
7261
+ filename: {
7262
+ type: "string",
7263
+ description: "Base filename to use when save_directory is specified (e.g., 'my-document'). Extension .md will be added automatically."
7264
+ }
7265
+ },
7266
+ anyOf: [{ required: ["url", "save_path"] }, { required: ["url", "save_directory"] }, { required: ["html_content", "save_path"] }, { required: ["html_content", "save_directory"] }]
7267
+ },
7268
+ handler: (args, context) => this.handleUrlToMarkdownFile(args, context)
7232
7269
  }
7233
7270
  ];
7234
7271
  this.setupRequestHandlers();
@@ -7407,6 +7444,93 @@ class StreamableHtmlToMarkdownMcpServer {
7407
7444
  };
7408
7445
  }
7409
7446
  }
7447
+ /**
7448
+ * Handle URL to Markdown file conversion tool call with streamable support.
7449
+ * streamable サポート付きの URL から Markdown ファイルへの変換ツール呼び出しを処理
7450
+ */
7451
+ async *handleUrlToMarkdownFile(args, _context) {
7452
+ try {
7453
+ const validatedArgs = parseUrlToMarkdownFileArgs(args);
7454
+ const { url, html_content, locale = "en-US", save_path, save_directory, filename } = validatedArgs;
7455
+ if (url) {
7456
+ try {
7457
+ new URL(url);
7458
+ } catch {
7459
+ throw new Error(`Invalid URL: ${url}`);
7460
+ }
7461
+ }
7462
+ yield {
7463
+ type: "progress",
7464
+ progress: 0,
7465
+ message: "Web ページの内容を取得して Markdown に変換します。"
7466
+ };
7467
+ const result = await htmlToMarkdown(url || "direct-html-input", {
7468
+ locale,
7469
+ htmlContent: html_content
7470
+ });
7471
+ yield {
7472
+ type: "progress",
7473
+ progress: 70,
7474
+ message: "Markdown への変換が完了しました。ファイルに保存しています。"
7475
+ };
7476
+ const markdownContent = result.markdown;
7477
+ let finalFilename = filename;
7478
+ if (!finalFilename && url) {
7479
+ finalFilename = this.generateFilenameFromUrl(url);
7480
+ }
7481
+ const savedPath = await saveContentToFile(markdownContent, save_path, save_directory, finalFilename);
7482
+ yield {
7483
+ type: "progress",
7484
+ progress: 100,
7485
+ message: "ファイルの保存が完了しました。"
7486
+ };
7487
+ const responseText = `URL successfully converted to Markdown and saved to: ${savedPath}`;
7488
+ yield {
7489
+ type: "result",
7490
+ result: {
7491
+ content: [
7492
+ {
7493
+ type: "text",
7494
+ text: responseText
7495
+ }
7496
+ ],
7497
+ isError: false
7498
+ }
7499
+ };
7500
+ } catch (error) {
7501
+ const errorMessage = error instanceof Error ? error.message : String(error);
7502
+ yield {
7503
+ type: "result",
7504
+ result: {
7505
+ content: [
7506
+ {
7507
+ type: "text",
7508
+ text: `エラーが発生しました: ${errorMessage}`
7509
+ }
7510
+ ],
7511
+ isError: true
7512
+ }
7513
+ };
7514
+ }
7515
+ }
7516
+ /**
7517
+ * Generate filename from URL.
7518
+ * URL からファイル名を生成
7519
+ */
7520
+ generateFilenameFromUrl(url) {
7521
+ try {
7522
+ const urlObj = new URL(url);
7523
+ let filename = urlObj.pathname.split("/").pop() || "page";
7524
+ filename = filename.replace(/\.[^.]*$/, "");
7525
+ filename = filename.replace(/[<>:"/\\|?*]/g, "_");
7526
+ if (!filename || filename.match(/^\.+$/)) {
7527
+ filename = "page";
7528
+ }
7529
+ return filename;
7530
+ } catch {
7531
+ return "page";
7532
+ }
7533
+ }
7410
7534
  /**
7411
7535
  * Start the streamable MCP server.
7412
7536
  * streamable MCP サーバーを開始
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";require("./mcp-server-streamable-mF26pg3E.cjs").runStreamableMcpServer().catch(e=>{process.exit(1)});
2
+ "use strict";require("./mcp-server-streamable-BNn6Kd9b.cjs").runStreamableMcpServer().catch(e=>{process.exit(1)});
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { r as runStreamableMcpServer } from "./mcp-server-streamable-CVDJHcWu.js";
2
+ import { r as runStreamableMcpServer } from "./mcp-server-streamable-CcZ7Lsel.js";
3
3
  runStreamableMcpServer().catch((error) => {
4
4
  console.error("Failed to start streamable MCP server:", error);
5
5
  process.exit(1);
package/dist/mcp.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});require("./mcp-server-CCu0Pcm3.cjs").runMcpServer().catch(e=>{process.exit(1)});
2
+ const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});require("./mcp-server-Co1kuNGX.cjs").runMcpServer().catch(e=>{process.exit(1)});
package/dist/mcp.js CHANGED
@@ -6,7 +6,7 @@ Object.assign(global, {
6
6
  window,
7
7
  self: window
8
8
  });
9
- import { r as runMcpServer } from "./mcp-server-BAmy7d8r.js";
9
+ import { r as runMcpServer } from "./mcp-server-DzB_5cTs.js";
10
10
  runMcpServer().catch((error) => {
11
11
  console.error("Failed to start MCP server:", error);
12
12
  process.exit(1);
@@ -18,6 +18,18 @@ export interface SaveContentArgs {
18
18
  save_directory?: string;
19
19
  filename?: string;
20
20
  }
21
+ /**
22
+ * Arguments for URL to Markdown file conversion tool.
23
+ * URL から Markdown ファイルへの変換ツールの引数
24
+ */
25
+ export interface UrlToMarkdownFileArgs {
26
+ url?: string;
27
+ html_content?: string;
28
+ locale?: "en-US" | "ja-JP";
29
+ save_path?: string;
30
+ save_directory?: string;
31
+ filename?: string;
32
+ }
21
33
  /**
22
34
  * Validate and parse arguments for HTML to Markdown conversion.
23
35
  * HTML から Markdown への変換の引数を検証・解析
@@ -28,6 +40,11 @@ export declare function parseHtmlToMarkdownArgs(args: HtmlToMarkdownArgs | undef
28
40
  * コンテンツ保存の引数を検証・解析
29
41
  */
30
42
  export declare function parseSaveContentArgs(args: SaveContentArgs | undefined): SaveContentArgs;
43
+ /**
44
+ * Validate and parse arguments for URL to Markdown file conversion.
45
+ * URL から Markdown ファイルへの変換の引数を検証・解析
46
+ */
47
+ export declare function parseUrlToMarkdownFileArgs(args: UrlToMarkdownFileArgs | undefined): UrlToMarkdownFileArgs;
31
48
  /**
32
49
  * Generate filename from URL or use default.
33
50
  * URL からファイル名を生成または既定値を使用
@@ -94,6 +111,46 @@ export declare const MCP_TOOL_SCHEMAS: {
94
111
  readonly required: readonly ["save_directory"];
95
112
  }];
96
113
  };
114
+ urlToMarkdownFile: {
115
+ readonly type: "object";
116
+ readonly properties: {
117
+ readonly url: {
118
+ readonly type: "string";
119
+ readonly description: "URL of the web page to convert and save as Markdown file (e.g., https://example.com). Handles JavaScript-rendered dynamic content effectively.";
120
+ };
121
+ readonly html_content: {
122
+ readonly type: "string";
123
+ readonly description: "HTML string to convert directly and save as Markdown file. Use instead of URL for local files or API response HTML content.";
124
+ };
125
+ readonly locale: {
126
+ readonly type: "string";
127
+ readonly description: "Browser locale setting. Use 'ja-JP' for Japanese sites, 'en-US' for English sites. Affects content rendering and language detection.";
128
+ readonly enum: readonly ["en-US", "ja-JP"];
129
+ readonly default: "en-US";
130
+ };
131
+ readonly save_path: {
132
+ readonly type: "string";
133
+ readonly description: "Complete file path including filename to save the converted Markdown content (e.g., '/home/user/output.md'). Cannot be used with save_directory.";
134
+ };
135
+ readonly save_directory: {
136
+ readonly type: "string";
137
+ readonly description: "Directory path to save the converted Markdown content with auto-generated filename (e.g., '/home/user/downloads'). Cannot be used with save_path.";
138
+ };
139
+ readonly filename: {
140
+ readonly type: "string";
141
+ readonly description: "Base filename to use when save_directory is specified (e.g., 'my-document'). Extension .md will be added automatically.";
142
+ };
143
+ };
144
+ readonly anyOf: readonly [{
145
+ readonly required: readonly ["url", "save_path"];
146
+ }, {
147
+ readonly required: readonly ["url", "save_directory"];
148
+ }, {
149
+ readonly required: readonly ["html_content", "save_path"];
150
+ }, {
151
+ readonly required: readonly ["html_content", "save_directory"];
152
+ }];
153
+ };
97
154
  };
98
155
  /**
99
156
  * Common error handling utility for MCP tools.
@@ -1,6 +1,6 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { CallToolResult, Progress, Tool } from '@modelcontextprotocol/sdk/types.js';
3
- import { HtmlToMarkdownArgs, SaveContentArgs } from './mcp-common.ts';
3
+ import { HtmlToMarkdownArgs, SaveContentArgs, UrlToMarkdownFileArgs } from './mcp-common.ts';
4
4
  /**
5
5
  * The context for a tool call.
6
6
  * ツール呼び出しのコンテキスト
@@ -13,7 +13,7 @@ export type ToolContext<T = unknown> = {
13
13
  * ハンドラー関数を含む拡張 Tool インターフェース
14
14
  */
15
15
  interface ExtendedTool extends Tool {
16
- handler: (args: HtmlToMarkdownArgs | SaveContentArgs, context: ToolContext<HtmlToMarkdownArgs | SaveContentArgs>) => AsyncGenerator<Progress | {
16
+ handler: (args: HtmlToMarkdownArgs | SaveContentArgs | UrlToMarkdownFileArgs, context: ToolContext<HtmlToMarkdownArgs | SaveContentArgs | UrlToMarkdownFileArgs>) => AsyncGenerator<Progress | {
17
17
  type: "result";
18
18
  result: CallToolResult;
19
19
  }>;
@@ -54,6 +54,19 @@ export declare class StreamableHtmlToMarkdownMcpServer {
54
54
  type: "result";
55
55
  result: CallToolResult;
56
56
  }>;
57
+ /**
58
+ * Handle URL to Markdown file conversion tool call with streamable support.
59
+ * streamable サポート付きの URL から Markdown ファイルへの変換ツール呼び出しを処理
60
+ */
61
+ handleUrlToMarkdownFile(args: UrlToMarkdownFileArgs, _context: ToolContext<UrlToMarkdownFileArgs>): AsyncGenerator<Progress | {
62
+ type: "result";
63
+ result: CallToolResult;
64
+ }>;
65
+ /**
66
+ * Generate filename from URL.
67
+ * URL からファイル名を生成
68
+ */
69
+ private generateFilenameFromUrl;
57
70
  /**
58
71
  * Start the streamable MCP server.
59
72
  * streamable MCP サーバーを開始
@@ -1,6 +1,6 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- import { HtmlToMarkdownArgs, SaveContentArgs } from './mcp-common.ts';
3
- export { type HtmlToMarkdownArgs, type SaveContentArgs, parseHtmlToMarkdownArgs, parseSaveContentArgs, saveContentToFile, createErrorResult, createSuccessResult, MCP_TOOL_SCHEMAS, } from './mcp-common.ts';
2
+ import { HtmlToMarkdownArgs, SaveContentArgs, UrlToMarkdownFileArgs } from './mcp-common.ts';
3
+ export { type HtmlToMarkdownArgs, type SaveContentArgs, type UrlToMarkdownFileArgs, parseHtmlToMarkdownArgs, parseSaveContentArgs, parseUrlToMarkdownFileArgs, saveContentToFile, createErrorResult, createSuccessResult, MCP_TOOL_SCHEMAS, } from './mcp-common.ts';
4
4
  /**
5
5
  * MCP Server for HTML to Markdown conversion.
6
6
  * HTML から Markdown への変換を行う MCP サーバー
@@ -158,6 +158,83 @@ export declare class HtmlToMarkdownMcpServer {
158
158
  } | undefined;
159
159
  isError?: boolean | undefined;
160
160
  }>;
161
+ /**
162
+ * Handle URL to Markdown file conversion tool call.
163
+ * URL から Markdown ファイルへの変換ツール呼び出しを処理
164
+ */
165
+ handleUrlToMarkdownFile(args: UrlToMarkdownFileArgs | undefined): Promise<{
166
+ [x: string]: unknown;
167
+ content: ({
168
+ [x: string]: unknown;
169
+ text: string;
170
+ type: "text";
171
+ _meta?: {
172
+ [x: string]: unknown;
173
+ } | undefined;
174
+ } | {
175
+ [x: string]: unknown;
176
+ type: "image";
177
+ data: string;
178
+ mimeType: string;
179
+ _meta?: {
180
+ [x: string]: unknown;
181
+ } | undefined;
182
+ } | {
183
+ [x: string]: unknown;
184
+ type: "audio";
185
+ data: string;
186
+ mimeType: string;
187
+ _meta?: {
188
+ [x: string]: unknown;
189
+ } | undefined;
190
+ } | {
191
+ [x: string]: unknown;
192
+ type: "resource_link";
193
+ name: string;
194
+ uri: string;
195
+ title?: string | undefined;
196
+ _meta?: {
197
+ [x: string]: unknown;
198
+ } | undefined;
199
+ mimeType?: string | undefined;
200
+ description?: string | undefined;
201
+ } | {
202
+ [x: string]: unknown;
203
+ type: "resource";
204
+ resource: {
205
+ [x: string]: unknown;
206
+ text: string;
207
+ uri: string;
208
+ _meta?: {
209
+ [x: string]: unknown;
210
+ } | undefined;
211
+ mimeType?: string | undefined;
212
+ } | {
213
+ [x: string]: unknown;
214
+ uri: string;
215
+ blob: string;
216
+ _meta?: {
217
+ [x: string]: unknown;
218
+ } | undefined;
219
+ mimeType?: string | undefined;
220
+ };
221
+ _meta?: {
222
+ [x: string]: unknown;
223
+ } | undefined;
224
+ })[];
225
+ _meta?: {
226
+ [x: string]: unknown;
227
+ } | undefined;
228
+ structuredContent?: {
229
+ [x: string]: unknown;
230
+ } | undefined;
231
+ isError?: boolean | undefined;
232
+ }>;
233
+ /**
234
+ * Generate filename from URL.
235
+ * URL からファイル名を生成
236
+ */
237
+ private generateFilenameFromUrl;
161
238
  /**
162
239
  * Start the MCP server.
163
240
  * MCP サーバーを開始
@@ -11345,6 +11345,47 @@ function parseSaveContentArgs(args) {
11345
11345
  filename
11346
11346
  };
11347
11347
  }
11348
+ function parseUrlToMarkdownFileArgs(args) {
11349
+ if (!args || typeof args !== "object") {
11350
+ throw new Error("Arguments are required");
11351
+ }
11352
+ const { url, html_content, locale = "en-US", save_path, save_directory, filename } = args;
11353
+ if (!url && !html_content) {
11354
+ throw new Error("Either 'url' or 'html_content' is required");
11355
+ }
11356
+ if (url && typeof url !== "string") {
11357
+ throw new Error("'url' must be a string");
11358
+ }
11359
+ if (html_content && typeof html_content !== "string") {
11360
+ throw new Error("'html_content' must be a string");
11361
+ }
11362
+ if (locale && !["en-US", "ja-JP"].includes(locale)) {
11363
+ throw new Error("'locale' must be 'en-US' or 'ja-JP'");
11364
+ }
11365
+ if (!save_path && !save_directory) {
11366
+ throw new Error("Either 'save_path' or 'save_directory' is required");
11367
+ }
11368
+ if (save_path && typeof save_path !== "string") {
11369
+ throw new Error("'save_path' must be a string");
11370
+ }
11371
+ if (save_directory && typeof save_directory !== "string") {
11372
+ throw new Error("'save_directory' must be a string");
11373
+ }
11374
+ if (filename && typeof filename !== "string") {
11375
+ throw new Error("'filename' must be a string");
11376
+ }
11377
+ if (save_path && save_directory) {
11378
+ throw new Error("Cannot specify both 'save_path' and 'save_directory'");
11379
+ }
11380
+ return {
11381
+ url,
11382
+ html_content,
11383
+ locale,
11384
+ save_path,
11385
+ save_directory,
11386
+ filename
11387
+ };
11388
+ }
11348
11389
  function generateFilename(url) {
11349
11390
  return "page";
11350
11391
  }
@@ -11406,6 +11447,38 @@ const MCP_TOOL_SCHEMAS = {
11406
11447
  },
11407
11448
  required: ["content"],
11408
11449
  anyOf: [{ required: ["save_path"] }, { required: ["save_directory"] }]
11450
+ },
11451
+ urlToMarkdownFile: {
11452
+ type: "object",
11453
+ properties: {
11454
+ url: {
11455
+ type: "string",
11456
+ description: "URL of the web page to convert and save as Markdown file (e.g., https://example.com). Handles JavaScript-rendered dynamic content effectively."
11457
+ },
11458
+ html_content: {
11459
+ type: "string",
11460
+ description: "HTML string to convert directly and save as Markdown file. Use instead of URL for local files or API response HTML content."
11461
+ },
11462
+ locale: {
11463
+ type: "string",
11464
+ description: "Browser locale setting. Use 'ja-JP' for Japanese sites, 'en-US' for English sites. Affects content rendering and language detection.",
11465
+ enum: ["en-US", "ja-JP"],
11466
+ default: "en-US"
11467
+ },
11468
+ save_path: {
11469
+ type: "string",
11470
+ description: "Complete file path including filename to save the converted Markdown content (e.g., '/home/user/output.md'). Cannot be used with save_directory."
11471
+ },
11472
+ save_directory: {
11473
+ type: "string",
11474
+ description: "Directory path to save the converted Markdown content with auto-generated filename (e.g., '/home/user/downloads'). Cannot be used with save_path."
11475
+ },
11476
+ filename: {
11477
+ type: "string",
11478
+ description: "Base filename to use when save_directory is specified (e.g., 'my-document'). Extension .md will be added automatically."
11479
+ }
11480
+ },
11481
+ anyOf: [{ required: ["url", "save_path"] }, { required: ["url", "save_directory"] }, { required: ["html_content", "save_path"] }, { required: ["html_content", "save_directory"] }]
11409
11482
  }
11410
11483
  };
11411
11484
  function createErrorResult(error) {
@@ -11454,12 +11527,13 @@ export {
11454
11527
  createErrorResult as a,
11455
11528
  parseSaveContentArgs as b,
11456
11529
  createSuccessResult as c,
11457
- isJSONRPCRequest as d,
11458
- SUPPORTED_PROTOCOL_VERSIONS as e,
11459
- isJSONRPCResponse as f,
11530
+ parseUrlToMarkdownFileArgs as d,
11531
+ isJSONRPCRequest as e,
11532
+ SUPPORTED_PROTOCOL_VERSIONS as f,
11460
11533
  getPackageVersion as g,
11461
- isJSONRPCError as h,
11534
+ isJSONRPCResponse as h,
11462
11535
  isInitializeRequest as i,
11536
+ isJSONRPCError as j,
11463
11537
  parseHtmlToMarkdownArgs as p,
11464
11538
  saveContentToFile as s
11465
11539
  };