Skip to content

fix: preserve ModelScope MCP transport#8270

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

fix: preserve ModelScope MCP transport#8270
he-yufeng wants to merge 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/modelscope-mcp-transport

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

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

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 and infer the correct transport type for synced ModelScope MCP servers based on provided metadata or URL patterns.

Bug Fixes:

  • Fix ModelScope MCP server configuration to use the transport indicated by metadata instead of always defaulting to SSE.

Enhancements:

  • Infer MCP transport type from multiple possible metadata keys or URL path, supporting Streamable HTTP and SSE transports.

Tests:

  • Add parameterized unit tests covering transport inference from ModelScope MCP URL and metadata information.

@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
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

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.

Copy link
Copy Markdown
Contributor

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

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.

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

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant