@chrischall/microsoft-teams-mcp 0.6.0 → 0.6.2

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.
package/dist/substrate.js CHANGED
@@ -50,9 +50,9 @@
50
50
  * As with the other clients, the bridge is touched only to capture the token
51
51
  * (`substrate-auth.ts`); every request is a plain Node `fetch`.
52
52
  */
53
- import { decodeJwtExp, fetchBounded, McpToolError, parseBoolEnv } from '@chrischall/mcp-utils';
53
+ import { fetchBounded, McpToolError, parseBoolEnv } from '@chrischall/mcp-utils';
54
54
  import { describeTransportFailure } from './network-error.js';
55
- import { TokenManager } from '@chrischall/mcp-utils/session';
55
+ import { createCapturedTokenManager } from '@chrischall/mcp-utils/session';
56
56
  import { createSubstrateTokenCache } from './substrate-token-cache.js';
57
57
  export const SUBSTRATE_QUERY_URL = 'https://substrate.office.com/searchservice/api/v2/query';
58
58
  /**
@@ -62,24 +62,10 @@ export const SUBSTRATE_QUERY_URL = 'https://substrate.office.com/searchservice/a
62
62
  * for another capture window. Mode "substrate" forces a fresh attempt.
63
63
  */
64
64
  export const CAPTURE_RETRY_COOLDOWN_MS = 10 * 60 * 1000;
65
- /** Fallback lifetime for a token whose `exp` we cannot read (as in `sharepoint.ts`). */
66
- const UNKNOWN_TOKEN_TTL_MS = 10 * 60 * 1000;
67
- /** Stands in for a refresh token this flow does not have (see `sharepoint.ts`). */
68
- const RECAPTURE_SENTINEL = 'fetchproxy:recapture';
69
65
  /** Per-request deadline, covering the body read. */
70
66
  const REQUEST_TIMEOUT_MS = 30_000;
71
67
  /** A search response is a page of summaries; anything near this is not one. */
72
68
  const MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
73
- function toBearerTokens(accessToken) {
74
- let expiresAt;
75
- try {
76
- expiresAt = decodeJwtExp(accessToken) * 1000;
77
- }
78
- catch {
79
- expiresAt = Date.now() + UNKNOWN_TOKEN_TTL_MS;
80
- }
81
- return { accessToken, refreshToken: RECAPTURE_SENTINEL, expiresAt };
82
- }
83
69
  /** Capture lazily, so boot never loads the bridge (see `sharepoint.ts`). */
84
70
  async function captureSubstrateTokenLazily() {
85
71
  const mod = await import('./substrate-auth.js');
@@ -224,20 +210,18 @@ export class SubstrateClient {
224
210
  this.#fetchImpl = opts.fetchImpl ?? ((input, init) => fetch(input, init));
225
211
  const recapture = async () => {
226
212
  try {
227
- const tokens = toBearerTokens(await capture());
213
+ const token = await capture();
228
214
  this.#captureFailure = null;
229
- return tokens;
215
+ return token;
230
216
  }
231
217
  catch (error) {
232
218
  this.#captureFailure = { at: Date.now(), error };
233
219
  throw error;
234
220
  }
235
221
  };
236
- const persistence = createSubstrateTokenCache(env);
237
- this.#manager = new TokenManager({
238
- initial: recapture,
239
- refresh: recapture,
240
- ...(persistence ? { persistence } : {}),
222
+ this.#manager = createCapturedTokenManager({
223
+ capture: recapture,
224
+ persistence: createSubstrateTokenCache(env),
241
225
  });
242
226
  // Like SharePoint, there is no direct-token env var: the bridge is the only source.
