类class
agentscope.app.hubGitHubMCPHub
class GitHubMCPHub(MCPHubBase)
源码Source
agentscope/app/hub/_mcp/_github_hub.py:101–467GitHub MCP 中心,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.hub 包,继承自 MCPHubBase。核心成员包括 list_mcps、get_mcp。
An MCP hub backed by GitHub's MCP registry. Declared in agentscope.app.hub. Extends MCPHubBase.
示例Example
hub = GitHubMCPHub()
page = await hub.list_mcps(user_id="alice", q="markdown")
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(hub_id: str = 'github', display_name: str = 'GitHub MCP Registry', description: str = "MCP servers publish… | 初始化 `GitHubMCPHub` 实例。 Initialize the GitHub MCP registry provider. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def __aenter__() -> 'GitHubMCPHub'async | 进入异步上下文并返回自身。 Open the HTTP client shared by every request. |
async def __aexit__(*exc: Any) -> Noneasync | 退出异步上下文并清理资源。 Close the shared HTTP client. |
async def list_mcps(user_id: str, q: str | None = None, cursor: str | None = None, limit: int = 20) -> MCPHubPageasync | 列出 `list_mcps`。 Browse the registry, one cursor page at a time. |
async def get_mcp(user_id: str, card_id: str) -> MCPCardasync | 获取MCP。 Fetch one registry entry. |
构造器详情Constructor Detail
GitHubMCPHub
def __init__(hub_id: str = 'github', display_name: str = 'GitHub MCP Registry', description: str = "MCP servers published to GitHub's registry.", icon_url: str | None = 'https://avatars.githubusercontent.com/u/9919?s=64', *, base_url: str = DEFAULT_BASE_URL, api_token: str | None = None, timeout: float = 30.0) -> None
初始化 GitHubMCPHub 实例。
Initialize the GitHub MCP registry provider.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hub_id默认default 'github' | str | 中心标识(类型 `str`)。The stable identifier addressing this hub in the routes. |
display_name默认default 'GitHub MCP Registry' | str | 展示名称(类型 `str`)。The user-facing hub name. |
description默认default "MCP servers published to GitHub's registry." | str | 描述(类型 `str`)。The user-facing hub description. |
icon_url默认default 'https://avatars.githubusercontent.com/u/9919?s=64' | str | None | icon URL(类型 `str | None`)。The hub's icon, defaulting to GitHub's avatar. |
base_urlkw默认default DEFAULT_BASE_URL | str | 注册表的基类 URL。The base URL of the registry. |
api_tokenkw默认default None | str | None | API 令牌(类型 `str | None`)。A GitHub token. The registry is public; a token only raises the rate limit. |
timeoutkw默认default 30.0 | float | 超时时间(类型 `float`)。The per-request timeout in seconds. |
源码Source
agentscope/app/hub/_mcp/_github_hub.py:110–145方法详情Method Detail
__aenter__
async def __aenter__() -> 'GitHubMCPHub'
async
进入异步上下文并返回自身。
Open the HTTP client shared by every request.
'GitHubMCPHub'
返回'GitHubMCPHub'。`GitHubMCPHub`:
源码Source
agentscope/app/hub/_mcp/_github_hub.py:147–157__aexit__
async def __aexit__(*exc: Any) -> None
async
退出异步上下文并清理资源。
Close the shared HTTP client.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc | Any | exc(类型 `Any`)。The exc. |
None
无返回值。No value is returned.
源码Source
agentscope/app/hub/_mcp/_github_hub.py:159–163list_mcps
async def list_mcps(user_id: str, q: str | None = None, cursor: str | None = None, limit: int = 20) -> MCPHubPage
async
列出 list_mcps。
q is applied here rather than upstream: the registry accepts no search parameter, so a page is fetched and then filtered.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。The user identifier. Unused by the public registry, kept for interface compatibility. |
q默认default None | str | None | q(类型 `str | None`)。A keyword matched against the name and description. |
cursor默认default None | str | None | 游标(类型 `str | None`)。The opaque cursor from a previous page. |
limit默认default 20 | int | 数量上限(类型 `int`)。The maximum number of entries to fetch. |
MCPHubPage
返回MCPHubPage。`MCPHubPage`:
- 可能抛出 `Exception`。`HubError`:
- 可能抛出 `Exception`。When the registry returns a non-success status code.
源码Source
agentscope/app/hub/_mcp/_github_hub.py:381–434get_mcp
async def get_mcp(user_id: str, card_id: str) -> MCPCard
async
获取MCP。
Fetch one registry entry.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。The user identifier. Unused by the public registry, kept for interface compatibility. |
card_id | str | 服务端的注册表标识。The registry id of the server. |
MCPCard
返回MCPCard。`MCPCard`:
- 可能抛出 `Exception`。`KeyError`:
- 可能抛出 `Exception`。When the registry has no such server, or describes no way
- 可能抛出 `Exception`。to reach it.
- 可能抛出 `Exception`。`HubError`:
- 可能抛出 `Exception`。When the registry returns any other failure.
源码Source
agentscope/app/hub/_mcp/_github_hub.py:436–467