UNPKG

@softeria/ms-365-mcp-server

Version:

A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API

27 lines (26 loc) 2.52 kB
function buildGeneralMcpInstructions(opts) { const parts = [ "Microsoft 365 MCP exposes Microsoft Graph through MCP tools. Use each tool name, description, and parameter schema as the source of truth.", "Microsoft Graph OData: do not combine $filter with $search on the same request. For lists, prefer modest $top (or top) and $select; avoid very large pages unless the user needs them.", "Mail and message $search uses KQL; the $search query parameter value must be double-quoted per Graph (see search-query-parameter in Microsoft Graph docs).", "When you need an organizational user or recipient address, resolve it with list-users (or another directory tool); do not invent SMTP addresses.", "Directory $search on collections such as /users or /groups requires ConsistencyLevel: eventual when the tool exposes that header.", "Teams chat and channel messages: prefer HTML contentType in the body; plain text is often mangled by Graph.", "Files / binary content: use download-bytes for any binary read (drive file content, mail attachments, profile photos, Teams hosted content, meeting recordings); pass it a Graph path or an absolute @microsoft.graph.downloadUrl from a metadata response. For uploads, upload-file-content takes a base64 string body up to 4MB; use create-upload-session above that." ]; if (opts.readOnly) parts.push("This server is read-only; write operations are disabled."); if (opts.multiAccount) parts.push("Multiple accounts: pass the account parameter when required (see list-accounts)."); if (!opts.orgMode) parts.push("Work/school-only tools require starting the server with --org-mode."); return parts.join(" "); } const DISCOVERY_MODE_INSTRUCTIONS_ADDON = "DISCOVERY MODE ADD-ON: Graph is reached via search-tools \u2192 get-tool-schema \u2192 execute-tool (plus auth helpers). Workflow: (1) call search-tools with short natural-language keywords (BM25-ranked); (2) call get-tool-schema(tool_name) to see the parameters, required fields, and enum values; (3) call execute-tool with tool_name exactly as returned and parameters shaped per the schema. Skipping get-tool-schema is the leading cause of Graph 400 errors here. If search-tools returns no matches, retry with shorter or different keywords."; function buildMcpServerInstructions(opts) { const general = buildGeneralMcpInstructions(opts); if (!opts.discovery) return general; return `${general} ${DISCOVERY_MODE_INSTRUCTIONS_ADDON}`; } export { buildMcpServerInstructions };