165 lines
4.4 KiB
Python
165 lines
4.4 KiB
Python
"""MCP upstream-source provider helpers.
|
|
|
|
Source registry symbols are exported lazily because importing them eagerly pulls
|
|
in compatibility `wf_mcp` DTOs, which can re-enter this package through
|
|
`wf_mcp.auth` during startup.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .auth import (
|
|
AuthRecord,
|
|
auth_missing_diagnostic,
|
|
auth_ref_for_connection,
|
|
connection_auth_diagnostic,
|
|
mcp_auth_env,
|
|
mcp_auth_from_neutral,
|
|
mcp_auth_headers,
|
|
neutral_auth_from_mcp,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
# type checked version of __getattr__
|
|
from .adapters import (
|
|
AdapterLookupRef,
|
|
LegacyAdapterRef,
|
|
SourceAdapterRef,
|
|
require_adapter,
|
|
)
|
|
from .connections import (
|
|
LegacyConnectionConfigLike,
|
|
McpSourceConnection,
|
|
mcp_source_connection_from_connection_config,
|
|
mcp_source_connection_from_registry_entry,
|
|
)
|
|
from .discovery import (
|
|
DiscoveredConnectionCapabilities,
|
|
discover_connection_capabilities,
|
|
specs_from_discovered_tools,
|
|
)
|
|
from .schema_models import model_from_schema
|
|
from .source_registry import (
|
|
FileSourceRegistryStore,
|
|
McpSourceRegistryEntry,
|
|
SourceRegistryFile,
|
|
SourceRegistryStore,
|
|
connection_config_to_registry_entry,
|
|
)
|
|
from .tool_events import (
|
|
ToolWrapperEvent,
|
|
ToolWrapperEventSink,
|
|
tool_call_completed_event,
|
|
tool_call_started_event,
|
|
)
|
|
from .tool_wrappers import wrap_discovered_tool
|
|
from .transports import (
|
|
HttpSourceTransport,
|
|
SourceTransport,
|
|
StdioSourceTransport,
|
|
)
|
|
|
|
|
|
__all__ = [
|
|
"AdapterLookupRef",
|
|
"AuthRecord",
|
|
"DiscoveredConnectionCapabilities",
|
|
"FileSourceRegistryStore",
|
|
"HttpSourceTransport",
|
|
"LegacyAdapterRef",
|
|
"LegacyConnectionConfigLike",
|
|
"McpSourceConnection",
|
|
"McpSourceRegistryEntry",
|
|
"SourceAdapterRef",
|
|
"SourceRegistryFile",
|
|
"SourceRegistryStore",
|
|
"SourceTransport",
|
|
"StdioSourceTransport",
|
|
"ToolWrapperEvent",
|
|
"ToolWrapperEventSink",
|
|
"auth_missing_diagnostic",
|
|
"auth_ref_for_connection",
|
|
"connection_auth_diagnostic",
|
|
"connection_config_to_registry_entry",
|
|
"discover_connection_capabilities",
|
|
"mcp_auth_env",
|
|
"mcp_auth_from_neutral",
|
|
"mcp_auth_headers",
|
|
"mcp_source_connection_from_connection_config",
|
|
"mcp_source_connection_from_registry_entry",
|
|
"model_from_schema",
|
|
"neutral_auth_from_mcp",
|
|
"require_adapter",
|
|
"specs_from_discovered_tools",
|
|
"tool_call_completed_event",
|
|
"tool_call_started_event",
|
|
"wrap_discovered_tool",
|
|
]
|
|
|
|
|
|
# these are heavy, so we import lazily
|
|
def __getattr__(name: str) -> object:
|
|
if name in {
|
|
"AdapterLookupRef",
|
|
"LegacyAdapterRef",
|
|
"SourceAdapterRef",
|
|
"require_adapter",
|
|
}:
|
|
from . import adapters
|
|
|
|
return getattr(adapters, name)
|
|
if name in {
|
|
"LegacyConnectionConfigLike",
|
|
"McpSourceConnection",
|
|
"mcp_source_connection_from_connection_config",
|
|
"mcp_source_connection_from_registry_entry",
|
|
}:
|
|
from . import connections
|
|
|
|
return getattr(connections, name)
|
|
if name in {
|
|
"FileSourceRegistryStore",
|
|
"McpSourceRegistryEntry",
|
|
"SourceRegistryFile",
|
|
"SourceRegistryStore",
|
|
"connection_config_to_registry_entry",
|
|
}:
|
|
from . import source_registry
|
|
|
|
return getattr(source_registry, name)
|
|
if name in {
|
|
"HttpSourceTransport",
|
|
"SourceTransport",
|
|
"StdioSourceTransport",
|
|
}:
|
|
from . import transports
|
|
|
|
return getattr(transports, name)
|
|
if name in {
|
|
"DiscoveredConnectionCapabilities",
|
|
"discover_connection_capabilities",
|
|
"specs_from_discovered_tools",
|
|
}:
|
|
from . import discovery
|
|
|
|
return getattr(discovery, name)
|
|
if name == "model_from_schema":
|
|
from . import schema_models
|
|
|
|
return schema_models.model_from_schema
|
|
if name == "wrap_discovered_tool":
|
|
from . import tool_wrappers
|
|
|
|
return tool_wrappers.wrap_discovered_tool
|
|
if name in {
|
|
"ToolWrapperEvent",
|
|
"ToolWrapperEventSink",
|
|
"tool_call_completed_event",
|
|
"tool_call_started_event",
|
|
}:
|
|
from . import tool_events
|
|
|
|
return getattr(tool_events, name)
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|