Skip to content

fix: preserve ModelScope MCP transport - #8270

Open
he-yufeng wants to merge 2 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/modelscope-mcp-transport
Open

he-yufeng wants to merge 2 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/modelscope-mcp-transport

Conversation

@he-yufeng

@he-yufeng he-yufeng commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • preserve the transport returned by ModelScope MCP sync metadata instead of hardcoding every synced server as SSE
  • fall back from the URL shape when ModelScope does not include an explicit transport field
  • cover Streamable HTTP, SSE, and /sse URL fallback cases

Fixes #8269

Test Plan

  • uv run pytest tests/unit/test_func_tool_manager.py::test_modelscope_mcp_transport_from_url_info -q --basetemp .tmp/pytest-modelscope-transport -o cache_dir=.tmp/pytest-cache-modelscope
  • uv run pytest tests/unit/test_func_tool_manager.py -q --basetemp .tmp/pytest-func-tool-manager -o cache_dir=.tmp/pytest-cache-func-tool-manager
  • uv run ruff check astrbot/core/provider/func_tool_manager.py tests/unit/test_func_tool_manager.py
  • python -m py_compile astrbot/core/provider/func_tool_manager.py tests/unit/test_func_tool_manager.py
  • git diff --check

Summary by Sourcery

Preserve ModelScope MCP server transport types during synchronization and infer them from endpoint URLs when metadata is incomplete.

Bug Fixes:

  • Preserve the transport type reported by ModelScope MCP metadata when synchronizing servers, including Streamable HTTP and SSE transports.
  • Infer the MCP transport from the server URL when ModelScope metadata omits an explicit transport, including /sse endpoints.

Tests:

  • Add coverage for transport metadata and URL-based fallback cases, and update synchronization expectations for Streamable HTTP.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels May 20, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper function, _modelscope_mcp_transport_from_url_info, to dynamically determine the MCP transport type for ModelScope servers based on provided URL information, replacing a previously hardcoded value. Unit tests were added to verify the new logic. Feedback suggests expanding the test suite to include scenarios where transport details are provided as nested dictionaries, ensuring that the implementation's handling of mapping types is fully covered and protected against regressions.

Comment on lines +301 to +307
[
({"transport": "Streamable HTTP", "url": "https://example.com/mcp"}, "streamable_http"),
({"transport_type": "sse", "url": "https://example.com/mcp"}, "sse"),
({"type": "streamable_http", "url": "https://example.com/mcp"}, "streamable_http"),
({"url": "https://example.com/mcp/sse"}, "sse"),
({"url": "https://example.com/mcp"}, "streamable_http"),
],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test coverage for _modelscope_mcp_transport_from_url_info is good, but it's missing cases for when the transport value is a nested dictionary. The implementation at astrbot/core/provider/func_tool_manager.py:152-153 handles this scenario, so it would be beneficial to add test cases for it to prevent future regressions. Specifically, the logic handling Mapping types (checking for type or name keys) is not covered. Please consider adding test cases to cover this path.

    [
        ({"transport": "Streamable HTTP", "url": "https://example.com/mcp"}, "streamable_http"),
        ({"transport_type": "sse", "url": "https://example.com/mcp"}, "sse"),
        ({"type": "streamable_http", "url": "https://example.com/mcp"}, "streamable_http"),
        ({"transport": {"type": "sse"}, "url": "https://example.com/mcp"}, "sse"),
        ({"protocol": {"name": "Streamable HTTP"}, "url": "https://example.com/mcp"}, "streamable_http"),
        ({"url": "https://example.com/mcp/sse"}, "sse"),
        ({"url": "https://example.com/mcp"}, "streamable_http"),
    ],
References
  1. New functionality should be accompanied by corresponding unit tests.

@Soulter
Soulter force-pushed the master branch 3 times, most recently from a4c4a7d to 9bd38ca Compare May 28, 2026 16:55
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Gentle ping on this ModelScope MCP transport fix. The change preserves the configured transport instead of falling back to the default path, which matters for deployments that intentionally choose the ModelScope transport.

Current checks are green. Could a maintainer review when convenient?

@he-yufeng
he-yufeng force-pushed the fix/modelscope-mcp-transport branch from 293e848 to be23f36 Compare July 12, 2026 14:21
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current master to clear the conflict (the recent ModelScope MCP sync refactors touched the same function). While resolving, I updated the expected transport in test_modelscope_sync_enables_only_synced_servers: its mock server (https://example.com/mcp, no transport hint) now derives streamable_http instead of the previously hardcoded sse — which is exactly what this PR is about, since a /mcp endpoint without an explicit sse marker is streamable HTTP. Full test_func_tool_manager.py passes (25).

@he-yufeng

Copy link
Copy Markdown
Contributor Author

在现在的 master(73b4fc9d)上又核了一遍:sync_modelscope_mcp_servers 里组配置时仍然写死 "transport": "sse"(func_tool_manager.py:1184),ModelScope 返回的 operational_urls 里实际是 streamable_http 的 server 会被按 sse 连,连不上。这个 PR 按 url_info 保留真实 transport 的修复仍然适用,有空麻烦看看。

@Soulter Soulter moved this to In Progress in AstrBot Roadmap Nov 2, 2026
…261110

# Conflicts:
#	tests/unit/test_func_tool_manager.py
@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit f6174b6

#8269 [Bug]ModelScope同步MCP服务器传输类型出错 · 1 of 1 met

# Requirement Status Notes
1 Sync ModelScope MCP servers using their selected transport type instead of always configuring them as SSE. ✅ Met Sync now derives the transport from the URL metadata and falls back to the URL path, with tests covering Streamable HTTP and SSE.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
astrbot/core/provider/func_tool_manager.py 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]ModelScope同步MCP服务器传输类型出错

2 participants