@fazer-ai/mcp-obsidian 1.1.2 → 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +106 -25
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  var __create = Object.create;
2
3
  var __getProtoOf = Object.getPrototypeOf;
3
4
  var __defProp = Object.defineProperty;
@@ -10269,12 +10270,19 @@ var CancelledNotificationSchema = NotificationSchema.extend({
10269
10270
  reason: z.string().optional()
10270
10271
  })
10271
10272
  });
10273
+ var IconSchema = z.object({
10274
+ src: z.string(),
10275
+ mimeType: z.optional(z.string()),
10276
+ sizes: z.optional(z.string())
10277
+ }).passthrough();
10272
10278
  var BaseMetadataSchema = z.object({
10273
10279
  name: z.string(),
10274
10280
  title: z.optional(z.string())
10275
10281
  }).passthrough();
10276
10282
  var ImplementationSchema = BaseMetadataSchema.extend({
10277
- version: z.string()
10283
+ version: z.string(),
10284
+ websiteUrl: z.optional(z.string()),
10285
+ icons: z.optional(z.array(IconSchema))
10278
10286
  });
10279
10287
  var ClientCapabilitiesSchema = z.object({
10280
10288
  experimental: z.optional(z.object({}).passthrough()),
@@ -10346,13 +10354,22 @@ var ResourceContentsSchema = z.object({
10346
10354
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
10347
10355
  text: z.string()
10348
10356
  });
10357
+ var Base64Schema = z.string().refine((val) => {
10358
+ try {
10359
+ atob(val);
10360
+ return true;
10361
+ } catch (_a) {
10362
+ return false;
10363
+ }
10364
+ }, { message: "Invalid Base64 string" });
10349
10365
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
10350
- blob: z.string().base64()
10366
+ blob: Base64Schema
10351
10367
  });
10352
10368
  var ResourceSchema = BaseMetadataSchema.extend({
10353
10369
  uri: z.string(),
10354
10370
  description: z.optional(z.string()),
10355
10371
  mimeType: z.optional(z.string()),
10372
+ icons: z.optional(z.array(IconSchema)),
10356
10373
  _meta: z.optional(z.object({}).passthrough())
10357
10374
  });
