diff --git a/CHANGELOG.md b/CHANGELOG.md index fd723c24..ff82fef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Fixed + +- **A fresh install was broken: every `/me` call failed with "me-token-to-replace is invalid".** + `uv tool install outlook-graph-mcp` resolved `microsoft-kiota-* 1.13+` (released 2026-09-18), + which moved per-request options from `request.options` to `request.extensions`; `msgraph-core` + 1.5.1 still reads the old attribute, so its rewrite of `/users/me-token-to-replace` → `/me` never + fires. Nothing capped kiota, and the lock file pinned 1.12.3 — so CI and every developer install + were green while every new user's install was not. kiota is now capped below 1.13 until a + `msgraph-core` release carries the upstream fix (msgraph-sdk-python-core#1129), and the + fresh-install and published-install jobs assert the resolved kiota version is inside the tested + range, so a dependency drifting outside it fails the canary instead of the user. Reported in #80. + + ### Fixed - **Calendar events are anchored in a real time zone, so recurring series survive daylight diff --git a/pyproject.toml b/pyproject.toml index 20141bf4..f0aa485b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,18 @@ classifiers = [ dependencies = [ "mcp[cli]>=2", "msgraph-sdk>=1.55", + # kiota 1.13.0 (2026-09-18) moved per-request options from a monkey-patched + # `request.options` attribute to `request.extensions["kiota_request_options"]`. + # msgraph-core 1.5.1 still reads the old attribute, so its UrlReplaceHandler + # never rewrites `/users/me-token-to-replace` to `/me` and every /me call + # 400s: "me-token-to-replace is invalid" (#80). The lock pins 1.12.3, which + # is why CI and every developer install were green while a fresh + # `uv tool install` broke. Lift these caps once a msgraph-core release + # carries microsoftgraph/msgraph-sdk-python-core#1129. + "microsoft-kiota-abstractions<1.13", + "microsoft-kiota-http<1.13", + "microsoft-kiota-authentication-azure<1.13", + "microsoft-kiota-serialization-json<1.13", "azure-identity>=1.25", "pydantic>=2.0", # zoneinfo reads the host's IANA time zone database. Windows ships none at diff --git a/tests/test_me_rewrite_reaches_the_wire.py b/tests/test_me_rewrite_reaches_the_wire.py new file mode 100644 index 00000000..1b844fa0 --- /dev/null +++ b/tests/test_me_rewrite_reaches_the_wire.py @@ -0,0 +1,114 @@ +"""Tier 4 of the silent-no-op audit: does ``/me`` actually reach the wire as ``/me``? + +Every ``/me`` request this server makes is built by the SDK as +``/users/me-token-to-replace`` and rewritten to ``/me`` by a middleware that +msgraph-core installs. kiota 1.13.0 moved per-request options from a +monkey-patched ``request.options`` attribute to ``request.extensions``; the +msgraph-core release available at the time still read the old attribute, so +the rewrite silently stopped firing and Graph received the literal placeholder: +``400 me-token-to-replace is invalid`` on every call (#80). + +Nothing in the offline suite could see it — the mocks never reach the +middleware — and the fresh-install canary imported the package, counted the +tools and never sent a request. The lock file pinned a working kiota, so every +developer and CI run was green while every new user's install was broken. + +So this test builds the client exactly the way ``msgraph`` does, hands the +factory an httpx client whose transport is a mock, and asserts on the URL the +real middleware pipeline hands to that transport. It runs against whatever +kiota/msgraph-core the environment resolved, which is the point: under the +lock it pins the rewrite; in the fresh-install and published-install jobs it +fails the moment a dependency resolves outside the range that works. +""" + +from __future__ import annotations + +import inspect + +import httpx +from azure.core.credentials import AccessToken +from kiota_authentication_azure.azure_identity_authentication_provider import ( + AzureIdentityAuthenticationProvider, +) +from msgraph import GraphServiceClient +from msgraph import graph_request_adapter as _gra +from msgraph_core import GraphClientFactory + + +class _FakeCredential: + def get_token(self, *args, **kwargs): + return AccessToken("not-a-real-token", 9_999_999_999) + + +def sent_url_for_me(nested: bool = False) -> str: + """The absolute URL the real middleware pipeline sends for a ``/me`` call. + + ``nested=True`` asks for ``/me/mailFolders/inbox/messages`` instead of bare + ``/me``. Both go through the same rewrite, but they fail differently against + the real service: Graph tolerates ``/users/`` one segment deep, so + a bare ``/me`` health check stays **200** with the placeholder in the URL + while every nested path 404s "The requested user ... is invalid". A canary + that only probed ``/me`` against Graph would have stayed green. Asserting on + the URL string catches both; the nested case is here so the reason is. + + Importable by the CI canaries, which run it against a fresh resolution. + """ + sent: list[str] = [] + + async def transport(request: httpx.Request) -> httpx.Response: + sent.append(str(request.url)) + return httpx.Response(200, json={"id": "probe"}) + + factory = GraphClientFactory.create_with_default_middleware + kwargs = {} + params = inspect.signature(factory).parameters + # msgraph registers the /me rewrite as a default request option on its + # adapter module; hand the same options to the factory so the middleware + # under test is the one users actually get. + if "options" in params: + kwargs["options"] = getattr(_gra, "options", None) + if "client" in params: + kwargs["client"] = httpx.AsyncClient(transport=httpx.MockTransport(transport)) + http_client = factory(**kwargs) + auth = AzureIdentityAuthenticationProvider( + _FakeCredential(), scopes=["https://graph.microsoft.com/.default"] + ) + client = GraphServiceClient(request_adapter=_gra.GraphRequestAdapter(auth, http_client)) + + import asyncio + + async def call(): + if nested: + await client.me.mail_folders.by_mail_folder_id("inbox").messages.get() + else: + await client.me.get() + + asyncio.run(call()) + assert sent, "the mock transport was never reached — the probe is wired to the wrong client" + return sent[-1] + + +def test_me_is_sent_as_me_not_as_the_placeholder(): + url = sent_url_for_me() + assert "me-token-to-replace" not in url, ( + f"/me reached the wire as the SDK placeholder: {url}\n" + "The msgraph-core rewrite did not fire. This is what a fresh install on " + "kiota >= 1.13 with msgraph-core <= 1.5.1 does (#80). Check the resolved " + "versions against the caps in pyproject.toml." + ) + assert url.endswith("/v1.0/me"), url + + +def test_a_nested_me_path_is_rewritten_too(): + url = sent_url_for_me(nested=True) + assert "me-token-to-replace" not in url, url + assert "//" not in url.split("://", 1)[1], f"double slash left where the placeholder was: {url}" + assert url.endswith("/v1.0/me/mailFolders/inbox/messages"), url + + +if __name__ == "__main__": # so CI can run it as a script against a fresh venv + print(sent_url_for_me()) + print(sent_url_for_me(nested=True)) + test_me_is_sent_as_me_not_as_the_placeholder() + test_a_nested_me_path_is_rewritten_too() + print("OK: /me reaches the wire as /me") diff --git a/uv.lock b/uv.lock index f5b01670..06ab05cf 100644 --- a/uv.lock +++ b/uv.lock @@ -1479,6 +1479,10 @@ source = { editable = "." } dependencies = [ { name = "azure-identity" }, { name = "mcp", extra = ["cli"] }, + { name = "microsoft-kiota-abstractions" }, + { name = "microsoft-kiota-authentication-azure" }, + { name = "microsoft-kiota-http" }, + { name = "microsoft-kiota-serialization-json" }, { name = "msgraph-sdk" }, { name = "pydantic" }, { name = "tzdata" }, @@ -1503,6 +1507,10 @@ dev = [ requires-dist = [ { name = "azure-identity", specifier = ">=1.25" }, { name = "mcp", extras = ["cli"], specifier = ">=2" }, + { name = "microsoft-kiota-abstractions", specifier = "<1.13" }, + { name = "microsoft-kiota-authentication-azure", specifier = "<1.13" }, + { name = "microsoft-kiota-http", specifier = "<1.13" }, + { name = "microsoft-kiota-serialization-json", specifier = "<1.13" }, { name = "msgraph-sdk", specifier = ">=1.55" }, { name = "pydantic", specifier = ">=2.0" }, { name = "pytest", marker = "extra == 'dev'", specifier = ">=8.0" },