mcp-teams 0.3.63 → 0.3.64
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/README.md +12 -0
- package/dist/bridge.js +69 -3
- package/dist/bridge.js.map +1 -1
- package/dist/build.json +2 -2
- package/dist/hubLog.js +57 -8
- package/dist/hubLog.js.map +1 -1
- package/dist/index.js +42 -12
- package/dist/index.js.map +1 -1
- package/dist/serverLog.js +226 -0
- package/dist/serverLog.js.map +1 -0
- package/dist/tools.js +63 -20
- package/dist/tools.js.map +1 -1
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,19 +3,35 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { DRAIN_MAX_WAIT_MS, ExtensionBridge } from "./bridge.js";
|
|
6
|
-
import { CONFIG_PATH, SERVER_VERSION, loadConfig } from "./config.js";
|
|
6
|
+
import { BUILD_DIR, CONFIG_PATH, RUNNING_BUILD, SERVER_VERSION, loadConfig } from "./config.js";
|
|
7
7
|
import { registerTools } from "./tools.js";
|
|
8
8
|
import { setup } from "./setup.js";
|
|
9
9
|
import { installedVersion, PACKAGED_EXTENSION_DIR, syncExtension, writePairing } from "./extension.js";
|
|
10
10
|
import { isNewer } from "./bridge.js";
|
|
11
11
|
import { reloadUntilUpdated } from "./extensionUpdate.js";
|
|
12
|
-
import { hubSocketPath } from "./native.js";
|
|
12
|
+
import { hubSocketPath, msFromEnv } from "./native.js";
|
|
13
|
+
import { diagnosticLog, watchState } from "./serverLog.js";
|
|
14
|
+
import { restartCheck } from "./buildInfo.js";
|
|
15
|
+
const command = process.argv[2];
|
|
16
|
+
const printsOnly = ["token", "version", "--version"].includes(command);
|
|
17
|
+
// Every server (not the commands that only print) keeps ~/.mcp-teams/server.log (#143): metadata
|
|
18
|
+
// to trace an outage after a restart. The role is the bridge's once it exists.
|
|
19
|
+
let roleNow = () => "none";
|
|
20
|
+
const diagnostics = printsOnly ? undefined : diagnosticLog({ version: SERVER_VERSION, role: () => roleNow() });
|
|
21
|
+
let exitReason = "unknown";
|
|
22
|
+
diagnostics?.start({ command: ["setup", "reload-extension"].includes(command) ? command : command ? "other" : "serve" });
|
|
23
|
+
process.on("exit", (code) => diagnostics?.exit(exitReason, code));
|
|
13
24
|
// A stray error in a socket callback must not end the server (the AI app would show it
|
|
14
|
-
// as "failed"); log it on stderr, which isn't the MCP channel.
|
|
15
|
-
process.on("unhandledRejection", (err) =>
|
|
16
|
-
|
|
25
|
+
// as "failed"); log it on stderr, which isn't the MCP channel, and by name in server.log.
|
|
26
|
+
process.on("unhandledRejection", (err) => {
|
|
27
|
+
console.error("[mcp-teams] unhandled rejection:", err);
|
|
28
|
+
diagnostics?.crash("unhandled-rejection", err);
|
|
29
|
+
});
|
|
30
|
+
process.on("uncaughtException", (err) => {
|
|
31
|
+
console.error("[mcp-teams] uncaught exception:", err);
|
|
32
|
+
diagnostics?.crash("uncaught-exception", err);
|
|
33
|
+
});
|
|
17
34
|
const config = loadConfig();
|
|
18
|
-
const command = process.argv[2];
|
|
19
35
|
if (command === "token") {
|
|
20
36
|
// Printed for pasting into the extension's options page.
|
|
21
37
|
console.log(config.token);
|
|
@@ -45,11 +61,16 @@ if (installed !== null && !["token", "version", "--version"].includes(command))
|
|
|
45
61
|
// With "nativeHost": true in config.json (off by default until #123's PR 5), the server first
|
|
46
62
|
// looks for the native host on its hub socket and moves to it from TCP once it has the extension.
|
|
47
63
|
// Off, it never touches the socket: TCP only, as before.
|
|
48
|
-
const bridge = new ExtensionBridge(config.port, config.token, SERVER_VERSION,
|
|
64
|
+
const bridge = new ExtensionBridge(config.port, config.token, SERVER_VERSION, {
|
|
65
|
+
...(config.nativeHost ? { hubSocket: hubSocketPath() } : {}),
|
|
66
|
+
diagnose: diagnostics?.bridge,
|
|
67
|
+
});
|
|
68
|
+
roleNow = () => bridge.role;
|
|
49
69
|
await bridge.start();
|
|
50
70
|
if (command === "setup") {
|
|
51
71
|
const ready = await setup(bridge, SERVER_VERSION, { yes: process.argv.includes("--yes") });
|
|
52
72
|
await bridge.close();
|
|
73
|
+
exitReason = "setup-done";
|
|
53
74
|
process.exit(ready ? 0 : 1);
|
|
54
75
|
}
|
|
55
76
|
if (command === "reload-extension") {
|
|
@@ -66,11 +87,13 @@ if (command === "reload-extension") {
|
|
|
66
87
|
const { before, after } = await bridge.reloadExtension();
|
|
67
88
|
console.log(`Extension reloaded: ${before ?? "?"} → ${after}${after === SERVER_VERSION ? "" : ` (server is ${SERVER_VERSION})`}`);
|
|
68
89
|
await bridge.close();
|
|
90
|
+
exitReason = "reload-done";
|
|
69
91
|
process.exit(0);
|
|
70
92
|
}
|
|
71
93
|
catch (err) {
|
|
72
94
|
console.error(err.message);
|
|
73
95
|
await bridge.close();
|
|
96
|
+
exitReason = "reload-failed";
|
|
74
97
|
process.exit(1);
|
|
75
98
|
}
|
|
76
99
|
}
|
|
@@ -89,22 +112,29 @@ const server = new McpServer({
|
|
|
89
112
|
version: SERVER_VERSION,
|
|
90
113
|
icons: [icon("icon.svg", "image/svg+xml", ["any"]), icon("icon-128.png", "image/png", ["128x128"]), icon("icon-48.png", "image/png", ["48x48"])],
|
|
91
114
|
});
|
|
92
|
-
registerTools(server, bridge, config);
|
|
115
|
+
registerTools(server, bridge, config, { diagnostics });
|
|
93
116
|
await server.connect(new StdioServerTransport());
|
|
117
|
+
// server.log stays current without tool calls (#143): every minute the hub reads the Teams state,
|
|
118
|
+
// and any server checks the build on disk. TEAMS_MCP_WATCH_MS shortens the period (tests).
|
|
119
|
+
if (diagnostics) {
|
|
120
|
+
watchState({ bridge, diagnostics, onDisk: restartCheck(RUNNING_BUILD, BUILD_DIR), everyMs: msFromEnv(process.env.TEAMS_MCP_WATCH_MS) });
|
|
121
|
+
}
|
|
94
122
|
// A signal closes at once. When the AI session ends (stdin closes), this server takes no more MCP
|
|
95
123
|
// calls, but as the hub it first lets other sessions' running calls finish for a few seconds
|
|
96
124
|
// (#112, ported from mcp-newoutlook src/index.ts, PR #108 there); TEAMS_MCP_DRAIN_MS changes that
|
|
97
125
|
// bound (tests). The process exits soon after the bound even if a connection is slow to close.
|
|
98
|
-
const shutdown = async () => {
|
|
126
|
+
const shutdown = (signal) => async () => {
|
|
127
|
+
exitReason = signal;
|
|
99
128
|
await bridge.close();
|
|
100
129
|
process.exit(0);
|
|
101
130
|
};
|
|
102
|
-
process.on("SIGINT", shutdown);
|
|
103
|
-
process.on("SIGTERM", shutdown);
|
|
131
|
+
process.on("SIGINT", shutdown("SIGINT"));
|
|
132
|
+
process.on("SIGTERM", shutdown("SIGTERM"));
|
|
104
133
|
process.stdin.on("close", async () => {
|
|
134
|
+
exitReason = "stdin-closed";
|
|
105
135
|
const fromEnv = process.env.TEAMS_MCP_DRAIN_MS ? Number(process.env.TEAMS_MCP_DRAIN_MS) : NaN;
|
|
106
136
|
const drainMs = Number.isFinite(fromEnv) && fromEnv >= 0 ? fromEnv : DRAIN_MAX_WAIT_MS; // 0: no drain
|
|
107
|
-
setTimeout(() => process.exit(0), drainMs + 2_000).unref();
|
|
137
|
+
setTimeout(() => ((exitReason = "drain-timeout"), process.exit(0)), drainMs + 2_000).unref();
|
|
108
138
|
await server.close().catch(() => { });
|
|
109
139
|
await bridge.drainAndClose(drainMs);
|
|
110
140
|
process.exit(0);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,a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GAAG,eAAe,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7F,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrC,MAAM,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,sFAAsF;AACtF,2CAA2C;AAC3C,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,IAAI,CAAC,gBAAgB;QAAE,OAAO;IAC9B,6FAA6F;IAC7F,MAAM,CAAC,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,cAAc,CAAC,CAAC;IACjF,IAAI,CAAC,CAAC,EAAE;QAAE,OAAO,CAAC,KAAK,CAAC,cAAc,cAAc,wBAAwB,CAAC,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5G,2FAA2F;;QACtF,OAAO,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAC/F,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every server's diagnostic log (#143): ~/.mcp-teams/server.log, 0600 in a 0700 folder, moved to
|
|
3
|
+
* server.log.1 once it passes 1 MB (hubLog's rotation, which is safe with many processes appending
|
|
4
|
+
* at once). It is what is left to trace an outage after a restart: when the server started and
|
|
5
|
+
* stopped, its role, the extension coming and going, the Teams state it reported, failed and slow
|
|
6
|
+
* tool calls, and crashes.
|
|
7
|
+
*
|
|
8
|
+
* Metadata only: event names and values this code chose, versions as version characters, errors by
|
|
9
|
+
* name and code. Never message text, names, tokens, chat ids, regions or the signed-in account (only
|
|
10
|
+
* whether it changed). Every value is cut to a few safe characters, so nothing can forge a line.
|
|
11
|
+
* States are logged when they change, not on every status read. Logging never throws.
|
|
12
|
+
*/
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { isLostCall } from "./bridge.js";
|
|
15
|
+
import { CONFIG_DIR } from "./config.js";
|
|
16
|
+
import { errorFields, hubLog, logVersion } from "./hubLog.js";
|
|
17
|
+
import { IDLE_MS, isMissingSession } from "./sessionNote.js";
|
|
18
|
+
/** Where every server logs: next to config.json (TEAMS_MCP_HOME moves both, for tests). */
|
|
19
|
+
export const SERVER_LOG_FILE = join(CONFIG_DIR, "server.log");
|
|
20
|
+
/** A tool call that takes longer than this is logged even when it succeeds. */
|
|
21
|
+
export const SLOW_TOOL_MS = 20_000;
|
|
22
|
+
/** A value as server.log writes it: word characters and `.,:-` only, at most 48. */
|
|
23
|
+
const safe = (v) => String(v).replace(/[^\w.,:-]/g, "").slice(0, 48) || "-";
|
|
24
|
+
/** A version, or "unknown": x.y.z with at most a short suffix, so no other text passes as one. */
|
|
25
|
+
const strictVersion = (v) => (/^\d{1,4}\.\d{1,4}\.\d{1,6}(?:[-.][\w]{1,12})?$/.test(logVersion(v)) ? logVersion(v) : "unknown");
|
|
26
|
+
/** Field → how its value is checked. A field not listed is never written: callers can't add free text. */
|
|
27
|
+
const WORD = (v) => (/^[a-z][\w-]{0,31}$/i.test(v) ? v : "-");
|
|
28
|
+
const FIELDS = {
|
|
29
|
+
role: WORD,
|
|
30
|
+
via: WORD,
|
|
31
|
+
transport: (v) => (/^[a-z][a-z,]{0,47}$/.test(v) ? v : "-"), // one, or several joined by commas
|
|
32
|
+
reason: WORD,
|
|
33
|
+
command: WORD,
|
|
34
|
+
kind: WORD,
|
|
35
|
+
status: WORD,
|
|
36
|
+
captured: WORD,
|
|
37
|
+
account: WORD,
|
|
38
|
+
ok: WORD,
|
|
39
|
+
slow: WORD,
|
|
40
|
+
name: WORD, // a tool's name, from this code's own list
|
|
41
|
+
services: (v) => (/^[a-z,]{1,64}$/.test(v) ? v : "-"),
|
|
42
|
+
node: (v) => (/^v\d+\.\d+\.\d+$/.test(v) ? v : "-"),
|
|
43
|
+
stale: WORD,
|
|
44
|
+
ext: strictVersion, // the extension's version, for version skew (#96, #111)
|
|
45
|
+
hub: strictVersion,
|
|
46
|
+
to: strictVersion,
|
|
47
|
+
onDisk: strictVersion,
|
|
48
|
+
version: strictVersion,
|
|
49
|
+
code: (v) => (/^(?:\d{1,5}|[A-Z][A-Z0-9_]{1,31})$/.test(v) ? v : "-"),
|
|
50
|
+
error: (v) => (/^(?:[A-Za-z]{0,24}(?:Error|Exception)|string|number|object|undefined|boolean|symbol|bigint|function)$/.test(v) ? v : "other"),
|
|
51
|
+
ms: (v) => (/^\d{1,9}$/.test(v) ? v : "-"),
|
|
52
|
+
tabs: (v) => (/^\d{1,4}$/.test(v) ? v : "-"),
|
|
53
|
+
count: (v) => (/^\d{1,4}$/.test(v) ? v : "-"),
|
|
54
|
+
};
|
|
55
|
+
/** Teams services the extension captures sessions for (extension/background.js). */
|
|
56
|
+
const SERVICES = new Set(["chatsvc", "csa", "mt", "substrate", "sharepoint"]);
|
|
57
|
+
/** An event name: lowercase words joined by dashes (anything else is written as "other"). */
|
|
58
|
+
const EVENT = /^[a-z][a-z-]{0,31}$/;
|
|
59
|
+
/** Tools whose long calls wait for the user, not for Teams: never logged as slow. */
|
|
60
|
+
const WAITS_FOR_USER = new Set(["send_message"]);
|
|
61
|
+
/**
|
|
62
|
+
* Whether the Teams session looks stale (yes/no), as get_version's note judges "stuck at sign-in"
|
|
63
|
+
* (sessionNote.ts): the tab keeps calling but made no signed-in call for IDLE_MS. captured=yes
|
|
64
|
+
* survives an expired token, so this is the sign that it went bad. Unknown (left out) for an
|
|
65
|
+
* extension from before #103, which reports no calls.
|
|
66
|
+
*/
|
|
67
|
+
function staleOf(st) {
|
|
68
|
+
if (!("lastTeamsCall" in st))
|
|
69
|
+
return undefined;
|
|
70
|
+
const last = Date.parse(st.lastTeamsCall?.at);
|
|
71
|
+
const signedIn = Date.parse(st.lastSignedInCall?.at);
|
|
72
|
+
if (!Number.isFinite(last))
|
|
73
|
+
return "no";
|
|
74
|
+
return !Number.isFinite(signedIn) || last - signedIn > IDLE_MS ? "yes" : "no";
|
|
75
|
+
}
|
|
76
|
+
/** What a failed tool call's error was, from a fixed set: its message is never logged. */
|
|
77
|
+
function errorKind(err) {
|
|
78
|
+
const message = err instanceof Error ? err.message : typeof err === "string" ? err : "";
|
|
79
|
+
if (isLostCall(message))
|
|
80
|
+
return "lost-call";
|
|
81
|
+
if (isMissingSession(message))
|
|
82
|
+
return "no-session";
|
|
83
|
+
if (/extension is not connected/i.test(message))
|
|
84
|
+
return "not-connected";
|
|
85
|
+
if (/timed out|timeout/i.test(message))
|
|
86
|
+
return "timeout";
|
|
87
|
+
return "other";
|
|
88
|
+
}
|
|
89
|
+
export function diagnosticLog(options) {
|
|
90
|
+
const append = hubLog(options.file ?? SERVER_LOG_FILE, options.maxBytes);
|
|
91
|
+
const version = logVersion(options.version);
|
|
92
|
+
const slowToolMs = options.slowToolMs ?? SLOW_TOOL_MS;
|
|
93
|
+
const write = (event, fields = {}) => {
|
|
94
|
+
try {
|
|
95
|
+
const out = { v: version, role: safe(options.role()) };
|
|
96
|
+
for (const [k, v] of Object.entries(fields))
|
|
97
|
+
if (v !== undefined && Object.hasOwn(FIELDS, k))
|
|
98
|
+
out[k] = FIELDS[k](safe(v));
|
|
99
|
+
append(EVENT.test(event) ? event : "other", out);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// logging must never stop the server
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const last = new Map(); // event → its last fields, to log a state only when it changes
|
|
106
|
+
const onChange = (event, fields) => {
|
|
107
|
+
const key = JSON.stringify(fields);
|
|
108
|
+
if (last.get(event) === key)
|
|
109
|
+
return;
|
|
110
|
+
last.set(event, key);
|
|
111
|
+
write(event, fields);
|
|
112
|
+
};
|
|
113
|
+
let account = { known: false };
|
|
114
|
+
let restartSeen = false;
|
|
115
|
+
const fieldsOf = (err) => {
|
|
116
|
+
try {
|
|
117
|
+
return errorFields(err);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return { name: "unreadable", code: undefined }; // a getter that throws must not reach an exception handler
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const kindOf = (err) => {
|
|
124
|
+
try {
|
|
125
|
+
return errorKind(err);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return "other";
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
start: (fields = {}) => write("start", { ...fields, node: process.version }),
|
|
133
|
+
exit: (reason, code) => write("exit", { reason, code }),
|
|
134
|
+
bridge(event, fields = {}) {
|
|
135
|
+
if (event === "role" || event === "extensions")
|
|
136
|
+
return onChange(event, fields);
|
|
137
|
+
// An extension with a bad token retries every 30 s: its refusal is logged when it changes,
|
|
138
|
+
// and again after something connected.
|
|
139
|
+
if (event === "handshake-closed")
|
|
140
|
+
return onChange(event, fields);
|
|
141
|
+
if (event === "extension-connected")
|
|
142
|
+
last.delete("handshake-closed");
|
|
143
|
+
write(event, fields);
|
|
144
|
+
},
|
|
145
|
+
teamsStatus(status, failure) {
|
|
146
|
+
try {
|
|
147
|
+
const st = status;
|
|
148
|
+
if (!st || typeof st !== "object" || "error" in st)
|
|
149
|
+
return onChange("teams", { status: failure ?? "unreadable" });
|
|
150
|
+
const services = st.services && typeof st.services === "object" ? Object.keys(st.services).filter((k) => SERVICES.has(k) && st.services[k]) : [];
|
|
151
|
+
const id = typeof st.signedInAs === "string" && st.signedInAs ? st.signedInAs : undefined;
|
|
152
|
+
// The account itself stays in memory: the log says only whether it changed.
|
|
153
|
+
const accountField = !id ? "none" : !account.known ? "first" : account.id === id ? "same" : "changed";
|
|
154
|
+
const state = {
|
|
155
|
+
tabs: Number.isFinite(Number(st.teamsTabs)) ? Number(st.teamsTabs) : "-",
|
|
156
|
+
captured: Array.isArray(st.sessions) && st.sessions.some((x) => x?.sessionCaptured) ? "yes" : "no",
|
|
157
|
+
services: services.length ? services.join(",") : "none",
|
|
158
|
+
stale: staleOf(st),
|
|
159
|
+
};
|
|
160
|
+
const changedAccount = !account.known || account.id !== id;
|
|
161
|
+
const key = JSON.stringify(state);
|
|
162
|
+
account = { known: true, id };
|
|
163
|
+
if (last.get("teams") === key && !changedAccount)
|
|
164
|
+
return;
|
|
165
|
+
last.set("teams", key);
|
|
166
|
+
write("teams", { ...state, account: accountField });
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// a status of an unexpected shape is not worth a crash
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
toolCall(name, ms, err) {
|
|
173
|
+
// send_message waits for the user's click in its confirmation window: a long wait isn't slow.
|
|
174
|
+
const slow = ms > slowToolMs && !WAITS_FOR_USER.has(name);
|
|
175
|
+
if (err === undefined && !slow)
|
|
176
|
+
return;
|
|
177
|
+
const e = err === undefined ? undefined : fieldsOf(err);
|
|
178
|
+
write("tool", { name, ok: err === undefined ? "yes" : "no", ms: Math.round(ms), error: e?.name, code: e?.code, kind: err === undefined ? undefined : kindOf(err), slow: slow ? "yes" : undefined });
|
|
179
|
+
},
|
|
180
|
+
restartNeeded(onDiskVersion) {
|
|
181
|
+
if (restartSeen)
|
|
182
|
+
return;
|
|
183
|
+
restartSeen = true;
|
|
184
|
+
write("restart-needed", { onDisk: logVersion(onDiskVersion) });
|
|
185
|
+
},
|
|
186
|
+
crash(kind, err) {
|
|
187
|
+
const e = fieldsOf(err);
|
|
188
|
+
write(kind, { error: e.name, code: e.code });
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** How often the background watch reads the Teams state and the build on disk. */
|
|
193
|
+
export const WATCH_MS = 60_000;
|
|
194
|
+
/** How long the background watch waits for the extension's status. */
|
|
195
|
+
const WATCH_STATUS_TIMEOUT_MS = 5_000;
|
|
196
|
+
/**
|
|
197
|
+
* Keeps server.log current while no tool is called (#143: the overnight outage had no calls, so
|
|
198
|
+
* nothing read the Teams state). Every period, the hub with an extension reads its status (logged
|
|
199
|
+
* when it changed), and any server checks the build on disk (restart-needed, once). The timer is
|
|
200
|
+
* unref'd, a read never overlaps the last one, and nothing here throws. Returns a stop function.
|
|
201
|
+
*/
|
|
202
|
+
export function watchState({ bridge, diagnostics, onDisk, everyMs = WATCH_MS }) {
|
|
203
|
+
let reading = false;
|
|
204
|
+
const tick = () => {
|
|
205
|
+
try {
|
|
206
|
+
const state = onDisk();
|
|
207
|
+
if (state.restartNeeded)
|
|
208
|
+
diagnostics.restartNeeded(state.onDisk.version);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// a build.json it can't read is no reason to stop watching
|
|
212
|
+
}
|
|
213
|
+
if (reading || bridge.role !== "hub" || !bridge.connected)
|
|
214
|
+
return;
|
|
215
|
+
reading = true;
|
|
216
|
+
bridge
|
|
217
|
+
.backgroundStatus(WATCH_STATUS_TIMEOUT_MS)
|
|
218
|
+
.then((st) => diagnostics.teamsStatus(st), () => diagnostics.teamsStatus(null))
|
|
219
|
+
.catch(() => { })
|
|
220
|
+
.finally(() => (reading = false));
|
|
221
|
+
};
|
|
222
|
+
const timer = setInterval(tick, everyMs);
|
|
223
|
+
timer.unref();
|
|
224
|
+
return () => clearInterval(timer);
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=serverLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverLog.js","sourceRoot":"","sources":["../src/serverLog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAA4B,MAAM,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AuB,GAAG,KAAK,CAAC;AAUtC;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAqB;IAC/F,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC;YACvB,IAAI,KAAK,CAAC,aAAa;gBAAE,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3E,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;QACD,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,OAAO;QAClE,OAAO,GAAG,IAAI,CAAC;QACf,MAAM;aACH,gBAAgB,CAAC,uBAAuB,CAAC;aACzC,IAAI,CACH,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC,EACnC,GAAG,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CACpC;aACA,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;aACf,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC;IACF,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/tools.js
CHANGED
|
@@ -23,16 +23,48 @@ const fail = (err, hint) => {
|
|
|
23
23
|
* (null keeps it). Handlers pass extra.signal to bridge.call, so cancelling a tool withdraws its
|
|
24
24
|
* extension call.
|
|
25
25
|
*/
|
|
26
|
-
function safeWith(hint, explain) {
|
|
26
|
+
function safeWith(hint, explain, failed) {
|
|
27
27
|
return (fn) => async (args, extra) => {
|
|
28
28
|
try {
|
|
29
29
|
return await fn(args, extra);
|
|
30
30
|
}
|
|
31
31
|
catch (err) {
|
|
32
|
-
|
|
32
|
+
const result = fail((await explain(err, extra).catch(() => null)) ?? err, hint());
|
|
33
|
+
failed?.(result, err);
|
|
34
|
+
return result;
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* `server.registerTool`, with each call's end told to `diagnostics` (server.log, #143): its tool,
|
|
40
|
+
* how long it took, and for a failed one the error `errorOf` has for its result. Logging never
|
|
41
|
+
* delays or changes the call's answer.
|
|
42
|
+
*/
|
|
43
|
+
function loggedRegister(server, diagnostics, errorOf) {
|
|
44
|
+
const register = server.registerTool.bind(server);
|
|
45
|
+
if (!diagnostics)
|
|
46
|
+
return register;
|
|
47
|
+
const note = (name, started, err) => {
|
|
48
|
+
try {
|
|
49
|
+
diagnostics.toolCall(name, performance.now() - started, err);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// logging never stops a call
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return ((name, config, cb) => register(name, config, async (...args) => {
|
|
56
|
+
const started = performance.now();
|
|
57
|
+
try {
|
|
58
|
+
const result = await cb(...args);
|
|
59
|
+
note(name, started, result?.isError ? (errorOf(result) ?? new Error("tool error")) : undefined);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
note(name, started, err);
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
36
68
|
const conversation = z
|
|
37
69
|
.string()
|
|
38
70
|
.trim()
|
|
@@ -67,7 +99,18 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
67
99
|
// The version of the code that runs (its build.json), not package.json's.
|
|
68
100
|
const serverVersion = running.version;
|
|
69
101
|
// Read on demand only (get_version, a failed call): no timers, no watchers.
|
|
70
|
-
const
|
|
102
|
+
const diagnostics = options.diagnostics;
|
|
103
|
+
const checkDisk = restartCheck(running, options.build?.dir ?? BUILD_DIR, options.build?.now);
|
|
104
|
+
const onDisk = () => {
|
|
105
|
+
const state = checkDisk();
|
|
106
|
+
if (state.restartNeeded)
|
|
107
|
+
diagnostics?.restartNeeded(state.onDisk.version);
|
|
108
|
+
return state;
|
|
109
|
+
};
|
|
110
|
+
// Every status read: server.log keeps the Teams state when it changed.
|
|
111
|
+
const status = (timeoutMs, signal) => bridge.call("status", {}, timeoutMs, signal).then((st) => (diagnostics?.teamsStatus(st), st), (err) => (diagnostics?.teamsStatus(null, signal?.aborted ? "aborted" : undefined), Promise.reject(err)));
|
|
112
|
+
const failures = new WeakMap(); // a failed call's result → its error, for server.log
|
|
113
|
+
const register = loggedRegister(server, diagnostics, (result) => failures.get(result));
|
|
71
114
|
const now = options.build?.now ?? (() => Date.now());
|
|
72
115
|
// A call that failed for a missing session says why, as get_version's note does (#103), from the
|
|
73
116
|
// extension's status, read only for such a failure.
|
|
@@ -75,19 +118,19 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
75
118
|
const message = err instanceof Error ? err.message : String(err);
|
|
76
119
|
if (!isMissingSession(message) || !bridge.connected)
|
|
77
120
|
return null;
|
|
78
|
-
const
|
|
79
|
-
return failedCallNote(message,
|
|
121
|
+
const st = await status(NOTE_STATUS_TIMEOUT_MS, extra.signal);
|
|
122
|
+
return failedCallNote(message, st, now());
|
|
80
123
|
};
|
|
81
|
-
const safe = safeWith(() => restartHint(running, onDisk()), explain);
|
|
124
|
+
const safe = safeWith(() => restartHint(running, onDisk()), explain, (result, err) => failures.set(result, err));
|
|
82
125
|
const autoSendTo = config.autoSendTo ?? [];
|
|
83
|
-
|
|
126
|
+
register("get_version", {
|
|
84
127
|
title: "Version and connection status",
|
|
85
128
|
description: "Shows the mcp-teams server version and build, the browser extension version, and whether Teams is reachable (which of its services have a session). restartNeeded: true means mcp-teams was updated on disk while this server still runs the old code: the user should reconnect it (in Claude Code: /mcp) and reload the extension.",
|
|
86
129
|
inputSchema: {},
|
|
87
130
|
}, safe(async (_, extra) => {
|
|
88
131
|
let teams = null;
|
|
89
132
|
if (bridge.connected) {
|
|
90
|
-
teams = await
|
|
133
|
+
teams = await status(undefined, extra.signal).catch((e) => ({ error: e.message }));
|
|
91
134
|
// #77: whether the account is unsure after a switch; an extension from before it doesn't say (null).
|
|
92
135
|
if (teams && typeof teams === "object" && !("error" in teams))
|
|
93
136
|
teams = { ...teams, accountUnsure: teams.accountUnsure ?? null };
|
|
@@ -134,7 +177,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
134
177
|
...noteOf(sessionNote(teams, now())),
|
|
135
178
|
});
|
|
136
179
|
}));
|
|
137
|
-
|
|
180
|
+
register("reload_extension", {
|
|
138
181
|
title: "Reload the browser extension",
|
|
139
182
|
description: "Reloads the mcp-teams browser extension from disk, e.g. after an update changed it, and waits until it is connected again. Returns the extension version before and after. Refused while a send confirmation window is open.",
|
|
140
183
|
inputSchema: {},
|
|
@@ -142,7 +185,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
142
185
|
const r = await bridge.reloadExtension();
|
|
143
186
|
return text({ ...r, server: serverVersion, versionsMatch: r.after === serverVersion });
|
|
144
187
|
}));
|
|
145
|
-
|
|
188
|
+
register("api_traffic", {
|
|
146
189
|
title: "Show the Teams web app's API calls (diagnostic)",
|
|
147
190
|
description: "Lists the API endpoints the open Teams tab called while recording was on: method, host, path, status, which headers were sent (names only, never values) and the auth scheme. Used to find out which API Teams uses for a feature. Recording is off until you turn it on: first call with record: true, then click through the feature in Teams, then call again to list what it called. Recording stops after 30 minutes or with record: false; what was recorded stays until clear.",
|
|
148
191
|
inputSchema: {
|
|
@@ -159,7 +202,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
159
202
|
.describe("Read the list from Teams again instead of reusing the one from the last minute: e.g. right after a chat was created or joined elsewhere, or for the current unread state");
|
|
160
203
|
/** The bridge param: sent only when asked, so a call without it reads as before. */
|
|
161
204
|
const refreshParam = (r) => (r ? { refresh: true } : {});
|
|
162
|
-
|
|
205
|
+
register("list_teams", {
|
|
163
206
|
title: "List teams and channels",
|
|
164
207
|
description: "Lists the teams you are a member of, each with its channels. Group chats and meeting chats are not teams, even when they are named like one: list_chats lists those. Use 'Team/Channel' or a channel id as the conversation for read_messages and send_message. The list may be up to a minute old (see refresh). Needs a Teams tab open in the browser: without one it fails at once.",
|
|
165
208
|
inputSchema: {
|
|
@@ -173,7 +216,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
173
216
|
? r
|
|
174
217
|
: { ...r, teams: r.teams.map(({ id, channels, ...t }) => ({ ...t, channels: channels.map(({ id: _, ...c }) => c) })) });
|
|
175
218
|
}));
|
|
176
|
-
|
|
219
|
+
register("list_chats", {
|
|
177
220
|
title: "List chats",
|
|
178
221
|
description: "Lists your chats (1:1, group and meeting chats), most recent first, with their title (or the other members' names), the last message and whether it is unread. Returns ids for read_messages and send_message. The list may be up to a minute old, so the last message and unread state can lag; pass refresh: true for the current ones. Needs a Teams tab open in the browser: without one it fails at once.",
|
|
179
222
|
inputSchema: {
|
|
@@ -183,7 +226,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
183
226
|
refresh,
|
|
184
227
|
},
|
|
185
228
|
}, safe(async ({ query, unread_only, limit, refresh }, extra) => text(await bridge.call("listChats", { query, unreadOnly: unread_only, limit, ...refreshParam(refresh) }, READ_TIMEOUT_MS, extra.signal))));
|
|
186
|
-
|
|
229
|
+
register("read_messages", {
|
|
187
230
|
title: "Read a chat or channel",
|
|
188
231
|
description: "Reads the latest messages of a chat or channel, oldest first: sender, time, text (formatting removed), files shared and reactions. In channels, replies are nested under their post (a reply whose post is on an older page comes on its own, with replyTo). To read further back, pass the returned olderCursor as `cursor` (with the same conversation and reply_to); it is there whenever older history exists, so keep paging while it is returned. A page usually costs one or two Teams requests, but one call reads at most 20 pages of Teams history: it may then return fewer messages than asked, even none, with `truncated: true`, a note and an olderCursor to go on. `before` (a time) also works but re-reads from the newest message each call, so it hits that limit sooner. Give cursor or before, not both. With reply_to, reads one channel post's whole thread.",
|
|
189
232
|
inputSchema: {
|
|
@@ -204,7 +247,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
204
247
|
.trim()
|
|
205
248
|
.min(1)
|
|
206
249
|
.describe("Which meeting: its chat id from list_meetings (19:meeting_…) or its title. A title must match exactly one meeting chat.");
|
|
207
|
-
|
|
250
|
+
register("list_meetings", {
|
|
208
251
|
title: "List Teams meetings",
|
|
209
252
|
description: "Lists your Teams meetings (each scheduled meeting or recurring series has a meeting chat), most recent activity first: subject, scheduled time (for a series, its first occurrence), organizer, whether a transcript exists, and whether another organization hosted it (`external`: its chat and recordings are usually no longer readable afterwards). The list may be up to a minute old (see refresh). Use get_meeting for the calls held and who attended, read_transcript for what was said, read_messages for the meeting chat.",
|
|
210
253
|
inputSchema: {
|
|
@@ -214,7 +257,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
214
257
|
refresh,
|
|
215
258
|
},
|
|
216
259
|
}, safe(async ({ query, transcript_only, limit, refresh }, extra) => text(await bridge.call("listMeetings", { query, transcriptOnly: transcript_only, limit, ...refreshParam(refresh) }, READ_TIMEOUT_MS, extra.signal))));
|
|
217
|
-
|
|
260
|
+
register("get_meeting", {
|
|
218
261
|
title: "Get a meeting's calls and attendance",
|
|
219
262
|
description: "One meeting with the calls held in it, newest first (a recurring meeting has one per occurrence): when it started and ended, who joined, the recording's link, and whether there is a transcript.",
|
|
220
263
|
inputSchema: {
|
|
@@ -222,7 +265,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
222
265
|
limit: z.number().int().min(1).max(100).default(10).describe("Most recent calls to return"),
|
|
223
266
|
},
|
|
224
267
|
}, safe(async (args, extra) => text(await bridge.call("getMeeting", args, READ_TIMEOUT_MS, extra.signal))));
|
|
225
|
-
|
|
268
|
+
register("read_transcript", {
|
|
226
269
|
title: "Read a meeting transcript",
|
|
227
270
|
description: "What was said in a meeting, from its Teams transcript: lines '[hh:mm:ss] Speaker: text', plus how long each speaker talked. Reads the latest call with a transcript unless `session` names another. Long transcripts are cut at max_length; pass the returned continueFrom as `from` to read on. Transcripts are stored in the organizer's OneDrive, so this may open OneDrive in a background tab.",
|
|
228
271
|
inputSchema: {
|
|
@@ -232,7 +275,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
232
275
|
max_length: z.number().int().min(1000).max(200_000).default(40_000).describe("Most characters of transcript to return"),
|
|
233
276
|
},
|
|
234
277
|
}, safe(async ({ meeting, session, from, max_length }, extra) => text(await bridge.call("readTranscript", { meeting, session, from, maxLength: max_length }, READ_TIMEOUT_MS, extra.signal))));
|
|
235
|
-
|
|
278
|
+
register("search_transcripts", {
|
|
236
279
|
title: "Search meeting transcripts",
|
|
237
280
|
description: "Finds what was said in meetings: the transcript lines containing all words of the query, each with the line before it, from the most recent meetings with a transcript (or one meeting). Then read_transcript with `from` reads around a match.",
|
|
238
281
|
inputSchema: {
|
|
@@ -242,7 +285,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
242
285
|
limit: z.number().int().min(1).max(200).default(30).describe("Most matching lines to return"),
|
|
243
286
|
},
|
|
244
287
|
}, safe(async (args, extra) => text(await bridge.call("searchTranscripts", args, 300_000, extra.signal))));
|
|
245
|
-
|
|
288
|
+
register("search_messages", {
|
|
246
289
|
title: "Search messages",
|
|
247
290
|
description: "Searches all your Teams chats and channels with Microsoft Search, like the search box in Teams. Returns matching messages with their conversation id (for read_messages), sender, time and a highlighted excerpt.",
|
|
248
291
|
inputSchema: {
|
|
@@ -251,7 +294,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
251
294
|
offset: z.number().int().min(0).default(0),
|
|
252
295
|
},
|
|
253
296
|
}, safe(async (args, extra) => text(await bridge.call("searchMessages", args, READ_TIMEOUT_MS, extra.signal))));
|
|
254
|
-
|
|
297
|
+
register("find_people", {
|
|
255
298
|
title: "Find people",
|
|
256
299
|
description: "Looks people up by name or email in your organization (and people you work with), as in Teams' people picker: name, email, job title, department, office.",
|
|
257
300
|
inputSchema: {
|
|
@@ -259,7 +302,7 @@ export function registerTools(server, bridge, config, options = {}) {
|
|
|
259
302
|
limit: z.number().int().min(1).max(50).default(10),
|
|
260
303
|
},
|
|
261
304
|
}, safe(async (args, extra) => text(await bridge.call("findPeople", args, READ_TIMEOUT_MS, extra.signal))));
|
|
262
|
-
|
|
305
|
+
register("send_message", {
|
|
263
306
|
title: "Send a message (needs your click)",
|
|
264
307
|
description: "Asks to post a message in an existing chat or channel (conversation), to reply to a channel post, or to start a chat with people (to): one person for a 1:1 chat, several for a group chat. If a chat with exactly those people already exists, the message goes there. The extension shows a confirmation window with the message, where it goes and who is in a new chat; nothing is posted, and no chat is created, unless the user clicks Send there. Returns whether it was sent, and when Teams recorded it (time). A sent result can have time: null with a timeNote when Teams accepted the message but its answer, or the time in it, couldn't be read: it was still posted, so don't send it again. Plain text; line breaks are kept and links become clickable." +
|
|
265
308
|
// Only with autoSendTo set, so the default description (and the tool contract) stays as it is.
|