AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.hub

GitHubMCPHub

class GitHubMCPHub(MCPHubBase)
源码Source agentscope/app/hub/_mcp/_github_hub.py:101–467

GitHub 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 | Noneicon URL(类型 `str | None`)。The hub's icon, defaulting to GitHub's avatar.
base_urlkw默认default DEFAULT_BASE_URLstr注册表的基类 URL。The base URL of the registry.
api_tokenkw默认default Nonestr | NoneAPI 令牌(类型 `str | None`)。A GitHub token. The registry is public; a token only raises the rate limit.
timeoutkw默认default 30.0float超时时间(类型 `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.

返回Returns '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
excAnyexc(类型 `Any`)。The exc.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/hub/_mcp/_github_hub.py:159–163

list_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_idstr用户标识(类型 `str`)。The user identifier. Unused by the public registry, kept for interface compatibility.
q默认default Nonestr | Noneq(类型 `str | None`)。A keyword matched against the name and description.
cursor默认default Nonestr | None游标(类型 `str | None`)。The opaque cursor from a previous page.
limit默认default 20int数量上限(类型 `int`)。The maximum number of entries to fetch.
返回Returns MCPHubPage
返回MCPHubPage。`MCPHubPage`:
异常Raises
  • 可能抛出 `Exception`。`HubError`:
  • 可能抛出 `Exception`。When the registry returns a non-success status code.
源码Source agentscope/app/hub/_mcp/_github_hub.py:381–434

get_mcp

async def get_mcp(user_id: str, card_id: str) -> MCPCard
async

获取MCP。

Fetch one registry entry.

参数Parameters
名称Name类型Type说明Description
user_idstr用户标识(类型 `str`)。The user identifier. Unused by the public registry, kept for interface compatibility.
card_idstr服务端的注册表标识。The registry id of the server.
返回Returns MCPCard
返回MCPCard。`MCPCard`:
异常Raises
  • 可能抛出 `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
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.