10358
10375
  var ResourceTemplateSchema = BaseMetadataSchema.extend({
@@ -10411,6 +10428,7 @@ var PromptArgumentSchema = z.object({
10411
10428
  var PromptSchema = BaseMetadataSchema.extend({
10412
10429
  description: z.optional(z.string()),
10413
10430
  arguments: z.optional(z.array(PromptArgumentSchema)),
10431
+ icons: z.optional(z.array(IconSchema)),
10414
10432
  _meta: z.optional(z.object({}).passthrough())
10415
10433
  });
10416
10434
  var ListPromptsRequestSchema = PaginatedRequestSchema.extend({
@@ -10433,13 +10451,13 @@ var TextContentSchema = z.object({
10433
10451
  }).passthrough();
10434
10452
  var ImageContentSchema = z.object({
10435
10453
  type: z.literal("image"),
10436
- data: z.string().base64(),
10454
+ data: Base64Schema,
10437
10455
  mimeType: z.string(),
10438
10456
  _meta: z.optional(z.object({}).passthrough())
10439
10457
  }).passthrough();
10440
10458
  var AudioContentSchema = z.object({
10441
10459
  type: z.literal("audio"),
10442
- data: z.string().base64(),
10460
+ data: Base64Schema,
10443
10461
  mimeType: z.string(),
10444
10462
  _meta: z.optional(z.object({}).passthrough())
10445
10463
  }).passthrough();
@@ -10489,6 +10507,7 @@ var ToolSchema = BaseMetadataSchema.extend({
10489
10507
  required: z.optional(z.array(z.string()))
10490
10508
  }).passthrough()),
10491
10509
  annotations: z.optional(ToolAnnotationsSchema),
10510
+ icons: z.optional(z.array(IconSchema)),
10492
10511
  _meta: z.optional(z.object({}).passthrough())
10493
10512
  });
10494
10513
  var ListToolsRequestSchema = PaginatedRequestSchema.extend({
@@ -10621,7 +10640,7 @@ var ElicitRequestSchema = RequestSchema.extend({
10621
10640
  })
10622
10641
  });
10623
10642
  var ElicitResultSchema = ResultSchema.extend({
10624
- action: z.enum(["accept", "reject", "cancel"]),
10643
+ action: z.enum(["accept", "decline", "cancel"]),
10625
10644
  content: z.optional(z.record(z.string(), z.unknown()))
10626
10645
  });
10627
10646
  var ResourceTemplateReferenceSchema = z.object({
@@ -10743,6 +10762,7 @@ class Protocol {
10743
10762
  this._responseHandlers = new Map;
10744
10763
  this._progressHandlers = new Map;
10745
10764
  this._timeoutInfo = new Map;
10765
+ this._pendingDebouncedNotifications = new Set;
10746
10766
  this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
10747
10767
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
10748
10768
  controller === null || controller === undefined || controller.abort(notification.params.reason);
@@ -10783,14 +10803,21 @@ class Protocol {
10783
10803
  }
10784
10804
  }
10785
10805
  async connect(transport) {
10806
+ var _a, _b, _c;
10786
10807
  this._transport = transport;
10808
+ const _onclose = (_a = this.transport) === null || _a === undefined ? undefined : _a.onclose;
10787
10809
  this._transport.onclose = () => {
10810
+ _onclose === null || _onclose === undefined || _onclose();
10788
10811
  this._onclose();
10789
10812
  };
10813
+ const _onerror = (_b = this.transport) === null || _b === undefined ? undefined : _b.onerror;
10790
10814
  this._transport.onerror = (error) => {
10815
+ _onerror === null || _onerror === undefined || _onerror(error);
10791
10816
  this._onerror(error);
10792
10817
  };
10818
+ const _onmessage = (_c = this._transport) === null || _c === undefined ? undefined : _c.onmessage;
10793
10819
  this._transport.onmessage = (message, extra) => {
10820
+ _onmessage === null || _onmessage === undefined || _onmessage(message, extra);
10794
10821
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
10795
10822
  this._onresponse(message);
10796
10823
  } else if (isJSONRPCRequest(message)) {
@@ -10808,6 +10835,7 @@ class Protocol {
10808
10835
  const responseHandlers = this._responseHandlers;
10809
10836
  this._responseHandlers = new Map;
10810
10837
  this._progressHandlers.clear();
10838
+ this._pendingDebouncedNotifications.clear();
10811
10839
  this._transport = undefined;
10812
10840
  (_a = this.onclose) === null || _a === undefined || _a.call(this);
10813
10841
  const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
@@ -10828,10 +10856,11 @@ class Protocol {
10828
10856
  Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
10829
10857
  }
10830
10858
  _onrequest(request, extra) {
10831
- var _a, _b, _c, _d;
10859
+ var _a, _b;
10832
10860
  const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== undefined ? _a : this.fallbackRequestHandler;
10861
+ const capturedTransport = this._transport;
10833
10862
  if (handler === undefined) {
10834
- (_b = this._transport) === null || _b === undefined || _b.send({
10863
+ capturedTransport === null || capturedTransport === undefined || capturedTransport.send({
10835
10864
  jsonrpc: "2.0",
10836
10865
  id: request.id,
10837
10866
  error: {
@@ -10845,34 +10874,34 @@ class Protocol {
10845
10874
  this._requestHandlerAbortControllers.set(request.id, abortController);
10846
10875
  const fullExtra = {
10847
10876
  signal: abortController.signal,
10848
- sessionId: (_c = this._transport) === null || _c === undefined ? undefined : _c.sessionId,
10849
- _meta: (_d = request.params) === null || _d === undefined ? undefined : _d._meta,
10877
+ sessionId: capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId,
10878
+ _meta: (_b = request.params) === null || _b === undefined ? undefined : _b._meta,
10850
10879
  sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
10851
10880
  sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
10852
10881
  authInfo: extra === null || extra === undefined ? undefined : extra.authInfo,
10853
- requestId: request.id
10882
+ requestId: request.id,
10883
+ requestInfo: extra === null || extra === undefined ? undefined : extra.requestInfo
10854
10884
  };
10855
10885
  Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
10856
- var _a2;
10857
10886
  if (abortController.signal.aborted) {
10858
10887
  return;
10859
10888
  }
10860
- return (_a2 = this._transport) === null || _a2 === undefined ? undefined : _a2.send({
10889
+ return capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send({
10861
10890
  result,
10862
10891
  jsonrpc: "2.0",
10863
10892
  id: request.id
10864
10893
  });
10865
10894
  }, (error) => {
10866
- var _a2, _b2;
10895
+ var _a2;
10867
10896
  if (abortController.signal.aborted) {
10868
10897
  return;
10869
10898
  }
10870
- return (_a2 = this._transport) === null || _a2 === undefined ? undefined : _a2.send({
10899
+ return capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send({
10871
10900
  jsonrpc: "2.0",
10872
10901
  id: request.id,
10873
10902
  error: {
10874
10903
  code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
10875
- message: (_b2 = error.message) !== null && _b2 !== undefined ? _b2 : "Internal error"
10904
+ message: (_a2 = error.message) !== null && _a2 !== undefined ? _a2 : "Internal error"
10876
10905
  }
10877
10906
  });
10878
10907
  }).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
@@ -10995,10 +11024,32 @@ class Protocol {
10995
11024
  });
10996
11025
  }
10997
11026
  async notification(notification, options) {
11027
+ var _a, _b;
10998
11028
  if (!this._transport) {
10999
11029
  throw new Error("Not connected");
11000
11030
  }
11001
11031
  this.assertNotificationCapability(notification.method);
11032
+ const debouncedMethods = (_b = (_a = this._options) === null || _a === undefined ? undefined : _a.debouncedNotificationMethods) !== null && _b !== undefined ? _b : [];
11033
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === undefined ? undefined : options.relatedRequestId);
11034
+ if (canDebounce) {
11035
+ if (this._pendingDebouncedNotifications.has(notification.method)) {
11036
+ return;
11037
+ }
11038
+ this._pendingDebouncedNotifications.add(notification.method);
11039
+ Promise.resolve().then(() => {
11040
+ var _a2;
11041
+ this._pendingDebouncedNotifications.delete(notification.method);
11042
+ if (!this._transport) {
11043
+ return;
11044
+ }
11045
+ const jsonrpcNotification2 = {
11046
+ ...notification,
11047
+ jsonrpc: "2.0"
11048
+ };
11049
+ (_a2 = this._transport) === null || _a2 === undefined || _a2.send(jsonrpcNotification2, options).catch((error) => this._onerror(error));
11050
+ });
11051
+ return;
11052
+ }
11002
11053
  const jsonrpcNotification = {
11003
11054
  ...notification,
11004
11055
  jsonrpc: "2.0"
@@ -11046,6 +11097,12 @@ class Server extends Protocol {
11046
11097
  var _a;
11047
11098
  super(options);
11048
11099
  this._serverInfo = _serverInfo;
11100
+ this._loggingLevels = new Map;
11101
+ this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
11102
+ this.isMessageIgnored = (level, sessionId) => {
11103
+ const currentLevel = this._loggingLevels.get(sessionId);
11104
+ return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
11105
+ };
11049
11106
  this._capabilities = (_a = options === null || options === undefined ? undefined : options.capabilities) !== null && _a !== undefined ? _a : {};
11050
11107
  this._instructions = options === null || options === undefined ? undefined : options.instructions;
11051
11108
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
@@ -11053,6 +11110,18 @@ class Server extends Protocol {
11053
11110
  var _a2;
11054
11111
  return (_a2 = this.oninitialized) === null || _a2 === undefined ? undefined : _a2.call(this);
11055
11112
  });
11113
+ if (this._capabilities.logging) {
11114
+ this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
11115
+ var _a2;
11116
+ const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === undefined ? undefined : _a2.headers["mcp-session-id"]) || undefined;
11117
+ const { level } = request.params;
11118
+ const parseResult = LoggingLevelSchema.safeParse(level);
11119
+ if (parseResult.success) {
11120
+ this._loggingLevels.set(transportSessionId, parseResult.data);
11121
+ }
11122
+ return {};
11123
+ });
11124
+ }
11056
11125
  }
11057
11126
  registerCapabilities(capabilities) {
11058
11127
  if (this.transport) {
@@ -11196,8 +11265,12 @@ class Server extends Protocol {
11196
11265
  async listRoots(params, options) {
11197
11266
  return this.request({ method: "roots/list", params }, ListRootsResultSchema, options);
11198
11267
  }
11199
- async sendLoggingMessage(params) {
11200
- return this.notification({ method: "notifications/message", params });
11268
+ async sendLoggingMessage(params, sessionId) {
11269
+ if (this._capabilities.logging) {
11270
+ if (!this.isMessageIgnored(params.level, sessionId)) {
11271
+ return this.notification({ method: "notifications/message", params });
11272
+ }
11273
+ }
11201
11274
  }
11202
11275
  async sendResourceUpdated(params) {
11203
11276
  return this.notification({
@@ -12512,7 +12585,8 @@ class McpServer {
12512
12585
  inputSchema: tool.inputSchema ? zodToJsonSchema(tool.inputSchema, {
12513
12586
  strictUnions: true
12514
12587
  }) : EMPTY_OBJECT_JSON_SCHEMA,
12515
- annotations: tool.annotations
12588
+ annotations: tool.annotations,
12589
+ _meta: tool._meta
12516
12590
  };
12517
12591
  if (tool.outputSchema) {
12518
12592
  toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, { strictUnions: true });
@@ -12565,7 +12639,7 @@ class McpServer {
12565
12639
  };
12566
12640
  }
12567
12641
  }
12568
- if (tool.outputSchema) {
12642
+ if (tool.outputSchema && !result.isError) {
12569
12643
  if (!result.structuredContent) {
12570
12644
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} has an output schema but no structured content was provided`);
12571
12645
  }
@@ -12877,13 +12951,14 @@ class McpServer {
12877
12951
  this._registeredPrompts[name] = registeredPrompt;
12878
12952
  return registeredPrompt;
12879
12953
  }
12880
- _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, callback) {
12954
+ _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, _meta, callback) {
12881
12955
  const registeredTool = {
12882
12956
  title,
12883
12957
  description,
12884
12958
  inputSchema: inputSchema === undefined ? undefined : z.object(inputSchema),
12885
12959
  outputSchema: outputSchema === undefined ? undefined : z.object(outputSchema),
12886
12960
  annotations,
12961
+ _meta,
12887
12962
  callback,
12888
12963
  enabled: true,
12889
12964
  disable: () => registeredTool.update({ enabled: false }),
@@ -12905,6 +12980,8 @@ class McpServer {
12905
12980
  registeredTool.callback = updates.callback;
12906
12981
  if (typeof updates.annotations !== "undefined")
12907
12982
  registeredTool.annotations = updates.annotations;
12983
+ if (typeof updates._meta !== "undefined")
12984
+ registeredTool._meta = updates._meta;
12908
12985
  if (typeof updates.enabled !== "undefined")
12909
12986
  registeredTool.enabled = updates.enabled;
12910
12987
  this.sendToolListChanged();
@@ -12938,14 +13015,14 @@ class McpServer {
12938
13015
  }
12939
13016
  }
12940
13017
  const callback = rest[0];
12941
- return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, callback);
13018
+ return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, undefined, callback);
12942
13019
  }
12943
13020
  registerTool(name, config, cb) {
12944
13021
  if (this._registeredTools[name]) {
12945
13022
  throw new Error(`Tool ${name} is already registered`);
12946
13023
  }
12947
- const { title, description, inputSchema, outputSchema, annotations } = config;
12948
- return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, cb);
13024
+ const { title, description, inputSchema, outputSchema, annotations, _meta } = config;
13025
+ return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, _meta, cb);
12949
13026
  }
12950
13027
  prompt(name, ...rest) {
12951
13028
  if (this._registeredPrompts[name]) {
@@ -12978,6 +13055,9 @@ class McpServer {
12978
13055
  isConnected() {
12979
13056
  return this.server.transport !== undefined;
12980
13057
  }
13058
+ async sendLoggingMessage(params, sessionId) {
13059
+ return this.server.sendLoggingMessage(params, sessionId);
13060
+ }
12981
13061
  sendResourceListChanged() {
12982
13062
  if (this.isConnected()) {
12983
13063
  this.server.sendResourceListChanged();
@@ -12995,7 +13075,8 @@ class McpServer {
12995
13075
  }
12996
13076
  }
12997
13077
  var EMPTY_OBJECT_JSON_SCHEMA = {
12998
- type: "object"
13078
+ type: "object",
13079
+ properties: {}
12999
13080
  };
13000
13081
  function isZodRawShape(obj) {
13001
13082
  if (typeof obj !== "object" || obj === null)
@@ -13577,7 +13658,7 @@ function registerTools(server) {
13577
13658
 
13578
13659
  // package.json
13579
13660
  var name = "@fazer-ai/mcp-obsidian";
13580
- var version = "1.1.2";
13661
+ var version = "1.2.0";
13581
13662
 
13582
13663
  // src/index.ts
13583
13664
  var server = new McpServer({ name, version }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fazer-ai/mcp-obsidian",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "module": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/index.js",
@@ -26,19 +26,19 @@
26
26
  ],
27
27
  "scripts": {
28
28
  "dev": "bun run --watch src/index.ts",
29
- "build": "bun build src/index.ts --target node --outdir=dist",
29
+ "build": "echo '#!/usr/bin/env node' > dist/index.js && bun build src/index.ts --target node >> dist/index.js",
30
30
  "lint": "bun biome check",
31
31
  "format": "bun biome check --write",
32
32
  "prepublishOnly": "bun run build"
33
33
  },
34
34
  "devDependencies": {
35
- "@biomejs/biome": "^2.0.5",
35
+ "@biomejs/biome": "^2.2.4",
36
36
  "@types/bun": "latest"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "typescript": "^5"
40
40
  },
41
41
  "dependencies": {
42
- "@modelcontextprotocol/sdk": "^1.13.1"
42
+ "@modelcontextprotocol/sdk": "^1.18.2"
43
43
  }
44
44
  }