Skip to content

Commit 7a5cc44

Browse files
author
YangSen-qn
committed
support bucket not config
1 parent 0ae9cf6 commit 7a5cc44

33 files changed

+35
-41
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ wheels/
1212
.env.dora
1313
.env.kodo
1414

15-
mcp_server/test.py
15+
src/mcp_server/test.py

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.1.0
2+
- 支持 Bucket 为空
3+
14
# v1.0.0
25

36
- 支持 Kodo 服务
File renamed without changes.

mcp_server/core/version/version.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

pyproject.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
[project]
22
name = "qiniu-mcp-server"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
description = "A MCP server project of Qiniu."
55
requires-python = ">=3.12"
6+
authors = [
7+
{ name = "Qiniu", email = "sdk@qiniu.com" },
8+
]
9+
keywords = ["qiniu", "mcp", "llm"]
610
dependencies = [
711
"aioboto3>=13.2.0",
812
"fastjsonschema>=2.21.1",
@@ -18,8 +22,8 @@ dependencies = [
1822
requires = [ "hatchling",]
1923
build-backend = "hatchling.build"
2024

21-
[tool.hatch.build.targets.wheel]
22-
packages = ["mcp_server"]
23-
2425
[project.scripts]
2526
qiniu-mcp-server = "mcp_server:main"
27+
28+
[tool.hatch.build.targets.wheel]
29+
packages = ["src/mcp_server"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

mcp_server/config/config.py renamed to src/mcp_server/config/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ def load_config() -> Config:
5252
logger.error("QINIU_REGION_NAME is not configured")
5353
raise ValueError("QINIU_REGION_NAME is not configured")
5454

55-
if not config.buckets:
56-
logger.error("QINIU_BUCKETS is not configured")
57-
raise ValueError("QINIU_BUCKETS is not configured")
58-
5955
logger.info(f"Configured access_key: {config.access_key}")
6056
logger.info(f"Configured endpoint_url: {config.endpoint_url}")
6157
logger.info(f"Configured region_name: {config.region_name}")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

mcp_server/core/storage/storage.py renamed to src/mcp_server/core/storage/storage.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def get_object_url(
9595
return object_urls
9696

9797
async def list_buckets(self, prefix: Optional[str] = None) -> List[dict]:
98-
"""
99-
List S3 buckets using async client with pagination
100-
"""
98+
if not self.config.buckets or len(self.config.buckets) == 0:
99+
return []
100+
101101
max_buckets = 50
102102

103103
async with self.s3_session.client(
@@ -107,32 +107,22 @@ async def list_buckets(self, prefix: Optional[str] = None) -> List[dict]:
107107
endpoint_url=self.config.endpoint_url,
108108
region_name=self.config.region_name,
109109
) as s3:
110-
if self.config.buckets:
111-
# If buckets are configured, only return those
112-
response = await s3.list_buckets()
113-
all_buckets = response.get("Buckets", [])
110+
# If buckets are configured, only return those
111+
response = await s3.list_buckets()
112+
all_buckets = response.get("Buckets", [])
114113

114+
configured_bucket_list = [
115+
bucket
116+
for bucket in all_buckets
117+
if bucket["Name"] in self.config.buckets
118+
]
119+
120+
if prefix:
115121
configured_bucket_list = [
116-
bucket
117-
for bucket in all_buckets
118-
if bucket["Name"] in self.config.buckets
122+
b for b in configured_bucket_list if b["Name"] > prefix
119123
]
120124

121-
if prefix:
122-
configured_bucket_list = [
123-
b for b in configured_bucket_list if b["Name"] > prefix
124-
]
125-
126-
return configured_bucket_list[:max_buckets]
127-
else:
128-
# Default behavior if no buckets configured
129-
response = await s3.list_buckets()
130-
buckets = response.get("Buckets", [])
131-
132-
if prefix:
133-
buckets = [b for b in buckets if b["Name"] > prefix]
134-
135-
return buckets[:max_buckets]
125+
return configured_bucket_list[:max_buckets]
136126

137127
async def list_objects(
138128
self, bucket: str, prefix: str = "", max_keys: int = 20, start_after: str = ""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
VERSION = '1.1.0'

src/mcp_server/resource/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

src/mcp_server/tools/__init__.py

Whitespace-only changes.

mcp_server/tools/tools.py renamed to src/mcp_server/tools/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from typing import List, Dict, Callable, Optional, Union, Awaitable
88
from dataclasses import dataclass
99
from mcp import types
10-
from mcp_server import consts
10+
11+
from .. import consts
1112

1213
logger = logging.getLogger(consts.LOGGER_NAME)
1314

@@ -36,8 +37,8 @@ def all_tools() -> List[types.Tool]:
3637

3738

3839
def register_tool(
39-
meta: types.Tool,
40-
func: Union[ToolFunc, AsyncToolFunc],
40+
meta: types.Tool,
41+
func: Union[ToolFunc, AsyncToolFunc],
4142
) -> None:
4243
"""注册工具,禁止重复名称"""
4344
name = meta.name

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)