teams-mcp
Copilot instructions140 starsChanged 2 months agoMITView on GitHub
MCP (Model Context Protocol) server that bridges AI assistants to Microsoft Teams via the Microsoft Graph API. Published as @floriscornel/teams-mcp on npm. Uses MSAL device-code auth with a file-based token cache (~/.teams-mcp-token-cache.json).
The file
We split this copilot-instructions.md into the rules it gives an agent
9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 40
Schema validation: Use zod for MCP tool parameter schemas, passed directly to server.tool().
- Very specific: line 42
Graph API response typing: Always cast Graph responses with as GraphApiResponse<T> or specific types.
- Very specific: line 58
Use microsoft_docs_search to find relevant docs (returns up to 10 content chunks with title, URL, and excerpt).
- Very specific: line 59
Use microsoft_code_sample_search to find code examples (returns up to 20 samples.
- Very specific: line 60
Use microsoft_docs_fetch to retrieve the full content of a specific doc page when search results are insufficient.
- Very specific: line 70
Add or extend a register*Tools function in src/tools/.
- Very specific: line 72
Use await graphService.getClient() then chain .api(endpoint) calls.
- Very specific: line 74
Add types to src/types/graph.ts if new Graph API shapes are needed.
- Very specific: line 75
Write tests in src/tools/__tests__/ following the mock-client pattern.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions — teams-mcp
Project Overview
MCP (Model Context Protocol) server that bridges AI assistants to Microsoft Teams via the Microsoft Graph API. Published as @floriscornel/teams-mcp on npm. Uses MSAL device-code auth with a file-based token cache (~/.teams-mcp-token-cache.json).
Architecture
src/index.ts— Dual-mode entrypoint: CLI commands (authenticate,check,logout) and MCP server (startMcpServer). Routes viaprocess.argv. Supports--read-onlyflag andTEAMS_MCP_READ_ONLYenv var.src/services/graph.ts— SingletonGraphServicewrapping the Microsoft Graph client. Handles token acquisition (envAUTH_TOKENor MSAL silent refresh). ExportsREAD_ONLY_SCOPESandFULL_SCOPES. Has areadOnlyModeproperty that controls which scopes are requested. All Graph API calls go throughgraphService.getClient().src/tools/*.ts— Each file exports aregister*Tools(server, graphService, readOnly)function that registers MCP tools viaserver.tool(name, description, zodSchema, handler). Tools are grouped by domain:auth,users,teams,chats,search. WhenreadOnlyis true, write tools are skipped.src/types/graph.ts— Re-exports@microsoft/microsoft-graph-typesand defines project-specific interfaces (GraphApiResponse<T>,*Summarytypes). All response shapes use optional properties with| undefinedto handle Graph API variability.src/utils/— Stateless helpers:markdown.ts(Markdown→sanitized HTML viamarked+DOMPurify),html-to-markdown.ts(Teams HTML→Markdown viaturndownwith custom rules for<at>,<attachment>,<systemEventMessage>),attachments.ts(image hosted content),file-upload.ts(file uploads with automatic simple ≤4MB / resumable >4MB split),users.ts(mention processing).src/msal-cache.ts— File-basedICachePluginfor MSAL token persistence.
Commands
npm run build # clean + tsc
npm run dev # tsx watch src/index.ts
npm test # vitest run
npm run test:watch # vitest (watch mode)
npm run test:coverage # vitest with v8 coverage (80% threshold on branches/functions/lines/statements)
npm run lint # biome check src/
npm run lint:fix # biome check --write --unsafe src/
npm run format # biome format --write src/
npm run ci # biome ci src/ (CI mode)CI/CD
- CI (
.github/workflows/ci.yml): Runs on PRs and pushes tomain. Matrix tests Node 20/22/24. Steps:npm run ci(Biome),tsc,vitest --coveragewith JUnit XML. Uploads coverage to Codecov. - Release (
.github/workflows/release.yml): Triggered byv*tags. Runs lint + tests thennpm publishwith provenance. Bump version inpackage.jsonandsrc/index.ts(McpServerversion string) before tagging.
Code Style & Conventions
- Formatter/Linter: Biome (not ESLint/Prettier). 2-space indent, double quotes, semicolons, LF line endings, 100-char line width, ES5 trailing commas. Run
npm run lint:fixto auto-fix. - Module system: ESM (
"type": "module"). Use.jsextensions in imports even for.tsfiles (e.g.,import { GraphService } from "../services/graph.js"). - TypeScript: Strict mode with
exactOptionalPropertyTypes,noImplicitAny,noUnusedLocals,noUnusedParameters. Target ES2022. Usenode:protocol for Node.js built-ins (e.g.,import { join } from "node:path"). - Schema validation: Use
zodfor MCP tool parameter schemas, passed directly toserver.tool(). - Error handling in tools: Catch errors inside each tool handler, return
{ content: [{ type: "text", text: "❌ Error: ..." }] }— never throw from a tool handler. - Graph API response typing: Always cast Graph responses with
as GraphApiResponse<T>or specific types. Checkresponse?.value?.lengthbefore mapping.
Testing
- Framework: Vitest with globals enabled (
describe,it,expectavailable without import, though they're typically imported explicitly). - HTTP mocking: MSW (
msw/node) for Graph API calls. The global setup insrc/test-utils/vitest.setup.tsstarts/resets/closes the MSW server. Fixtures and default handlers live insrc/test-utils/setup.ts. - Unit test mocking:
vi.mock()for modules,vi.fn()for functions. Tests mockGraphService.getClient()to return a mockClientwith chainable.api().get()/.post()methods. - Test location: Co-located
__tests__/directories mirroringsrc/structure (e.g.,src/tools/__tests__/chats.test.tstestssrc/tools/chats.ts). - Coverage: v8 provider, 80% global threshold.
index.tsandtest-utils/are excluded from coverage. - Auth in tests:
GraphServiceis a singleton — tests mock it viavi.mock()on@azure/msal-nodeand@microsoft/microsoft-graph-client, setting upPublicClientApplication/Client.initWithMiddlewarestubs before importing the module under test. Seesrc/services/__tests__/graph.test.tsfor the pattern.
Microsoft Graph Documentation (microsoftdocs/mcp)
The workspace has a microsoftdocs/mcp server configured (.vscode/mcp.json) that provides access to official Microsoft Learn documentation. Use it to look up Graph API endpoints, permissions, and SDK usage.
Workflow:
- Use
microsoft_docs_searchto find relevant docs (returns up to 10 content chunks with title, URL, and excerpt). - Use
microsoft_code_sample_searchto find code examples (returns up to 20 samples; optionallanguagefilter). - Use
microsoft_docs_fetchto retrieve the full content of a specific doc page when search results are insufficient.
When to use:
- Verifying Graph API endpoint paths, query parameters, or response shapes.
- Checking required permissions/scopes for a Graph API call.
- Looking up SDK patterns for
@microsoft/microsoft-graph-client. - Resolving questions about Microsoft Teams-specific Graph API behavior (e.g., message types, mention formats, hosted content).
Adding a New MCP Tool
- Add or extend a
register*Toolsfunction insrc/tools/. - Define parameters with
zodschemas and pass toserver.tool(). - Use
await graphService.getClient()then chain.api(endpoint)calls. - Return
{ content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }. - Add types to
src/types/graph.tsif new Graph API shapes are needed. - Write tests in
src/tools/__tests__/following the mock-client pattern. - Register the new tool group in
src/index.ts→startMcpServer()if it's a new file.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

