@chrischall/microsoft-teams-mcp 0.6.2 → 0.8.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.
@@ -0,0 +1,124 @@
1
+ import { decodeEntities } from './model.js';
2
+ const RECORDING_TYPE = 'RichText/Media_CallRecording';
3
+ /**
4
+ * An AMS object id as Teams issues them: `0-<region>-<shard>-<32 hex>`. Only
5
+ * an id of this shape is ever put in a URL, so a message cannot point the
6
+ * bearer at another path or host.
7
+ */
8
+ export function isAmsObjectId(id) {
9
+ return /^\d-[a-z]{2,8}-[a-z0-9]{1,8}-[0-9a-f]{32}$/.test(id);
10
+ }
11
+ /** The transcript view of an object on the Teams gateway (see the module note). */
12
+ export function transcriptUrl(objectId) {
13
+ if (!isAmsObjectId(objectId))
14
+ throw new Error(`not an AMS object id: ${JSON.stringify(objectId)}`);
15
+ return `https://us-prod.asyncgw.teams.microsoft.com/v1/objects/${objectId}/views/transcript`;
16
+ }
17
+ function attr(tagRe, xml) {
18
+ const m = tagRe.exec(xml);
19
+ return m?.[1] !== undefined ? decodeEntities(m[1]) : undefined;
20
+ }
21
+ /** `0:22:43.96` → `{ text: '0:22:43', seconds: 1363 }`. */
22
+ function parseDuration(raw) {
23
+ const m = raw !== undefined ? /^(\d+):(\d{2}):(\d{2})/.exec(raw) : null;
24
+ if (!m)
25
+ return undefined;
26
+ const [h, mm, ss] = [Number(m[1]), Number(m[2]), Number(m[3])];
27
+ return { text: `${h}:${m[2]}:${m[3]}`, seconds: h * 3600 + mm * 60 + ss };
28
+ }
29
+ /** The recording a `RichText/Media_CallRecording` message describes, or undefined for any other message. */
30
+ export function parseRecording(m) {
31
+ if (m.messagetype !== RECORDING_TYPE || typeof m.content !== 'string' || m.id === undefined)
32
+ return undefined;
33
+ const xml = m.content;
34
+ const objectId = attr(/<Id\s+type="AMSDocumentID"\s+value="([^"]*)"/i, xml);
35
+ if (objectId === undefined || !isAmsObjectId(objectId))
36
+ return undefined;
37
+ const title = attr(/<Title>([^<]*)<\/Title>/i, xml);
38
+ const duration = parseDuration(attr(/<RecordingContent\b[^>]*\bduration="([^"]*)"/i, xml));
39
+ const status = attr(/<RecordingStatus\b[^>]*\bstatus="([^"]*)"/i, xml);
40
+ const playUrl = attr(/<item\s+type="onedriveForBusinessVideo"\s+uri="(https:[^"]*)"/i, xml) ?? attr(/<a\s+href="(https:[^"]*)"/i, xml);
41
+ return {
42
+ message_id: m.id,
43
+ time: m.composetime ?? m.originalarrivaltime ?? new Date(Number(m.id)).toISOString(),
44
+ ...(title !== undefined && title.trim() !== '' ? { title: title.trim() } : {}),
45
+ ...(duration !== undefined ? { duration: duration.text, duration_seconds: duration.seconds } : {}),
46
+ ...(status !== undefined ? { status } : {}),
47
+ object_id: objectId,
48
+ has_transcript: /<item\s+type="amsTranscript"/i.test(xml),
49
+ ...(playUrl !== undefined ? { play_url: playUrl } : {}),
50
+ };
51
+ }
52
+ /**
53
+ * The transcribed recordings among `messages`, newest first: one per object,
54
+ * described by its newest message (a chunk posts several as its status moves).
55
+ */
56
+ export function listRecordings(messages) {
57
+ const byObject = new Map();
58
+ for (const m of messages) {
59
+ const r = parseRecording(m);
60
+ if (r === undefined)
61
+ continue;
62
+ const seen = byObject.get(r.object_id);
63
+ if (seen === undefined || Number(r.message_id) > Number(seen.message_id))
64
+ byObject.set(r.object_id, r);
65
+ }
66
+ return [...byObject.values()].filter((r) => r.has_transcript).sort((a, b) => Number(b.message_id) - Number(a.message_id));
67
+ }
68
+ const TIMING = /^(\d{1,2}:)?\d{2}:\d{2}\.\d{3}\s+-->\s+((?:\d{1,2}:)?\d{2}:\d{2}\.\d{3})/;
69
+ /** Parse a WebVTT document into cues; a `<v Speaker>` voice span names the speaker. */
70
+ export function parseVtt(vtt) {
71
+ const blocks = vtt.replace(/^/, '').replace(/\r\n?/g, '\n').split(/\n{2,}/);
72
+ const cues = [];
73
+ for (const block of blocks) {
74
+ const lines = block.split('\n').filter((l) => l.trim() !== '');
75
+ const at = lines.findIndex((l) => TIMING.test(l.trim()));
76
+ if (at < 0)
77
+ continue; // the header, a NOTE, a STYLE or REGION block
78
+ const timing = lines[at].trim();
79
+ const start = timing.split(/\s+-->/)[0];
80
+ const end = TIMING.exec(timing)[2];
81
+ const body = lines.slice(at + 1).join('\n');
82
+ const voice = /<v(?:\.[^\s>]*)?\s+([^>]+)>/.exec(body);
83
+ const text = decodeEntities(body.replace(/<[^>]*>/g, ''))
84
+ .replace(/\s+/g, ' ')
85
+ .trim();
86
+ if (text === '')
87
+ continue;
88
+ cues.push({ start, end, ...(voice ? { speaker: decodeEntities(voice[1].trim()) } : {}), text });
89
+ }
90
+ return cues;
91
+ }
92
+ /**
93
+ * The transcript as readable text: one line per speaker turn — a speaker's
94
+ * consecutive cues run together under the first cue's time (`[hh:mm:ss]`).
95
+ */
96
+ export function renderTranscriptText(cues) {
97
+ const lines = [];
98
+ let turn;
99
+ const flush = () => {
100
+ if (turn)
101
+ lines.push(`[${turn.at}] ${turn.speaker !== undefined ? `${turn.speaker}: ` : ''}${turn.parts.join(' ')}`);
102
+ };
103
+ for (const c of cues) {
104
+ if (turn && c.speaker !== undefined && c.speaker === turn.speaker) {
105
+ turn.parts.push(c.text);
106
+ continue;
107
+ }
108
+ flush();
109
+ turn = { at: clockTime(c.start), speaker: c.speaker, parts: [c.text] };
110
+ }
111
+ flush();
112
+ return lines.join('\n');
113
+ }
114
+ /** A cue time (`[h]h:mm:ss.mmm` or `mm:ss.mmm`) as `hh:mm:ss`. */
115
+ function clockTime(t) {
116
+ const parts = t.replace(/\.\d+$/, '').split(':');
117
+ while (parts.length < 3)
118
+ parts.unshift('0');
119
+ return parts.map((p) => p.padStart(2, '0')).join(':');
120
+ }
121
+ /** Each speaker once, in order of first appearance. */
122
+ export function transcriptSpeakers(cues) {
123
+ return [...new Set(cues.flatMap((c) => (c.speaker !== undefined ? [c.speaker] : [])))];
124
+ }
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.2'; // x-release-please-version
13
+ export const VERSION = '0.8.0'; // x-release-please-version
package/mint.yaml CHANGED
@@ -72,6 +72,11 @@ env:
72
72
  help: >-
