Index
bridge
¶
Marianne Ollama Bridge components.
This package provides integration between Marianne and local Ollama models with MCP tool support. The main components are:
- MCPProxyService: Manages MCP server subprocesses for tool execution
- ContextOptimizer: Optimizes tool context for limited context windows (Sheet 5)
- HybridRouter: Routes between Ollama and Claude based on complexity (Sheet 6)
- BridgeCoordinator: Top-level orchestrator for bridge components (Sheet 7)
Classes¶
ContentBlock
dataclass
¶
Content block in tool results.
MCPConnection
dataclass
¶
MCPConnection(config, process, stdin, stdout, capabilities=None, tools=list(), last_tool_refresh=0.0)
Active connection to an MCP server.
MCPProxyService
¶
MCP client that manages server subprocesses and executes tools.
This service acts as an MCP CLIENT - it spawns and communicates with MCP SERVERS. Marianne's existing MCP server (for external integration) is separate from this client functionality.
Lifecycle
- start() - Spawn server processes and perform initialize handshake
- list_tools() - Get available tools (cached with TTL)
- execute_tool() - Call a specific tool
- stop() - Clean shutdown of all servers
Initialize MCP proxy service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
servers
|
list[MCPServerConfig]
|
List of MCP server configurations to connect to |
required |
tool_cache_ttl
|
int
|
Seconds before refreshing tool list from servers |
300
|
request_timeout
|
float
|
Default timeout for JSON-RPC requests |
30.0
|
Source code in src/marianne/bridge/mcp_proxy.py
Functions¶
start
async
¶
Start all configured MCP servers.
For each server: 1. Spawn subprocess with asyncio.create_subprocess_exec 2. Send initialize request (JSON-RPC) 3. Wait for initialize response 4. Send initialized notification 5. Call tools/list to cache available tools
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no servers could be started (total failure). |
Source code in src/marianne/bridge/mcp_proxy.py
stop
async
¶
Stop all MCP server subprocesses.
Sends SIGTERM and waits for graceful shutdown, then SIGKILL if needed.
Source code in src/marianne/bridge/mcp_proxy.py
__aenter__
async
¶
__aexit__
async
¶
Async context manager exit.
list_tools
async
¶
Get all available tools from all servers.
Uses cached tool list if within TTL, otherwise refreshes.
Returns:
| Type | Description |
|---|---|
list[MCPTool]
|
List of MCPTool objects from all connected servers |
Source code in src/marianne/bridge/mcp_proxy.py
execute_tool
async
¶
Execute a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to execute |
required |
arguments
|
dict[str, Any]
|
Arguments to pass to the tool |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with content and error status |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If tool doesn't exist |
ToolExecutionTimeout
|
If execution times out |
Source code in src/marianne/bridge/mcp_proxy.py
MCPTool
dataclass
¶
Represents an MCP tool definition.
ServerCapabilities
dataclass
¶
Capabilities reported by MCP server.
ToolExecutionTimeout
¶
Bases: Exception
Raised when tool execution times out.
ToolNotFoundError
¶
Bases: Exception
Raised when requested tool doesn't exist.