MCPcopy Create free account
hub / github.com/modelscope/modelscope / get_mcp_server

Method get_mcp_server

modelscope/hub/mcp_api.py:230–313  ·  view source on GitHub ↗

Get detailed information for a specific MCP Server, a valid token shall be provided if the MCP server is private. Args: server_id: MCP server ID (e.g., "@amap/amap-maps") token: Optional access token for authentication Returns: D

(self,
                       server_id: str,
                       token: Optional[str] = None)

Source from the content-addressed store, hash-verified

228 }
229
230 def get_mcp_server(self,
231 server_id: str,
232 token: Optional[str] = None) -> Dict[str, Any]:
233 """
234 Get detailed information for a specific MCP Server,
235 a valid token shall be provided if the MCP server is private.
236
237 Args:
238 server_id: MCP server ID (e.g., "@amap/amap-maps")
239 token: Optional access token for authentication
240
241 Returns:
242 Dict containing:
243 - name: Server name
244 - description: Server description
245 - id: Server ID
246 - service_config: Connection configuration with type and url
247
248 Raises:
249 ValueError: If server_id is empty or None
250 MCPApiRequestError: If API request fails or server not found
251 MCPApiResponseError: If response format is invalid or JSON parsing fails
252
253 Returns:
254 {
255 'name': 'ServerA',
256 'description': 'This is a demo server for xxx.',
257 'id': '@demo/serverA',
258 'servers': [
259 {
260 'type': 'sse',
261 'url': 'https://mcp.api-inference.modelscope.net/{uuid}/sse'
262 },
263 {
264 'type': 'streamable_http',
265 'url': 'https://mcp.api-inference.modelscope.net/{uuid}/streamable_http'
266 }
267 ...
268 ]
269 }
270 """
271 if not server_id:
272 raise ValueError('server_id cannot be empty')
273
274 url = f'{self.mcp_base_url}/{server_id}'
275
276 try:
277 headers = self._build_bearer_headers(
278 token=token, token_required=False)
279 r = self.session.get(
280 url, headers=headers, params={'get_operational_url': True})
281 raise_for_http_status(r)
282 except requests.exceptions.RequestException as e:
283 logger.error(f'Failed to get MCP server {server_id}: {e}')
284 raise MCPApiRequestError(
285 f'Failed to get MCP server {server_id}: {e}') from e
286
287 try:

Callers 1

test_get_mcp_serverMethod · 0.80

Calls 6

raise_for_http_statusFunction · 0.90
MCPApiRequestErrorClass · 0.85
MCPApiResponseErrorClass · 0.85
getMethod · 0.45
appendMethod · 0.45

Tested by 1

test_get_mcp_serverMethod · 0.64