@fre4x/hn 1.0.50 → 1.0.51

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.
Files changed (2) hide show
  1. package/dist/index.js +485 -116
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -40847,6 +40847,250 @@ var ExperimentalMcpServerTasks = class {
40847
40847
  }
40848
40848
  };
40849
40849
 
40850
+ // ../node_modules/zod/index.js
40851
+ var zod_exports = {};
40852
+ __export(zod_exports, {
40853
+ $brand: () => $brand,
40854
+ $input: () => $input,
40855
+ $output: () => $output,
40856
+ NEVER: () => NEVER,
40857
+ TimePrecision: () => TimePrecision,
40858
+ ZodAny: () => ZodAny2,
40859
+ ZodArray: () => ZodArray2,
40860
+ ZodBase64: () => ZodBase64,
40861
+ ZodBase64URL: () => ZodBase64URL,
40862
+ ZodBigInt: () => ZodBigInt2,
40863
+ ZodBigIntFormat: () => ZodBigIntFormat,
40864
+ ZodBoolean: () => ZodBoolean2,
40865
+ ZodCIDRv4: () => ZodCIDRv4,
40866
+ ZodCIDRv6: () => ZodCIDRv6,
40867
+ ZodCUID: () => ZodCUID,
40868
+ ZodCUID2: () => ZodCUID2,
40869
+ ZodCatch: () => ZodCatch2,
40870
+ ZodCodec: () => ZodCodec,
40871
+ ZodCustom: () => ZodCustom,
40872
+ ZodCustomStringFormat: () => ZodCustomStringFormat,
40873
+ ZodDate: () => ZodDate2,
40874
+ ZodDefault: () => ZodDefault2,
40875
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion2,
40876
+ ZodE164: () => ZodE164,
40877
+ ZodEmail: () => ZodEmail,
40878
+ ZodEmoji: () => ZodEmoji,
40879
+ ZodEnum: () => ZodEnum2,
40880
+ ZodError: () => ZodError2,
40881
+ ZodExactOptional: () => ZodExactOptional,
40882
+ ZodFile: () => ZodFile,
40883
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind2,
40884
+ ZodFunction: () => ZodFunction2,
40885
+ ZodGUID: () => ZodGUID,
40886
+ ZodIPv4: () => ZodIPv4,
40887
+ ZodIPv6: () => ZodIPv6,
40888
+ ZodISODate: () => ZodISODate,
40889
+ ZodISODateTime: () => ZodISODateTime,
40890
+ ZodISODuration: () => ZodISODuration,
40891
+ ZodISOTime: () => ZodISOTime,
40892
+ ZodIntersection: () => ZodIntersection2,
40893
+ ZodIssueCode: () => ZodIssueCode2,
40894
+ ZodJWT: () => ZodJWT,
40895
+ ZodKSUID: () => ZodKSUID,
40896
+ ZodLazy: () => ZodLazy2,
40897
+ ZodLiteral: () => ZodLiteral2,
40898
+ ZodMAC: () => ZodMAC,
40899
+ ZodMap: () => ZodMap2,
40900
+ ZodNaN: () => ZodNaN2,
40901
+ ZodNanoID: () => ZodNanoID,
40902
+ ZodNever: () => ZodNever2,
40903
+ ZodNonOptional: () => ZodNonOptional,
40904
+ ZodNull: () => ZodNull2,
40905
+ ZodNullable: () => ZodNullable2,
40906
+ ZodNumber: () => ZodNumber2,
40907
+ ZodNumberFormat: () => ZodNumberFormat,
40908
+ ZodObject: () => ZodObject2,
40909
+ ZodOptional: () => ZodOptional2,
40910
+ ZodPipe: () => ZodPipe,
40911
+ ZodPrefault: () => ZodPrefault,
40912
+ ZodPromise: () => ZodPromise2,
40913
+ ZodReadonly: () => ZodReadonly2,
40914
+ ZodRealError: () => ZodRealError,
40915
+ ZodRecord: () => ZodRecord2,
40916
+ ZodSet: () => ZodSet2,
40917
+ ZodString: () => ZodString2,
40918
+ ZodStringFormat: () => ZodStringFormat,
40919
+ ZodSuccess: () => ZodSuccess,
40920
+ ZodSymbol: () => ZodSymbol2,
40921
+ ZodTemplateLiteral: () => ZodTemplateLiteral,
40922
+ ZodTransform: () => ZodTransform,
40923
+ ZodTuple: () => ZodTuple2,
40924
+ ZodType: () => ZodType2,
40925
+ ZodULID: () => ZodULID,
40926
+ ZodURL: () => ZodURL,
40927
+ ZodUUID: () => ZodUUID,
40928
+ ZodUndefined: () => ZodUndefined2,
40929
+ ZodUnion: () => ZodUnion2,
40930
+ ZodUnknown: () => ZodUnknown2,
40931
+ ZodVoid: () => ZodVoid2,
40932
+ ZodXID: () => ZodXID,
40933
+ ZodXor: () => ZodXor,
40934
+ _ZodString: () => _ZodString,
40935
+ _default: () => _default2,
40936
+ _function: () => _function,
40937
+ any: () => any,
40938
+ array: () => array,
40939
+ base64: () => base642,
40940
+ base64url: () => base64url2,
40941
+ bigint: () => bigint2,
40942
+ boolean: () => boolean2,
40943
+ catch: () => _catch2,
40944
+ check: () => check,
40945
+ cidrv4: () => cidrv42,
40946
+ cidrv6: () => cidrv62,
40947
+ clone: () => clone,
40948
+ codec: () => codec,
40949
+ coerce: () => coerce_exports2,
40950
+ config: () => config,
40951
+ core: () => core_exports2,
40952
+ cuid: () => cuid3,
40953
+ cuid2: () => cuid22,
40954
+ custom: () => custom,
40955
+ date: () => date3,
40956
+ decode: () => decode2,
40957
+ decodeAsync: () => decodeAsync2,
40958
+ default: () => zod_default,
40959
+ describe: () => describe2,
40960
+ discriminatedUnion: () => discriminatedUnion,
40961
+ e164: () => e1642,
40962
+ email: () => email2,
40963
+ emoji: () => emoji2,
40964
+ encode: () => encode2,
40965
+ encodeAsync: () => encodeAsync2,
40966
+ endsWith: () => _endsWith,
40967
+ enum: () => _enum2,
40968
+ exactOptional: () => exactOptional,
40969
+ file: () => file,
40970
+ flattenError: () => flattenError,
40971
+ float32: () => float32,
40972
+ float64: () => float64,
40973
+ formatError: () => formatError,
40974
+ fromJSONSchema: () => fromJSONSchema,
40975
+ function: () => _function,
40976
+ getErrorMap: () => getErrorMap2,
40977
+ globalRegistry: () => globalRegistry,
40978
+ gt: () => _gt,
40979
+ gte: () => _gte,
40980
+ guid: () => guid2,
40981
+ hash: () => hash,
40982
+ hex: () => hex2,
40983
+ hostname: () => hostname2,
40984
+ httpUrl: () => httpUrl,
40985
+ includes: () => _includes,
40986
+ instanceof: () => _instanceof,
40987
+ int: () => int,
40988
+ int32: () => int32,
40989
+ int64: () => int64,
40990
+ intersection: () => intersection,
40991
+ ipv4: () => ipv42,
40992
+ ipv6: () => ipv62,
40993
+ iso: () => iso_exports2,
40994
+ json: () => json,
40995
+ jwt: () => jwt,
40996
+ keyof: () => keyof,
40997
+ ksuid: () => ksuid2,
40998
+ lazy: () => lazy,
40999
+ length: () => _length,
41000
+ literal: () => literal,
41001
+ locales: () => locales_exports,
41002
+ looseObject: () => looseObject,
41003
+ looseRecord: () => looseRecord,
41004
+ lowercase: () => _lowercase,
41005
+ lt: () => _lt,
41006
+ lte: () => _lte,
41007
+ mac: () => mac2,
41008
+ map: () => map,
41009
+ maxLength: () => _maxLength,
41010
+ maxSize: () => _maxSize,
41011
+ meta: () => meta2,
41012
+ mime: () => _mime,
41013
+ minLength: () => _minLength,
41014
+ minSize: () => _minSize,
41015
+ multipleOf: () => _multipleOf,
41016
+ nan: () => nan,
41017
+ nanoid: () => nanoid2,
41018
+ nativeEnum: () => nativeEnum,
41019
+ negative: () => _negative,
41020
+ never: () => never,
41021
+ nonnegative: () => _nonnegative,
41022
+ nonoptional: () => nonoptional,
41023
+ nonpositive: () => _nonpositive,
41024
+ normalize: () => _normalize,
41025
+ null: () => _null3,
41026
+ nullable: () => nullable,
41027
+ nullish: () => nullish2,
41028
+ number: () => number2,
41029
+ object: () => object2,
41030
+ optional: () => optional,
41031
+ overwrite: () => _overwrite,
41032
+ parse: () => parse2,
41033
+ parseAsync: () => parseAsync2,
41034
+ partialRecord: () => partialRecord,
41035
+ pipe: () => pipe,
41036
+ positive: () => _positive,
41037
+ prefault: () => prefault,
41038
+ preprocess: () => preprocess,
41039
+ prettifyError: () => prettifyError,
41040
+ promise: () => promise,
41041
+ property: () => _property,
41042
+ readonly: () => readonly,
41043
+ record: () => record,
41044
+ refine: () => refine,
41045
+ regex: () => _regex,
41046
+ regexes: () => regexes_exports,
41047
+ registry: () => registry,
41048
+ safeDecode: () => safeDecode2,
41049
+ safeDecodeAsync: () => safeDecodeAsync2,
41050
+ safeEncode: () => safeEncode2,
41051
+ safeEncodeAsync: () => safeEncodeAsync2,
41052
+ safeParse: () => safeParse3,
41053
+ safeParseAsync: () => safeParseAsync3,
41054
+ set: () => set,
41055
+ setErrorMap: () => setErrorMap,
41056
+ size: () => _size,
41057
+ slugify: () => _slugify,
41058
+ startsWith: () => _startsWith,
41059
+ strictObject: () => strictObject,
41060
+ string: () => string2,
41061
+ stringFormat: () => stringFormat,
41062
+ stringbool: () => stringbool,
41063
+ success: () => success,
41064
+ superRefine: () => superRefine,
41065
+ symbol: () => symbol,
41066
+ templateLiteral: () => templateLiteral,
41067
+ toJSONSchema: () => toJSONSchema,
41068
+ toLowerCase: () => _toLowerCase,
41069
+ toUpperCase: () => _toUpperCase,
41070
+ transform: () => transform,
41071
+ treeifyError: () => treeifyError,
41072
+ trim: () => _trim,
41073
+ tuple: () => tuple,
41074
+ uint32: () => uint32,
41075
+ uint64: () => uint64,
41076
+ ulid: () => ulid2,
41077
+ undefined: () => _undefined3,
41078
+ union: () => union,
41079
+ unknown: () => unknown,
41080
+ uppercase: () => _uppercase,
41081
+ url: () => url,
41082
+ util: () => util_exports,
41083
+ uuid: () => uuid2,
41084
+ uuidv4: () => uuidv4,
41085
+ uuidv6: () => uuidv6,
41086
+ uuidv7: () => uuidv7,
41087
+ void: () => _void2,
41088
+ xid: () => xid2,
41089
+ xor: () => xor,
41090
+ z: () => external_exports3
41091
+ });
41092
+ var zod_default = external_exports3;
41093
+
40850
41094
  // ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