243
227
  if (parseBoolEnv('TEAMS_DISABLE_FETCHPROXY', { env })) {
@@ -1,4 +1,4 @@
1
- import { createFileStatePersistence, resolveStateFile, } from '@chrischall/mcp-utils/session';
1
+ import { createFileStatePersistence, isBearerTokens, resolveStateFile, } from '@chrischall/mcp-utils/session';
2
2
  import { readEnvVar, parseBoolEnv } from '@chrischall/mcp-utils';
3
3
  /**
4
4
  * Where the captured chat-service access token is cached between runs.
@@ -15,15 +15,6 @@ export function tokenCachePath(env = process.env) {
15
15
  fileName: 'token.json',
16
16
  });
17
17
  }
18
- function isToken(raw) {
19
- if (raw === null || typeof raw !== 'object')
20
- return false;
21
- const t = raw;
22
- return (typeof t.accessToken === 'string' &&
23
- t.accessToken !== '' &&
24
- typeof t.expiresAt === 'number' &&
25
- (t.refreshToken === undefined || typeof t.refreshToken === 'string'));
26
- }
27
18
  /**
28
19
  * What a cached token is bound to, or `null` when there is nothing worth
29
20
  * caching.
@@ -50,7 +41,7 @@ export function createTokenCache(env = process.env) {
50
41
  return createFileStatePersistence({
51
42
  filePath: tokenCachePath(env),
52
43
  boundTo,
53
- validate: (raw) => (isToken(raw) ? raw : null),
44
+ validate: (raw) => (isBearerTokens(raw) ? raw : null),
54
45
  });
55
46
  }
56
47
  /**
@@ -1,6 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, mapWithConcurrency, McpToolError, toolAnnotations, WriteOutcomeUnknownError, } from '@chrischall/mcp-utils';
3
- import { outcomeUnknownStatus } from '../chatsvc.js';
2
+ import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, mapWithConcurrency, McpToolError, toolAnnotations, WriteOutcomeUnknownError, writeOutcomeStatus, } from '@chrischall/mcp-utils';
4
3
  import { clipText } from '../compose.js';
5
4
  import { htmlToText, isUnread, readHorizon, SELF_CHAT, senderMri } from '../model.js';
6
5
  import { confirmedSummary } from './confirm.js';
@@ -101,7 +100,7 @@ export async function confirmMarks(ctx, opts) {
101
100
  }
102
101
  /** Why a write went unconfirmed, for a warning. */
103
102
  function unconfirmedWhy(e) {
104
- const status = outcomeUnknownStatus(e);
103
+ const status = writeOutcomeStatus(e);
105
104
  return e.timedOut ? 'it did not answer in time' : status !== undefined ? `it answered HTTP ${status}` : 'the connection dropped';
106
105
  }
107
106
  /**
@@ -1,6 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, WriteOutcomeUnknownError, } from '@chrischall/mcp-utils';
3
- import { outcomeUnknownStatus } from '../chatsvc.js';
2
+ import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, WriteOutcomeUnknownError, writeOutcomeStatus, } from '@chrischall/mcp-utils';
4
3
  import { clipText } from '../compose.js';
5
4
  import { htmlToText, normaliseMessage, senderMri } from '../model.js';
6
5
  import { wrapApiError } from './errors.js';
@@ -169,7 +168,7 @@ export function registerReactTools(server, { chatsvc }) {
169
168
  }
170
169
  const shown = remove ? 'gone' : 'present';
171
170
  if (unconfirmed !== undefined && verified !== true) {
172
- const status = outcomeUnknownStatus(unconfirmed);
171
+ const status = writeOutcomeStatus(unconfirmed);
173
172
  const why = unconfirmed.timedOut
174
173
  ? 'it did not answer in time'
175
174
  : status !== undefined
@@ -1,6 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, WriteOutcomeUnknownError, } from '@chrischall/mcp-utils';
3
- import { outcomeUnknownStatus } from '../chatsvc.js';
2
+ import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, unknownOutcomeReason, writeOrUnknown, } from '@chrischall/mcp-utils';
4
3
  import { buildSendBody, clipText, mentionsProperty, newClientMessageId, qtdMsgsProperty, quoteHtml, renderMessageHtml, } from '../compose.js';
5
4
  import { htmlToText, isUserMessage, normaliseMessage, SELF_CHAT, senderMri } from '../model.js';
6
5
  import { resolveListed } from './conversation.js';
@@ -133,32 +132,16 @@ async function threadRoot(chatsvc, channelId, id, me) {
133
132
  /**
134
133
  * A send that may or may not have landed becomes a `status: "unknown"`
135
134
  * result, never an error: an error invites a fresh preview and a second post.
136
- * Any other failure is a real failure and still throws.
135
+ * Any other failure is a real failure and still throws (`writeOrUnknown`).
137
136
  */
138
- async function writeOrUnknown(run, conversation) {
139
- try {
140
- return { ok: true, value: await run() };
141
- }
142
- catch (e) {
143
- if (!(e instanceof WriteOutcomeUnknownError))
144
- throw e;
145
- const status = outcomeUnknownStatus(e);
146
- const why = e.timedOut
147
- ? 'it did not answer in time'
148
- : status !== undefined
149
- ? `it answered HTTP ${status} after the post was sent`
150
- : 'the connection dropped';
151
- return {
152
- ok: false,
153
- result: untrustedResult({
154
- status: 'unknown',
155
- conversation,
156
- warning: `Teams did not confirm this post (${why}), ` +
157
- 'so it may already be in the conversation. Check the conversation before retrying ' +
158
- '(teams_read_conversation); do not resend blindly.',
159
- }),
160
- };
161
- }
137
+ function unconfirmedPost(conversation) {
138
+ return (e) => untrustedResult({
139
+ status: 'unknown',
140
+ conversation,
141
+ warning: `Teams did not confirm this post (${unknownOutcomeReason(e, { sent: 'the post' })}), ` +
142
+ 'so it may already be in the conversation. Check the conversation before retrying ' +
143
+ '(teams_read_conversation); do not resend blindly.',
144
+ });
162
145
  }
163
146
  export function registerSendTools(server, { chatsvc }) {
164
147
  server.registerTool(TOOL, {
@@ -273,7 +256,7 @@ export function registerSendTools(server, { chatsvc }) {
273
256
  now: new Date(),
274
257
  ...properties,
275
258
  });
276
- const sent = await writeOrUnknown(() => chatsvc.sendMessage(postTo, body), target);
259
+ const sent = await writeOrUnknown(() => chatsvc.sendMessage(postTo, body), unconfirmedPost(target));
277
260
  if (!sent.ok)
278
261
  return sent.result;
279
262
  // Read back: a channel lists its thread replies, so read the channel itself.
package/dist/version.js CHANGED
@@ -10,4 +10,4 @@
10
10
  * line below and nowhere else — not even in prose.
11
11
  */
12
12
  export const PACKAGE_NAME = 'microsoft-teams-mcp';
13
- export const VERSION = '0.6.0'; // x-release-please-version
13
+ export const VERSION = '0.6.2'; // x-release-please-version
package/mint.yaml CHANGED
@@ -77,6 +77,12 @@ env:
77
77
  help: >-
78
78
  Path to the cached Substrate search token file. Defaults to
79
79
  ~/.microsoft-teams-mcp/substrate-token.json.
80
+ - name: TEAMS_SHAREPOINT_TOKEN_FILE
81
+ required: false
82
+ help: >-
83
+ Path to the cached SharePoint token file (one token per SharePoint host,
84
+ used to download shared files). Defaults to
85
+ ~/.microsoft-teams-mcp/sharepoint-tokens.json.
80
86
  state:
81
87
  dataDir: true
82
88
  reason: >-
@@ -91,9 +97,17 @@ egress:
91
97
  # (us-api.asm.skype.com and the like), retried through the Teams gateway
92
98
  # (us-prod.asyncgw.teams.microsoft.com) when the store cannot be reached —
93
99
  # the client sends its token nowhere else. Message search goes to Microsoft
94
- # Substrate (src/substrate.ts) with its own token.
100
+ # Substrate (src/substrate.ts) with its own token. Shared files
101
+ # (teams_get_attachment) download from the file's SharePoint tenant host
102
+ # (<tenant>.sharepoint.com / <tenant>-my.sharepoint.com, src/sharepoint.ts):
103
+ # the authed driveItem GET and then its pre-signed @content.downloadUrl,
104
+ # which SharePoint issues on the same tenant host (download.aspx + tempauth).
105
+ # That the pre-signed link never redirects off *.sharepoint.com has not been
106
+ # confirmed on a live fenced download; if it does, the refusal now names the
107
+ # host it was refused (src/network-error.ts), and that host belongs here.
95
108
  allow:
96
109
  - teams.cloud.microsoft
97
110
  - '*.asm.skype.com'
98
111
  - us-prod.asyncgw.teams.microsoft.com
99
112
  - substrate.office.com
113
+ - '*.sharepoint.com'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/microsoft-teams-mcp",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "mcpName": "io.github.chrischall/microsoft-teams-mcp",
5
5
  "description": "Microsoft Teams MCP server for Claude — developed and maintained by AI (Claude Code)",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
@@ -45,8 +45,8 @@
45
45
  "typecheck": "tsc -p tsconfig.check.json"
46
46
  },
47
47
  "dependencies": {
48
- "@chrischall/mcp-utils": "^3.0.0",
49
- "@fetchproxy/server": "^3.6.0",
48
+ "@chrischall/mcp-utils": "^3.1.0",
49
+ "@fetchproxy/server": "^3.6.2",
50
50
  "@modelcontextprotocol/server": "^2.3.0",
51
51
  "dotenv": "^18.0.1",
52
52
  "zod": "^4.6.5"
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/microsoft-teams-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.6.0",
9
+ "version": "0.6.2",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/microsoft-teams-mcp",
14
- "version": "0.6.0",
14
+ "version": "0.6.2",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -86,6 +86,20 @@
86
86
  "format": "string",
87
87
  "isSecret": false
88
88
  },
89
+ {
90
+ "name": "TEAMS_SUBSTRATE_TOKEN_FILE",
91
+ "description": "Where the captured Substrate search token is cached. Defaults to ~/.microsoft-teams-mcp/substrate-token.json.",
92
+ "isRequired": false,
93
+ "format": "string",
94
+ "isSecret": false
95
+ },
96
+ {
97
+ "name": "TEAMS_SHAREPOINT_TOKEN_FILE",
98
+ "description": "Where the captured SharePoint tokens are cached. Defaults to ~/.microsoft-teams-mcp/sharepoint-tokens.json.",
99
+ "isRequired": false,
100
+ "format": "string",
101
+ "isSecret": false
102
+ },
89
103
  {
90
104
  "name": "TEAMS_TIME_ZONE",
91
105
  "description": "Default IANA time zone (e.g. America/New_York) for time_local on read results. Unset means UTC only.",