Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ucode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2990,10 +2990,12 @@ def configure(
# The workspaces were just configured, so enable tracing for them
# directly instead of re-prompting. Fall back to the workspace that
# `configure_workspace_command` made current (the interactive pick).
tracing_workspaces = workspace_entries
tracing_workspaces: list[tuple[str, str | None]] | None = workspace_entries
if tracing_workspaces is None:
current = load_full_state().get("current_workspace")
tracing_workspaces = [(current, None)] if current else None
tracing_workspaces = (
[(current, None)] if isinstance(current, str) and current else None
Comment thread
lilly-luo marked this conversation as resolved.
)
if tracing_workspaces:
configure_tracing_command(workspaces=tracing_workspaces)
if mcp is not None:
Expand Down
39 changes: 31 additions & 8 deletions src/ucode/mcp_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
from __future__ import annotations

import sys
from types import ModuleType
from collections.abc import AsyncIterator
from types import ModuleType, TracebackType
from typing import Protocol, Self

import anyio
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
from mcp.client.streamable_http import streamable_http_client
from mcp.server.stdio import stdio_server

Expand Down Expand Up @@ -79,6 +80,28 @@ class ProxyTransportError(RuntimeError):
"""The upstream MCP transport failed or closed unexpectedly."""


class _ReceiveStream[T](Protocol):
def __aiter__(self) -> AsyncIterator[T]: ...
async def __aenter__(self) -> Self: ...
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> bool | None: ...


class _SendStream[T](Protocol):
async def send(self, item: T, /) -> None: ...
async def __aenter__(self) -> Self: ...
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> bool | None: ...


def _fail_fast(message: str) -> None:
"""Report a terminal proxy failure on stderr and exit non-zero.

Expand Down Expand Up @@ -116,9 +139,9 @@ def auth_flow(self, request):
return _DatabricksTokenAuth()


async def _pump(
source: MemoryObjectReceiveStream,
dest: MemoryObjectSendStream,
async def _pump[T](
source: _ReceiveStream[T],
dest: _SendStream[T],
) -> None:
"""Forward every message from ``source`` to ``dest``.

Expand All @@ -129,9 +152,9 @@ async def _pump(
await dest.send(message)


async def _pump_upstream(
source: MemoryObjectReceiveStream,
dest: MemoryObjectSendStream,
async def _pump_upstream[T](
source: _ReceiveStream[T | Exception],
dest: _SendStream[T],
) -> None:
"""Forward upstream messages, failing if the transport closes first."""
async with source, dest:
Expand Down
Loading
Loading