App Service Custom AI Middleware
Python middleware and tools for AI agents hosted behind Azure App Service Authentication and App Service Hooks.
Install
pip install aw-appservice-custom-ai-middleware-extension
The distribution name is aw-appservice-custom-ai-middleware-extension. The
stable Python import remains:
import app_service_extensions as ase
For Azure Functions:
pip install "aw-appservice-custom-ai-middleware-extension[functions]"
For Azure Functions hosted skills:
pip install "aw-appservice-custom-ai-middleware-extension[hosted-skills]"
The hosted-skills integration patches runtime seams that are not yet public API. Its dependency range is intentionally narrow and is expanded only after the integration suite passes against a new runtime release.
Azure Functions
Configure the middleware before creating the hosted-skills app, then attach it to the generated Function app:
import app_service_extensions as ase
from azure_functions_agents import create_function_app
ase.configure()
app = create_function_app()
ase.configure(app)
Or use the convenience factory, which runs that same sequence internally:
import app_service_extensions as ase
app = ase.create_function_app()
Both initialization styles remain supported. Choose one style for an app rather than combining them.
The package preserves the opaque X-MS-Hook-Invocation recursion chain for
same-site callbacks. Caller identity forwarding requires the explicit opt-in
described below. Neither credential is sent to third-party MCP servers.
ase.current_request().request.origin exposes the proxy-aware, client-facing
site origin supplied by App Service Hooks for callbacks to the originating site.
Application identity and acting as the user
By default, the SDK ignores X-MS-CONTEXT-TOKEN and leaves outbound authentication
to the application's configured credentials. Authenticated MCP connections retain
the Hosted Skills runtime's managed-identity default; an anonymous MCP connection
remains anonymous. The SDK does not infer or inject auth.type: "obo".
To explicitly opt into acting as the user:
app = ase.create_function_app(act_as_user=True)
For the two-step initialization style, set the policy before creating the runtime:
ase.configure(act_as_user=True)
app = create_function_app()
ase.configure(app)
This is an SDK-wide caller-context policy, not an MCP server authentication type
or an OAuth on-behalf-of token exchange. Keep the MCP connection's transport
authentication in mcp.json; setting its auth.type does not opt into SDK
user-context forwarding.
Acting as the user requires a context token supplied by the web app's middleware. The option does not mint a token or derive one from a browser cookie. If it is enabled but no context token arrives, same-site user-context MCP tools are withheld rather than silently falling back to the application's permissions. With a caller, application-identity MCP tools are withheld instead. Context tokens are forwarded only to the originating web app, never to an external MCP server.
ase.configure() and ase.configure(app) preserve a previous act_as_user choice
when the option is omitted. Pass act_as_user=False to explicitly return to
application mode. The convenience factory defaults to False.
Publish to PyPI
Publishing is manual because this repository does not have an Actions runner.
PyPI does not allow replacing an existing release, so first update the version
in both pyproject.toml and src\app_service_extensions\__init__.py.
Save the token once from the repository root in PowerShell:
.\scripts\publish-pypi.ps1 -SaveToken
This prompts for the token, stores it outside the repository at
$env:LOCALAPPDATA\AppExtensionsLibrary\pypi-token.dpapi, encrypted by Windows
DPAPI for the current user and machine, and exits without publishing.
To publish, run:
.\scripts\publish-pypi.ps1
The publish command verifies that both version declarations match, installs
the build tools, runs the tests, rebuilds a clean dist directory, validates
the artifacts, and uploads them using the saved token.
Remove the saved token with:
.\scripts\publish-pypi.ps1 -ForgetToken
The script exposes the decrypted value only to the twine child process and
restores the process environment afterward. Do not save the plaintext token in
the script, commit it, or include it in an issue, pull request, or chat.
After the upload succeeds, tag the exact commit that produced the package:
$version = python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])"
git tag "v$version"
git push origin "v$version"
Metadata
Release files for aw-appservice-custom-ai-middleware-extension 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aw_appservice_custom_ai_middleware_extension-0.3.7.tar.gz | 71.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aw_appservice_custom_ai_middleware_extension-0.3.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 161.2 kB
Release files / aw_appservice_custom_ai_middleware_extension-0.3.7.tar.gz
| Download URL | aw_appservice_custom_ai_middleware_extension-0.3.7.tar.gz |
|---|---|
| Size | 71.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab4b31b8ad715de29c5237a251027e8b81b929c5966947acaf2bf95e394c6ac7
|
|
BLAKE2b-256 checksum How to use checksums |
8ef0ed62e9da3c5b5edac054f87aa8113675ff7fef061e2f9315af3aa65affbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / aw_appservice_custom_ai_middleware_extension-0.3.7-py3-none-any.whl
| Download URL | aw_appservice_custom_ai_middleware_extension-0.3.7-py3-none-any.whl |
|---|---|
| Size | 89.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b7e859e03ec8062ff329982850f0a6cf6b1cd1010c75aedfec3bd39e3bf4eb6
|
|
BLAKE2b-256 checksum How to use checksums |
18531bfe3b04be47bfff2ec0cbed462217dae582447fe5688b8e2f95ce5c38aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for aw-appservice-custom-ai-middleware-extension 0.3.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.