forked from phil65/agentpool
-
Notifications
You must be signed in to change notification settings - Fork 9
feat(mcp): expose MCP server status across all protocols #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Million-mo
wants to merge
6
commits into
wolf1069b:develop/agentic
Choose a base branch
from
Million-mo:feat/mcp-server-status
base: develop/agentic
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13caf2b
feat(mcp): expose MCP server status across all protocols
Million-mo 05c6c03
fix: address PR review — add None guards for type safety
Million-mo 251ee31
fix: remove accidentally added exclude_type_checking_imports
Million-mo 5af3dde
test: add tests for MCP server status visibility
Million-mo b97e474
test: use TestModelConfig to avoid OPENAI_API_KEY requirement
Million-mo b8d62de
ci: re-trigger CI for flaky test
Million-mo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """Tests for ACP initialize response MCP server status metadata. | ||
|
|
||
| Verifies that AgentPoolACPAgent.initialize() includes MCP server connection | ||
| statuses in the response's field_meta.mcp_servers. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| from acp import InitializeRequest | ||
| from agentpool.common_types import MCPServerStatus | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from agentpool_server.acp_server.acp_agent import AgentPoolACPAgent | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
|
|
||
| def _make_mock_provider(status: MCPServerStatus) -> Mock: | ||
| """Create a mock MCPResourceProvider with the given status.""" | ||
| provider = Mock() | ||
| provider.get_status = Mock(return_value=status) | ||
| return provider | ||
|
|
||
|
|
||
| async def test_initialize_includes_mcp_servers_in_field_meta( | ||
| mock_acp_agent: AgentPoolACPAgent, | ||
| ) -> None: | ||
| """initialize() response includes mcp_servers in field_meta.""" | ||
| pool = mock_acp_agent.agent_pool | ||
| assert pool is not None | ||
|
|
||
| providers = [ | ||
| _make_mock_provider( | ||
| MCPServerStatus( | ||
| name="srv-1", | ||
| status="connected", | ||
| server_type="stdio", | ||
| display_name="Server One", | ||
| ), | ||
| ), | ||
| _make_mock_provider( | ||
| MCPServerStatus( | ||
| name="srv-2", | ||
| status="error", | ||
| server_type="sse", | ||
| display_name="Server Two", | ||
| error="Connection refused", | ||
| ), | ||
| ), | ||
| ] | ||
| pool.mcp.get_mcp_providers = Mock(return_value=providers) | ||
|
|
||
| response = await mock_acp_agent.initialize( | ||
| InitializeRequest(protocol_version=1), | ||
| ) | ||
|
|
||
| assert response.field_meta is not None | ||
| assert "mcp_servers" in response.field_meta | ||
| servers = response.field_meta["mcp_servers"] | ||
| assert len(servers) == 2 | ||
| assert servers[0]["name"] == "srv-1" | ||
| assert servers[0]["status"] == "connected" | ||
| assert servers[0]["server_type"] == "stdio" | ||
| assert servers[1]["name"] == "srv-2" | ||
| assert servers[1]["status"] == "error" | ||
| assert servers[1]["error"] == "Connection refused" | ||
|
|
||
|
|
||
| async def test_initialize_field_meta_none_when_no_providers( | ||
| mock_acp_agent: AgentPoolACPAgent, | ||
| ) -> None: | ||
| """initialize() response has field_meta None when no MCP servers configured.""" | ||
| pool = mock_acp_agent.agent_pool | ||
| assert pool is not None | ||
| pool.mcp.get_mcp_providers = Mock(return_value=[]) | ||
|
|
||
| response = await mock_acp_agent.initialize( | ||
| InitializeRequest(protocol_version=1), | ||
| ) | ||
|
|
||
| assert response.field_meta is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for MCP server protocol.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| """Tests for the agentpool://mcp-servers/status MCP resource. | ||
|
|
||
| Tests that the MCPServer registers a resource exposing MCP server | ||
| connection statuses as JSON. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| from agentpool.common_types import MCPServerStatus | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
|
|
||
| def _make_mock_pool_with_providers( | ||
| providers: list[MCPResourceProviderStub], | ||
| ) -> Mock: | ||
| """Create a mock AgentPool with the given MCP providers.""" | ||
| pool = Mock() | ||
| mcp_manager = Mock() | ||
| mcp_manager.get_mcp_providers = Mock(return_value=providers) | ||
| pool.mcp = mcp_manager | ||
| return pool | ||
|
|
||
|
|
||
| class MCPResourceProviderStub: | ||
| """Minimal stub matching the interface used by the resource handler.""" | ||
|
|
||
| def __init__(self, status: MCPServerStatus) -> None: | ||
| self._status = status | ||
|
|
||
| def get_status(self) -> MCPServerStatus: | ||
| return self._status | ||
|
|
||
|
|
||
| async def test_mcp_status_resource_returns_json() -> None: | ||
| """The status resource returns JSON with server connection info.""" | ||
| from agentpool_config.pool_server import MCPPoolServerConfig | ||
| from agentpool_server.mcp_server.server import MCPServer | ||
|
|
||
| providers = [ | ||
| MCPResourceProviderStub( | ||
| MCPServerStatus( | ||
| name="srv-1", | ||
| status="connected", | ||
| server_type="stdio", | ||
| display_name="Server One", | ||
| ), | ||
| ), | ||
| MCPResourceProviderStub( | ||
| MCPServerStatus( | ||
| name="srv-2", | ||
| status="error", | ||
| server_type="sse", | ||
| display_name="Server Two", | ||
| error="Connection refused", | ||
| ), | ||
| ), | ||
| ] | ||
| pool = _make_mock_pool_with_providers(providers) | ||
| config = MCPPoolServerConfig(enabled=True, transport="stdio") | ||
| server = MCPServer(pool, config) | ||
|
|
||
| server._register_mcp_status_resource() | ||
|
|
||
| fastmcp = server.fastmcp | ||
| resources = await fastmcp.list_resources() | ||
| status_resource = next( | ||
| (r for r in resources if str(r.uri) == "agentpool://mcp-servers/status"), | ||
| None, | ||
| ) | ||
| assert status_resource is not None | ||
| assert status_resource.mime_type == "application/json" | ||
| read_result = await fastmcp.read_resource( | ||
| "agentpool://mcp-servers/status", | ||
| run_middleware=False, | ||
| ) | ||
| content = read_result.contents[0].content | ||
| data = json.loads(content) | ||
| assert "servers" in data | ||
| servers = data["servers"] | ||
| assert len(servers) == 2 | ||
| assert servers[0]["name"] == "srv-1" | ||
| assert servers[0]["status"] == "connected" | ||
| assert servers[0]["server_type"] == "stdio" | ||
| assert servers[1]["name"] == "srv-2" | ||
| assert servers[1]["status"] == "error" | ||
| assert servers[1]["error"] == "Connection refused" | ||
|
|
||
|
|
||
| async def test_mcp_status_resource_empty_when_no_providers() -> None: | ||
| """The status resource returns empty servers list when no providers exist.""" | ||
| from agentpool_config.pool_server import MCPPoolServerConfig | ||
| from agentpool_server.mcp_server.server import MCPServer | ||
|
|
||
| pool = _make_mock_pool_with_providers([]) | ||
| config = MCPPoolServerConfig(enabled=True, transport="stdio") | ||
| server = MCPServer(pool, config) | ||
|
|
||
| server._register_mcp_status_resource() | ||
|
|
||
| read_result = await server.fastmcp.read_resource( | ||
| "agentpool://mcp-servers/status", | ||
| run_middleware=False, | ||
| ) | ||
| data = json.loads(read_result.contents[0].content) | ||
| assert data["servers"] == [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.