Pietro Zullo
|
a9bc4db3ae
|
feat(python): add protocol handlers for logging, completions, subscriptions, and DNS protection (#1004)
* feat(python): add protocol handlers for logging, completions, subscriptions, and DNS protection
Server SDK changes:
- logging/setLevel: stores client level, Context.log() filters by RFC 5424 severity
- completion/complete: default empty handler, overridable via mcp.completion()
- resources/subscribe + unsubscribe: tracks per-session subscriptions
- notify_resource_updated(): broadcasts to all subscribed sessions via WeakSet
- dns_rebinding_protection: explicit constructor parameter (default: False)
- Capabilities patch for subscribe=True
Middleware:
- Added hooks: on_set_logging_level, on_subscribe_resource, on_unsubscribe_resource, on_complete
Tests:
- 9 unit tests for log level filtering (RFC 5424)
- Updated DNS protection tests for explicit flag
Docs:
- logging.mdx: MCP protocol logging section with level filtering
- resources.mdx: subscription section with example
- middleware.mdx: new hooks documented
Refs:
- https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/logging
- https://modelcontextprotocol.io/specification/2025-11-25/server/resources#subscriptions
* style: format adapter files for ruff 0.15
|
2026-02-14 18:53:30 -08:00 |
|
Vincenzo Reina
|
4997674559
|
feat(python): Intercept MCP handshake with on_initialize middleware (#769)
* Wrap server session from MCP
* Update server and middleware
* Update middleware example
* Fix formatting and linting
* Update docs
* Fix monkeypatch for tests
* Update docs and remove comment
* feat(python): add tests, docs, and docstrings for on_initialize middleware
- Add 13 unit tests covering dispatch, chain order, rejection, and context enrichment
- Rewrite middleware.mdx documentation with Mintlify components (Tabs, Tips, Cards)
- Add comprehensive docstring to MiddlewareServerSession documenting single-server-per-process limitation
- Add docs/CLAUDE.md with documentation improvement guidelines
- Regenerate API documentation
* docs: highlight typed context feature in middleware docs
* example: add ClientCapabilitiesGuard demonstrating typed context
* style: fix linting in middleware example
* docs(examples): add comprehensive docstrings to middleware_example.py
- Add module docstring explaining key concepts and middleware hooks
- Document each middleware class with typed context details
- Organize code with section headers (CONNECTION, REQUEST, TOOL-SPECIFIC)
- Add ClientCapabilitiesGuard example showing typed context usage
---------
Co-authored-by: pietrozullo <pietro.zullo@gmail.com>
|
2026-01-14 16:47:57 +01:00 |
|