@softeria/ms-365-mcp-server 0.2.2 → 0.3.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,317 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- export function registerExcelTools(server, graphClient) {
4
- server.tool(
5
- 'update-excel',
6
- {
7
- filePath: z
8
- .string()
9
- .describe(
10
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
11
- ),
12
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
13
- address: z.string().describe("Range address (e.g., 'A1:B5')"),
14
- values: z.array(z.array(z.any())).describe('Values to update'),
15
- },
16
- async ({ filePath, worksheet, address, values }) => {
17
- return graphClient.graphRequest(
18
- `/workbook/worksheets('${worksheet}')/range(address='${address}')`,
19
- {
20
- method: 'PATCH',
21
- body: JSON.stringify({ values }),
22
- excelFile: filePath,
23
- }
24
- );
25
- }
26
- );
27
-
28
- server.tool(
29
- 'create-chart',
30
- {
31
- filePath: z
32
- .string()
33
- .describe(
34
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
35
- ),
36
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
37
- type: z.string().describe("Chart type (e.g., 'ColumnClustered', 'Line', 'Pie')"),
38
- dataRange: z.string().describe("Data range for the chart (e.g., 'A1:B10')"),
39
- title: z.string().optional().describe('Title for the chart'),
40
- position: z
41
- .object({
42
- x: z.number().describe('X position'),
43
- y: z.number().describe('Y position'),
44
- width: z.number().describe('Width'),
45
- height: z.number().describe('Height'),
46
- })
47
- .describe('Chart position and dimensions'),
48
- },
49
- async ({ filePath, worksheet, type, dataRange, title, position }) => {
50
- const body = {
51
- type,
52
- sourceData: dataRange,
53
- position,
54
- };
55
-
56
- if (title) {
57
- body.title = { text: title };
58
- }
59
-
60
- return graphClient.graphRequest(`/workbook/worksheets('${worksheet}')/charts/add`, {
61
- method: 'POST',
62
- body: JSON.stringify(body),
63
- excelFile: filePath,
64
- });
65
- }
66
- );
67
-
68
- server.tool(
69
- 'format-range',
70
- {
71
- filePath: z
72
- .string()
73
- .describe(
74
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
75
- ),
76
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
77
- range: z.string().describe("Range address (e.g., 'A1:B5')"),
78
- format: z
79
- .object({
80
- fill: z
81
- .object({
82
- color: z.string().optional().describe("Background color (e.g., '#FFFF00')"),
83
- })
84
- .optional(),
85
- font: z
86
- .object({
87
- bold: z.boolean().optional().describe('Bold text'),
88
- italic: z.boolean().optional().describe('Italic text'),
89
- color: z.string().optional().describe("Font color (e.g., '#FF0000')"),
90
- size: z.number().optional().describe('Font size'),
91
- })
92
- .optional(),
93
- numberFormat: z
94
- .string()
95
- .optional()
96
- .describe("Number format (e.g., '0.00%', 'mm/dd/yyyy')"),
97
- })
98
- .describe('Formatting to apply'),
99
- },
100
- async ({ filePath, worksheet, range, format }) => {
101
- return graphClient.graphRequest(
102
- `/workbook/worksheets('${worksheet}')/range(address='${range}')/format`,
103
- {
104
- method: 'PATCH',
105
- body: JSON.stringify(format),
106
- excelFile: filePath,
107
- }
108
- );
109
- }
110
- );
111
-
112
- server.tool(
113
- 'sort-range',
114
- {
115
- filePath: z
116
- .string()
117
- .describe(
118
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
119
- ),
120
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
121
- range: z.string().describe("Range address (e.g., 'A1:B5')"),
122
- sortFields: z
123
- .array(
124
- z.object({
125
- key: z.number().describe('Column index to sort by (zero-based)'),
126
- sortOn: z
127
- .string()
128
- .optional()
129
- .describe("Sorting criteria (e.g., 'Value', 'CellColor', 'FontColor', 'Icon')"),
130
- ascending: z.boolean().optional().describe('Sort in ascending order (default: true)'),
131
- color: z
132
- .object({
133
- color: z.string().describe('HTML color code'),
134
- type: z.string().describe("Color type (e.g., 'Background', 'Font')"),
135
- })
136
- .optional()
137
- .describe('Color information for sorting by color'),
138
- dataOption: z
139
- .string()
140
- .optional()
141
- .describe("Data option for sorting (e.g., 'Normal', 'TextAsNumber')"),
142
- icon: z
143
- .object({
144
- set: z.string().describe('Icon set name'),
145
- index: z.number().describe('Icon index'),
146
- })
147
- .optional()
148
- .describe('Icon information for sorting by icon'),
149
- })
150
- )
151
- .describe('Fields to sort by'),
152
- matchCase: z.boolean().optional().describe('Whether the sort is case-sensitive'),
153
- hasHeaders: z.boolean().optional().describe('Whether the range has headers (default: false)'),
154
- orientation: z.string().optional().describe("Sort orientation ('Rows' or 'Columns')"),
155
- method: z
156
- .string()
157
- .optional()
158
- .describe("Sort method for Chinese characters ('PinYin' or 'StrokeCount')"),
159
- },
160
- async ({
161
- filePath,
162
- worksheet,
163
- range,
164
- sortFields,
165
- matchCase,
166
- hasHeaders,
167
- orientation,
168
- method,
169
- }) => {
170
- const body = {
171
- fields: sortFields,
172
- };
173
-
174
- if (matchCase !== undefined) body.matchCase = matchCase;
175
- if (hasHeaders !== undefined) body.hasHeaders = hasHeaders;
176
- if (orientation) body.orientation = orientation;
177
- if (method) body.method = method;
178
-
179
- return graphClient.graphRequest(
180
- `/workbook/worksheets('${worksheet}')/range(address='${range}')/sort/apply`,
181
- {
182
- method: 'POST',
183
- body: JSON.stringify(body),
184
- excelFile: filePath,
185
- }
186
- );
187
- }
188
- );
189
-
190
- server.tool(
191
- 'create-table',
192
- {
193
- filePath: z
194
- .string()
195
- .describe(
196
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
197
- ),
198
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
199
- range: z.string().describe("Range address (e.g., 'A1:B5')"),
200
- hasHeaders: z.boolean().optional().describe('Whether the range has headers'),
201
- tableName: z.string().optional().describe('Name for the new table'),
202
- },
203
- async ({ filePath, worksheet, range, hasHeaders = true, tableName }) => {
204
- const body = {
205
- address: range,
206
- hasHeaders,
207
- };
208
-
209
- if (tableName) {
210
- body.name = tableName;
211
- }
212
-
213
- return graphClient.graphRequest(`/workbook/worksheets('${worksheet}')/tables/add`, {
214
- method: 'POST',
215
- body: JSON.stringify(body),
216
- excelFile: filePath,
217
- });
218
- }
219
- );
220
-
221
- server.tool(
222
- 'get-range',
223
- {
224
- filePath: z
225
- .string()
226
- .describe(
227
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
228
- ),
229
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
230
- range: z.string().describe("Range address (e.g., 'A1:B5')"),
231
- },
232
- async ({ filePath, worksheet, range }) => {
233
- return graphClient.graphRequest(
234
- `/workbook/worksheets('${worksheet}')/range(address='${range}')`,
235
- {
236
- method: 'GET',
237
- excelFile: filePath,
238
- }
239
- );
240
- }
241
- );
242
-
243
- server.tool(
244
- 'list-worksheets',
245
- {
246
- filePath: z
247
- .string()
248
- .describe(
249
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
250
- ),
251
- },
252
- async ({ filePath }) => {
253
- return graphClient.graphRequest('/workbook/worksheets', {
254
- method: 'GET',
255
- excelFile: filePath,
256
- });
257
- }
258
- );
259
-
260
- server.tool(
261
- 'close-session',
262
- {
263
- filePath: z
264
- .string()
265
- .describe(
266
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
267
- ),
268
- },
269
- async ({ filePath }) => {
270
- return graphClient.closeSession(filePath);
271
- }
272
- );
273
-
274
- server.tool(
275
- 'delete-chart',
276
- {
277
- filePath: z
278
- .string()
279
- .describe(
280
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
281
- ),
282
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
283
- chartName: z.string().describe('The name of the chart to delete'),
284
- },
285
- async ({ filePath, worksheet, chartName }) => {
286
- return graphClient.graphRequest(
287
- `/workbook/worksheets('${worksheet}')/charts('${chartName}')`,
288
- {
289
- method: 'DELETE',
290
- excelFile: filePath,
291
- }
292
- );
293
- }
294
- );
295
-
296
- server.tool(
297
- 'get-charts',
298
- {
299
- filePath: z
300
- .string()
301
- .describe(
302
- 'Path to the Excel file, including leading slash (e.g., "/Documents/budget.xlsx")'
303
- ),
304
- worksheet: z.string().default('Sheet1').describe('Worksheet name'),
305
- },
306
- async ({ filePath, worksheet }) => {
307
- return graphClient.graphRequest(`/workbook/worksheets('${worksheet}')/charts`, {
308
- method: 'GET',
309
- excelFile: filePath,
310
- });
311
- }
312
- );
313
-
314
- server.tool('close-all-sessions', {}, async () => {
315
- return graphClient.closeAllSessions();
316
- });
317
- }