-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
1126 lines (1063 loc) · 33.9 KB
/
server.ts
File metadata and controls
1126 lines (1063 loc) · 33.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
ListResourcesRequestSchema,
ReadResourceRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { readFileSync, existsSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import {
TableToolInputSchema,
QueryTableDataInputSchema,
ImageToolInputSchema,
MasterDetailToolInputSchema,
TreeToolInputSchema,
ListToolInputSchema,
ChartToolInputSchema,
} from "./types.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Helper to convert file paths to data URIs
function fileToDataUri(src: string): string {
// If already a data URI or HTTP URL, return as-is
if (
src.startsWith("data:") ||
src.startsWith("http://") ||
src.startsWith("https://")
) {
return src;
}
// Convert file:// URL to local path
let filePath = src;
if (src.startsWith("file://")) {
// Remove file:// prefix and decode URL encoding
filePath = decodeURIComponent(src.slice(7));
// On Windows, handle drive letters correctly
// file:///C:/path -> C:/path (already ok)
// file://d:/path -> d:/path (remove leading slash)
if (
process.platform === "win32" &&
filePath.startsWith("/") &&
filePath[2] === ":"
) {
filePath = filePath.slice(1);
}
}
// Normalize the path
filePath = filePath.replace(/\\/g, "/");
console.log(`Converting to data URI: ${filePath}`);
// Check if file exists
if (!existsSync(filePath)) {
console.warn(`File not found: ${filePath}, returning original src`);
return src;
}
// Determine MIME type from extension
const ext = filePath.toLowerCase().split(".").pop() || "";
const mimeTypes: Record<string, string> = {
png: "image/png",
jpg: "image/jpeg",
jpeg: "image/jpeg",
gif: "image/gif",
svg: "image/svg+xml",
webp: "image/webp",
bmp: "image/bmp",
};
const mimeType = mimeTypes[ext] || "image/png";
// Read file and convert to base64
try {
const buffer = readFileSync(filePath);
const base64 = buffer.toString("base64");
console.log(`Successfully converted ${filePath} to data URI`);
return `data:${mimeType};base64,${base64}`;
} catch (error) {
console.error(`Failed to read file ${filePath}:`, error);
return src;
}
}
// Store table data for server-side operations (in memory for demo)
let currentTableData: any = null;
const server = new Server(
{
name: "visuals-mcp",
version: "1.0.0",
},
{
capabilities: {
tools: {},
resources: {},
},
},
);
/**
* List available tools
*/
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "display_table",
title: "Display Table",
description:
"Display an interactive table with sorting, filtering, pagination, column visibility, and row selection. " +
"Accepts column definitions and row data. Returns a visual table component that users can interact with.",
inputSchema: {
type: "object",
properties: {
columns: {
type: "array",
description: "Array of column definitions",
items: {
type: "object",
properties: {
key: {
type: "string",
description:
"Unique key for the column (maps to data property)",
},
label: {
type: "string",
description: "Display label for the column header",
},
type: {
type: "string",
enum: ["string", "number", "date", "boolean"],
default: "string",
},
sortable: { type: "boolean", default: true },
filterable: { type: "boolean", default: true },
width: {
type: "number",
description: "Column width in pixels",
},
},
required: ["key", "label"],
},
},
rows: {
type: "array",
description: "Array of row data objects",
items: { type: "object" },
},
title: {
type: "string",
description: "Optional title for the table",
},
allowRowSelection: { type: "boolean", default: true },
allowColumnVisibility: { type: "boolean", default: true },
pageSize: { type: "number", default: 10 },
},
required: ["columns", "rows"],
},
_meta: {
ui: {
resourceUri: "table://display",
visibility: ["model", "app"],
},
},
},
{
name: "query_table_data",
title: "Query Table Data",
description:
"Query table data with server-side sorting and filtering. UI-only tool for performance with large datasets.",
inputSchema: {
type: "object",
properties: {
sortBy: {
type: "array",
items: {
type: "object",
properties: {
columnKey: { type: "string" },
direction: { type: "string", enum: ["asc", "desc"] },
},
},
},
filters: { type: "object" },
page: { type: "number" },
pageSize: { type: "number" },
},
},
_meta: {
ui: {
visibility: ["app"], // UI-only tool - hidden from model
},
},
},
{
name: "display_image",
title: "Display Image",
description:
"Display/show any image to the user with an interactive preview card. Use this tool to show screenshots, diagrams, charts, photographs, or any visual content. Provides optional metadata including title, caption, dimensions, and file information. Always use this tool whenever you need to present visual content. This also applies to listings and any other imageoperations like get, download etc..these formats are explicitly handled: PNG, JPG, JPEG, GIF, SVG, WebP, BMP. The UI itself can display any image if the src is a valid URL or data URI, but local file paths are only auto-converted for those extensions",
inputSchema: {
type: "object",
properties: {
src: {
type: "string",
description:
"Image URL or data URI. Required. This is the source of the image to display.",
},
title: {
type: "string",
description:
"Optional title displayed above the image. Use to provide context or describe what the image shows.",
},
alt: {
type: "string",
description:
"Alt text for accessibility. Describe the image content for screen readers and when image fails to load.",
},
caption: {
type: "string",
description:
"Optional caption displayed below the image. Use to explain key details, findings, or analysis related to the image.",
},
width: {
type: "number",
description:
"Optional width in pixels to constrain the image. Use to control display size.",
},
height: {
type: "number",
description:
"Optional height in pixels to constrain the image. Use to control display size.",
},
filename: {
type: "string",
description:
"Optional original filename to display. Useful for showing file information alongside the preview.",
},
sizeBytes: {
type: "number",
description:
"Optional file size in bytes. Displayed as formatted file size (KB, MB). Useful for showing storage information.",
},
},
required: ["src"],
},
_meta: {
ui: {
resourceUri: "image://preview",
visibility: ["model", "app"],
},
},
},
{
name: "display_master_detail",
title: "Display Master Detail",
description:
"Display a master-detail view with a list of items on the left/top and details on the right/bottom. " +
"The detail panel can show tables, images, lists, or custom text/HTML content. Perfect for browsing collections, " +
"comparing items, or navigating hierarchical data.",
inputSchema: {
type: "object",
properties: {
title: {
type: "string",
description: "Optional title for the master-detail view",
},
masterItems: {
type: "array",
description: "Array of items to display in the master list",
items: {
type: "object",
properties: {
id: {
type: "string",
description: "Unique identifier for the item",
},
label: {
type: "string",
description: "Display label for the item",
},
description: {
type: "string",
description: "Optional description shown below the label",
},
icon: {
type: "string",
description: "Optional icon or emoji to display",
},
metadata: {
type: "object",
description: "Additional metadata for the item",
},
},
required: ["id", "label"],
},
},
detailContents: {
type: "object",
description:
"Map of item IDs to their detail content. Each key should match a masterItems ID.",
additionalProperties: {
oneOf: [
{
type: "object",
properties: {
type: { type: "string", enum: ["table"] },
data: {
type: "object",
description:
"Table data following display_table schema",
},
},
required: ["type", "data"],
},
{
type: "object",
properties: {
type: { type: "string", enum: ["image"] },
data: {
type: "object",
description:
"Image data following display_image schema",
},
},
required: ["type", "data"],
},
{
type: "object",
properties: {
type: { type: "string", enum: ["list"] },
data: {
type: "object",
description: "List data following display_list schema",
},
},
required: ["type", "data"],
},
{
type: "object",
properties: {
type: { type: "string", enum: ["text"] },
data: {
type: "object",
properties: {
content: {
type: "string",
description: "Text or HTML content to display",
},
isHtml: {
type: "boolean",
description: "Whether content is HTML",
default: false,
},
},
required: ["content"],
},
},
required: ["type", "data"],
},
],
},
},
defaultSelectedId: {
type: "string",
description: "ID of item to select by default",
},
masterWidth: {
type: "number",
description: "Width of master panel in pixels (default: 300)",
default: 300,
},
orientation: {
type: "string",
enum: ["horizontal", "vertical"],
description:
"Layout orientation: horizontal (side-by-side) or vertical (stacked)",
default: "horizontal",
},
},
required: ["masterItems", "detailContents"],
},
_meta: {
ui: {
resourceUri: "master-detail://display",
visibility: ["model", "app"],
},
},
},
{
name: "display_tree",
title: "Display Tree",
description:
"Display an interactive tree view for hierarchical data structures. " +
"Use this tool to visualize file systems, organizational charts, nested categories, JSON/XML structures, or any hierarchical relationships. " +
"Supports node expansion/collapse, metadata display, and export functionality.",
inputSchema: {
type: "object",
properties: {
nodes: {
type: "array",
description: "Array of root tree nodes",
items: {
type: "object",
properties: {
id: {
type: "string",
description: "Unique identifier for the node",
},
label: {
type: "string",
description: "Display label for the node",
},
children: {
type: "array",
description: "Optional child nodes",
items: { type: "object" },
},
metadata: {
type: "object",
description: "Optional metadata for the node",
},
icon: {
type: "string",
description: "Optional icon/emoji for the node",
},
expanded: {
type: "boolean",
default: false,
description:
"Whether the node should be initially expanded",
},
},
required: ["id", "label"],
},
},
title: {
type: "string",
description: "Optional title for the tree view",
},
expandAll: {
type: "boolean",
default: false,
description: "Expand all nodes initially",
},
showMetadata: {
type: "boolean",
default: true,
description: "Show metadata in tree nodes",
},
},
required: ["nodes"],
},
_meta: {
ui: {
resourceUri: "tree://display",
visibility: ["model", "app"],
},
},
},
{
name: "display_list",
title: "Display List",
description:
"Display an interactive, customizable list with optional checkboxes, drag-and-drop reordering, image thumbnails, and copy/export functionality. " +
"Perfect for displaying any type of list: tasks, items, options, files, or any sequential data. " +
"Features include compact/comfortable views, individual item copy, and bulk export (CSV, JSON, text).",
inputSchema: {
type: "object",
properties: {
items: {
type: "array",
description: "Array of list items to display",
items: {
type: "object",
properties: {
id: {
type: "string",
description: "Unique identifier for the list item",
},
content: {
type: "string",
description: "Text content of the list item",
},
checked: {
type: "boolean",
default: false,
description: "Whether the item is checked",
},
image: {
type: "string",
description: "Optional image URL or data URI for the item",
},
subtext: {
type: "string",
description: "Optional secondary text/description",
},
metadata: {
type: "object",
description: "Optional metadata for the item",
},
},
required: ["id", "content"],
},
},
title: {
type: "string",
description: "Optional title for the list",
},
allowReorder: {
type: "boolean",
default: true,
description: "Allow drag-and-drop reordering",
},
allowCheckboxes: {
type: "boolean",
default: true,
description: "Show checkboxes for items",
},
compact: {
type: "boolean",
default: false,
description: "Use compact layout mode",
},
showImages: {
type: "boolean",
default: true,
description: "Display item images if available",
},
},
required: ["items"],
},
_meta: {
ui: {
resourceUri: "list://display",
visibility: ["model", "app"],
},
},
},
{
name: "display_chart",
title: "Display Chart",
description:
"Display interactive charts with support for multiple chart types: line, bar, area, pie, scatter, and composed charts. " +
"Use this to visualize data trends, comparisons, distributions, and relationships. " +
"Supports multiple charts in a single view with customizable layouts (vertical, horizontal, grid). " +
"Features include legends, tooltips, grid lines, dual Y-axes, and data export (JSON, CSV).",
inputSchema: {
type: "object",
properties: {
charts: {
type: "array",
description: "Array of chart configurations to display",
items: {
type: "object",
properties: {
type: {
type: "string",
enum: ["line", "bar", "area", "pie", "scatter", "composed"],
description: "Type of chart to display",
},
data: {
type: "array",
description: "Array of data points for the chart",
items: { type: "object" },
},
series: {
type: "array",
description:
"Series configurations (for line, bar, area charts)",
items: {
type: "object",
properties: {
dataKey: {
type: "string",
description: "Key in data objects for this series",
},
name: {
type: "string",
description: "Display name for the series",
},
color: {
type: "string",
description:
"Color for the series (hex or CSS color)",
},
type: {
type: "string",
enum: ["line", "bar", "area"],
description: "Type for composed charts",
},
yAxisId: {
type: "string",
default: "left",
description: "Y-axis identifier (left or right)",
},
},
required: ["dataKey"],
},
},
xAxisKey: {
type: "string",
description:
"Key for X-axis data (for line, bar, area, scatter charts)",
},
nameKey: {
type: "string",
description: "Key for labels (for pie charts)",
},
dataKey: {
type: "string",
description: "Key for values (for pie charts)",
},
title: {
type: "string",
description: "Title for this chart",
},
width: {
type: "number",
description: "Width in pixels (default: 100%)",
},
height: {
type: "number",
default: 300,
description: "Height in pixels",
},
showLegend: {
type: "boolean",
default: true,
description: "Show legend",
},
showGrid: {
type: "boolean",
default: true,
description: "Show grid lines",
},
showTooltip: {
type: "boolean",
default: true,
description: "Show tooltips on hover",
},
stacked: {
type: "boolean",
default: false,
description: "Stack bars/areas (for bar and area charts)",
},
},
required: ["type", "data"],
},
},
title: {
type: "string",
description: "Overall title for the chart view",
},
layout: {
type: "string",
enum: ["vertical", "horizontal", "grid"],
default: "vertical",
description: "Layout for multiple charts",
},
},
required: ["charts"],
},
_meta: {
ui: {
resourceUri: "chart://display",
visibility: ["model", "app"],
},
},
},
],
};
});
/**
* Handle tool calls
*/
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === "display_table") {
// Validate input
const input = TableToolInputSchema.parse(args);
// Store data for server-side operations
currentTableData = input;
return {
content: [
{
type: "text",
text: `Displaying table with ${input.rows.length} rows and ${input.columns.length} columns.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: input, // Pass data to the UI
},
},
};
}
if (name === "query_table_data") {
// Validate input
const query = QueryTableDataInputSchema.parse(args);
if (!currentTableData) {
throw new Error("No table data available. Call display_table first.");
}
let filteredRows = [...currentTableData.rows];
// Apply filters
if (query.filters) {
Object.entries(query.filters).forEach(([key, value]) => {
filteredRows = filteredRows.filter((row) =>
String(row[key]).toLowerCase().includes(String(value).toLowerCase()),
);
});
}
// Apply sorting
if (query.sortBy && query.sortBy.length > 0) {
filteredRows.sort((a, b) => {
for (const sort of query.sortBy!) {
const aVal = a[sort.columnKey];
const bVal = b[sort.columnKey];
let comparison = 0;
if (aVal < bVal) comparison = -1;
if (aVal > bVal) comparison = 1;
if (comparison !== 0) {
return sort.direction === "asc" ? comparison : -comparison;
}
}
return 0;
});
}
// Apply pagination
const page = query.page ?? 0;
const pageSize = query.pageSize ?? currentTableData.pageSize ?? 10;
const start = page * pageSize;
const paginatedRows = filteredRows.slice(start, start + pageSize);
return {
content: [
{
type: "text",
text: `Returned ${paginatedRows.length} rows (page ${page + 1})`,
},
],
_meta: {
ui: {
data: {
rows: paginatedRows,
totalRows: filteredRows.length,
page,
pageSize,
},
},
},
};
}
if (name === "display_image") {
const input = ImageToolInputSchema.parse(args);
// Convert file paths to data URIs for browser compatibility
const processedInput = {
...input,
src: fileToDataUri(input.src),
};
return {
content: [
{
type: "text",
text: `Displaying image preview.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: processedInput,
},
},
};
}
if (name === "display_master_detail") {
const input = MasterDetailToolInputSchema.parse(args);
// Process image sources in detail contents
const processedDetailContents: Record<string, any> = {};
for (const [itemId, content] of Object.entries(input.detailContents)) {
if (content.type === "image") {
processedDetailContents[itemId] = {
...content,
data: {
...content.data,
src: fileToDataUri(content.data.src),
},
};
} else {
processedDetailContents[itemId] = content;
}
}
const processedInput = {
...input,
detailContents: processedDetailContents,
};
return {
content: [
{
type: "text",
text: `Displaying master-detail view with ${input.masterItems.length} items.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: processedInput,
},
},
};
}
if (name === "display_tree") {
const input = TreeToolInputSchema.parse(args);
// Count total nodes recursively
const countNodes = (nodes: any[]): number => {
return nodes.reduce(
(count, node) =>
count + 1 + (node.children ? countNodes(node.children) : 0),
0,
);
};
const totalNodes = countNodes(input.nodes);
return {
content: [
{
type: "text",
text: `Displaying tree view with ${totalNodes} total nodes.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: input,
},
},
};
}
if (name === "display_list") {
const input = ListToolInputSchema.parse(args);
// Convert image file paths to data URIs if present
const processedItems = input.items.map((item) => {
if (item.image) {
return {
...item,
image: fileToDataUri(item.image),
};
}
return item;
});
const processedInput = {
...input,
items: processedItems,
};
return {
content: [
{
type: "text",
text: `Displaying list with ${input.items.length} items.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: processedInput,
},
},
};
}
if (name === "display_chart") {
const input = ChartToolInputSchema.parse(args);
const totalDataPoints = input.charts.reduce(
(sum, chart) => sum + chart.data.length,
0,
);
return {
content: [
{
type: "text",
text: `Displaying ${input.charts.length} chart${input.charts.length !== 1 ? "s" : ""} with ${totalDataPoints} total data points.${input.title ? ` Title: ${input.title}` : ""}`,
},
],
_meta: {
ui: {
data: input,
},
},
};
}
throw new Error(`Unknown tool: ${name}`);
});
/**
* List available resources
*/
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "table://display",
name: "Interactive Table Display",
description:
"HTML resource for rendering interactive tables with TanStack Table",
mimeType: "text/html",
},
{
uri: "image://preview",
name: "Image Preview Card",
description: "HTML resource for rendering image preview cards",
mimeType: "text/html",
},
{
uri: "master-detail://display",
name: "Master-Detail View",
description:
"HTML resource for rendering master-detail layouts with tables, images, and text",
mimeType: "text/html",
},
{
uri: "tree://display",
name: "Interactive Tree View",
description:
"HTML resource for rendering hierarchical tree structures with expand/collapse and export",
mimeType: "text/html",
},
{
uri: "list://display",
name: "Interactive List Display",
description:
"HTML resource for rendering interactive lists with drag-and-drop reordering, checkboxes, and export",
mimeType: "text/html",
},
{
uri: "chart://display",
name: "Interactive Chart Display",
description:
"HTML resource for rendering interactive charts (line, bar, area, pie, scatter, composed) with Recharts",
mimeType: "text/html",
},
],
};
});
/**
* Read resource content
*/
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const { uri } = request.params;
if (uri === "table://display") {
try {
const htmlPath = join(__dirname, "mcp-table.html");
const htmlContent = readFileSync(htmlPath, "utf-8");
return {
contents: [
{
uri,
mimeType: "text/html",
text: htmlContent,
},
],
};
} catch (error) {
throw new Error(