@softeria/ms-365-mcp-server 0.14.0 → 0.15.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.
@@ -2,38 +2,14 @@ import logger from "./logger.js";
2
2
  import { refreshAccessToken } from "./lib/microsoft-auth.js";
3
3
  class GraphClient {
4
4
  constructor(authManager) {
5
- // accountId -> (filePath -> sessionId)
6
5
  this.accessToken = null;
7
6
  this.refreshToken = null;
8
7
  this.authManager = authManager;
9
- this.sessions = /* @__PURE__ */ new Map();
10
8
  }
11
9
  setOAuthTokens(accessToken, refreshToken) {
12
10
  this.accessToken = accessToken;
13
11
  this.refreshToken = refreshToken || null;
14
12
  }
15
- async getCurrentAccountId() {
16
- const currentAccount = await this.authManager.getCurrentAccount();
17
- return currentAccount?.homeAccountId || null;
18
- }
19
- getAccountSessions(accountId) {
20
- if (!this.sessions.has(accountId)) {
21
- this.sessions.set(accountId, /* @__PURE__ */ new Map());
22
- }
23
- return this.sessions.get(accountId);
24
- }
25
- async getSessionForFile(filePath) {
26
- const accountId = await this.getCurrentAccountId();
27
- if (!accountId) return null;
28
- const accountSessions = this.getAccountSessions(accountId);
29
- return accountSessions.get(filePath) || null;
30
- }
31
- async setSessionForFile(filePath, sessionId) {
32
- const accountId = await this.getCurrentAccountId();
33
- if (!accountId) return;
34
- const accountSessions = this.getAccountSessions(accountId);
35
- accountSessions.set(filePath, sessionId);
36
- }
37
13
  async makeRequest(endpoint, options = {}) {
38
14
  let accessToken = options.accessToken || this.accessToken || await this.authManager.getToken();
39
15
  let refreshToken = options.refreshToken || this.refreshToken;
@@ -94,23 +70,10 @@ class GraphClient {
94
70
  }
95
71
  }
96
72
  async performRequest(endpoint, accessToken, options) {
97
- let url;
98
- let sessionId = null;
99
- if (options.excelFile && !endpoint.startsWith("/drive") && !endpoint.startsWith("/users") && !endpoint.startsWith("/me") && !endpoint.startsWith("/teams") && !endpoint.startsWith("/chats") && !endpoint.startsWith("/planner")) {
100
- sessionId = await this.getSessionForFile(options.excelFile);
101
- if (!sessionId) {
102
- sessionId = await this.createSessionWithToken(options.excelFile, accessToken);
103
- }
104
- url = `https://graph.microsoft.com/v1.0/me/drive/root:${options.excelFile}:${endpoint}`;
105
- } else if (endpoint.startsWith("/drive") || endpoint.startsWith("/users") || endpoint.startsWith("/me") || endpoint.startsWith("/teams") || endpoint.startsWith("/chats") || endpoint.startsWith("/planner") || endpoint.startsWith("/search")) {
106
- url = `https://graph.microsoft.com/v1.0${endpoint}`;
107
- } else {
108
- throw new Error("Excel operation requested without specifying a file");
109
- }
73
+ const url = `https://graph.microsoft.com/v1.0${endpoint}`;
110
74
  const headers = {
111
75
  Authorization: `Bearer ${accessToken}`,
112
76
  "Content-Type": "application/json",
113
- ...sessionId && { "workbook-session-id": sessionId },
114
77
  ...options.headers
115
78
  };
116
79
  return fetch(url, {
@@ -132,42 +95,6 @@ class GraphClient {
132
95
  };
133
96
  }
134
97
  }
135
- async createSessionWithToken(filePath, accessToken) {
136
- try {
137
- if (!filePath) {
138
- logger.error("No file path provided for Excel session");
139
- return null;
140
- }
141
- const existingSession = await this.getSessionForFile(filePath);
142
- if (existingSession) {
143
- return existingSession;
144
- }
145
- logger.info(`Creating new Excel session for file: ${filePath}`);
146
- const response = await fetch(
147
- `https://graph.microsoft.com/v1.0/me/drive/root:${filePath}:/workbook/createSession`,
148
- {
149
- method: "POST",
150
- headers: {
151
- Authorization: `Bearer ${accessToken}`,
152
- "Content-Type": "application/json"
153
- },
154
- body: JSON.stringify({ persistChanges: true })
155
- }
156
- );
157
- if (!response.ok) {
158
- const errorText = await response.text();
159
- logger.error(`Failed to create session: ${response.status} - ${errorText}`);
160
- return null;
161
- }
162
- const result = await response.json();
163
- logger.info(`Session created successfully for file: ${filePath}`);
164
- await this.setSessionForFile(filePath, result.id);
165
- return result.id;
166
- } catch (error) {
167
- logger.error(`Error creating Excel session: ${error}`);
168
- return null;
169
- }
170
- }
171
98
  formatJsonResponse(data, rawResponse = false) {
172
99
  if (rawResponse) {
173
100
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softeria/ms-365-mcp-server",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",