73
73
  Default IANA time zone (e.g. America/New_York) for the tz argument of
74
74
  the read tools; messages then carry time_local. Unset means UTC only.
75
+ - name: TEAMS_OUTPUT_DIR
76
+ required: false
77
+ help: >-
78
+ Folder teams_export_messages writes exports into (each export gets its own
79
+ subfolder). Unset means ~/Downloads/microsoft-teams-mcp.
75
80
  - name: TEAMS_SUBSTRATE_TOKEN_FILE
76
81
  required: false
77
82
  help: >-
@@ -111,3 +116,16 @@ egress:
111
116
  - us-prod.asyncgw.teams.microsoft.com
112
117
  - substrate.office.com
113
118
  - '*.sharepoint.com'
119
+ # Sample prompts for the public catalog — each is answered by the read tools
120
+ # alone (teams_list_unread_messages, teams_search_messages, teams_list_activity), and none
121
+ # marks anything read.
122
+ examples:
123
+ - prompt: >-
124
+ Catch me up on my unread Teams messages and tell me which ones need a
125
+ reply from me.
126
+ note: Reads unread chats and channels; nothing is marked read.
127
+ - prompt: >-
128
+ Search my Teams chats from the last two weeks for messages about the
129
+ quarterly budget review.
130
+ note: Uses the same search the Teams search box does.
131
+ - prompt: What mentions and replies have I had in my Teams Activity feed today?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/microsoft-teams-mcp",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
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.1.0",
48
+ "@chrischall/mcp-utils": "^3.3.0",
49
49
  "@fetchproxy/server": "^3.6.2",
