@chrischall/microsoft-teams-mcp 0.6.1 → 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.
@@ -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 { parseBoolEnv } from '@chrischall/mcp-utils';
3
3
  import { reportCacheWriteFailure } from './token-cache.js';
4
4
  /**
@@ -16,16 +16,6 @@ export function substrateTokenCachePath(env = process.env) {
16
16
  fileName: 'substrate-token.json',
17
17
  });
18
18
  }
19
- /** Same `BearerTokens` guard as the other caches; copied, as it is module-private there. */
20
- function isToken(raw) {
21
- if (raw === null || typeof raw !== 'object')
22
- return false;
23
- const t = raw;
24
- return (typeof t.accessToken === 'string' &&
25
- t.accessToken !== '' &&
26
- typeof t.expiresAt === 'number' &&
27
- (t.refreshToken === undefined || typeof t.refreshToken === 'string'));
28
- }
29
19
  /**
30
20
  * The Substrate token cache, or `null` when it is off or there is nothing to
31
21
  * cache. Gated like the SharePoint cache: `TEAMS_TOKEN_CACHE` (default on), and
@@ -40,7 +30,7 @@ export function createSubstrateTokenCache(env = process.env) {
40
30
  const file = createFileStatePersistence({
41
31
  filePath: substrateTokenCachePath(env),
42
32
  boundTo: 'fetchproxy',
43
- validate: (raw) => (isToken(raw) ? raw : null),
33
+ validate: (raw) => (isBearerTokens(raw) ? raw : null),
44
34
  });
45
35
  return {
46
36
  load: () => file.load(),
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.1'; // x-release-please-version
13
+ export const VERSION = '0.6.2'; // x-release-please-version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/microsoft-teams-mcp",
3
- "version": "0.6.1",
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,7 +45,7 @@
45
45
  "typecheck": "tsc -p tsconfig.check.json"
46
46
  },
47
47
  "dependencies": {
48
- "@chrischall/mcp-utils": "^3.0.3",
48
+ "@chrischall/mcp-utils": "^3.1.0",
49
49
  "@fetchproxy/server": "^3.6.2",
50
50
  "@modelcontextprotocol/server": "^2.3.0",
51
51
  "dotenv": "^18.0.1",
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.1",
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.1",
14
+ "version": "0.6.2",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },