judgevet.adapters.inbound.mcp_dispatch
Status: draft.
judgevet.adapters.inbound.mcp_dispatch
Serialize synchronous MCP text and media work outside the event loop.
Source: https://github.com/Alberto-Codes/judgevet/issues/202#issuecomment-5850906357.
Examples:
from judgevet.adapters.inbound.mcp_dispatch import ProviderDispatch
from judgevet.testing import FakeSystemOnePort
dispatch = ProviderDispatch(port=FakeSystemOnePort())
assert dispatch.port is not None
See Also
- judgevet.adapters.inbound.mcp: SDK server construction.
- judgevet.providers: Application ownership contexts.
ProviderDispatch
Own one worker for a serving session and serialize its provider calls.
Attributes:
| Name | Type | Description |
|---|---|---|
port |
SystemOnePort | None
|
Selected provider once acquisition succeeds. |
Examples:
from judgevet.adapters.inbound.mcp_dispatch import ProviderDispatch
from judgevet.testing import FakeSystemOnePort
port = FakeSystemOnePort()
dispatch = ProviderDispatch(port=port)
assert dispatch.port is port
__init__(*, port=None, factory=None)
Retain selection without acquiring resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
SystemOnePort | None
|
Borrowed provider. |
None
|
factory
|
ProviderFactory | None
|
Owning application factory. |
None
|
session()
async
Keep acquisition, work and cleanup on one worker thread.
Yields:
| Type | Description |
|---|---|
AsyncIterator[None]
|
Control while the selected provider is available. |
Raises:
| Type | Description |
|---|---|
BaseException
|
Acquisition, serving, cleanup or cancellation failed. |
system_one(state, questions, model)
async
Serialize a judgment and never submit a canceled queued request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str | dict[str, Any] | list[Any]
|
Original caller state. |
required |
questions
|
Mapping[str, Question | Mapping[str, Any]]
|
Original question definitions. |
required |
model
|
str
|
Host-selected model. |
required |
Returns:
| Type | Description |
|---|---|
SystemOneResponse
|
The provider's unchanged answer envelope. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Acquisition yielded no provider. |
BaseException
|
Provider failure or drained cancellation. |
system_one_media(state, questions, model, evidence)
async
Decode and validate media on the same cancellation-safe worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str | dict[str, Any] | list[Any]
|
Original caller state. |
required |
questions
|
Mapping[str, Question | Mapping[str, Any]]
|
Parsed question definitions. |
required |
model
|
str
|
Host-selected model. |
required |
evidence
|
Any
|
Embedded JSON text, validated on the worker. |
required |
Returns:
| Type | Description |
|---|---|
SystemOneResponse
|
The unchanged validated answer envelope. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Acquisition yielded no provider. |
BaseException
|
Media validation, provider failure or drained cancellation. |
dispatch_for(port)
Reuse the composition root's worker for its selected provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
SystemOnePort
|
Selected provider passed to the server factory. |
required |
Returns:
| Type | Description |
|---|---|
ProviderDispatch
|
The active matching dispatcher or a new borrowed dispatcher. |