fix: update allowed_senders handling and improve logging configuration

This commit is contained in:
X-iZhang
2026-02-10 22:20:56 +00:00
parent 100b74dd63
commit 8404a8e013
8 changed files with 26 additions and 29 deletions
+7 -7
View File
@@ -25,11 +25,6 @@ from typing import Callable
from . import IMessageChannel, IMessageConfig
from ..base import OutgoingMessage
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%H:%M:%S",
)
logger = logging.getLogger(__name__)
@@ -223,7 +218,7 @@ class IMessageServer:
await self.channel.send(OutgoingMessage(
recipient=sender,
content=response,
metadata=metadata,
metadata=metadata or {},
))
if self._on_activity:
try:
@@ -387,7 +382,7 @@ async def async_main():
config = IMessageConfig(
cli_path=args.cli_path,
db_path=args.db_path,
allowed_senders=set(args.allowed_senders) if args.allowed_senders else None,
allowed_senders=list(args.allowed_senders) if args.allowed_senders else [],
include_attachments=args.attachments,
)
@@ -421,6 +416,11 @@ async def async_main():
def main():
"""Entry point."""
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%H:%M:%S",
)
asyncio.run(async_main())
+2 -2
View File
@@ -183,7 +183,7 @@ def _cmd_channel(args: str, agent: Any, thread_id: str) -> None:
allowed.add(parts[i + 1])
config = IMessageConfig(
allowed_senders=allowed if allowed else None,
allowed_senders=list(allowed) if allowed else [],
)
# Store shared agent reference — no separate agent creation
@@ -264,7 +264,7 @@ def _auto_start_channel(agent: Any, thread_id: str, allowed_senders_csv: str) ->
if allowed_senders_csv.strip():
allowed = {s.strip() for s in allowed_senders_csv.split(",") if s.strip()}
config = IMessageConfig(allowed_senders=allowed if allowed else None)
config = IMessageConfig(allowed_senders=list(allowed) if allowed else [])
_ChannelState.agent = agent
_ChannelState.thread_id = thread_id
+1 -1
View File
@@ -16,7 +16,7 @@ def _mcp_list_servers() -> None:
if not config:
console.print("[dim]No MCP servers configured.[/dim]")
console.print("[dim]Add one with:[/dim] /mcp add <name> <transport> <command-or-url> [args...]")
console.print("[dim]Add one with:[/dim] /mcp add <name> <command-or-url> [args...]")
console.print()
return
+2 -6
View File
@@ -1,12 +1,8 @@
# MCP (Model Context Protocol) Integration
Optional feature for connecting external tools to EvoScientist agents via [MCP](https://modelcontextprotocol.io/).
Connects external tools to EvoScientist agents via [MCP](https://modelcontextprotocol.io/).
## Install
```bash
pip install "evoscientist[mcp]"
```
Included with `pip install evoscientist` (requires `langchain-mcp-adapters`).
## Quick Start
+1 -2
View File
@@ -1,6 +1,5 @@
"""MCP (Model Context Protocol) integration — optional external tool support.
"""MCP (Model Context Protocol) integration — external tool support.
Install with: pip install "evoscientist[mcp]"
See mcp/README.md for usage details.
"""
+5 -3
View File
@@ -216,8 +216,10 @@ def remove_mcp_server(name: str) -> bool:
def _infer_transport(target: str) -> str:
"""Return ``'http'`` if *target* looks like a URL, else ``'stdio'``."""
if target.startswith(("http://", "https://", "ws://", "wss://")):
"""Return transport type inferred from *target* URL scheme."""
if target.startswith(("ws://", "wss://")):
return "websocket"
if target.startswith(("http://", "https://")):
return "http"
return "stdio"
@@ -589,7 +591,7 @@ async def _load_tools(config: dict[str, Any]) -> dict[str, list]:
except ImportError:
raise ImportError(
"MCP servers are configured but langchain-mcp-adapters is not installed.\n"
"Install with: pip install 'evoscientist[mcp]'"
"Install with: pip install langchain-mcp-adapters"
)
connections = _build_connections(config)
+7 -7
View File
@@ -317,23 +317,23 @@ EvoScientist supports [MCP](https://modelcontextprotocol.io/) servers, allowing
The quickest way to add an MCP server is from the CLI:
```Shell
# stdio transport (local process)
EvoSci mcp add filesystem stdio npx -- -y @modelcontextprotocol/server-filesystem /tmp
# stdio transport (auto-detected from command)
EvoSci mcp add filesystem npx -- -y @modelcontextprotocol/server-filesystem /tmp
# http transport
EvoSci mcp add brave-search http http://localhost:8080/mcp -H "Authorization:Bearer ${BRAVE_API_KEY}"
# http transport (auto-detected from URL)
EvoSci mcp add brave-search http://localhost:8080/mcp -H "Authorization:Bearer ${BRAVE_API_KEY}"
# sse transport, routed to a specific agent
EvoSci mcp add my-sse sse http://localhost:9090/sse -e research-agent
EvoSci mcp add my-sse http://localhost:9090/sse --transport sse -e research-agent
# With tool allowlist
EvoSci mcp add fs stdio npx -- -y @modelcontextprotocol/server-filesystem /tmp -t read_file,write_file
EvoSci mcp add fs npx -- -y @modelcontextprotocol/server-filesystem /tmp -t read_file,write_file
```
Or from the interactive CLI:
```
/mcp add filesystem stdio npx -y @modelcontextprotocol/server-filesystem /tmp
/mcp add filesystem npx -y @modelcontextprotocol/server-filesystem /tmp
/mcp remove filesystem
/mcp list
```
+1 -1
View File
@@ -399,7 +399,7 @@ class TestParseMcpAddArgs:
def test_ws_auto_detected(self):
r = parse_mcp_add_args(["ws", "ws://localhost:9090"])
assert r["transport"] == "http"
assert r["transport"] == "websocket"
def test_explicit_transport_override(self):
r = parse_mcp_add_args(["srv", "https://example.com/sse", "--transport", "sse"])