@chrischall/microsoft-teams-mcp 0.2.6 → 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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +9 -1
- package/dist/bundle.js +430 -91
- package/dist/client.js +21 -12
- package/dist/tools/activity.js +11 -4
- package/dist/tools/channels.js +17 -9
- package/dist/tools/chat.js +17 -9
- package/dist/tools/conversation.js +7 -1
- package/dist/tools/healthcheck.js +15 -0
- package/dist/tools/limit.js +52 -0
- package/dist/version.js +1 -1
- package/package.json +5 -5
- package/server.json +18 -3
package/dist/client.js
CHANGED
|
@@ -182,7 +182,13 @@ export const DOM_LIST_SELECTORS = [
|
|
|
182
182
|
];
|
|
183
183
|
export class TeamsClient {
|
|
184
184
|
#transport;
|
|
185
|
-
|
|
185
|
+
/**
|
|
186
|
+
* The in-flight (or settled) start, memoized so parallel first calls share
|
|
187
|
+
* ONE `transport.start()` — two concurrent starts would each create and
|
|
188
|
+
* persist a fresh fetchproxy identity keypair, leaving the paired key and
|
|
189
|
+
* the on-disk key out of step. Cleared on failure so the next call retries.
|
|
190
|
+
*/
|
|
191
|
+
#starting;
|
|
186
192
|
constructor(opts = {}) {
|
|
187
193
|
this.#transport =
|
|
188
194
|
opts.transport ??
|
|
@@ -208,11 +214,12 @@ export class TeamsClient {
|
|
|
208
214
|
* lazily, so a server that never gets a tool call never touches the
|
|
209
215
|
* bridge at all.
|
|
210
216
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
#ensureStarted() {
|
|
218
|
+
this.#starting ??= this.#transport.start().catch((e) => {
|
|
219
|
+
this.#starting = undefined;
|
|
220
|
+
throw e;
|
|
221
|
+
});
|
|
222
|
+
return this.#starting;
|
|
216
223
|
}
|
|
217
224
|
/** Reads a declared selector off the single supported domain's live tab. */
|
|
218
225
|
async #readDomList(name) {
|
|
@@ -255,12 +262,14 @@ export class TeamsClient {
|
|
|
255
262
|
return (await this.#readDomList('channelPosts'));
|
|
256
263
|
}
|
|
257
264
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
265
|
+
* Every sidebar row Teams marks as selected (up to 5). Usually one, but the
|
|
266
|
+
* selector spans BOTH the Chat and the Teams-and-Channels sidebars, so a
|
|
267
|
+
* channel row can stay selected while a chat is open (and vice versa) —
|
|
268
|
+
* callers must pick by `itemType` (see `tools/conversation.ts`), never
|
|
269
|
+
* just take the first row.
|
|
260
270
|
*/
|
|
261
|
-
async
|
|
262
|
-
|
|
263
|
-
return rows[0] ?? null;
|
|
271
|
+
async getSelectedConversations() {
|
|
272
|
+
return (await this.#readDomList('openConversation'));
|
|
264
273
|
}
|
|
265
274
|
/** The Activity feed (the bell icon in the left nav), regardless of which item is selected. */
|
|
266
275
|
async getActivity() {
|
|
@@ -268,7 +277,7 @@ export class TeamsClient {
|
|
|
268
277
|
}
|
|
269
278
|
async close() {
|
|
270
279
|
await this.#transport.close();
|
|
271
|
-
this.#
|
|
280
|
+
this.#starting = undefined;
|
|
272
281
|
}
|
|
273
282
|
/** Non-secret bridge status for the healthcheck tool. */
|
|
274
283
|
status() {
|
package/dist/tools/activity.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toolAnnotations } from '@chrischall/mcp-utils';
|
|
2
2
|
import { wrapBridgeError } from './errors.js';
|
|
3
3
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
4
|
+
import { limitArg, trimRows } from './limit.js';
|
|
4
5
|
export function registerActivityTools(server, client) {
|
|
5
6
|
server.registerTool('teams_get_activity', {
|
|
6
7
|
title: 'Read the Activity feed',
|
|
@@ -10,12 +11,18 @@ export function registerActivityTools(server, client) {
|
|
|
10
11
|
'or chat it happened in). Requires the user\'s browser to have the Activity view ' +
|
|
11
12
|
'open — if it returns nothing, ask them to click the bell icon in the left nav.' +
|
|
12
13
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
13
|
-
annotations: toolAnnotations({ readOnly: true }),
|
|
14
|
-
inputSchema: {},
|
|
15
|
-
}, async () => {
|
|
14
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
15
|
+
inputSchema: { limit: limitArg(200, 'activity rows') },
|
|
16
|
+
}, async ({ limit }) => {
|
|
16
17
|
try {
|
|
17
18
|
const rows = await client.getActivity();
|
|
18
|
-
return untrustedResult(
|
|
19
|
+
return untrustedResult(rows.length > 0
|
|
20
|
+
? trimRows(rows, limit, 'start', 200)
|
|
21
|
+
: {
|
|
22
|
+
rows,
|
|
23
|
+
empty_hint: 'No Activity feed is rendered. The Teams tab is probably not on the Activity view — ' +
|
|
24
|
+
'ask the user to click the bell icon (Activity) in the left nav, then retry.',
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
27
|
catch (err) {
|
|
21
28
|
throw wrapBridgeError(err, 'read the Activity feed');
|
package/dist/tools/channels.js
CHANGED
|
@@ -2,6 +2,7 @@ import { toolAnnotations } from '@chrischall/mcp-utils';
|
|
|
2
2
|
import { wrapBridgeError } from './errors.js';
|
|
3
3
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
4
4
|
import { OPEN_CONVERSATION_DESCRIPTION, readOpenConversation } from './conversation.js';
|
|
5
|
+
import { limitArg, trimRows } from './limit.js';
|
|
5
6
|
export function registerChannelTools(server, client) {
|
|
6
7
|
server.registerTool('teams_list_teams_and_channels', {
|
|
7
8
|
title: 'List Teams and their channels',
|
|
@@ -11,12 +12,18 @@ export function registerChannelTools(server, client) {
|
|
|
11
12
|
'team. Requires the user\'s browser to have the Teams-and-Channels view open (not ' +
|
|
12
13
|
'Chat) — if it returns nothing, ask them to click "Teams" in the left nav.' +
|
|
13
14
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
14
|
-
annotations: toolAnnotations({ readOnly: true }),
|
|
15
|
-
inputSchema: {},
|
|
16
|
-
}, async () => {
|
|
15
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
16
|
+
inputSchema: { limit: limitArg(300, 'team and channel rows') },
|
|
17
|
+
}, async ({ limit }) => {
|
|
17
18
|
try {
|
|
18
19
|
const rows = await client.listTeamsAndChannels();
|
|
19
|
-
return untrustedResult(
|
|
20
|
+
return untrustedResult(rows.length > 0
|
|
21
|
+
? trimRows(rows, limit, 'start', 300)
|
|
22
|
+
: {
|
|
23
|
+
rows,
|
|
24
|
+
empty_hint: 'No teams or channels are rendered. The Teams tab is probably not on the Teams view — ' +
|
|
25
|
+
'ask the user to click Teams in the left nav, then retry.',
|
|
26
|
+
});
|
|
20
27
|
}
|
|
21
28
|
catch (err) {
|
|
22
29
|
throw wrapBridgeError(err, 'list teams and channels');
|
|
@@ -33,13 +40,14 @@ export function registerChannelTools(server, client) {
|
|
|
33
40
|
'teams_list_teams_and_channels to show them what is available.' +
|
|
34
41
|
OPEN_CONVERSATION_DESCRIPTION +
|
|
35
42
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
36
|
-
annotations: toolAnnotations({ readOnly: true }),
|
|
37
|
-
inputSchema: {},
|
|
38
|
-
}, async () => {
|
|
43
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
44
|
+
inputSchema: { limit: limitArg(200, 'posts') },
|
|
45
|
+
}, async ({ limit }) => {
|
|
39
46
|
try {
|
|
40
|
-
const
|
|
47
|
+
const all = await client.getOpenChannelPosts();
|
|
41
48
|
const identity = await readOpenConversation(client, 'channel');
|
|
42
|
-
|
|
49
|
+
const { rows: posts, truncated } = trimRows(all, limit, 'end', 200);
|
|
50
|
+
return untrustedResult({ ...identity, posts, ...(truncated ? { truncated } : {}) });
|
|
43
51
|
}
|
|
44
52
|
catch (err) {
|
|
45
53
|
throw wrapBridgeError(err, 'read the open channel');
|
package/dist/tools/chat.js
CHANGED
|
@@ -2,6 +2,7 @@ import { toolAnnotations } from '@chrischall/mcp-utils';
|
|
|
2
2
|
import { wrapBridgeError } from './errors.js';
|
|
3
3
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
4
4
|
import { OPEN_CONVERSATION_DESCRIPTION, readOpenConversation } from './conversation.js';
|
|
5
|
+
import { filterSince, limitArg, sinceArg, trimRows } from './limit.js';
|
|
5
6
|
export function registerChatTools(server, client) {
|
|
6
7
|
server.registerTool('teams_list_chats', {
|
|
7
8
|
title: 'List Teams chats',
|
|
@@ -10,12 +11,18 @@ export function registerChatTools(server, client) {
|
|
|
10
11
|
'conversationKey (Teams\' internal thread id — not usable to open the chat, there is no ' +
|
|
11
12
|
'navigate capability). Reads the currently-rendered list from the user\'s live browser tab.' +
|
|
12
13
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
13
|
-
annotations: toolAnnotations({ readOnly: true }),
|
|
14
|
-
inputSchema: {},
|
|
15
|
-
}, async () => {
|
|
14
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
15
|
+
inputSchema: { limit: limitArg(200, 'chats') },
|
|
16
|
+
}, async ({ limit }) => {
|
|
16
17
|
try {
|
|
17
18
|
const rows = await client.listChats();
|
|
18
|
-
return untrustedResult(
|
|
19
|
+
return untrustedResult(rows.length > 0
|
|
20
|
+
? trimRows(rows, limit, 'start', 200)
|
|
21
|
+
: {
|
|
22
|
+
rows,
|
|
23
|
+
empty_hint: 'No chat list is rendered. The Teams tab is probably not on the Chat view — ' +
|
|
24
|
+
'ask the user to click Chat in the left nav, then retry.',
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
27
|
catch (err) {
|
|
21
28
|
throw wrapBridgeError(err, 'list chats');
|
|
@@ -31,13 +38,14 @@ export function registerChatTools(server, client) {
|
|
|
31
38
|
'include the quoted preview concatenated in.' +
|
|
32
39
|
OPEN_CONVERSATION_DESCRIPTION +
|
|
33
40
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
34
|
-
annotations: toolAnnotations({ readOnly: true }),
|
|
35
|
-
inputSchema: {},
|
|
36
|
-
}, async () => {
|
|
41
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
42
|
+
inputSchema: { limit: limitArg(200, 'messages'), since: sinceArg },
|
|
43
|
+
}, async ({ limit, since }) => {
|
|
37
44
|
try {
|
|
38
|
-
const
|
|
45
|
+
const all = await client.getOpenChatMessages();
|
|
39
46
|
const identity = await readOpenConversation(client, 'chat');
|
|
40
|
-
|
|
47
|
+
const { rows: messages, truncated } = trimRows(filterSince(all, since), limit, 'end', 200);
|
|
48
|
+
return untrustedResult({ ...identity, messages, ...(truncated ? { truncated } : {}) });
|
|
41
49
|
}
|
|
42
50
|
catch (err) {
|
|
43
51
|
throw wrapBridgeError(err, 'read the open chat');
|
|
@@ -7,11 +7,17 @@ export const OPEN_CONVERSATION_DESCRIPTION = ' The result names the open convers
|
|
|
7
7
|
/**
|
|
8
8
|
* Best-effort: the identity read must never cost the user the messages
|
|
9
9
|
* themselves, so a failed read degrades to `null` plus a warning.
|
|
10
|
+
*
|
|
11
|
+
* Only a selected row whose `itemType` matches `kind` counts: the selector
|
|
12
|
+
* spans both sidebars, so a channel row left selected while a chat is open
|
|
13
|
+
* must not be reported as "the chat". If no row matches, more than one does,
|
|
14
|
+
* or the row carries no `itemType`, the conversation is unidentified.
|
|
10
15
|
*/
|
|
11
16
|
export async function readOpenConversation(client, kind) {
|
|
12
17
|
let conversation = null;
|
|
13
18
|
try {
|
|
14
|
-
|
|
19
|
+
const matches = (await client.getSelectedConversations()).filter((row) => row.itemType === kind);
|
|
20
|
+
conversation = matches.length === 1 ? matches[0] : null;
|
|
15
21
|
}
|
|
16
22
|
catch {
|
|
17
23
|
conversation = null;
|
|
@@ -8,7 +8,22 @@ export function registerHealthcheckTool(server, client) {
|
|
|
8
8
|
probePath: 'chat list (read_dom_list against the currently open Teams tab)',
|
|
9
9
|
probeFn: async () => {
|
|
10
10
|
const rows = await client.listChats();
|
|
11
|
+
// The chat list renders only while the Chat view is open, and on any
|
|
12
|
+
// other view (Teams, Activity, Calendar…) the read returns [] rather
|
|
13
|
+
// than throwing — so an empty read means "wrong view", not "healthy".
|
|
14
|
+
if (rows.length === 0)
|
|
15
|
+
throw new ChatViewNotOpenError();
|
|
11
16
|
return `${rows.length} chat(s) visible in the sidebar`;
|
|
12
17
|
},
|
|
18
|
+
classifyThrown: (err) => err instanceof ChatViewNotOpenError ? { kind: 'chat_view_not_open', hint: CHAT_VIEW_NOT_OPEN_HINT } : undefined,
|
|
13
19
|
});
|
|
14
20
|
}
|
|
21
|
+
const CHAT_VIEW_NOT_OPEN_HINT = 'The bridge reached the teams.cloud.microsoft tab, but no chat list is rendered: the Chat view ' +
|
|
22
|
+
'is not open (the tab is probably on Teams, Activity or Calendar). Ask the user to click Chat ' +
|
|
23
|
+
'in the left nav, then retry.';
|
|
24
|
+
class ChatViewNotOpenError extends Error {
|
|
25
|
+
constructor() {
|
|
26
|
+
super('bridge OK but no chat list rendered — is the Chat view open?');
|
|
27
|
+
this.name = 'ChatViewNotOpenError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side trimming for every list/read tool. The bridge returns up to the
|
|
3
|
+
* selector's `maxItems` rows (200, or 300 for the teams-and-channels sidebar)
|
|
4
|
+
* in one read; dumping all of them into one result fills the context window
|
|
5
|
+
* with other people's messages the question did not need. Each tool takes an
|
|
6
|
+
* optional `limit` (default {@link DEFAULT_LIMIT}) and keeps the NEWEST rows —
|
|
7
|
+
* which sit at the END of a message thread (rendered oldest-first) and at the
|
|
8
|
+
* START of a sidebar or the Activity feed (rendered newest-first).
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
export const DEFAULT_LIMIT = 50;
|
|
12
|
+
/** The optional `limit` argument, capped at what the selector can return. */
|
|
13
|
+
export function limitArg(max, what) {
|
|
14
|
+
return z
|
|
15
|
+
.number()
|
|
16
|
+
.int()
|
|
17
|
+
.min(1)
|
|
18
|
+
.max(max)
|
|
19
|
+
.optional()
|
|
20
|
+
.describe(`Maximum ${what} to return, newest first kept (default ${DEFAULT_LIMIT}, max ${max}).`);
|
|
21
|
+
}
|
|
22
|
+
export function trimRows(rows, limit, newestAt, max) {
|
|
23
|
+
const n = limit ?? DEFAULT_LIMIT;
|
|
24
|
+
if (rows.length <= n)
|
|
25
|
+
return { rows };
|
|
26
|
+
const kept = newestAt === 'end' ? rows.slice(rows.length - n) : rows.slice(0, n);
|
|
27
|
+
return {
|
|
28
|
+
rows: kept,
|
|
29
|
+
truncated: {
|
|
30
|
+
total: rows.length,
|
|
31
|
+
returned: kept.length,
|
|
32
|
+
hint: `Only the newest ${kept.length} of ${rows.length} were returned; pass a larger limit (max ${max}) to read more.`,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The optional `since` argument (ISO 8601 date-time) for ISO-timed rows. */
|
|
37
|
+
export const sinceArg = z
|
|
38
|
+
.string()
|
|
39
|
+
.refine((s) => !Number.isNaN(Date.parse(s)), { message: 'since must be an ISO 8601 date-time' })
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('Only return messages at or after this ISO 8601 date-time (e.g. 2026-09-21T09:00:00Z). ' +
|
|
42
|
+
'Messages whose time cannot be read are kept.');
|
|
43
|
+
/** Drop rows whose ISO `time` is before `since`; rows with no readable time are kept. */
|
|
44
|
+
export function filterSince(rows, since) {
|
|
45
|
+
if (since === undefined)
|
|
46
|
+
return rows;
|
|
47
|
+
const cutoff = Date.parse(since);
|
|
48
|
+
return rows.filter((row) => {
|
|
49
|
+
const t = row.time === undefined ? Number.NaN : Date.parse(row.time);
|
|
50
|
+
return Number.isNaN(t) || t >= cutoff;
|
|
51
|
+
});
|
|
52
|
+
}
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/microsoft-teams-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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>",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc && npm run bundle",
|
|
40
|
-
"bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --external:dotenv --banner:js='import { createRequire as __createRequire } from \"module\"; const require = __createRequire(import.meta.url);' --outfile=dist/bundle.js",
|
|
40
|
+
"bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --external:dotenv --define:process.env.FETCHPROXY_WS_PORT=undefined --define:process.env.WS_NO_BUFFER_UTIL='\"1\"' --define:process.env.WS_NO_UTF_8_VALIDATE='\"1\"' --banner:js='import { createRequire as __createRequire } from \"module\"; const require = __createRequire(import.meta.url);' --outfile=dist/bundle.js",
|
|
41
41
|
"dev": "node dist/index.js",
|
|
42
42
|
"test": "npm run typecheck && vitest run",
|
|
43
43
|
"test:watch": "vitest",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"typecheck": "tsc -p tsconfig.check.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@chrischall/mcp-utils": "^
|
|
49
|
-
"@fetchproxy/protocol": "^3.
|
|
50
|
-
"@fetchproxy/server": "^3.
|
|
48
|
+
"@chrischall/mcp-utils": "^3.0.0",
|
|
49
|
+
"@fetchproxy/protocol": "^3.6.0",
|
|
50
|
+
"@fetchproxy/server": "^3.6.0",
|
|
51
51
|
"@modelcontextprotocol/server": "^2.3.0",
|
|
52
52
|
"dotenv": "^18.0.1",
|
|
53
53
|
"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.
|
|
9
|
+
"version": "0.3.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/microsoft-teams-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.3.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -20,7 +20,22 @@
|
|
|
20
20
|
"name": "TEAMS_WS_PORT",
|
|
21
21
|
"description": "fetchproxy concentrator port used for the browser bridge. Defaults to 37149, the fleet-wide shared port.",
|
|
22
22
|
"isRequired": false,
|
|
23
|
-
"format": "string"
|
|
23
|
+
"format": "string",
|
|
24
|
+
"isSecret": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "FETCHPROXY_WS_HOST",
|
|
28
|
+
"description": "Bind interface for the bridge (default 127.0.0.1; a literal IP only, anything else is ignored). Keep on loopback — it exists for ONE topology: a hosted child in its own network namespace.",
|
|
29
|
+
"isRequired": false,
|
|
30
|
+
"format": "string",
|
|
31
|
+
"isSecret": false
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "FETCHPROXY_IDENTITY_DIR",
|
|
35
|
+
"description": "Where to store the long-term fetchproxy identity keypair (default ~/.fetchproxy/identity/; an absolute path only, anything else is ignored). Exists for a host that runs a separate child per caller, so they can share one identity.",
|
|
36
|
+
"isRequired": false,
|
|
37
|
+
"format": "string",
|
|
38
|
+
"isSecret": false
|
|
24
39
|
}
|
|
25
40
|
]
|
|
26
41
|
}
|