Skip to content

Commit 970ebba

Browse files
author
YangSen-qn
committed
add upload
1 parent 9d6bb87 commit 970ebba

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/mcp_server/core/storage/storage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ def upload_file(self, bucket: str, key: str, file_path: str, overwrite: bool = F
237237

238238
return self.get_object_url(bucket, key)
239239

240+
def fetch_object(self, bucket: str, key: str, url: str):
241+
ret, info = self.bucket_manager.fetch(url, bucket, key=key)
242+
if info.status_code != 200:
243+
raise Exception(f"Failed to fetch object: {info.text}")
244+
245+
return self.get_object_url(bucket, key)
246+
240247
def is_text_file(self, key: str) -> bool:
241248
"""Determine if a file is text-based by its extension"""
242249
text_extensions = {

src/mcp_server/core/storage/tools.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def get_object(self, **kwargs) -> list[ImageContent] | list[TextContent]:
112112
@tools.tool_meta(
113113
types.Tool(
114114
name="UploadTextData",
115-
description="Upload text data to Qiniu bucket. In the UploadData request, specify the full key name for the object. Path-style requests are not supported.",
115+
description="Upload text data to Qiniu bucket.",
116116
inputSchema={
117117
"type": "object",
118118
"properties": {
@@ -144,7 +144,7 @@ def upload_text_data(self, **kwargs) -> list[types.TextContent]:
144144
@tools.tool_meta(
145145
types.Tool(
146146
name="UploadFile",
147-
description="Upload file to Qiniu bucket. In the UploadFile request, specify the full key name for the object. Path-style requests are not supported.",
147+
description="Upload a local file to Qiniu bucket.",
148148
inputSchema={
149149
"type": "object",
150150
"properties": {
@@ -173,6 +173,28 @@ def upload_file(self, **kwargs) -> list[types.TextContent]:
173173
urls = self.storage.upload_file(**kwargs)
174174
return [types.TextContent(type="text", text=str(urls))]
175175

176+
@tools.tool_meta(
177+
types.Tool(
178+
name="FetchObject",
179+
description="Fetch a http object to Qiniu bucket.",
180+
inputSchema={
181+
"type": "object",
182+
"properties": {
183+
"bucket": {
184+
"type": "string",
185+
"description": _BUCKET_DESC,
186+
},
187+
"key": {
188+
"type": "string",
189+
}
190+
}
191+
}
192+
)
193+
)
194+
def fetch_object(self, **kwargs) -> list[types.TextContent]:
195+
urls = self.storage.fetch_object(**kwargs)
196+
return [types.TextContent(type="text", text=str(urls))]
197+
176198
@tools.tool_meta(
177199
types.Tool(
178200
name="GetObjectURL",
@@ -215,6 +237,7 @@ def register_tools(storage: StorageService):
215237
tool_impl.get_object,
216238
tool_impl.upload_text_data,
217239
tool_impl.upload_file,
240+
tool_impl.fetch_object,
218241
tool_impl.get_object_url,
219242
]
220243
)

0 commit comments

Comments
 (0)