50
50
  "@modelcontextprotocol/server": "^2.3.0",
51
51
  "dotenv": "^18.0.1",
@@ -58,5 +58,9 @@
58
58
  "esbuild": "^0.28.1",
59
59
  "typescript": "^7.0.2",
60
60
  "vitest": "^5.0.0"
61
+ },
62
+ "allowScripts": {
63
+ "esbuild": false,
64
+ "fsevents": false
61
65
  }
62
66
  }
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.2",
9
+ "version": "0.8.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/microsoft-teams-mcp",
14
- "version": "0.6.2",
14
+ "version": "0.8.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -107,6 +107,13 @@
107
107
  "format": "string",
108
108
  "isSecret": false
109
109
  },
110
+ {
111
+ "name": "TEAMS_OUTPUT_DIR",
112
+ "description": "Folder teams_export_messages writes exports into. Unset means ~/Downloads/microsoft-teams-mcp.",
113
+ "isRequired": false,
114
+ "format": "string",
115
+ "isSecret": false
116
+ },
110
117
  {
111
118
  "name": "MCP_CONFIRM_MODE",
112
119
  "description": "What the writes (teams_send_message, teams_react, teams_mark_read and the read tools' mark_read) do on a client that cannot show a confirmation prompt (claude.ai, Claude Desktop): \"ask-user\" (default: the first call returns a preview and a confirmToken, and the model must get your approval in chat before using it), \"auto\" (the model may use the token after reviewing the preview itself) or \"refuse\". An unrecognised value is treated as refuse.",
@@ -96,6 +96,21 @@ messages, read the Activity feed, fetch an inline image — are in
96
96
  SharePoint (Graph and SharePoint both refuse it). `properties.files` is a
97
97
  JSON *string*; parse it for each file's name and `openUrl`.
98
98
 
99
+ ## In context groups
100
+
101
+ When the MCP is served through mcp-host, its tools join the **work** group
102
+ (`_meta.mint.domain: "work"`; the healthcheck joins none). The one canonical
103
+ read is **`teams_list_changed_conversations`** for *what's new*: no subject
104
+ (Teams serves one signed-in account) and no range (it takes a cursor; none
105
+ means the last 24 hours). With `view: "brief"` it answers one line per
106
+ changed chat or channel — `title — <newest ISO time | no date> — <n> new,
107
+ <m> from others`. There is no *what's due* or *what's on* read here (Teams'
108
+ Calendar is Outlook's). A compound ask such as "anything new in Teams, and
109
+ what's on my calendar today?" is answered by the work group fanning out to
110
+ this read and the Outlook one. The group needs the signed-in Teams tab: with
111
+ no browser bridge it answers "Microsoft Teams needs your browser open" for
112
+ this source rather than guessing.
113
+
99
114
  ## Writes (sending, reacting, marking read)
100
115
 
101
116
  Everything above only reads. To post a message or a reaction, prefer the