Skip to content

feat(mcp): implement MCP Roots protocol and cap tool descriptions (#2445, #2450)#2454

Merged
bug-ops merged 2 commits intomainfrom
feat-issue-2445-mcp-roots-protocol
Mar 30, 2026
Merged

feat(mcp): implement MCP Roots protocol and cap tool descriptions (#2445, #2450)#2454
bug-ops merged 2 commits intomainfrom
feat-issue-2445-mcp-roots-protocol

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 30, 2026

Summary

Changes

  • zeph-config: McpRootEntry { uri, name }, roots field on McpServerConfig, max_description_bytes/max_instructions_bytes on McpConfig
  • zeph-mcp/client.rs: ToolListChangedHandler advertises roots capability, responds to roots/list; HandlerConfig struct reduces arg count across 4 connect methods
  • zeph-mcp/manager.rs: validate_roots() filters non-file:// URIs; ConnectState and run_probe() refactor reduce arg counts and line counts; server instructions stored and accessible via McpManager::server_instructions()
  • zeph-mcp/sanitize.rs: truncate_utf8() helper (UTF-8 safe), truncate_instructions(), configurable limit plumbed through sanitize_tools()
  • zeph-core/bootstrap/mcp.rs, src/init.rs: roots and limits wired from config

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace --features full -- -D warnings — 0 warnings
  • cargo nextest run --workspace --features full --lib --bins — 7299 passed
  • 8 new validate_roots_* tests covering URI filtering edge cases
  • 5 client handler tests verifying roots/list and capability advertisement
  • Configure [[mcp.servers]] with roots = [{uri="file:///path", name="project"}] and verify a root-aware MCP server receives correct roots

Follow-up

  • Follow-up: add std::fs::canonicalize() to validate_roots() for path traversal hardening
  • Follow-up: apply sanitize_string() to server instructions in truncate_instructions()

Closes #2445, #2450

@github-actions github-actions bot added enhancement New feature or request size/XL Extra large PR (500+ lines) documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate and removed enhancement New feature or request labels Mar 30, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 30, 2026 18:27
bug-ops added 2 commits March 30, 2026 20:36
…caps (#2445, #2450)

Add MCP Roots protocol support: McpRootEntry config struct, roots field on
McpServerConfig, ToolListChangedHandler advertises roots capability (list_changed=false)
and responds to roots/list requests with configured roots. Roots validated at connection
time: non-file:// URIs rejected, missing paths warned.

Add configurable tool description and server instructions length caps: max_description_bytes
and max_instructions_bytes on McpConfig (default 2048), truncate_instructions() helper,
server instructions stored after handshake and accessible via McpManager::server_instructions.

Fix double-sanitization: handler now uses self.max_description_bytes instead of a stale
hardcoded constant, matching the configurable limit used in ingest_tools.
- Remove unused `use rmcp::ClientHandler` import (client.rs)
- Introduce `HandlerConfig { roots, max_description_bytes }` to reduce argument
  count on connect_url (8→7) and unify handler params across connect/connect_url/
  connect_url_with_headers/connect_url_oauth
- Introduce `ConnectState<'a>` struct to collapse 4 mutable ref params in
  handle_connect_result (9 args → 5 args, resolves too_many_arguments)
- Extract `run_probe()` method to reduce body line count in handle_connect_result
  and add_server (resolves too_many_lines in both)
- Add #[allow(clippy::too_many_lines)] to connect_url_oauth (OAuth flow is
  inherently stateful; extraction would obscure the multi-step protocol)
- Add #[must_use] to truncate_instructions
- Fix implicit-clone lint: use to_owned() on &str, remove spurious .to_string()
  on already-owned String from truncate_to_bytes
- Update module doc: 1024 bytes → 2048 bytes
@bug-ops bug-ops force-pushed the feat-issue-2445-mcp-roots-protocol branch from 423ad1c to a5a47d2 Compare March 30, 2026 18:36
@github-actions github-actions bot added the enhancement New feature or request label Mar 30, 2026
@bug-ops bug-ops merged commit 4b34cca into main Mar 30, 2026
47 of 49 checks passed
@bug-ops bug-ops deleted the feat-issue-2445-mcp-roots-protocol branch March 30, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

1 participant