@chrischall/microsoft-teams-mcp 0.8.7 → 0.9.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 +1 -1
- package/README.md +101 -26
- package/dist/auth-fetchproxy.js +2 -2
- package/dist/bridge-scope.js +4 -6
- package/dist/bundle.js +800 -135
- package/dist/chatsvc.js +52 -7
- package/dist/index.js +3 -1
- package/dist/sharepoint-auth.js +94 -40
- package/dist/sharepoint-token-cache.js +19 -17
- package/dist/sharepoint.js +46 -33
- package/dist/substrate.js +126 -11
- package/dist/tools/attachment.js +77 -31
- package/dist/tools/group-chat.js +385 -0
- package/dist/tools/healthcheck.js +4 -4
- package/dist/tools/people.js +236 -0
- package/dist/tools/send.js +3 -16
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -37090,11 +37090,11 @@ async function confirmWrite(ctx, options) {
|
|
|
37090
37090
|
}
|
|
37091
37091
|
const query = request?.query ? Object.fromEntries(Object.entries(request.query).filter(([, v]) => v !== void 0)) : void 0;
|
|
37092
37092
|
const hasQuery = query !== void 0 && Object.keys(query).length > 0;
|
|
37093
|
-
const
|
|
37093
|
+
const shown3 = willSend !== void 0 ? willSend : request?.body !== void 0 ? request.body : payload;
|
|
37094
37094
|
const preview = {
|
|
37095
37095
|
...summary === void 0 ? {} : { action: summary },
|
|
37096
37096
|
...request === void 0 ? {} : { method: request.method, path: request.path },
|
|
37097
|
-
...
|
|
37097
|
+
...shown3 === void 0 ? {} : { willSend: shown3 },
|
|
37098
37098
|
...hasQuery ? { willSendQuery: query } : {},
|
|
37099
37099
|
...extra
|
|
37100
37100
|
};
|
|
@@ -38523,7 +38523,7 @@ var init_version = __esm({
|
|
|
38523
38523
|
"src/version.ts"() {
|
|
38524
38524
|
"use strict";
|
|
38525
38525
|
PACKAGE_NAME = "microsoft-teams-mcp";
|
|
38526
|
-
VERSION = "0.
|
|
38526
|
+
VERSION = "0.9.0";
|
|
38527
38527
|
}
|
|
38528
38528
|
});
|
|
38529
38529
|
|
|
@@ -43636,7 +43636,7 @@ var require_websocket = __commonJS({
|
|
|
43636
43636
|
BINARY_TYPES,
|
|
43637
43637
|
CLOSE_TIMEOUT,
|
|
43638
43638
|
EMPTY_BUFFER,
|
|
43639
|
-
GUID,
|
|
43639
|
+
GUID: GUID3,
|
|
43640
43640
|
kForOnEventAttribute,
|
|
43641
43641
|
kListener,
|
|
43642
43642
|
kStatusCode,
|
|
@@ -44312,7 +44312,7 @@ var require_websocket = __commonJS({
|
|
|
44312
44312
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
44313
44313
|
return;
|
|
44314
44314
|
}
|
|
44315
|
-
const digest = createHash5("sha1").update(key +
|
|
44315
|
+
const digest = createHash5("sha1").update(key + GUID3).digest("base64");
|
|
44316
44316
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
44317
44317
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
44318
44318
|
return;
|
|
@@ -44691,7 +44691,7 @@ var require_websocket_server = __commonJS({
|
|
|
44691
44691
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
44692
44692
|
var subprotocol2 = require_subprotocol();
|
|
44693
44693
|
var WebSocket2 = require_websocket();
|
|
44694
|
-
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
44694
|
+
var { CLOSE_TIMEOUT, GUID: GUID3, kWebSocket } = require_constants();
|
|
44695
44695
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
44696
44696
|
var RUNNING = 0;
|
|
44697
44697
|
var CLOSING = 1;
|
|
@@ -44993,7 +44993,7 @@ var require_websocket_server = __commonJS({
|
|
|
44993
44993
|
);
|
|
44994
44994
|
}
|
|
44995
44995
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
44996
|
-
const digest = createHash5("sha1").update(key +
|
|
44996
|
+
const digest = createHash5("sha1").update(key + GUID3).digest("base64");
|
|
44997
44997
|
const headers = [
|
|
44998
44998
|
"HTTP/1.1 101 Switching Protocols",
|
|
44999
44999
|
"Upgrade: websocket",
|
|
@@ -49916,27 +49916,25 @@ function createSharePointTokenCache(env = process.env) {
|
|
|
49916
49916
|
validate: validateMap
|
|
49917
49917
|
});
|
|
49918
49918
|
return {
|
|
49919
|
-
|
|
49919
|
+
shared() {
|
|
49920
49920
|
return {
|
|
49921
49921
|
load() {
|
|
49922
|
-
|
|
49922
|
+
const map2 = file2.load();
|
|
49923
|
+
if (!map2) return null;
|
|
49924
|
+
if (map2[SHARED_KEY]) return map2[SHARED_KEY];
|
|
49925
|
+
const legacy = Object.values(map2).sort((a, b) => (b.expiresAt ?? 0) - (a.expiresAt ?? 0));
|
|
49926
|
+
return legacy[0] ?? null;
|
|
49923
49927
|
},
|
|
49924
49928
|
save(tokens) {
|
|
49925
49929
|
try {
|
|
49926
|
-
|
|
49927
|
-
map2[host] = tokens;
|
|
49928
|
-
file2.save(map2);
|
|
49930
|
+
file2.save({ [SHARED_KEY]: tokens });
|
|
49929
49931
|
} catch (err) {
|
|
49930
49932
|
reportCacheWriteFailure(err);
|
|
49931
49933
|
}
|
|
49932
49934
|
},
|
|
49933
49935
|
clear() {
|
|
49934
49936
|
try {
|
|
49935
|
-
|
|
49936
|
-
if (map2 && host in map2) {
|
|
49937
|
-
delete map2[host];
|
|
49938
|
-
file2.save(map2);
|
|
49939
|
-
}
|
|
49937
|
+
if (file2.load()) file2.save({});
|
|
49940
49938
|
} catch (err) {
|
|
49941
49939
|
reportCacheWriteFailure(err);
|
|
49942
49940
|
}
|
|
@@ -49945,12 +49943,14 @@ function createSharePointTokenCache(env = process.env) {
|
|
|
49945
49943
|
}
|
|
49946
49944
|
};
|
|
49947
49945
|
}
|
|
49946
|
+
var SHARED_KEY;
|
|
49948
49947
|
var init_sharepoint_token_cache = __esm({
|
|
49949
49948
|
"src/sharepoint-token-cache.ts"() {
|
|
49950
49949
|
"use strict";
|
|
49951
49950
|
init_session();
|
|
49952
49951
|
init_dist2();
|
|
49953
49952
|
init_token_cache();
|
|
49953
|
+
SHARED_KEY = "*";
|
|
49954
49954
|
}
|
|
49955
49955
|
});
|
|
49956
49956
|
|
|
@@ -49997,9 +49997,8 @@ function rememberSharePointHost(host, env = process.env) {
|
|
|
49997
49997
|
reportCacheWriteFailure(err);
|
|
49998
49998
|
}
|
|
49999
49999
|
}
|
|
50000
|
-
function withBridgeScope(opts, env,
|
|
50001
|
-
const hosts = knownSharePointHosts(env);
|
|
50002
|
-
if (extraSharePointHost !== void 0) hosts.push(extraSharePointHost);
|
|
50000
|
+
function withBridgeScope(opts, env, extraSharePointHosts = []) {
|
|
50001
|
+
const hosts = [...knownSharePointHosts(env), ...extraSharePointHosts];
|
|
50003
50002
|
return {
|
|
50004
50003
|
...opts,
|
|
50005
50004
|
domains: [...BRIDGE_TRUST_DOMAINS],
|
|
@@ -50073,7 +50072,7 @@ var init_auth_fetchproxy = __esm({
|
|
|
50073
50072
|
DEFAULT_WS_PORT = 37149;
|
|
50074
50073
|
TRUST_DOMAINS = [...BRIDGE_TRUST_DOMAINS];
|
|
50075
50074
|
createCaptureTransport = (opts) => createFetchproxyTransport(opts);
|
|
50076
|
-
bridgeScopedTransport = (env,
|
|
50075
|
+
bridgeScopedTransport = (env, sharePointHosts = []) => (opts) => createCaptureTransport(withBridgeScope(opts, env, sharePointHosts));
|
|
50077
50076
|
}
|
|
50078
50077
|
});
|
|
50079
50078
|
|
|
@@ -50091,38 +50090,70 @@ function captureHostFor(fileHost) {
|
|
|
50091
50090
|
const m = /^([a-z0-9][a-z0-9-]*)\.sharepoint\.com$/.exec(h);
|
|
50092
50091
|
return m ? `${m[1]}-my.sharepoint.com` : h;
|
|
50093
50092
|
}
|
|
50094
|
-
async function captureSharePointTokenViaFetchproxy(
|
|
50095
|
-
|
|
50093
|
+
async function captureSharePointTokenViaFetchproxy(hosts, env = process.env) {
|
|
50094
|
+
const list = [...new Set((typeof hosts === "string" ? [hosts] : [...hosts]).map((h) => h.toLowerCase()))];
|
|
50095
|
+
const bad = list.find((h) => !isSharePointHost(h));
|
|
50096
|
+
if (list.length === 0 || bad !== void 0) {
|
|
50096
50097
|
throw new Error(
|
|
50097
|
-
`refusing to capture a SharePoint token for ${JSON.stringify(
|
|
50098
|
+
`refusing to capture a SharePoint token for ${JSON.stringify(bad ?? "")}: not a *.sharepoint.com host`
|
|
50098
50099
|
);
|
|
50099
50100
|
}
|
|
50100
|
-
const
|
|
50101
|
-
|
|
50102
|
-
|
|
50103
|
-
|
|
50104
|
-
|
|
50105
|
-
|
|
50106
|
-
|
|
50107
|
-
|
|
50108
|
-
|
|
50109
|
-
|
|
50110
|
-
|
|
50111
|
-
|
|
50112
|
-
|
|
50113
|
-
|
|
50114
|
-
|
|
50115
|
-
|
|
50116
|
-
|
|
50117
|
-
|
|
50118
|
-
|
|
50101
|
+
const label = list.join(" or ");
|
|
50102
|
+
let refused = false;
|
|
50103
|
+
const scoped = bridgeScopedTransport(env, list);
|
|
50104
|
+
let token;
|
|
50105
|
+
try {
|
|
50106
|
+
token = await captureBearerHeader({
|
|
50107
|
+
// Any call the browser makes to one of these hosts. Concrete hosts, never
|
|
50108
|
+
// a wildcard — see the module note.
|
|
50109
|
+
captures: list.map(sharePointCaptureDecl),
|
|
50110
|
+
// The one bridge scope (`bridge-scope.ts`), with these hosts' captures
|
|
50111
|
+
// added to the remembered ones so the hello asks for exactly what it is
|
|
50112
|
+
// about to read.
|
|
50113
|
+
domains: SHAREPOINT_TRUST_DOMAINS,
|
|
50114
|
+
// Read per capture, not at import: see `capture-window.ts`.
|
|
50115
|
+
windowMs: captureWindowMs(env),
|
|
50116
|
+
port: getWsPort(),
|
|
50117
|
+
serverName: PACKAGE_NAME,
|
|
50118
|
+
version: VERSION,
|
|
50119
|
+
what: `a SharePoint token for ${label}`,
|
|
50120
|
+
guidance: `Reload your signed-in Teams tab and retry while it loads \u2014 that makes the page call ${label} with the SharePoint token we capture.`,
|
|
50121
|
+
createTransport: (opts) => noteScopeRefusal(scoped(opts), () => refused = true)
|
|
50122
|
+
});
|
|
50123
|
+
} catch (err) {
|
|
50124
|
+
if (!refused) throw err;
|
|
50125
|
+
throw new McpToolError(`The ContextMint Bridge has not yet allowed a SharePoint token capture from ${label}.`, {
|
|
50126
|
+
hint: `Open the ContextMint Bridge extension popup and approve the pending scope update for ${PACKAGE_NAME}, which adds ${label} (no need to remove or re-pair it). Then retry, and reload your Teams tab while it waits.`,
|
|
50127
|
+
cause: err
|
|
50128
|
+
});
|
|
50129
|
+
}
|
|
50130
|
+
for (const h of list) rememberSharePointHost(h, env);
|
|
50119
50131
|
return token;
|
|
50120
50132
|
}
|
|
50133
|
+
function noteScopeRefusal(transport, onRefused) {
|
|
50134
|
+
const server = transport.server;
|
|
50135
|
+
const capture = server.captureRequestHeader.bind(server);
|
|
50136
|
+
return {
|
|
50137
|
+
start: () => transport.start(),
|
|
50138
|
+
close: () => transport.close(),
|
|
50139
|
+
server: {
|
|
50140
|
+
captureRequestHeader: async (...args) => {
|
|
50141
|
+
try {
|
|
50142
|
+
return await capture(...args);
|
|
50143
|
+
} catch (err) {
|
|
50144
|
+
if (err instanceof Error && err.name === "FetchproxyScopeError") onRefused();
|
|
50145
|
+
throw err;
|
|
50146
|
+
}
|
|
50147
|
+
}
|
|
50148
|
+
}
|
|
50149
|
+
};
|
|
50150
|
+
}
|
|
50121
50151
|
var SHAREPOINT_TRUST_DOMAINS;
|
|
50122
50152
|
var init_sharepoint_auth = __esm({
|
|
50123
50153
|
"src/sharepoint-auth.ts"() {
|
|
50124
50154
|
"use strict";
|
|
50125
50155
|
init_fetchproxy();
|
|
50156
|
+
init_dist2();
|
|
50126
50157
|
init_capture_window();
|
|
50127
50158
|
init_auth_fetchproxy();
|
|
50128
50159
|
init_bridge_scope();
|
|
@@ -50730,6 +50761,7 @@ function outcomeUnknown(method, e, hint) {
|
|
|
50730
50761
|
}
|
|
50731
50762
|
var SEND_OUTCOME_HINT = "The message may already have been posted \u2014 check the conversation (teams_list_messages) before retrying; do not resend blindly.";
|
|
50732
50763
|
var REACTION_OUTCOME_HINT = "The reaction change may already have been applied \u2014 check the message (teams_list_messages) before retrying.";
|
|
50764
|
+
var THREAD_OUTCOME_HINT = "The change to the chat may already have been applied \u2014 check the chat (its name and members) before retrying.";
|
|
50733
50765
|
var HORIZON_OUTCOME_HINT = "The read marker may already have moved \u2014 check the conversation (teams_list_messages) before retrying; moving it again to the same message is harmless.";
|
|
50734
50766
|
var ChatServiceClient = class {
|
|
50735
50767
|
#baseUrl;
|
|
@@ -50825,13 +50857,16 @@ var ChatServiceClient = class {
|
|
|
50825
50857
|
async listConversations() {
|
|
50826
50858
|
this.#requireConfigured();
|
|
50827
50859
|
const out = [];
|
|
50860
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50828
50861
|
let url2 = `${this.#baseUrl}/users/ME/conversations?view=msnp24Equivalent&pageSize=200`;
|
|
50829
50862
|
for (let page = 0; url2 !== void 0 && page < MAX_CONVERSATION_PAGES; page++) {
|
|
50830
50863
|
const body = await this.#getJson(url2);
|
|
50831
50864
|
const convs = body.conversations ?? [];
|
|
50832
50865
|
if (convs.length === 0) break;
|
|
50833
50866
|
for (const c of convs) {
|
|
50834
|
-
if (typeof c?.id
|
|
50867
|
+
if (typeof c?.id !== "string" || c.id.startsWith("48:") && c.id !== SELF_CHAT || seen.has(c.id)) continue;
|
|
50868
|
+
seen.add(c.id);
|
|
50869
|
+
out.push(c);
|
|
50835
50870
|
}
|
|
50836
50871
|
url2 = this.#nextLink(body);
|
|
50837
50872
|
}
|
|
@@ -50957,6 +50992,41 @@ var ChatServiceClient = class {
|
|
|
50957
50992
|
const { status } = await this.#send(url2, "text", void 0, { method: "PUT", body, hint: HORIZON_OUTCOME_HINT });
|
|
50958
50993
|
this.#checkWriteStatus("PUT", status, HORIZON_OUTCOME_HINT);
|
|
50959
50994
|
}
|
|
50995
|
+
/**
|
|
50996
|
+
* A chat thread's topic and members (`GET /threads/{id}?view=msnp24Equivalent`,
|
|
50997
|
+
* verified live 2026-11-09). Members are MRIs and roles only.
|
|
50998
|
+
*/
|
|
50999
|
+
async getThread(id) {
|
|
51000
|
+
this.#requireConfigured();
|
|
51001
|
+
return this.#getJson(`${this.#threadUrl(id)}?view=msnp24Equivalent`);
|
|
51002
|
+
}
|
|
51003
|
+
/**
|
|
51004
|
+
* Rename a group chat: `PUT /threads/{id}/properties?name=topic` with
|
|
51005
|
+
* `{ topic }` (verified live 2026-11-09: 200, `{}`). Teams posts a notice in
|
|
51006
|
+
* the chat. A lost answer is a `WriteOutcomeUnknownError`.
|
|
51007
|
+
*/
|
|
51008
|
+
async setTopic(id, topic) {
|
|
51009
|
+
await this.#writeThread("PUT", `${this.#threadUrl(id)}/properties?name=topic`, { topic });
|
|
51010
|
+
}
|
|
51011
|
+
/**
|
|
51012
|
+
* Add someone to a group chat: `PUT /threads/{id}/members/{mri}` with
|
|
51013
|
+
* `{ role }` (verified live 2026-11-09). Repeating it is harmless.
|
|
51014
|
+
*/
|
|
51015
|
+
async addMember(id, mri, role = "User") {
|
|
51016
|
+
await this.#writeThread("PUT", `${this.#threadUrl(id)}/members/${encodeURIComponent(mri)}`, { role });
|
|
51017
|
+
}
|
|
51018
|
+
/** Remove someone from a group chat: `DELETE /threads/{id}/members/{mri}`, no body (verified live 2026-11-09). */
|
|
51019
|
+
async removeMember(id, mri) {
|
|
51020
|
+
await this.#writeThread("DELETE", `${this.#threadUrl(id)}/members/${encodeURIComponent(mri)}`);
|
|
51021
|
+
}
|
|
51022
|
+
#threadUrl(id) {
|
|
51023
|
+
return `${this.#baseUrl}/threads/${encodeURIComponent(id)}`;
|
|
51024
|
+
}
|
|
51025
|
+
async #writeThread(method, url2, body) {
|
|
51026
|
+
this.#requireConfigured();
|
|
51027
|
+
const { status } = await this.#send(url2, "text", void 0, { method, body, hint: THREAD_OUTCOME_HINT });
|
|
51028
|
+
this.#checkWriteStatus(method, status, THREAD_OUTCOME_HINT);
|
|
51029
|
+
}
|
|
50960
51030
|
/**
|
|
50961
51031
|
* Download an inline image (`<img src>` in a message body).
|
|
50962
51032
|
*
|
|
@@ -51064,6 +51134,7 @@ var ChatServiceClient = class {
|
|
|
51064
51134
|
async #send(url2, read, maxBytes, write) {
|
|
51065
51135
|
let body = "";
|
|
51066
51136
|
const method = write?.method ?? "GET";
|
|
51137
|
+
const payload = write?.body !== void 0 ? JSON.stringify(write.body) : void 0;
|
|
51067
51138
|
const res = await this.#tokenManager().withAuth(async (token) => {
|
|
51068
51139
|
const init = {
|
|
51069
51140
|
method,
|
|
@@ -51073,9 +51144,9 @@ var ChatServiceClient = class {
|
|
|
51073
51144
|
// a redirect to a sign-in page instead of a status we can act on.
|
|
51074
51145
|
behavioroverride: "redirectAs404",
|
|
51075
51146
|
accept: read === "text" ? "application/json" : "*/*",
|
|
51076
|
-
...
|
|
51147
|
+
...payload !== void 0 ? { "content-type": "application/json" } : {}
|
|
51077
51148
|
},
|
|
51078
|
-
...
|
|
51149
|
+
...payload !== void 0 ? { body: payload } : {},
|
|
51079
51150
|
// Never let a redirect carry the bearer somewhere we did not vet.
|
|
51080
51151
|
redirect: "error"
|
|
51081
51152
|
};
|
|
@@ -51183,9 +51254,10 @@ var ChatServiceClient = class {
|
|
|
51183
51254
|
init_dist2();
|
|
51184
51255
|
init_session();
|
|
51185
51256
|
init_sharepoint_token_cache();
|
|
51186
|
-
|
|
51257
|
+
init_bridge_scope();
|
|
51258
|
+
async function captureSharePointTokenLazily(hosts) {
|
|
51187
51259
|
const mod = await Promise.resolve().then(() => (init_sharepoint_auth(), sharepoint_auth_exports));
|
|
51188
|
-
return mod.captureSharePointTokenViaFetchproxy(
|
|
51260
|
+
return mod.captureSharePointTokenViaFetchproxy(hosts);
|
|
51189
51261
|
}
|
|
51190
51262
|
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
51191
51263
|
async function reachable(url2, run) {
|
|
@@ -51198,6 +51270,7 @@ async function reachable(url2, run) {
|
|
|
51198
51270
|
var SharePointClient = class {
|
|
51199
51271
|
#env;
|
|
51200
51272
|
#capture;
|
|
51273
|
+
#knownHosts;
|
|
51201
51274
|
#fetchImpl;
|
|
51202
51275
|
#cache;
|
|
51203
51276
|
/**
|
|
@@ -51205,11 +51278,14 @@ var SharePointClient = class {
|
|
|
51205
51278
|
* still boots (and answers `tools/list`) with no credential present.
|
|
51206
51279
|
*/
|
|
51207
51280
|
#configError = null;
|
|
51208
|
-
/**
|
|
51209
|
-
#
|
|
51281
|
+
/** The one `TokenManager`: one SharePoint token serves every host of the tenant. */
|
|
51282
|
+
#manager = null;
|
|
51283
|
+
/** The capture host of the file being fetched — where a first-ever capture looks. */
|
|
51284
|
+
#fileCaptureHost = "";
|
|
51210
51285
|
constructor(opts = {}) {
|
|
51211
51286
|
this.#env = opts.env ?? process.env;
|
|
51212
51287
|
this.#capture = opts.captureToken ?? captureSharePointTokenLazily;
|
|
51288
|
+
this.#knownHosts = opts.knownHosts ?? (() => knownSharePointHosts(this.#env));
|
|
51213
51289
|
this.#fetchImpl = opts.fetchImpl ?? ((input2, init) => fetch(input2, init));
|
|
51214
51290
|
this.#cache = createSharePointTokenCache(this.#env);
|
|
51215
51291
|
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env: this.#env })) {
|
|
@@ -51250,10 +51326,10 @@ var SharePointClient = class {
|
|
|
51250
51326
|
});
|
|
51251
51327
|
}
|
|
51252
51328
|
const { captureHostFor: captureHostFor2 } = await Promise.resolve().then(() => (init_sharepoint_auth(), sharepoint_auth_exports));
|
|
51253
|
-
|
|
51329
|
+
this.#fileCaptureHost = captureHostFor2(host);
|
|
51254
51330
|
const share = `u!${Buffer.from(objectUrl, "utf8").toString("base64url")}`;
|
|
51255
51331
|
const driveItemUrl = `https://${host}/_api/v2.1/shares/${share}/driveItem?$select=id,size,@content.downloadUrl`;
|
|
51256
|
-
const meta3 = await this.#getDriveItem(
|
|
51332
|
+
const meta3 = await this.#getDriveItem(driveItemUrl);
|
|
51257
51333
|
if (typeof meta3.size === "number" && meta3.size > maxBytes) {
|
|
51258
51334
|
const mb = (n) => `${Math.round(n / (1024 * 1024))} MB`;
|
|
51259
51335
|
throw new McpToolError(`The file is ${mb(meta3.size)}, larger than the ${mb(maxBytes)} download limit.`, {
|
|
@@ -51273,16 +51349,23 @@ var SharePointClient = class {
|
|
|
51273
51349
|
#requireConfigured() {
|
|
51274
51350
|
if (this.#configError) throw this.#configError;
|
|
51275
51351
|
}
|
|
51276
|
-
/**
|
|
51277
|
-
|
|
51278
|
-
|
|
51279
|
-
|
|
51280
|
-
|
|
51281
|
-
|
|
51282
|
-
|
|
51352
|
+
/**
|
|
51353
|
+
* Where to capture the token from: the hosts the bridge has already granted
|
|
51354
|
+
* (any of them yields a token every host accepts), or this file's OneDrive
|
|
51355
|
+
* host when none has been. Declaring a new host when a granted one would do
|
|
51356
|
+
* only widens the bridge scope, which the extension refuses until approved.
|
|
51357
|
+
*/
|
|
51358
|
+
#captureHosts() {
|
|
51359
|
+
const known = this.#knownHosts();
|
|
51360
|
+
return known.length > 0 ? known : [this.#fileCaptureHost];
|
|
51361
|
+
}
|
|
51362
|
+
/** The one `TokenManager`, created on first use. */
|
|
51363
|
+
#tokens() {
|
|
51364
|
+
this.#manager ??= createCapturedTokenManager({
|
|
51365
|
+
capture: () => this.#capture(this.#captureHosts()),
|
|
51366
|
+
persistence: this.#cache?.shared() ?? null
|
|
51283
51367
|
});
|
|
51284
|
-
this.#
|
|
51285
|
-
return mgr;
|
|
51368
|
+
return this.#manager;
|
|
51286
51369
|
}
|
|
51287
51370
|
/**
|
|
51288
51371
|
* The authed driveItem GET, with chatsvc's discipline: `behavioroverride:
|
|
@@ -51291,9 +51374,9 @@ var SharePointClient = class {
|
|
|
51291
51374
|
* `TokenManager.withAuth` supplies the token and, on a 401, re-captures once
|
|
51292
51375
|
* and replays once — so a 401 that reaches here is the second one.
|
|
51293
51376
|
*/
|
|
51294
|
-
async #getDriveItem(
|
|
51377
|
+
async #getDriveItem(url2) {
|
|
51295
51378
|
let body = "";
|
|
51296
|
-
const res = await this.#
|
|
51379
|
+
const res = await this.#tokens().withAuth(async (token) => {
|
|
51297
51380
|
const r = await reachable(
|
|
51298
51381
|
url2,
|
|
51299
51382
|
() => fetchBounded(
|
|
@@ -51318,7 +51401,7 @@ var SharePointClient = class {
|
|
|
51318
51401
|
throw new McpToolError("SharePoint refused access to the file (403).", {
|
|
51319
51402
|
status,
|
|
51320
51403
|
kind: "http",
|
|
51321
|
-
hint: "Your account cannot open this file
|
|
51404
|
+
hint: "Your account cannot open this file. Ask whoever shared it to give you access, then retry."
|
|
51322
51405
|
});
|
|
51323
51406
|
}
|
|
51324
51407
|
if (status === 404) {
|
|
@@ -51439,6 +51522,9 @@ function createSubstrateTokenCache(env = process.env) {
|
|
|
51439
51522
|
|
|
51440
51523
|
// src/substrate.ts
|
|
51441
51524
|
var SUBSTRATE_QUERY_URL = "https://substrate.office.com/searchservice/api/v2/query";
|
|
51525
|
+
var SUBSTRATE_SUGGESTIONS_URL = "https://substrate.office.com/search/api/v1/suggestions?scenario=powerbar";
|
|
51526
|
+
var DEFAULT_SUGGESTIONS = 10;
|
|
51527
|
+
var MAX_SUGGESTIONS = 25;
|
|
51442
51528
|
var CAPTURE_RETRY_COOLDOWN_MS = 10 * 60 * 1e3;
|
|
51443
51529
|
var REQUEST_TIMEOUT_MS3 = 3e4;
|
|
51444
51530
|
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
@@ -51545,6 +51631,55 @@ function parseQueryResponse(body) {
|
|
|
51545
51631
|
unmapped
|
|
51546
51632
|
};
|
|
51547
51633
|
}
|
|
51634
|
+
function buildSuggestionsBody(text, size) {
|
|
51635
|
+
return {
|
|
51636
|
+
EntityRequests: [{ EntityType: "People", Query: { QueryString: text }, Size: size }],
|
|
51637
|
+
Cvid: crypto.randomUUID(),
|
|
51638
|
+
LogicalId: crypto.randomUUID(),
|
|
51639
|
+
Scenario: { Name: "powerbar" }
|
|
51640
|
+
};
|
|
51641
|
+
}
|
|
51642
|
+
var GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
51643
|
+
var ORGID_MRI = /^8:orgid:\S+$/i;
|
|
51644
|
+
function mapSuggestion(raw) {
|
|
51645
|
+
const r = obj(raw);
|
|
51646
|
+
if (r === void 0) return void 0;
|
|
51647
|
+
const subtype = str(r.PeopleSubtype);
|
|
51648
|
+
if (subtype !== void 0 && subtype !== "OrganizationUser") return void 0;
|
|
51649
|
+
const mriField = str(r.MRI)?.trim();
|
|
51650
|
+
const oid = str(r.ExternalDirectoryObjectId)?.trim();
|
|
51651
|
+
const mri = mriField !== void 0 && ORGID_MRI.test(mriField) ? mriField : oid !== void 0 && GUID.test(oid) ? `8:orgid:${oid.toLowerCase()}` : void 0;
|
|
51652
|
+
if (mri === void 0) return void 0;
|
|
51653
|
+
const email3 = Array.isArray(r.EmailAddresses) ? r.EmailAddresses.map(str).find((e) => e !== void 0) : void 0;
|
|
51654
|
+
const upn = str(r.UserPrincipalName);
|
|
51655
|
+
const name = str(r.DisplayName)?.trim() ?? email3 ?? upn ?? mri;
|
|
51656
|
+
const jobTitle = str(r.JobTitle);
|
|
51657
|
+
const department = str(r.Department);
|
|
51658
|
+
return {
|
|
51659
|
+
mri,
|
|
51660
|
+
name,
|
|
51661
|
+
...email3 !== void 0 ? { email: email3 } : {},
|
|
51662
|
+
...upn !== void 0 ? { upn } : {},
|
|
51663
|
+
...jobTitle !== void 0 ? { jobTitle } : {},
|
|
51664
|
+
...department !== void 0 ? { department } : {}
|
|
51665
|
+
};
|
|
51666
|
+
}
|
|
51667
|
+
function parseSuggestionsResponse(body) {
|
|
51668
|
+
const groups = obj(body)?.Groups;
|
|
51669
|
+
if (!Array.isArray(groups)) return [];
|
|
51670
|
+
const byMri = /* @__PURE__ */ new Map();
|
|
51671
|
+
for (const g of groups) {
|
|
51672
|
+
const group = obj(g);
|
|
51673
|
+
if (group?.Type !== "People" || !Array.isArray(group.Suggestions)) continue;
|
|
51674
|
+
for (const raw of group.Suggestions) {
|
|
51675
|
+
const p = mapSuggestion(raw);
|
|
51676
|
+
if (p !== void 0 && !byMri.has(p.mri.toLowerCase())) byMri.set(p.mri.toLowerCase(), p);
|
|
51677
|
+
}
|
|
51678
|
+
}
|
|
51679
|
+
return [...byMri.values()];
|
|
51680
|
+
}
|
|
51681
|
+
var SEARCH = { url: SUBSTRATE_QUERY_URL, service: "Substrate search", plural: "searches" };
|
|
51682
|
+
var PEOPLE = { url: SUBSTRATE_SUGGESTIONS_URL, service: "Substrate people lookup", plural: "people lookups" };
|
|
51548
51683
|
var SubstrateClient = class {
|
|
51549
51684
|
#fetchImpl;
|
|
51550
51685
|
#configError = null;
|
|
@@ -51584,15 +51719,35 @@ var SubstrateClient = class {
|
|
|
51584
51719
|
return this.#configError === null;
|
|
51585
51720
|
}
|
|
51586
51721
|
async searchMessages(req, opts = {}) {
|
|
51722
|
+
return parseQueryResponse(await this.#post(SEARCH, buildQueryBody(req), opts.force === true));
|
|
51723
|
+
}
|
|
51724
|
+
/**
|
|
51725
|
+
* People in the directory matching `text` (a name, part of one, or an
|
|
51726
|
+
* address), as Teams' search box suggests them — only those who can be a
|
|
51727
|
+
* chat member (see {@link parseSuggestionsResponse}). Blank text asks nothing.
|
|
51728
|
+
*/
|
|
51729
|
+
async suggestPeople(text, opts = {}) {
|
|
51730
|
+
const q = text.trim();
|
|
51731
|
+
if (q === "") return [];
|
|
51732
|
+
const size = Math.min(Math.max(1, Math.floor(opts.size ?? DEFAULT_SUGGESTIONS)), MAX_SUGGESTIONS);
|
|
51733
|
+
return parseSuggestionsResponse(await this.#post(PEOPLE, buildSuggestionsBody(q, size), opts.force === true));
|
|
51734
|
+
}
|
|
51735
|
+
/**
|
|
51736
|
+
* POST `body` to Substrate with the captured token and return the parsed
|
|
51737
|
+
* JSON: the config error, the capture cooldown (unless `force`), one
|
|
51738
|
+
* re-capture on a 401, a bounded read, no redirects, and the status mapped
|
|
51739
|
+
* to an `McpToolError` — the body is never echoed.
|
|
51740
|
+
*/
|
|
51741
|
+
async #post(lookup, body, force) {
|
|
51587
51742
|
if (this.#configError) throw this.#configError;
|
|
51588
51743
|
const failed = this.#captureFailure;
|
|
51589
|
-
if (!
|
|
51744
|
+
if (!force && failed !== null && Date.now() - failed.at < CAPTURE_RETRY_COOLDOWN_MS) throw failed.error;
|
|
51590
51745
|
let text = "";
|
|
51591
51746
|
const res = await this.#manager.withAuth(async (token) => {
|
|
51592
51747
|
let r;
|
|
51593
51748
|
try {
|
|
51594
51749
|
r = await fetchBounded(
|
|
51595
|
-
|
|
51750
|
+
lookup.url,
|
|
51596
51751
|
{
|
|
51597
51752
|
method: "POST",
|
|
51598
51753
|
headers: {
|
|
@@ -51600,7 +51755,7 @@ var SubstrateClient = class {
|
|
|
51600
51755
|
"content-type": "application/json",
|
|
51601
51756
|
accept: "application/json"
|
|
51602
51757
|
},
|
|
51603
|
-
body: JSON.stringify(
|
|
51758
|
+
body: JSON.stringify(body),
|
|
51604
51759
|
redirect: "error"
|
|
51605
51760
|
},
|
|
51606
51761
|
{
|
|
@@ -51612,25 +51767,25 @@ var SubstrateClient = class {
|
|
|
51612
51767
|
}
|
|
51613
51768
|
);
|
|
51614
51769
|
} catch (e) {
|
|
51615
|
-
throw describeTransportFailure2(e,
|
|
51770
|
+
throw describeTransportFailure2(e, lookup.url, lookup.service) ?? e;
|
|
51616
51771
|
}
|
|
51617
51772
|
text = r.body;
|
|
51618
51773
|
return r.res;
|
|
51619
51774
|
});
|
|
51620
51775
|
try {
|
|
51621
|
-
checkStatus(res.status);
|
|
51776
|
+
checkStatus(res.status, lookup);
|
|
51622
51777
|
} catch (error62) {
|
|
51623
51778
|
if (res.status === 401) this.#captureFailure = { at: Date.now(), error: error62 };
|
|
51624
51779
|
throw error62;
|
|
51625
51780
|
}
|
|
51626
51781
|
try {
|
|
51627
|
-
return
|
|
51782
|
+
return JSON.parse(text);
|
|
51628
51783
|
} catch {
|
|
51629
51784
|
throw new McpToolError("Substrate returned a response that is not JSON.", { status: res.status, kind: "http" });
|
|
51630
51785
|
}
|
|
51631
51786
|
}
|
|
51632
51787
|
};
|
|
51633
|
-
function checkStatus(status) {
|
|
51788
|
+
function checkStatus(status, lookup) {
|
|
51634
51789
|
if (status >= 200 && status < 300) return;
|
|
51635
51790
|
if (status === 401) {
|
|
51636
51791
|
throw new McpToolError("Substrate rejected the search token (401) even after a fresh capture.", {
|
|
@@ -51640,9 +51795,13 @@ function checkStatus(status) {
|
|
|
51640
51795
|
});
|
|
51641
51796
|
}
|
|
51642
51797
|
if (status === 429) {
|
|
51643
|
-
throw new McpToolError(
|
|
51798
|
+
throw new McpToolError(`Substrate is rate-limiting ${lookup.plural} (429).`, {
|
|
51799
|
+
status,
|
|
51800
|
+
kind: "http",
|
|
51801
|
+
hint: "Wait a minute before retrying."
|
|
51802
|
+
});
|
|
51644
51803
|
}
|
|
51645
|
-
throw new McpToolError(
|
|
51804
|
+
throw new McpToolError(`${lookup.service} returned HTTP ${status}.`, {
|
|
51646
51805
|
status,
|
|
51647
51806
|
kind: "http",
|
|
51648
51807
|
...status >= 500 ? { hint: "A Substrate-side failure; retry shortly." } : {}
|
|
@@ -52594,10 +52753,10 @@ function renderMessageHtml(text, mentions) {
|
|
|
52594
52753
|
let at = 0;
|
|
52595
52754
|
const out = [];
|
|
52596
52755
|
placed.forEach((p, n) => {
|
|
52597
|
-
const
|
|
52756
|
+
const shown3 = text.slice(p.start, p.end).replace(/^@/, "");
|
|
52598
52757
|
html += renderPlain(text.slice(at, p.start));
|
|
52599
|
-
html += `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(
|
|
52600
|
-
out.push({ itemid: String(n), mri: p.mri, displayName:
|
|
52758
|
+
html += `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(shown3)}</span>`;
|
|
52759
|
+
out.push({ itemid: String(n), mri: p.mri, displayName: shown3 });
|
|
52601
52760
|
at = p.end;
|
|
52602
52761
|
});
|
|
52603
52762
|
html += renderPlain(text.slice(at));
|
|
@@ -53207,25 +53366,25 @@ async function unreadFrom(chatsvc, raw, me, candidates, pos, { limit, timeZone,
|
|
|
53207
53366
|
if (failed.length > 0 && !anyRead) throw failed[0].error;
|
|
53208
53367
|
const listed = Math.max(pos.t, ...raw.map((c) => lastChangeMs(c) ?? 0));
|
|
53209
53368
|
const { page, has_more, remaining, next } = takePage(items, pos, limit, failed.length > 0 ? pos.t : listed);
|
|
53210
|
-
const
|
|
53369
|
+
const shown3 = [...new Map(page.map(({ summary }) => [summary.id, summary])).values()];
|
|
53211
53370
|
const titled = await enrichTitles(chatsvc, raw, me, [
|
|
53212
|
-
...
|
|
53371
|
+
...shown3,
|
|
53213
53372
|
...failed.map((f) => f.summary),
|
|
53214
53373
|
...tooDeep.map((d) => d.summary)
|
|
53215
53374
|
]);
|
|
53216
|
-
const titledDeep = titled.slice(
|
|
53375
|
+
const titledDeep = titled.slice(shown3.length + failed.length);
|
|
53217
53376
|
return {
|
|
53218
53377
|
total_unread: page.length + remaining,
|
|
53219
53378
|
messages: page.map(({ summary, m }) => ({
|
|
53220
53379
|
conversation_id: summary.id,
|
|
53221
53380
|
...formatFlatMessage(normaliseMessage(m, me, { timeZone }), format)
|
|
53222
53381
|
})),
|
|
53223
|
-
conversations: titled.slice(0,
|
|
53382
|
+
conversations: titled.slice(0, shown3.length).map((s) => formatConversation(confirmedSummary(s, true), format)),
|
|
53224
53383
|
...fromReport(pos, next, has_more),
|
|
53225
53384
|
skipped_unreachable: skippedUnreachable,
|
|
53226
53385
|
...failed.length > 0 ? {
|
|
53227
53386
|
errors: failed.map((f, i) => ({
|
|
53228
|
-
conversation: titled[
|
|
53387
|
+
conversation: titled[shown3.length + i],
|
|
53229
53388
|
error: wrapApiError(f.error, "read this conversation").message
|
|
53230
53389
|
}))
|
|
53231
53390
|
} : {},
|
|
@@ -53369,17 +53528,17 @@ function registerUnreadTools(server, { chatsvc }) {
|
|
|
53369
53528
|
marks = await applyMarks(chatsvc, plans);
|
|
53370
53529
|
}
|
|
53371
53530
|
const budget = rootBudget();
|
|
53372
|
-
const
|
|
53531
|
+
const shown3 = returned.map(({ summary, read }) => ({
|
|
53373
53532
|
summary,
|
|
53374
53533
|
read,
|
|
53375
53534
|
messages: oldestFirst(read.messages).map((m) => normaliseMessage(m, me, { timeZone }))
|
|
53376
53535
|
}));
|
|
53377
53536
|
const roots = await mapWithConcurrency(
|
|
53378
|
-
|
|
53537
|
+
shown3,
|
|
53379
53538
|
ROOT_CONVERSATION_CONCURRENCY,
|
|
53380
53539
|
({ summary, messages }) => summary.kind === "channel" ? fetchOutsideRoots(chatsvc, summary.id, messages, me, { budget, timeZone }) : Promise.resolve(void 0)
|
|
53381
53540
|
);
|
|
53382
|
-
const conversations =
|
|
53541
|
+
const conversations = shown3.map(({ summary, read, messages }, i) => ({
|
|
53383
53542
|
conversation: formatConversation(confirmedSummary(summary, true), format ?? "full"),
|
|
53384
53543
|
unread_count: messages.length,
|
|
53385
53544
|
...formatBody(summary.kind, messages, format ?? "full", roots[i]),
|
|
@@ -53505,8 +53664,8 @@ function briefLine(title, time3, status) {
|
|
|
53505
53664
|
const flat = title.replace(/\s+/g, " ").trim() || "(untitled)";
|
|
53506
53665
|
const escaped = flat.startsWith("-- ") || flat.startsWith("\\") ? `\\${flat}` : flat;
|
|
53507
53666
|
const room = BRIEF_MAX - tail.length;
|
|
53508
|
-
const
|
|
53509
|
-
return `${
|
|
53667
|
+
const shown3 = escaped.length > room ? `${escaped.slice(0, Math.max(room - 1, 0)).trimEnd()}\u2026` : escaped;
|
|
53668
|
+
return `${shown3}${tail}`;
|
|
53510
53669
|
}
|
|
53511
53670
|
var BRIEF_NOTE = `Conversation titles below are set by other people in Microsoft Teams. ${UNTRUSTED_CONTENT_RULE}`;
|
|
53512
53671
|
function briefResult(lines, failed) {
|
|
@@ -53576,15 +53735,15 @@ function registerChangesTools(server, { chatsvc }) {
|
|
|
53576
53735
|
const listed = Math.max(t, ...[...lastChange.values()].map((n) => n ?? 0));
|
|
53577
53736
|
const next = failed.length > 0 ? t : Math.min(maxSeen, listed);
|
|
53578
53737
|
const cap = limit ?? DEFAULT_LIMIT;
|
|
53579
|
-
const
|
|
53738
|
+
const shown3 = changed.slice(0, cap);
|
|
53580
53739
|
const rest = changed.slice(cap);
|
|
53581
53740
|
const titled = await enrichTitles(chatsvc, raw, me, [
|
|
53582
|
-
...
|
|
53741
|
+
...shown3.map((c) => c.summary),
|
|
53583
53742
|
...rest.map((c) => c.summary),
|
|
53584
53743
|
...failed.map((f) => f.summary)
|
|
53585
53744
|
]);
|
|
53586
53745
|
const after_message_id = String(Math.floor(t));
|
|
53587
|
-
const conversations =
|
|
53746
|
+
const conversations = shown3.map(({ read }, i) => ({
|
|
53588
53747
|
conversation: titled[i],
|
|
53589
53748
|
new_message_count: read.count,
|
|
53590
53749
|
new_from_others_count: read.fromOthers,
|
|
@@ -53594,9 +53753,9 @@ function registerChangesTools(server, { chatsvc }) {
|
|
|
53594
53753
|
...read.truncated ? { truncated: true } : {}
|
|
53595
53754
|
}));
|
|
53596
53755
|
const more = rest.map(({ read }, i) => ({
|
|
53597
|
-
id: titled[
|
|
53598
|
-
title: titled[
|
|
53599
|
-
...participantsOf(titled[
|
|
53756
|
+
id: titled[shown3.length + i].id,
|
|
53757
|
+
title: titled[shown3.length + i].title,
|
|
53758
|
+
...participantsOf(titled[shown3.length + i]),
|
|
53600
53759
|
new_message_count: read.count,
|
|
53601
53760
|
after_message_id
|
|
53602
53761
|
}));
|
|
@@ -55045,22 +55204,27 @@ function registerExportTools(server, deps2, opts = {}) {
|
|
|
55045
55204
|
// src/tools/attachment.ts
|
|
55046
55205
|
var MAX_RAW_MESSAGES4 = 4e3;
|
|
55047
55206
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
55048
|
-
var FILE_HINT = "A shared file is downloaded from SharePoint and returned as its contents (an image as an image, anything else as an embedded resource; over 10 MiB as a download link
|
|
55207
|
+
var FILE_HINT = "A shared file is downloaded from SharePoint and returned as its contents (an image as an image, anything else as an embedded resource; over 10 MiB, or with save, as a download link or a saved file on a local install). The first download may need your Teams tab reloaded to capture a SharePoint token; a file your account cannot open comes back as metadata and its link.";
|
|
55049
55208
|
function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
55050
55209
|
server.registerTool(
|
|
55051
55210
|
"teams_get_attachment",
|
|
55052
55211
|
{
|
|
55053
55212
|
title: "Get a Teams message attachment",
|
|
55054
|
-
description: `Fetch one attachment of a Teams chat or channel message, as listed by teams_list_messages / teams_list_unread_messages.
|
|
55213
|
+
description: `Fetch one attachment of a Teams chat or channel message, as listed by teams_list_messages / teams_list_unread_messages. ref names it: an inline image's ref (attachments.images[].ref) or a shared file's name (attachments.files[].name), matched ignoring case and, for a file, with or without its extension. An inline image is returned as the image itself. A shared file is downloaded from SharePoint and returned as its contents: an image as the image, anything else as an embedded resource carrying the bytes. Anything over 10 MiB comes back instead as a signed, expiring download link (downloadUrl) on a hosted install, or saved to a fresh file (path) under ${EXPORT_OUTPUT_ENV}, else ~/Downloads/${EXPORT_SERVER_NAME}, on a local one; the caption's via says which. save: true does the same for any size \u2014 use it when the user wants the file itself rather than its contents read here. The first download may need your Teams tab reloaded to capture a short-lived SharePoint token, which then serves every SharePoint host; a file your account cannot open, or one that could not be fetched, comes back as metadata and its open link instead of failing. Its caption names the conversation beside its id: title (as teams_list_conversations names it \u2014 an untitled group chat by its participants, a 1:1 by the other person) and participants. Does not mark anything read.` + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
55055
55214
|
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
55056
55215
|
_meta: workMeta("other", { aliases: ["attachment", "image", "file", "screenshot"] }),
|
|
55057
55216
|
inputSchema: {
|
|
55058
55217
|
conversation: external_exports.string().min(1).describe("The conversation id the message is in (from teams_list_messages or teams_list_unread_messages)."),
|
|
55059
55218
|
message_id: external_exports.string().min(1).describe("The message id, exactly as a message listing returned it."),
|
|
55060
|
-
ref: external_exports.string().min(1).describe(
|
|
55219
|
+
ref: external_exports.string().min(1).describe(
|
|
55220
|
+
"An inline image's ref (attachments.images[].ref) or a shared file's name (attachments.files[].name). Case is ignored, and a file may be named without its extension."
|
|
55221
|
+
),
|
|
55222
|
+
save: external_exports.boolean().optional().describe(
|
|
55223
|
+
`Save the attachment to a fresh file under ${EXPORT_OUTPUT_ENV} (else ~/Downloads/${EXPORT_SERVER_NAME}) and return its path instead of its contents; a hosted install returns a download link instead. Default false.`
|
|
55224
|
+
)
|
|
55061
55225
|
}
|
|
55062
55226
|
},
|
|
55063
|
-
async ({ conversation, message_id, ref }) => {
|
|
55227
|
+
async ({ conversation, message_id, ref, save = false }) => {
|
|
55064
55228
|
try {
|
|
55065
55229
|
const target = Number(message_id);
|
|
55066
55230
|
const stopAt = Number.isFinite(target) && target > 0 ? (m) => Number(m.id) < target : void 0;
|
|
@@ -55073,15 +55237,16 @@ function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
55073
55237
|
}
|
|
55074
55238
|
const message = normaliseMessage(raw, "");
|
|
55075
55239
|
const naming = nameConversations(chatsvc, [conversation]).then((names) => nameFields(names.get(conversation)));
|
|
55076
|
-
const
|
|
55077
|
-
if (
|
|
55240
|
+
const found = findAttachment(message, ref, message_id);
|
|
55241
|
+
if (found.kind === "image") {
|
|
55242
|
+
const image = found.image;
|
|
55078
55243
|
const { mimeType, data } = await chatsvc.fetchImage(image.url);
|
|
55079
55244
|
if (!mimeType.startsWith("image/")) {
|
|
55080
|
-
throw new McpToolError(`The attachment ${ref} is not an image (the image store returned ${mimeType}).`);
|
|
55245
|
+
throw new McpToolError(`The attachment ${image.ref} is not an image (the image store returned ${mimeType}).`);
|
|
55081
55246
|
}
|
|
55082
|
-
const delivered = await deliver(data, imageFileName(ref, mimeType), mimeType);
|
|
55247
|
+
const delivered = await deliver(data, imageFileName(image.ref, mimeType), mimeType, save);
|
|
55083
55248
|
const caption = untrustedResult2({
|
|
55084
|
-
ref,
|
|
55249
|
+
ref: image.ref,
|
|
55085
55250
|
message_id,
|
|
55086
55251
|
conversation,
|
|
55087
55252
|
...await naming,
|
|
@@ -55093,21 +55258,14 @@ function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
55093
55258
|
});
|
|
55094
55259
|
return { content: [...delivered.content, ...caption.content] };
|
|
55095
55260
|
}
|
|
55096
|
-
|
|
55097
|
-
if (file2 !== void 0) {
|
|
55098
|
-
return downloadSharedFile(sharepoint, file2, message, { conversation, message_id }, naming);
|
|
55099
|
-
}
|
|
55100
|
-
const { images, files } = message.attachments;
|
|
55101
|
-
throw new McpToolError(`Message ${message_id} has no attachment "${ref}".`, {
|
|
55102
|
-
hint: `It has ${images.length} inline image(s) and ${files.length} shared file(s); pass an image ref or a file name exactly as teams_list_messages listed it.`
|
|
55103
|
-
});
|
|
55261
|
+
return downloadSharedFile(sharepoint, found.file, message, { conversation, message_id }, naming, save);
|
|
55104
55262
|
} catch (err) {
|
|
55105
55263
|
throw wrapApiError(err, "get the attachment");
|
|
55106
55264
|
}
|
|
55107
55265
|
}
|
|
55108
55266
|
);
|
|
55109
55267
|
}
|
|
55110
|
-
async function downloadSharedFile(sharepoint, file2, message, ids, naming) {
|
|
55268
|
+
async function downloadSharedFile(sharepoint, file2, message, ids, naming, save) {
|
|
55111
55269
|
if (file2.url === void 0) {
|
|
55112
55270
|
return untrustedResult2({ ...file2, content_available: false, hint: FILE_HINT });
|
|
55113
55271
|
}
|
|
@@ -55119,7 +55277,7 @@ async function downloadSharedFile(sharepoint, file2, message, ids, naming) {
|
|
|
55119
55277
|
}
|
|
55120
55278
|
let delivered;
|
|
55121
55279
|
try {
|
|
55122
|
-
delivered = await deliver(downloaded.data, file2.name, downloaded.mimeType);
|
|
55280
|
+
delivered = await deliver(downloaded.data, file2.name, downloaded.mimeType, save);
|
|
55123
55281
|
} catch (err) {
|
|
55124
55282
|
if (err instanceof McpToolError && file2.openUrl !== void 0) {
|
|
55125
55283
|
throw new McpToolError(err.message, {
|
|
@@ -55153,12 +55311,46 @@ async function downloadSharedFile(sharepoint, file2, message, ids, naming) {
|
|
|
55153
55311
|
);
|
|
55154
55312
|
return { content: [...content, ...caption.content] };
|
|
55155
55313
|
}
|
|
55156
|
-
function
|
|
55314
|
+
function withoutExtension(name) {
|
|
55315
|
+
const dot = name.lastIndexOf(".");
|
|
55316
|
+
return dot > 0 ? name.slice(0, dot) : name;
|
|
55317
|
+
}
|
|
55318
|
+
function findAttachment(message, ref, messageId2) {
|
|
55319
|
+
const { images, files } = message.attachments;
|
|
55320
|
+
const all = [
|
|
55321
|
+
...images.map((image) => ({ kind: "image", image })),
|
|
55322
|
+
...files.map((file2) => ({ kind: "file", file: file2 }))
|
|
55323
|
+
];
|
|
55324
|
+
const nameOf = (a) => a.kind === "image" ? a.image.ref : a.file.name;
|
|
55325
|
+
const lower = ref.toLowerCase();
|
|
55326
|
+
const rules = [
|
|
55327
|
+
(a) => nameOf(a) === ref,
|
|
55328
|
+
(a) => nameOf(a).toLowerCase() === lower,
|
|
55329
|
+
(a) => a.kind === "file" && withoutExtension(a.file.name).toLowerCase() === lower
|
|
55330
|
+
];
|
|
55331
|
+
for (const rule of rules) {
|
|
55332
|
+
const hits = all.filter(rule);
|
|
55333
|
+
if (hits.length === 1) return hits[0];
|
|
55334
|
+
if (hits.length > 1) {
|
|
55335
|
+
throw new McpToolError(`"${ref}" matches ${hits.length} attachments of message ${messageId2}.`, {
|
|
55336
|
+
hint: `Pass one of them exactly: ${hits.map((h) => JSON.stringify(nameOf(h))).join(", ")}.`
|
|
55337
|
+
});
|
|
55338
|
+
}
|
|
55339
|
+
}
|
|
55340
|
+
const names = files.map((f) => JSON.stringify(f.name));
|
|
55341
|
+
throw new McpToolError(`Message ${messageId2} has no attachment "${ref}".`, {
|
|
55342
|
+
hint: `It has ${images.length} inline image(s) and ${files.length} shared file(s)` + (names.length > 0 ? ` (${names.join(", ")})` : "") + "; pass an image ref or a file name as teams_list_messages listed it."
|
|
55343
|
+
});
|
|
55344
|
+
}
|
|
55345
|
+
function deliver(bytes, fileName, mimeType, save) {
|
|
55157
55346
|
return deliverFile({
|
|
55158
55347
|
bytes,
|
|
55159
55348
|
fileName,
|
|
55160
55349
|
mimeType,
|
|
55161
55350
|
keyPrefix: "attachments",
|
|
55351
|
+
// `save` asks for a file rather than the contents; on a hosted install
|
|
55352
|
+
// deliverFile turns the disk route into a link, saying why in `note`.
|
|
55353
|
+
...save ? { prefer: "disk" } : {},
|
|
55162
55354
|
...isHostedEnv() ? {} : { disk: { dir: downloadDir() } }
|
|
55163
55355
|
});
|
|
55164
55356
|
}
|
|
@@ -55192,7 +55384,7 @@ function hostOf2(url2) {
|
|
|
55192
55384
|
}
|
|
55193
55385
|
function degradeHint(err, host) {
|
|
55194
55386
|
if (errorStatusOf(err) === 403) {
|
|
55195
|
-
return `Your account cannot open this file
|
|
55387
|
+
return `Your account cannot open this file on ${host}. Ask whoever shared it to give you access, then retry.`;
|
|
55196
55388
|
}
|
|
55197
55389
|
if (errorKindOf(err) === "no_credential") {
|
|
55198
55390
|
return "SharePoint file download is disabled here (no token source). Unset TEAMS_DISABLE_FETCHPROXY, then retry.";
|
|
@@ -55208,12 +55400,172 @@ function degradeHint(err, host) {
|
|
|
55208
55400
|
// src/tools/send.ts
|
|
55209
55401
|
init_zod();
|
|
55210
55402
|
init_dist2();
|
|
55211
|
-
|
|
55403
|
+
|
|
55404
|
+
// src/tools/people.ts
|
|
55405
|
+
init_dist2();
|
|
55406
|
+
var MRI = /^\d+:\S+$/;
|
|
55407
|
+
var GUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
55212
55408
|
var RECENT_MESSAGES = 200;
|
|
55213
|
-
var READBACK_MESSAGES = 50;
|
|
55214
55409
|
var MAX_CANDIDATES2 = 10;
|
|
55410
|
+
function personMri(input2) {
|
|
55411
|
+
const s = input2.trim();
|
|
55412
|
+
if (MRI.test(s)) return s;
|
|
55413
|
+
if (GUID2.test(s)) return `8:orgid:${s.toLowerCase()}`;
|
|
55414
|
+
return void 0;
|
|
55415
|
+
}
|
|
55416
|
+
function normaliseName(name) {
|
|
55417
|
+
const s = name.trim().toLowerCase().replace(/\s+/g, " ");
|
|
55418
|
+
const m = /^([^,]+),\s*([^,]+)$/.exec(s);
|
|
55419
|
+
return m ? `${m[2].trim()} ${m[1].trim()}` : s;
|
|
55420
|
+
}
|
|
55421
|
+
async function recentSenders(chatsvc, conversationId) {
|
|
55422
|
+
const out = /* @__PURE__ */ new Map();
|
|
55423
|
+
for (const m of await chatsvc.getMessages(conversationId, { max: RECENT_MESSAGES })) {
|
|
55424
|
+
const mri = senderMri(m.from);
|
|
55425
|
+
const name = m.imdisplayname?.trim();
|
|
55426
|
+
if (isUserMessage(m) && mri !== void 0 && name && !out.has(mri)) out.set(mri, name);
|
|
55427
|
+
}
|
|
55428
|
+
return out;
|
|
55429
|
+
}
|
|
55430
|
+
async function knownPeople(chatsvc, me, conversationId) {
|
|
55431
|
+
const byMri = /* @__PURE__ */ new Map();
|
|
55432
|
+
const add = (mri, name) => {
|
|
55433
|
+
const key = mri.toLowerCase();
|
|
55434
|
+
if (name.trim() && !byMri.has(key)) byMri.set(key, { mri, name: name.trim() });
|
|
55435
|
+
};
|
|
55436
|
+
try {
|
|
55437
|
+
const raw = await chatsvc.listConversations();
|
|
55438
|
+
const oneOnOnes = summariseAll(raw, me).filter((s) => s.kind === "oneOnOne");
|
|
55439
|
+
for (const s of await enrichTitles(chatsvc, raw, me, oneOnOnes)) {
|
|
55440
|
+
const peer = oneOnOnePeerMri(s.id, me);
|
|
55441
|
+
const name = s.participants?.[0];
|
|
55442
|
+
if (peer !== void 0 && name !== void 0) add(peer, name);
|
|
55443
|
+
}
|
|
55444
|
+
} catch {
|
|
55445
|
+
}
|
|
55446
|
+
try {
|
|
55447
|
+
for (const [mri, name] of await recentSenders(chatsvc, conversationId)) add(mri, name);
|
|
55448
|
+
} catch {
|
|
55449
|
+
}
|
|
55450
|
+
return [...byMri.values()];
|
|
55451
|
+
}
|
|
55452
|
+
function knownName(mri, known) {
|
|
55453
|
+
const key = mri.toLowerCase();
|
|
55454
|
+
return known.find((k) => k.mri.toLowerCase() === key)?.name;
|
|
55455
|
+
}
|
|
55456
|
+
function isEmail(input2) {
|
|
55457
|
+
return /^[^@\s]+@[^@\s]+$/.test(input2.trim());
|
|
55458
|
+
}
|
|
55459
|
+
function candidateList(people) {
|
|
55460
|
+
return people.slice(0, MAX_CANDIDATES2).map((k) => {
|
|
55461
|
+
const email3 = k.email ?? k.upn;
|
|
55462
|
+
return `${JSON.stringify(k.name)}${email3 !== void 0 ? ` <${email3}>` : ""} (${k.mri})`;
|
|
55463
|
+
}).join("; ");
|
|
55464
|
+
}
|
|
55465
|
+
function matchKnown(person, known) {
|
|
55466
|
+
const q = normaliseName(person);
|
|
55467
|
+
const raw = person.trim().toLowerCase();
|
|
55468
|
+
const exact = known.filter((k) => normaliseName(k.name) === q);
|
|
55469
|
+
const found = exact.length > 0 ? exact : known.filter((k) => normaliseName(k.name).includes(q) || k.name.toLowerCase().includes(raw));
|
|
55470
|
+
if (found.length === 1) return found[0];
|
|
55471
|
+
if (found.length > 1) {
|
|
55472
|
+
throw new McpToolError(
|
|
55473
|
+
`"${person}" matches ${found.length} people: ${candidateList(found)}. ${THIRD_PARTY_NAMES_NOTE}`,
|
|
55474
|
+
{ hint: "Pass the MRI (8:orgid:\u2026) of the one you mean." }
|
|
55475
|
+
);
|
|
55476
|
+
}
|
|
55477
|
+
return void 0;
|
|
55478
|
+
}
|
|
55479
|
+
var PASS_ID = "Pass the person's email address or MRI (8:orgid:\u2026) instead.";
|
|
55480
|
+
function directoryFailed(person, err, email3) {
|
|
55481
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
55482
|
+
const own2 = err instanceof McpToolError ? err.hint : void 0;
|
|
55483
|
+
const remedy = own2 ?? "Run any search in the Teams search box of a signed-in Teams tab while retrying (that is what lets this server capture the token it searches the directory with).";
|
|
55484
|
+
const lead = email3 ? `Could not look up "${person}" because` : `No one in your chats is called "${person}", and`;
|
|
55485
|
+
return new McpToolError(`${lead} the directory could not be searched: ${message}`, {
|
|
55486
|
+
hint: `${remedy} Or pass the person's MRI (8:orgid:\u2026) instead.`,
|
|
55487
|
+
...err instanceof McpToolError && err.kind !== void 0 ? { kind: err.kind } : {},
|
|
55488
|
+
cause: err
|
|
55489
|
+
});
|
|
55490
|
+
}
|
|
55491
|
+
function fromDirectory(person, p) {
|
|
55492
|
+
const email3 = p.email ?? p.upn;
|
|
55493
|
+
return { person, mri: p.mri, name: p.name, source: "directory", ...email3 !== void 0 ? { email: email3 } : {} };
|
|
55494
|
+
}
|
|
55495
|
+
function pickByEmail(person, found) {
|
|
55496
|
+
const want = person.trim().toLowerCase();
|
|
55497
|
+
const hits = found.filter((p) => p.email?.toLowerCase() === want || p.upn?.toLowerCase() === want);
|
|
55498
|
+
if (hits.length === 1) return fromDirectory(person, hits[0]);
|
|
55499
|
+
if (hits.length > 1) {
|
|
55500
|
+
throw new McpToolError(
|
|
55501
|
+
`"${person}" is the address of ${hits.length} people in the directory: ${candidateList(hits)}. ${THIRD_PARTY_NAMES_NOTE}`,
|
|
55502
|
+
{ hint: "Pass the MRI (8:orgid:\u2026) of the one you mean." }
|
|
55503
|
+
);
|
|
55504
|
+
}
|
|
55505
|
+
throw new McpToolError(`No one in your organisation's directory has the address "${person}".`, {
|
|
55506
|
+
hint: "Check the address, or pass the person's name or MRI (8:orgid:\u2026) instead. Only people in your organisation (not distribution lists or personal contacts) are found there."
|
|
55507
|
+
});
|
|
55508
|
+
}
|
|
55509
|
+
function pickByName(person, found) {
|
|
55510
|
+
const q = normaliseName(person);
|
|
55511
|
+
const exact = found.filter((p) => normaliseName(p.name) === q);
|
|
55512
|
+
if (exact.length === 1) return fromDirectory(person, exact[0]);
|
|
55513
|
+
if (exact.length > 1) {
|
|
55514
|
+
throw new McpToolError(
|
|
55515
|
+
`"${person}" matches ${exact.length} people in the directory: ${candidateList(exact)}. ${THIRD_PARTY_NAMES_NOTE}`,
|
|
55516
|
+
{ hint: "Pass the email address or MRI (8:orgid:\u2026) of the one you mean." }
|
|
55517
|
+
);
|
|
55518
|
+
}
|
|
55519
|
+
if (found.length === 1 && ` ${normaliseName(found[0].name)} `.includes(` ${q} `)) return fromDirectory(person, found[0]);
|
|
55520
|
+
if (found.length > 0) {
|
|
55521
|
+
throw new McpToolError(
|
|
55522
|
+
`No one in your chats is called "${person}", and no one in the directory is called exactly that; it suggested: ${candidateList(found)}. ${THIRD_PARTY_NAMES_NOTE}`,
|
|
55523
|
+
{ hint: "If one of them is who you mean, pass their email address or MRI (8:orgid:\u2026)." }
|
|
55524
|
+
);
|
|
55525
|
+
}
|
|
55526
|
+
throw new McpToolError(`No one in your chats or your organisation's directory is called "${person}".`, {
|
|
55527
|
+
hint: `${PASS_ID} A name is matched among the other person of each of your 1:1 chats and this chat's recent senders, then searched in your organisation's directory.`
|
|
55528
|
+
});
|
|
55529
|
+
}
|
|
55530
|
+
async function resolvePeople(inputs, known, directory) {
|
|
55531
|
+
const local = inputs.map((person) => {
|
|
55532
|
+
const direct = personMri(person);
|
|
55533
|
+
if (direct !== void 0) {
|
|
55534
|
+
const name = knownName(direct, known);
|
|
55535
|
+
return { person, mri: direct, ...name !== void 0 ? { name } : {}, source: "id" };
|
|
55536
|
+
}
|
|
55537
|
+
if (isEmail(person)) return { person, email: true };
|
|
55538
|
+
const k = matchKnown(person, known);
|
|
55539
|
+
return k !== void 0 ? { person, mri: k.mri, name: k.name, source: "chat" } : { person, email: false };
|
|
55540
|
+
});
|
|
55541
|
+
const asked = /* @__PURE__ */ new Map();
|
|
55542
|
+
const out = [];
|
|
55543
|
+
for (const r of local) {
|
|
55544
|
+
if ("mri" in r) {
|
|
55545
|
+
out.push(r);
|
|
55546
|
+
continue;
|
|
55547
|
+
}
|
|
55548
|
+
const text = r.person.trim();
|
|
55549
|
+
const key = r.email ? `@${text.toLowerCase()}` : normaliseName(text);
|
|
55550
|
+
let found = asked.get(key);
|
|
55551
|
+
if (found === void 0) {
|
|
55552
|
+
try {
|
|
55553
|
+
found = await directory.suggestPeople(text, { force: true });
|
|
55554
|
+
} catch (err) {
|
|
55555
|
+
throw directoryFailed(r.person, err, r.email);
|
|
55556
|
+
}
|
|
55557
|
+
asked.set(key, found);
|
|
55558
|
+
}
|
|
55559
|
+
out.push(r.email ? pickByEmail(r.person, found) : pickByName(r.person, found));
|
|
55560
|
+
}
|
|
55561
|
+
return out;
|
|
55562
|
+
}
|
|
55563
|
+
|
|
55564
|
+
// src/tools/send.ts
|
|
55565
|
+
var TOOL2 = "teams_send_message";
|
|
55566
|
+
var READBACK_MESSAGES = 50;
|
|
55567
|
+
var MAX_CANDIDATES3 = 10;
|
|
55215
55568
|
var PREVIEW_CHARS3 = 200;
|
|
55216
|
-
var MRI = /^\d+:\S+$/;
|
|
55217
55569
|
var mentionArg = external_exports.object({
|
|
55218
55570
|
name_in_text: external_exports.string().min(1).describe('How the person is named in text \u2014 its first "@name" (else "name") becomes the mention.'),
|
|
55219
55571
|
person: external_exports.string().min(1).describe("Who to mention: an MRI (8:orgid:\u2026), or a display name matched among recent senders in this conversation.")
|
|
@@ -55229,15 +55581,6 @@ async function resolveTarget(chatsvc, conversation, me, verb = "post to") {
|
|
|
55229
55581
|
const s = await resolveListed(chatsvc, raw, me, conversation, verb);
|
|
55230
55582
|
return { id: s.id, title: s.title, kind: s.kind, ...s.participants !== void 0 ? { participants: s.participants } : {} };
|
|
55231
55583
|
}
|
|
55232
|
-
async function recentSenders(chatsvc, conversationId) {
|
|
55233
|
-
const out = /* @__PURE__ */ new Map();
|
|
55234
|
-
for (const m of await chatsvc.getMessages(conversationId, { max: RECENT_MESSAGES })) {
|
|
55235
|
-
const mri = senderMri(m.from);
|
|
55236
|
-
const name = m.imdisplayname?.trim();
|
|
55237
|
-
if (isUserMessage(m) && mri !== void 0 && name && !out.has(mri)) out.set(mri, name);
|
|
55238
|
-
}
|
|
55239
|
-
return out;
|
|
55240
|
-
}
|
|
55241
55584
|
async function resolveMentions(chatsvc, conversationId, mentions) {
|
|
55242
55585
|
if (mentions.length === 0) return [];
|
|
55243
55586
|
const senders = mentions.every((m) => MRI.test(m.person.trim())) ? /* @__PURE__ */ new Map() : await recentSenders(chatsvc, conversationId);
|
|
@@ -55250,13 +55593,13 @@ async function resolveMentions(chatsvc, conversationId, mentions) {
|
|
|
55250
55593
|
const found = exact.length > 0 ? exact : known.filter((k) => k.name.toLowerCase().includes(q));
|
|
55251
55594
|
if (found.length === 1) return { target: { text: name_in_text, mri: found[0].mri }, person: found[0].name };
|
|
55252
55595
|
if (found.length > 1) {
|
|
55253
|
-
const named = found.slice(0,
|
|
55596
|
+
const named = found.slice(0, MAX_CANDIDATES3).map((k) => `${JSON.stringify(k.name)} (${k.mri})`).join("; ");
|
|
55254
55597
|
throw new McpToolError(
|
|
55255
55598
|
`"${person}" matches ${found.length} people in this conversation: ${named}. ${THIRD_PARTY_NAMES_NOTE}`,
|
|
55256
55599
|
{ hint: "Pass the MRI of the one to mention as person." }
|
|
55257
55600
|
);
|
|
55258
55601
|
}
|
|
55259
|
-
const some = known.slice(0,
|
|
55602
|
+
const some = known.slice(0, MAX_CANDIDATES3).map((k) => JSON.stringify(k.name)).join(", ");
|
|
55260
55603
|
throw new McpToolError(`No recent sender in this conversation is called "${person}".`, {
|
|
55261
55604
|
hint: (some ? `Recent senders: ${some}. ${THIRD_PARTY_NAMES_NOTE} ` : "") + "Pass an exact display name, or the person's MRI (8:orgid:\u2026) as person."
|
|
55262
55605
|
});
|
|
@@ -55531,7 +55874,7 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
55531
55874
|
} catch {
|
|
55532
55875
|
readBackFailed = true;
|
|
55533
55876
|
}
|
|
55534
|
-
const
|
|
55877
|
+
const shown3 = remove ? "gone" : "present";
|
|
55535
55878
|
if (unconfirmed !== void 0 && verified !== true) {
|
|
55536
55879
|
const status = writeOutcomeStatus(unconfirmed);
|
|
55537
55880
|
const why = unconfirmed.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status}` : "the connection dropped";
|
|
@@ -55541,18 +55884,18 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
55541
55884
|
message_id,
|
|
55542
55885
|
reaction: key,
|
|
55543
55886
|
verified,
|
|
55544
|
-
warning: `Teams did not confirm this change (${why}), and reading the message back ${readBackFailed ? "failed" : verified === null ? "did not find it" : `did not show the reaction ${
|
|
55887
|
+
warning: `Teams did not confirm this change (${why}), and reading the message back ${readBackFailed ? "failed" : verified === null ? "did not find it" : `did not show the reaction ${shown3}`} \u2014 check the message (teams_list_messages) before retrying.`
|
|
55545
55888
|
});
|
|
55546
55889
|
}
|
|
55547
55890
|
let warning;
|
|
55548
55891
|
if (unconfirmed !== void 0) {
|
|
55549
|
-
warning = `Teams did not confirm this change, but reading the message back shows the reaction ${
|
|
55892
|
+
warning = `Teams did not confirm this change, but reading the message back shows the reaction ${shown3}.`;
|
|
55550
55893
|
} else if (readBackFailed) {
|
|
55551
55894
|
warning = "Teams accepted the change, but reading the message back failed \u2014 check the message (teams_list_messages).";
|
|
55552
55895
|
} else if (verified === null) {
|
|
55553
55896
|
warning = "Teams accepted the change, but the message was not found on reading it back (it may have been deleted) \u2014 check the conversation (teams_list_messages).";
|
|
55554
55897
|
} else if (!verified) {
|
|
55555
|
-
warning = `Teams accepted the change, but reading the message back did not show the reaction ${
|
|
55898
|
+
warning = `Teams accepted the change, but reading the message back did not show the reaction ${shown3} \u2014 check the message (teams_list_messages); the key may not be one Teams knows.`;
|
|
55556
55899
|
}
|
|
55557
55900
|
return untrustedResult2({
|
|
55558
55901
|
status: remove ? "removed" : "reacted",
|
|
@@ -55569,6 +55912,327 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
55569
55912
|
);
|
|
55570
55913
|
}
|
|
55571
55914
|
|
|
55915
|
+
// src/tools/group-chat.ts
|
|
55916
|
+
init_zod();
|
|
55917
|
+
init_dist2();
|
|
55918
|
+
var RENAME = "teams_rename_chat";
|
|
55919
|
+
var ADD = "teams_add_chat_members";
|
|
55920
|
+
var REMOVE = "teams_remove_chat_members";
|
|
55921
|
+
var MAX_PEOPLE = 20;
|
|
55922
|
+
var KIND_LABELS = {
|
|
55923
|
+
oneOnOne: "a 1:1 chat",
|
|
55924
|
+
meeting: "a meeting chat",
|
|
55925
|
+
channel: "a channel",
|
|
55926
|
+
self: "your notes self-chat"
|
|
55927
|
+
};
|
|
55928
|
+
var conversationParam = external_exports.string().min(1).describe(
|
|
55929
|
+
"The group chat: its id (from teams_list_conversations), or a case-insensitive substring of its title or an untitled chat's participant names."
|
|
55930
|
+
);
|
|
55931
|
+
var peopleParam = external_exports.array(external_exports.string().trim().min(1)).min(1).max(MAX_PEOPLE).describe(
|
|
55932
|
+
`Who: each an MRI (8:orgid:\u2026), a bare Entra object id, an email address (looked up in your organisation's directory), or a display name ("Greg King" and "King, Greg" are the same) matched among the other people of your 1:1 chats and recent senders in this chat, then \u2014 only if no one there matches \u2014 in the directory.`
|
|
55933
|
+
);
|
|
55934
|
+
var PEOPLE_SENTENCE = `people are MRIs (8:orgid:\u2026), bare object ids, email addresses, or display names. A name is matched (ignoring case, in either "First Last" or "Last, First" order) among the other person of each of the user's 1:1 chats and the chat's recent senders first; only when no one there matches is the organisation's directory searched, where the one person with exactly that name is taken (or the only suggestion, when the name is whole words of it). An email address is looked up in the directory and must be exactly one person's email or UPN. An ambiguous or unknown person refuses the whole call, listing candidates. The directory is searched with the same token as teams_search_messages: the first lookup may need the user to run any search in the Teams search box so it can be captured. `;
|
|
55935
|
+
async function groupChat(chatsvc, conversation, me, doing) {
|
|
55936
|
+
const target = await resolveTarget(chatsvc, conversation, me, `change`);
|
|
55937
|
+
if (target.kind === "group") return target;
|
|
55938
|
+
const what = KIND_LABELS[target.kind] ?? `a ${target.kind}`;
|
|
55939
|
+
throw new McpToolError(
|
|
55940
|
+
`${JSON.stringify(target.title)} is ${what}, not a group chat: only a group chat can be ${doing}.`,
|
|
55941
|
+
{
|
|
55942
|
+
hint: target.kind === "oneOnOne" ? "A 1:1 cannot take more people or a name; start a group chat in Teams instead." : 'Pass a group chat (kind "group" in teams_list_conversations).'
|
|
55943
|
+
}
|
|
55944
|
+
);
|
|
55945
|
+
}
|
|
55946
|
+
function unconfirmedWhy2(e) {
|
|
55947
|
+
const status = writeOutcomeStatus(e);
|
|
55948
|
+
return e.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status}` : "the connection dropped";
|
|
55949
|
+
}
|
|
55950
|
+
function memberSet(thread) {
|
|
55951
|
+
return new Set((thread.members ?? []).map((m) => m.id.toLowerCase()));
|
|
55952
|
+
}
|
|
55953
|
+
function shown(p) {
|
|
55954
|
+
return {
|
|
55955
|
+
person: p.person,
|
|
55956
|
+
mri: p.mri,
|
|
55957
|
+
...p.name !== void 0 ? { name: p.name } : {},
|
|
55958
|
+
source: p.source,
|
|
55959
|
+
...p.email !== void 0 ? { email: p.email } : {}
|
|
55960
|
+
};
|
|
55961
|
+
}
|
|
55962
|
+
async function resolveFor(chatsvc, directory, me, conversationId, people) {
|
|
55963
|
+
const known = await knownPeople(chatsvc, me, conversationId);
|
|
55964
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55965
|
+
return (await resolvePeople(people, known, directory)).filter((p) => {
|
|
55966
|
+
const key = p.mri.toLowerCase();
|
|
55967
|
+
if (seen.has(key)) return false;
|
|
55968
|
+
seen.add(key);
|
|
55969
|
+
return true;
|
|
55970
|
+
});
|
|
55971
|
+
}
|
|
55972
|
+
async function applyMemberChanges(chatsvc, threadId, people, write, done) {
|
|
55973
|
+
const outcomes = [];
|
|
55974
|
+
for (const p of people) {
|
|
55975
|
+
try {
|
|
55976
|
+
await write(p.mri);
|
|
55977
|
+
outcomes.push({ p });
|
|
55978
|
+
} catch (e) {
|
|
55979
|
+
if (e instanceof WriteOutcomeUnknownError) outcomes.push({ p, unconfirmed: e });
|
|
55980
|
+
else outcomes.push({ p, error: e instanceof Error ? e.message : String(e) });
|
|
55981
|
+
}
|
|
55982
|
+
}
|
|
55983
|
+
let members2;
|
|
55984
|
+
try {
|
|
55985
|
+
members2 = memberSet(await chatsvc.getThread(threadId));
|
|
55986
|
+
} catch {
|
|
55987
|
+
members2 = void 0;
|
|
55988
|
+
}
|
|
55989
|
+
const changed = (mri) => {
|
|
55990
|
+
const present = members2?.has(mri.toLowerCase());
|
|
55991
|
+
return present === void 0 ? null : done === "added" ? present : !present;
|
|
55992
|
+
};
|
|
55993
|
+
const notes = [];
|
|
55994
|
+
const results = outcomes.map(({ p, unconfirmed, error: error62 }) => {
|
|
55995
|
+
if (error62 !== void 0) return { ...shown(p), status: "failed", error: error62 };
|
|
55996
|
+
const verified = changed(p.mri);
|
|
55997
|
+
if (unconfirmed !== void 0 && verified !== true) {
|
|
55998
|
+
notes.push(
|
|
55999
|
+
`Teams did not confirm the change for ${p.mri} (${unconfirmedWhy2(unconfirmed)}), and reading the chat back ${verified === null ? "failed" : `did not show it ${done}`}.`
|
|
56000
|
+
);
|
|
56001
|
+
return { ...shown(p), status: "unknown", verified: verified ?? false };
|
|
56002
|
+
}
|
|
56003
|
+
if (unconfirmed !== void 0) {
|
|
56004
|
+
notes.push(`Teams did not confirm the change for ${p.mri}, but reading the chat back shows it ${done}.`);
|
|
56005
|
+
} else if (verified === false) {
|
|
56006
|
+
notes.push(`Teams accepted the change for ${p.mri}, but reading the chat back did not show it ${done}.`);
|
|
56007
|
+
}
|
|
56008
|
+
return { ...shown(p), status: done, verified };
|
|
56009
|
+
});
|
|
56010
|
+
if (members2 === void 0) notes.push("Teams accepted the changes, but reading the chat back failed.");
|
|
56011
|
+
if (results.some((r) => r.status === "failed")) notes.push("Some changes failed: see each person's error.");
|
|
56012
|
+
if (notes.length === 0) return { results };
|
|
56013
|
+
return {
|
|
56014
|
+
results,
|
|
56015
|
+
warning: `${notes.join(" ")} Check the chat before retrying \u2014 running this tool again is safe: anyone already ${done === "added" ? "in the chat is reported as already_member" : "gone is reported as not_member"} and not written again.`
|
|
56016
|
+
};
|
|
56017
|
+
}
|
|
56018
|
+
function registerGroupChatTools(server, { chatsvc, substrate }) {
|
|
56019
|
+
server.registerTool(
|
|
56020
|
+
RENAME,
|
|
56021
|
+
{
|
|
56022
|
+
title: "Rename a Teams group chat",
|
|
56023
|
+
description: `Rename a group chat (set its topic) as the signed-in user. conversation is the chat's id or name as for teams_list_messages; only group chats can be renamed \u2014 1:1s, meeting chats, channels and the self-chat (${SELF_CHAT}) are refused. Teams posts a notice in the chat that the user renamed it, so everyone in it sees the change. Renaming to the current name changes nothing and asks for no confirmation. The result says whether reading the chat back showed the new name (verified); status "unknown" means Teams did not confirm the change and the read-back did not show it \u2014 check the chat before retrying. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the chat, its current name and the new one. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
56024
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
56025
|
+
_meta: workMeta("send", { aliases: ["rename chat", "rename", "chat name", "topic", "set topic"] }),
|
|
56026
|
+
inputSchema: {
|
|
56027
|
+
conversation: conversationParam,
|
|
56028
|
+
name: external_exports.string().trim().min(1).describe("The new name for the chat (surrounding spaces are trimmed)."),
|
|
56029
|
+
confirmToken: confirmTokenParam
|
|
56030
|
+
}
|
|
56031
|
+
},
|
|
56032
|
+
async ({ conversation, name, confirmToken }, ctx) => {
|
|
56033
|
+
try {
|
|
56034
|
+
const me = await chatsvc.meMri();
|
|
56035
|
+
const target = await groupChat(chatsvc, conversation, me, "renamed");
|
|
56036
|
+
const current = (await chatsvc.getThread(target.id)).properties?.topic ?? "";
|
|
56037
|
+
if (current === name) {
|
|
56038
|
+
return untrustedResult2({ status: "unchanged", conversation: target, name });
|
|
56039
|
+
}
|
|
56040
|
+
const path = `/threads/${encodeURIComponent(target.id)}/properties?name=topic`;
|
|
56041
|
+
const gate = await confirmWrite(ctx, {
|
|
56042
|
+
tool: RENAME,
|
|
56043
|
+
action: "chat.rename",
|
|
56044
|
+
message: "Review and confirm this group chat rename before it is made:",
|
|
56045
|
+
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
56046
|
+
summary: `Rename group chat ${JSON.stringify(target.title)} to ${JSON.stringify(name)}`,
|
|
56047
|
+
// The signed-in user, so an approval minted under one account never acts as another.
|
|
56048
|
+
account: me,
|
|
56049
|
+
target: target.id,
|
|
56050
|
+
request: { method: "PUT", path, body: { topic: name } },
|
|
56051
|
+
// The title and the current name are set by other people, so each is fenced.
|
|
56052
|
+
preview: {
|
|
56053
|
+
conversation: untrustedField(target),
|
|
56054
|
+
current_name: untrustedField(current),
|
|
56055
|
+
new_name: name,
|
|
56056
|
+
note: "Teams posts a notice in the chat that you renamed it."
|
|
56057
|
+
},
|
|
56058
|
+
confirmToken
|
|
56059
|
+
});
|
|
56060
|
+
if (gate) return gate;
|
|
56061
|
+
let unconfirmed;
|
|
56062
|
+
try {
|
|
56063
|
+
await chatsvc.setTopic(target.id, name);
|
|
56064
|
+
} catch (e) {
|
|
56065
|
+
if (!(e instanceof WriteOutcomeUnknownError)) throw e;
|
|
56066
|
+
unconfirmed = e;
|
|
56067
|
+
}
|
|
56068
|
+
let verified = false;
|
|
56069
|
+
try {
|
|
56070
|
+
verified = (await chatsvc.getThread(target.id)).properties?.topic === name;
|
|
56071
|
+
} catch {
|
|
56072
|
+
verified = null;
|
|
56073
|
+
}
|
|
56074
|
+
const base = { conversation: target, previous_name: current, name };
|
|
56075
|
+
if (unconfirmed !== void 0 && verified !== true) {
|
|
56076
|
+
return untrustedResult2({
|
|
56077
|
+
status: "unknown",
|
|
56078
|
+
...base,
|
|
56079
|
+
verified: verified ?? false,
|
|
56080
|
+
warning: `Teams did not confirm this rename (${unconfirmedWhy2(unconfirmed)}), and reading the chat back ${verified === null ? "failed" : "did not show the new name"} \u2014 check the chat (teams_list_conversations) before retrying; renaming again to the same name is harmless.`
|
|
56081
|
+
});
|
|
56082
|
+
}
|
|
56083
|
+
let warning;
|
|
56084
|
+
if (unconfirmed !== void 0) {
|
|
56085
|
+
warning = "Teams did not confirm this rename, but reading the chat back shows the new name.";
|
|
56086
|
+
} else if (verified === null) {
|
|
56087
|
+
warning = "Teams accepted the rename, but reading the chat back failed \u2014 check the chat (teams_list_conversations).";
|
|
56088
|
+
} else if (!verified) {
|
|
56089
|
+
warning = "Teams accepted the rename, but reading the chat back did not show the new name \u2014 check the chat (teams_list_conversations).";
|
|
56090
|
+
}
|
|
56091
|
+
return untrustedResult2({ status: "renamed", ...base, verified, ...warning !== void 0 ? { warning } : {} });
|
|
56092
|
+
} catch (err) {
|
|
56093
|
+
throw wrapApiError(err, "rename the chat");
|
|
56094
|
+
}
|
|
56095
|
+
}
|
|
56096
|
+
);
|
|
56097
|
+
server.registerTool(
|
|
56098
|
+
ADD,
|
|
56099
|
+
{
|
|
56100
|
+
title: "Add people to a Teams group chat",
|
|
56101
|
+
description: `Add people to a group chat as the signed-in user, as ordinary members. conversation is the chat's id or name as for teams_list_messages; only group chats take people \u2014 1:1s, meeting chats, channels and the self-chat are refused. ${PEOPLE_SENTENCE}People already in the chat are reported as already_member and not written; if everyone is, nothing is asked or changed. Teams posts a notice in the chat for each person added, and they can read the chat's history as Teams allows. The result lists each person: added, already_member, unknown (Teams did not confirm and reading the chat back does not show them \u2014 check before retrying) or failed (with the error). ` + CONFIRM_FLOW_SENTENCE + " The preview shows the chat and exactly who would be added \u2014 each with their source (id, chat or directory) and, from the directory, their email \u2014 so the user can check it is the right person. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
56102
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
56103
|
+
_meta: workMeta("send", { aliases: ["add people", "add to chat", "invite", "add members", "members"] }),
|
|
56104
|
+
inputSchema: {
|
|
56105
|
+
conversation: conversationParam,
|
|
56106
|
+
people: peopleParam,
|
|
56107
|
+
confirmToken: confirmTokenParam
|
|
56108
|
+
}
|
|
56109
|
+
},
|
|
56110
|
+
async ({ conversation, people, confirmToken }, ctx) => {
|
|
56111
|
+
try {
|
|
56112
|
+
const me = await chatsvc.meMri();
|
|
56113
|
+
const target = await groupChat(chatsvc, conversation, me, "given more people");
|
|
56114
|
+
const resolved = await resolveFor(chatsvc, substrate, me, target.id, people);
|
|
56115
|
+
const members2 = memberSet(await chatsvc.getThread(target.id));
|
|
56116
|
+
const already = resolved.filter((p) => members2.has(p.mri.toLowerCase()));
|
|
56117
|
+
const toAdd = resolved.filter((p) => !members2.has(p.mri.toLowerCase()));
|
|
56118
|
+
const alreadyResults = already.map((p) => ({ ...shown(p), status: "already_member" }));
|
|
56119
|
+
if (toAdd.length === 0) {
|
|
56120
|
+
return untrustedResult2({ status: "unchanged", conversation: target, results: alreadyResults });
|
|
56121
|
+
}
|
|
56122
|
+
const gate = await confirmWrite(ctx, {
|
|
56123
|
+
tool: ADD,
|
|
56124
|
+
action: "chat.add_members",
|
|
56125
|
+
message: "Review and confirm who is added to this group chat:",
|
|
56126
|
+
summary: `Add ${toAdd.length} ${toAdd.length === 1 ? "person" : "people"} to group chat ${JSON.stringify(target.title)}`,
|
|
56127
|
+
account: me,
|
|
56128
|
+
target: target.id,
|
|
56129
|
+
request: {
|
|
56130
|
+
method: "PUT",
|
|
56131
|
+
path: `/threads/${encodeURIComponent(target.id)}/members`,
|
|
56132
|
+
body: { members: toAdd.map((p) => ({ id: p.mri, role: "User" })) }
|
|
56133
|
+
},
|
|
56134
|
+
// The title and the resolved names are set by other people, so each is fenced.
|
|
56135
|
+
preview: {
|
|
56136
|
+
conversation: untrustedField(target),
|
|
56137
|
+
add: untrustedField(toAdd.map(shown)),
|
|
56138
|
+
...already.length > 0 ? { already_members: untrustedField(already.map(shown)) } : {},
|
|
56139
|
+
note: 'Sent as one PUT /threads/{id}/members/{mri} with {"role":"User"} per person. Teams posts a notice in the chat for each person added.'
|
|
56140
|
+
},
|
|
56141
|
+
confirmToken
|
|
56142
|
+
});
|
|
56143
|
+
if (gate) return gate;
|
|
56144
|
+
const { results, warning } = await applyMemberChanges(
|
|
56145
|
+
chatsvc,
|
|
56146
|
+
target.id,
|
|
56147
|
+
toAdd,
|
|
56148
|
+
(mri) => chatsvc.addMember(target.id, mri, "User"),
|
|
56149
|
+
"added"
|
|
56150
|
+
);
|
|
56151
|
+
return untrustedResult2({
|
|
56152
|
+
status: "done",
|
|
56153
|
+
conversation: target,
|
|
56154
|
+
results: orderAs(resolved, [...results, ...alreadyResults]),
|
|
56155
|
+
...warning !== void 0 ? { warning } : {}
|
|
56156
|
+
});
|
|
56157
|
+
} catch (err) {
|
|
56158
|
+
throw wrapApiError(err, "add people to the chat");
|
|
56159
|
+
}
|
|
56160
|
+
}
|
|
56161
|
+
);
|
|
56162
|
+
server.registerTool(
|
|
56163
|
+
REMOVE,
|
|
56164
|
+
{
|
|
56165
|
+
title: "Remove people from a Teams group chat",
|
|
56166
|
+
description: `Remove people from a group chat as the signed-in user. conversation is the chat's id or name as for teams_list_messages; only group chats are changed \u2014 1:1s, meeting chats, channels and the self-chat are refused, and so is removing the signed-in user (leave the chat in Teams instead). ${PEOPLE_SENTENCE}People not in the chat are reported as not_member and not written; if no one is, nothing is asked or changed. Teams posts a notice in the chat for each person removed, and they lose access to it. The result lists each person: removed, not_member, unknown (Teams did not confirm and reading the chat back still shows them \u2014 check before retrying) or failed (with the error). ` + CONFIRM_FLOW_SENTENCE + " The preview shows the chat and exactly who would be removed \u2014 each with their source (id, chat or directory) and, from the directory, their email. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
56167
|
+
annotations: toolAnnotations({ readOnly: false, destructive: true, idempotent: true, openWorld: true }),
|
|
56168
|
+
_meta: workMeta("send", { aliases: ["remove people", "remove from chat", "kick", "remove members", "members"] }),
|
|
56169
|
+
inputSchema: {
|
|
56170
|
+
conversation: conversationParam,
|
|
56171
|
+
people: peopleParam,
|
|
56172
|
+
confirmToken: confirmTokenParam
|
|
56173
|
+
}
|
|
56174
|
+
},
|
|
56175
|
+
async ({ conversation, people, confirmToken }, ctx) => {
|
|
56176
|
+
try {
|
|
56177
|
+
const me = await chatsvc.meMri();
|
|
56178
|
+
const target = await groupChat(chatsvc, conversation, me, "changed");
|
|
56179
|
+
const resolved = await resolveFor(chatsvc, substrate, me, target.id, people);
|
|
56180
|
+
const self = resolved.find((p) => p.mri.toLowerCase() === me.toLowerCase());
|
|
56181
|
+
if (self !== void 0) {
|
|
56182
|
+
throw new McpToolError(`Refusing to remove you (the signed-in user, "${self.person}") from the chat.`, {
|
|
56183
|
+
hint: "To leave a group chat, use Leave in Teams. Remove the others by passing them without yourself."
|
|
56184
|
+
});
|
|
56185
|
+
}
|
|
56186
|
+
const members2 = memberSet(await chatsvc.getThread(target.id));
|
|
56187
|
+
const toRemove = resolved.filter((p) => members2.has(p.mri.toLowerCase()));
|
|
56188
|
+
const absent = resolved.filter((p) => !members2.has(p.mri.toLowerCase())).map((p) => ({ ...shown(p), status: "not_member" }));
|
|
56189
|
+
if (toRemove.length === 0) {
|
|
56190
|
+
return untrustedResult2({ status: "unchanged", conversation: target, results: absent });
|
|
56191
|
+
}
|
|
56192
|
+
const gate = await confirmWrite(ctx, {
|
|
56193
|
+
tool: REMOVE,
|
|
56194
|
+
action: "chat.remove_members",
|
|
56195
|
+
message: "Review and confirm who is removed from this group chat:",
|
|
56196
|
+
summary: `Remove ${toRemove.length} ${toRemove.length === 1 ? "person" : "people"} from group chat ` + JSON.stringify(target.title),
|
|
56197
|
+
account: me,
|
|
56198
|
+
target: target.id,
|
|
56199
|
+
request: {
|
|
56200
|
+
method: "DELETE",
|
|
56201
|
+
path: `/threads/${encodeURIComponent(target.id)}/members`,
|
|
56202
|
+
body: { members: toRemove.map((p) => p.mri) }
|
|
56203
|
+
},
|
|
56204
|
+
preview: {
|
|
56205
|
+
conversation: untrustedField(target),
|
|
56206
|
+
remove: untrustedField(toRemove.map(shown)),
|
|
56207
|
+
...absent.length > 0 ? { not_members: untrustedField(absent.map(shown)) } : {},
|
|
56208
|
+
note: "Sent as one DELETE /threads/{id}/members/{mri} per person. Teams posts a notice in the chat for each person removed."
|
|
56209
|
+
},
|
|
56210
|
+
confirmToken
|
|
56211
|
+
});
|
|
56212
|
+
if (gate) return gate;
|
|
56213
|
+
const { results, warning } = await applyMemberChanges(
|
|
56214
|
+
chatsvc,
|
|
56215
|
+
target.id,
|
|
56216
|
+
toRemove,
|
|
56217
|
+
(mri) => chatsvc.removeMember(target.id, mri),
|
|
56218
|
+
"removed"
|
|
56219
|
+
);
|
|
56220
|
+
return untrustedResult2({
|
|
56221
|
+
status: "done",
|
|
56222
|
+
conversation: target,
|
|
56223
|
+
results: orderAs(resolved, [...results, ...absent]),
|
|
56224
|
+
...warning !== void 0 ? { warning } : {}
|
|
56225
|
+
});
|
|
56226
|
+
} catch (err) {
|
|
56227
|
+
throw wrapApiError(err, "remove people from the chat");
|
|
56228
|
+
}
|
|
56229
|
+
}
|
|
56230
|
+
);
|
|
56231
|
+
}
|
|
56232
|
+
function orderAs(people, results) {
|
|
56233
|
+
return people.map((p) => results.find((r) => r.mri === p.mri));
|
|
56234
|
+
}
|
|
56235
|
+
|
|
55572
56236
|
// src/tools/activity.ts
|
|
55573
56237
|
init_zod();
|
|
55574
56238
|
init_dist2();
|
|
@@ -56021,7 +56685,7 @@ init_dist2();
|
|
|
56021
56685
|
init_healthcheck();
|
|
56022
56686
|
var HOST_LABEL = "teams.cloud.microsoft";
|
|
56023
56687
|
var TITLE = "Verify the Teams chat-service token and API end-to-end";
|
|
56024
|
-
var SHAREPOINT_NOTE = "Shared-file download (teams_get_attachment) uses a separate SharePoint token, captured on demand
|
|
56688
|
+
var SHAREPOINT_NOTE = "Shared-file download (teams_get_attachment) uses a separate SharePoint token, captured on demand and short-lived; one token serves every SharePoint host. None is held until you download a file, and this healthcheck neither mints nor requires one.";
|
|
56025
56689
|
var SUBSTRATE_NOTE = "Search (teams_search_messages) uses a separate Microsoft Substrate token for substrate.office.com, captured on demand when you run a search in a Teams tab (the bridge pairing must trust substrate.office.com). Without one, search falls back to a scan of recent conversations; this healthcheck neither mints nor requires one.";
|
|
56026
56690
|
function registerHealthcheckTool(server, { chatsvc }) {
|
|
56027
56691
|
server.registerTool(
|
|
@@ -56096,7 +56760,7 @@ init_dist2();
|
|
|
56096
56760
|
var MAX_SCAN = 2e3;
|
|
56097
56761
|
var MAX_INLINE_CHARS = 2e5;
|
|
56098
56762
|
var MAX_OTHERS = 20;
|
|
56099
|
-
function
|
|
56763
|
+
function shown2(r) {
|
|
56100
56764
|
const { message_id, object_id: _objectId, has_transcript: _has, duration_seconds: _secs, ...rest } = r;
|
|
56101
56765
|
return { recording_id: message_id, ...rest };
|
|
56102
56766
|
}
|
|
@@ -56141,7 +56805,7 @@ function registerTranscriptTools(server, { chatsvc }) {
|
|
|
56141
56805
|
}
|
|
56142
56806
|
}
|
|
56143
56807
|
const picked = chosen;
|
|
56144
|
-
const others = recordings.filter((r) => r !== picked).slice(0, MAX_OTHERS).map(
|
|
56808
|
+
const others = recordings.filter((r) => r !== picked).slice(0, MAX_OTHERS).map(shown2);
|
|
56145
56809
|
let vtt;
|
|
56146
56810
|
try {
|
|
56147
56811
|
vtt = await chatsvc.fetchTranscript(picked.object_id);
|
|
@@ -56153,7 +56817,7 @@ function registerTranscriptTools(server, { chatsvc }) {
|
|
|
56153
56817
|
const base = {
|
|
56154
56818
|
conversation: summary.id,
|
|
56155
56819
|
title: summary.title,
|
|
56156
|
-
recording:
|
|
56820
|
+
recording: shown2(chosen),
|
|
56157
56821
|
speakers: transcriptSpeakers(cues),
|
|
56158
56822
|
cue_count: cues.length,
|
|
56159
56823
|
...others.length > 0 ? { other_recordings: others } : {}
|
|
@@ -56238,6 +56902,7 @@ await runMcp({
|
|
|
56238
56902
|
registerSendTools,
|
|
56239
56903
|
registerReactTools,
|
|
56240
56904
|
registerMarkReadTools,
|
|
56905
|
+
registerGroupChatTools,
|
|
56241
56906
|
registerActivityTools,
|
|
56242
56907
|
registerSearchTools,
|
|
56243
56908
|
registerExportTools,
|