Skip to content

Commit eaf4ef6

Browse files
committed
feat: add modelscope_url to user and model info
1 parent 6542b4f commit eaf4ef6

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

src/modelscope_mcp_server/tools/context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ async def get_current_user() -> UserInfo:
5353

5454
user_data = response.get("Data", {})
5555

56+
username = user_data.get("Name")
57+
modelscope_url = f"{settings.main_domain}/profile/{username}"
58+
5659
return UserInfo(
5760
authenticated=True,
58-
username=user_data.get("Name"),
61+
username=username,
5962
email=user_data.get("Email"),
6063
avatar_url=user_data.get("Avatar"),
6164
description=user_data.get("Description") or "",
65+
modelscope_url=modelscope_url,
6266
)
6367

6468
@mcp.tool(

src/modelscope_mcp_server/tools/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ async def search_models(
106106
for model_data in models_data:
107107
path = model_data.get("Path", "")
108108
name = model_data.get("Name", "")
109+
modelscope_url = f"{settings.main_domain}/models/{path}/{name}"
109110

110111
if not path or not name:
111112
logger.warning(f"Skipping model with invalid path or name: {model_data}")
@@ -117,6 +118,7 @@ async def search_models(
117118
name=name,
118119
chinese_name=model_data.get("ChineseName", ""),
119120
created_by=model_data.get("CreatedBy"),
121+
modelscope_url=modelscope_url,
120122
# Non-empty value means True, else False
121123
support_inference=bool(model_data.get("SupportInference", "")),
122124
downloads_count=model_data.get("Downloads", 0),

src/modelscope_mcp_server/types.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ class GenerationType(str, Enum):
1616
class UserInfo(BaseModel):
1717
"""User information."""
1818

19+
# Authentication result
1920
authenticated: Annotated[bool, Field(description="Whether the user is authenticated")]
2021
reason: Annotated[str | None, Field(description="Reason for failed authentication")] = None
22+
23+
# Basic information
2124
username: Annotated[str | None, Field(description="Username")] = None
2225
email: Annotated[str | None, Field(description="Email")] = None
2326
avatar_url: Annotated[str | None, Field(description="Avatar URL")] = None
2427
description: Annotated[str | None, Field(description="Description")] = None
2528

29+
# Links
30+
modelscope_url: Annotated[str | None, Field(description="Profile page URL on ModelScope")] = None
31+
2632

2733
class Model(BaseModel):
2834
"""Model information."""
@@ -34,6 +40,9 @@ class Model(BaseModel):
3440
chinese_name: Annotated[str, Field(description="Chinese name")]
3541
created_by: Annotated[str, Field(description="User who created the model")]
3642

43+
# Links
44+
modelscope_url: Annotated[str, Field(description="Detail page URL on ModelScope")]
45+
3746
# Capabilities
3847
support_inference: Annotated[bool, Field(description="Whether the model supports inference API")] = False
3948

@@ -58,7 +67,7 @@ class Paper(BaseModel):
5867
abstract_en: Annotated[str, Field(description="Abstract in English")]
5968

6069
# Links
61-
modelscope_url: Annotated[str, Field(description="ModelScope page URL")]
70+
modelscope_url: Annotated[str, Field(description="Detail page URL on ModelScope")]
6271
arxiv_url: Annotated[str, Field(description="Arxiv page URL")]
6372
pdf_url: Annotated[str, Field(description="PDF URL")]
6473
code_link: Annotated[str | None, Field(description="Code link")] = None
@@ -81,7 +90,7 @@ class McpServer(BaseModel):
8190
tags: Annotated[list[str], Field(description="Tags")] = []
8291

8392
# Links
84-
modelscope_url: Annotated[str, Field(description="ModelScope page URL")]
93+
modelscope_url: Annotated[str, Field(description="Detail page URL on ModelScope")]
8594

8695
# Metrics
8796
view_count: Annotated[int, Field(description="View count")] = 0

tests/tools/test_get_current_user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async def test_get_current_user_success(mcp_server):
2222
assert user_info.authenticated is True, "User should be authenticated"
2323
assert user_info.username is not None, "Username should be present"
2424
assert user_info.email is not None, "Email should be present"
25+
assert user_info.modelscope_url is not None, "ModelScope URL should be present"
2526

2627

2728
@pytest.mark.integration

tests/tools/test_search_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def validate_model_fields(model):
4242
"path",
4343
"chinese_name",
4444
"created_by",
45+
"modelscope_url",
4546
"support_inference",
4647
"downloads_count",
4748
"stars_count",

0 commit comments

Comments
 (0)