40851
41095
  var McpServer = class {
40852
41096
  constructor(serverInfo, options) {
@@ -41725,6 +41969,63 @@ var StdioServerTransport = class {
41725
41969
  }
41726
41970
  };
41727
41971
 
41972
+ // ../packages/shared/dist/errors.js
41973
+ function createInternalError(error48) {
41974
+ const message = error48 instanceof Error ? error48.message : String(error48);
41975
+ return {
41976
+ isError: true,
41977
+ content: [
41978
+ {
41979
+ type: "text",
41980
+ text: `Internal Error: ${message}
41981
+
41982
+ Suggestion: If the problem persists, check server logs.`
41983
+ }
41984
+ ]
41985
+ };
41986
+ }
41987
+
41988
+ // ../packages/shared/dist/format.js
41989
+ function formatListItems(items, renderer, emptyMessage = "_No results found._") {
41990
+ if (items.length === 0)
41991
+ return emptyMessage;
41992
+ return items.map((item, i) => renderer(item, i)).join("\n\n");
41993
+ }
41994
+ function formatField(label, value) {
41995
+ if (value === null || value === void 0 || value === "")
41996
+ return "";
41997
+ return `**${label}:** ${value}`;
41998
+ }
41999
+ function formatFields(fields) {
42000
+ return fields.map(([label, value]) => formatField(label, value)).filter(Boolean).join(" \n");
42001
+ }
42002
+ function formatPaginationFooter(offset, limit, total) {
42003
+ const start = offset + 1;
42004
+ const end = Math.min(offset + limit, total);
42005
+ return `
42006
+ ---
42007
+ _Showing ${start}\u2013${end} of ${total}. Use \`offset: ${offset + limit}\` for the next page._`;
42008
+ }
42009
+
42010
+ // ../packages/shared/dist/pagination.js
42011
+ var z2 = external_exports3 || zod_default || zod_exports;
42012
+ var paginationSchema = z2.object({
42013
+ limit: z2.number().int().min(1).max(100).default(20).describe("Maximum results to return (1\u2013100, default 20)"),
42014
+ offset: z2.number().int().min(0).default(0).describe("Number of results to skip for pagination (default 0)")
42015
+ });
42016
+ function applyPagination(items, params) {
42017
+ const { limit, offset } = params;
42018
+ const total = items.length;
42019
+ const sliced = items.slice(offset, offset + limit);
42020
+ return {
42021
+ items: sliced,
42022
+ total,
42023
+ offset,
42024
+ limit,
42025
+ hasMore: offset + limit < total
42026
+ };
42027
+ }
42028
+
41728
42029
  // src/api.ts
41729
42030
  import https2 from "node:https";
41730
42031
 
@@ -45593,17 +45894,17 @@ var server = new McpServer({
45593
45894
  function formatItemMarkdown(item) {
45594
45895
  if (!item) return "Item not found.";
45595
45896
  const lines = [];
45596
- if (item.title) lines.push(`# ${item.title}`);
45597
- if (item.by) lines.push(`**By**: ${item.by}`);
45598
- if (item.time)
45599
- lines.push(`**Time**: ${new Date(item.time * 1e3).toLocaleString()}`);
45600
- if (item.score !== void 0) lines.push(`**Score**: ${item.score}`);
45601
- if (item.url) lines.push(`**URL**: ${item.url}`);
45897
+ if (item.title) lines.push(`# ${item.title}
45898
+ `);
45899
+ lines.push(formatFields([
45900
+ ["By", item.by],
45901
+ ["Time", item.time ? new Date(item.time * 1e3).toLocaleString() : void 0],
45902
+ ["Score", item.score],
45903
+ ["URL", item.url],
45904
+ ["Comments", item.descendants]
45905
+ ]));
45602
45906
  if (item.text) lines.push(`
45603
45907
  ${item.text}`);
45604
- if (item.descendants !== void 0)
45605
- lines.push(`
45606
- **Comments**: ${item.descendants}`);
45607
45908
  if (item.kids && item.kids.length > 0) {
45608
45909
  lines.push(`
45609
45910
  **Kids/Replies**: ${item.kids.join(", ")}`);
@@ -45625,19 +45926,17 @@ function handleLimit(content, format) {
45625
45926
  });
45626
45927
  }
45627
45928
  }
45628
- var storySchema = {
45629
- limit: external_exports3.number().int().min(1).max(500).default(20).describe("Number of stories to return"),
45630
- offset: external_exports3.number().int().min(0).default(0).describe("Offset for pagination"),
45929
+ var storySchema = paginationSchema.extend({
45631
45930
  response_format: external_exports3.enum(Object.values(ResponseFormat)).default("markdown" /* MARKDOWN */).describe("Output format (markdown or json)")
45632
- };
45931
+ });
45633
45932
  async function handleStories(ids, params) {
45634
- const paginatedIds = ids.slice(params.offset, params.offset + params.limit);
45933
+ const paginated = applyPagination(ids, params);
45635
45934
  const result = {
45636
- total: ids.length,
45637
- count: paginatedIds.length,
45638
- offset: params.offset,
45639
- items: paginatedIds,
45640
- has_more: ids.length > params.offset + params.limit
45935
+ total: paginated.total,
45936
+ count: paginated.items.length,
45937
+ offset: paginated.offset,
45938
+ items: paginated.items,
45939
+ has_more: paginated.hasMore
45641
45940
  };
45642
45941
  if (params.response_format === "json" /* JSON */) {
45643
45942
  return {
@@ -45655,13 +45954,10 @@ async function handleStories(ids, params) {
45655
45954
  }
45656
45955
  const markdown = `# Hacker News Stories
45657
45956
 
45658
- Showing ${paginatedIds.length} of ${ids.length} stories (Offset: ${params.offset})
45659
-
45660
- ` + paginatedIds.map(
45661
- (id, i) => `${i + 1 + params.offset}. [${id}](https://news.ycombinator.com/item?id=${id})`
45662
- ).join("\n") + (result.has_more ? `
45663
-
45664
- *More stories available. Use offset=${params.offset + params.limit}*` : "");
45957
+ ` + formatListItems(
45958
+ paginated.items,
45959
+ (id, i) => `${i + 1 + paginated.offset}. [${id}](https://news.ycombinator.com/item?id=${id})`
45960
+ ) + (paginated.hasMore ? formatPaginationFooter(paginated.offset, paginated.limit, paginated.total) : "");
45665
45961
  return {
45666
45962
  content: [
45667
45963
  {
@@ -45676,84 +45972,120 @@ server.registerTool(
45676
45972
  {
45677
45973
  title: "Get Top Stories",
45678
45974
  description: "Retrieve IDs of the current top stories on Hacker News.",
45679
- inputSchema: external_exports3.object(storySchema),
45975
+ inputSchema: storySchema,
45680
45976
  annotations: {
45681
45977
  readOnlyHint: true,
45682
45978
  idempotentHint: true,
45683
45979
  openWorldHint: true
45684
45980
  }
45685
45981
  },
45686
- async (params) => handleStories(await api.getTopStories(), params)
45982
+ async (params) => {
45983
+ try {
45984
+ return await handleStories(await api.getTopStories(), params);
45985
+ } catch (error48) {
45986
+ return createInternalError(error48);
45987
+ }
45988
+ }
45687
45989
  );
45688
45990
  server.registerTool(
45689
45991
  "hn_get_new_stories",
45690
45992
  {
45691
45993
  title: "Get New Stories",
45692
45994
  description: "Retrieve IDs of the newest stories on Hacker News.",
45693
- inputSchema: external_exports3.object(storySchema),
45995
+ inputSchema: storySchema,
45694
45996
  annotations: {
45695
45997
  readOnlyHint: true,
45696
45998
  idempotentHint: true,
45697
45999
  openWorldHint: true
45698
46000
  }
45699
46001
  },
45700
- async (params) => handleStories(await api.getNewStories(), params)
46002
+ async (params) => {
46003
+ try {
46004
+ return await handleStories(await api.getNewStories(), params);
46005
+ } catch (error48) {
46006
+ return createInternalError(error48);
46007
+ }
46008
+ }
45701
46009
  );
45702
46010
  server.registerTool(
45703
46011
  "hn_get_best_stories",
45704
46012
  {
45705
46013
  title: "Get Best Stories",
45706
46014
  description: "Retrieve IDs of the best stories on Hacker News.",
45707
- inputSchema: external_exports3.object(storySchema),
46015
+ inputSchema: storySchema,
45708
46016
  annotations: {
45709
46017
  readOnlyHint: true,
45710
46018
  idempotentHint: true,
45711
46019
  openWorldHint: true
45712
46020
  }
45713
46021
  },
45714
- async (params) => handleStories(await api.getBestStories(), params)
46022
+ async (params) => {
46023
+ try {
46024
+ return await handleStories(await api.getBestStories(), params);
46025
+ } catch (error48) {
46026
+ return createInternalError(error48);
46027
+ }
46028
+ }
45715
46029
  );
45716
46030
  server.registerTool(
45717
46031
  "hn_get_ask_stories",
45718
46032
  {
45719
46033
  title: "Get Ask HN Stories",
45720
46034
  description: "Retrieve IDs of the latest Ask HN stories.",
45721
- inputSchema: external_exports3.object(storySchema),
46035
+ inputSchema: storySchema,
45722
46036
  annotations: {
45723
46037
  readOnlyHint: true,
45724
46038
  idempotentHint: true,
45725
46039
  openWorldHint: true
45726
46040
  }
45727
46041
  },
45728
- async (params) => handleStories(await api.getAskStories(), params)
46042
+ async (params) => {
46043
+ try {
46044
+ return await handleStories(await api.getAskStories(), params);
46045
+ } catch (error48) {
46046
+ return createInternalError(error48);
46047
+ }
46048
+ }
45729
46049
  );
45730
46050
  server.registerTool(
45731
46051
  "hn_get_show_stories",
45732
46052
  {
45733
46053
  title: "Get Show HN Stories",
45734
46054
  description: "Retrieve IDs of the latest Show HN stories.",
45735
- inputSchema: external_exports3.object(storySchema),
46055
+ inputSchema: storySchema,
45736
46056
  annotations: {
45737
46057
  readOnlyHint: true,
45738
46058
  idempotentHint: true,
45739
46059
  openWorldHint: true
45740
46060
  }
45741
46061
  },
45742
- async (params) => handleStories(await api.getShowStories(), params)
46062
+ async (params) => {
46063
+ try {
46064
+ return await handleStories(await api.getShowStories(), params);
46065
+ } catch (error48) {
46066
+ return createInternalError(error48);
46067
+ }
46068
+ }
45743
46069
  );
45744
46070
  server.registerTool(
45745
46071
  "hn_get_job_stories",
45746
46072
  {
45747
46073
  title: "Get Job Stories",
45748
46074
  description: "Retrieve IDs of the latest Job stories.",
45749
- inputSchema: external_exports3.object(storySchema),
46075
+ inputSchema: storySchema,
45750
46076
  annotations: {
45751
46077
  readOnlyHint: true,
45752
46078
  idempotentHint: true,
45753
46079
  openWorldHint: true
45754
46080
  }
45755
46081
  },
45756
- async (params) => handleStories(await api.getJobStories(), params)
46082
+ async (params) => {
46083
+ try {
46084
+ return await handleStories(await api.getJobStories(), params);
46085
+ } catch (error48) {
46086
+ return createInternalError(error48);
46087
+ }
46088
+ }
45757
46089
  );
45758
46090
  server.registerTool(
45759
46091
  "hn_get_item",
@@ -45771,32 +46103,36 @@ server.registerTool(
45771
46103
  }
45772
46104
  },
45773
46105
  async (params) => {
45774
- const item = await api.getItem(params.id);
45775
- if (params.response_format === "json" /* JSON */) {
46106
+ try {
46107
+ const item = await api.getItem(params.id);
46108
+ if (params.response_format === "json" /* JSON */) {
46109
+ return {
46110
+ content: [
46111
+ {
46112
+ type: "text",
46113
+ text: handleLimit(
46114
+ JSON.stringify(item, null, 2),
46115
+ "json" /* JSON */
46116
+ )
46117
+ }
46118
+ ],
46119
+ structuredContent: item
46120
+ };
46121
+ }
45776
46122
  return {
45777
46123
  content: [
45778
46124
  {
45779
46125
  type: "text",
45780
46126
  text: handleLimit(
45781
- JSON.stringify(item, null, 2),
45782
- "json" /* JSON */
46127
+ formatItemMarkdown(item),
46128
+ "markdown" /* MARKDOWN */
45783
46129
  )
45784
46130
  }
45785
- ],
45786
- structuredContent: item
46131
+ ]
45787
46132
  };
46133
+ } catch (error48) {
46134
+ return createInternalError(error48);
45788
46135
  }
45789
- return {
45790
- content: [
45791
- {
45792
- type: "text",
45793
- text: handleLimit(
45794
- formatItemMarkdown(item),
45795
- "markdown" /* MARKDOWN */
45796
- )
45797
- }
45798
- ]
45799
- };
45800
46136
  }
45801
46137
  );
45802
46138
  server.registerTool(
@@ -45815,43 +46151,48 @@ server.registerTool(
45815
46151
  }
45816
46152
  },
45817
46153
  async (params) => {
45818
- const user = await api.getUser(params.id);
45819
- if (params.response_format === "json" /* JSON */) {
46154
+ try {
46155
+ const user = await api.getUser(params.id);
46156
+ if (params.response_format === "json" /* JSON */) {
46157
+ return {
46158
+ content: [
46159
+ {
46160
+ type: "text",
46161
+ text: handleLimit(
46162
+ JSON.stringify(user, null, 2),
46163
+ "json" /* JSON */
46164
+ )
46165
+ }
46166
+ ],
46167
+ structuredContent: user
46168
+ };
46169
+ }
46170
+ const lines = [
46171
+ `# User: ${user.id}
46172
+ `,
46173
+ formatFields([
46174
+ ["Karma", user.karma],
46175
+ ["Created", new Date(user.created * 1e3).toLocaleString()],
46176
+ ["Submitted Items Count", user.submitted?.length]
46177
+ ])
46178
+ ];
46179
+ if (user.about) lines.push(`
46180
+ **About**:
46181
+ ${user.about}`);
45820
46182
  return {
45821
46183
  content: [
45822
46184
  {
45823
46185
  type: "text",
45824
46186
  text: handleLimit(
45825
- JSON.stringify(user, null, 2),
45826
- "json" /* JSON */
46187
+ lines.join("\n"),
46188
+ "markdown" /* MARKDOWN */
45827
46189
  )
45828
46190
  }
45829
- ],
45830
- structuredContent: user
46191
+ ]
45831
46192
  };
46193
+ } catch (error48) {
46194
+ return createInternalError(error48);
45832
46195
  }
45833
- const lines = [
45834
- `# User: ${user.id}`,
45835
- `**Karma**: ${user.karma}`,
45836
- `**Created**: ${new Date(user.created * 1e3).toLocaleString()}`
45837
- ];
45838
- if (user.about) lines.push(`
45839
- **About**:
45840
- ${user.about}`);
45841
- if (user.submitted)
45842
- lines.push(`
45843
- **Submitted Items Count**: ${user.submitted.length}`);
45844
- return {
45845
- content: [
45846
- {
45847
- type: "text",
45848
- text: handleLimit(
45849
- lines.join("\n"),
45850
- "markdown" /* MARKDOWN */
45851
- )
45852
- }
45853
- ]
45854
- };
45855
46196
  }
45856
46197
  );
45857
46198
  server.registerTool(
@@ -45859,9 +46200,7 @@ server.registerTool(
45859
46200
  {
45860
46201
  title: "Get Updates",
45861
46202
  description: "Retrieve recently updated item and profile IDs.",
45862
- inputSchema: external_exports3.object({
45863
- response_format: external_exports3.enum(Object.values(ResponseFormat)).default("markdown" /* MARKDOWN */)
45864
- }),
46203
+ inputSchema: storySchema,
45865
46204
  annotations: {
45866
46205
  readOnlyHint: true,
45867
46206
  idempotentHint: true,
@@ -45869,34 +46208,60 @@ server.registerTool(
45869
46208
  }
45870
46209
  },
45871
46210
  async (params) => {
45872
- const updates = await api.getUpdates();
45873
- if (params.response_format === "json" /* JSON */) {
46211
+ try {
46212
+ const updates = await api.getUpdates();
46213
+ const paginatedItems = applyPagination(updates.items, params);
46214
+ const paginatedProfiles = applyPagination(updates.profiles, params);
46215
+ if (params.response_format === "json" /* JSON */) {
46216
+ const result = {
46217
+ items: {
46218
+ total: paginatedItems.total,
46219
+ count: paginatedItems.items.length,
46220
+ offset: paginatedItems.offset,
46221
+ data: paginatedItems.items,
46222
+ has_more: paginatedItems.hasMore
46223
+ },
46224
+ profiles: {
46225
+ total: paginatedProfiles.total,
46226
+ count: paginatedProfiles.items.length,
46227
+ offset: paginatedProfiles.offset,
46228
+ data: paginatedProfiles.items,
46229
+ has_more: paginatedProfiles.hasMore
46230
+ }
46231
+ };
46232
+ return {
46233
+ content: [
46234
+ {
46235
+ type: "text",
46236
+ text: handleLimit(
46237
+ JSON.stringify(result, null, 2),
46238
+ "json" /* JSON */
46239
+ )
46240
+ }
46241
+ ],
46242
+ structuredContent: result
46243
+ };
46244
+ }
46245
+ let markdown = `# HN Recent Updates
46246
+
46247
+ `;
46248
+ markdown += `## Items
46249
+ ` + formatListItems(paginatedItems.items, (id) => `- [${id}](https://news.ycombinator.com/item?id=${id})`) + (paginatedItems.hasMore ? formatPaginationFooter(paginatedItems.offset, paginatedItems.limit, paginatedItems.total) : "") + `
46250
+
46251
+ `;
46252
+ markdown += `## Profiles
46253
+ ` + formatListItems(paginatedProfiles.items, (profile) => `- [${profile}](https://news.ycombinator.com/user?id=${profile})`) + (paginatedProfiles.hasMore ? formatPaginationFooter(paginatedProfiles.offset, paginatedProfiles.limit, paginatedProfiles.total) : "");
45874
46254
  return {
45875
46255
  content: [
45876
46256
  {
45877
46257
  type: "text",
45878
- text: handleLimit(
45879
- JSON.stringify(updates, null, 2),
45880
- "json" /* JSON */
45881
- )
46258
+ text: handleLimit(markdown, "markdown" /* MARKDOWN */)
45882
46259
  }
45883
- ],
45884
- structuredContent: updates
46260
+ ]
45885
46261
  };
46262
+ } catch (error48) {
46263
+ return createInternalError(error48);
45886
46264
  }
45887
- const markdown = `# HN Recent Updates
45888
-
45889
- **Items**: ${updates.items.slice(0, 50).join(", ")}${updates.items.length > 50 ? "..." : ""}
45890
-
45891
- **Profiles**: ${updates.profiles.slice(0, 50).join(", ")}${updates.profiles.length > 50 ? "..." : ""}`;
45892
- return {
45893
- content: [
45894
- {
45895
- type: "text",
45896
- text: handleLimit(markdown, "markdown" /* MARKDOWN */)
45897
- }
45898
- ]
45899
- };
45900
46265
  }
45901
46266
  );
45902
46267
  server.registerTool(
@@ -45912,16 +46277,20 @@ server.registerTool(
45912
46277
  }
45913
46278
  },
45914
46279
  async () => {
45915
- const maxId = await api.getMaxItem();
45916
- return {
45917
- content: [
45918
- {
45919
- type: "text",
45920
- text: `Current Max Item ID: ${maxId}
46280
+ try {
46281
+ const maxId = await api.getMaxItem();
46282
+ return {
46283
+ content: [
46284
+ {
46285
+ type: "text",
46286
+ text: `Current Max Item ID: ${maxId}
45921
46287
  URL: https://news.ycombinator.com/item?id=${maxId}`
45922
- }
45923
- ]
45924
- };
46288
+ }
46289
+ ]
46290
+ };
46291
+ } catch (error48) {
46292
+ return createInternalError(error48);
46293
+ }
45925
46294
  }
45926
46295
  );
45927
46296
  async function run() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fre4x/hn",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "A Hacker News MCP server for LLMs.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",