Skip to content

change doc and add version tool #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added CHANGELOG.md
Empty file.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ uv --directory . run qiniu-mcp-server --transport sse --port 8000
## 开发

扩展功能,首先在 core 目录下新增一个业务目录(eg: 存储 -> storage),在此业务目录下完成功能拓展。
在业务目录下新建一个 `loader.py` 文件,在此文件中定义 load 函数用于注册业务工具或者资源,最后在 `core` 目录下的 `__init__.py`
在业务包目录下的 `__init__.py` 文件中定义 load 函数用于注册业务工具或者资源,最后在 `core` 目录下的 `__init__.py`
中调用此 load 函数完成工具和资源的注册。

```shell
core
├── __init__.py # 各个业务工具或者资源加载
└── storage # 存储业务目录
├── __init__.py
├── loader.py # 加载存储工具或者资源
├── __init__.py # 加载存储工具或者资源
├── resource.py # 存储资源扩展
├── storage.py # 存储工具类
└── tools.py # 存储工具扩展
Expand Down
4 changes: 4 additions & 0 deletions mcp_server/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
from .storage import load as load_storage
from .media_processing import load as load_media_processing
from .cdn import load as load_cdn
from .version import load as load_version


def load():
# 加载配置
cfg = config.load_config()

# 版本
load_version(cfg)
# 存储业务
load_storage(cfg)
# CDN
load_cdn(cfg)
# 智能多媒体
load_media_processing(cfg)

14 changes: 7 additions & 7 deletions mcp_server/core/storage/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, storage: StorageService):

@tools.tool_meta(
types.Tool(
name="ListBuckets", # https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html
name="ListBuckets",
description="Returns a list of all buckets owned by the authenticated sender of the request. To grant IAM permission to use this operation, you must add the s3:ListAllMyBuckets policy action.",
inputSchema={
"type": "object",
Expand All @@ -37,7 +37,7 @@ async def list_buckets(self, **kwargs) -> list[types.TextContent]:

@tools.tool_meta(
types.Tool(
name="ListObjects", # https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
name="ListObjects",
description="Each request will return some or all (up to 100) objects in the bucket. You can use request parameters as selection criteria to return some objects in the bucket. If you want to continue listing, set start_after to the key of the last file in the last listing result so that you can list new content. To get a list of buckets, see ListBuckets.",
inputSchema={
"type": "object",
Expand Down Expand Up @@ -69,7 +69,7 @@ async def list_objects(self, **kwargs) -> list[types.TextContent]:

@tools.tool_meta(
types.Tool(
name="GetObject", # https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
name="GetObject",
description="Retrieves an object from Amazon S3. In the GetObject request, specify the full key name for the object. General purpose buckets - Both the virtual-hosted-style requests and the path-style requests are supported. For a virtual hosted-style request example, if you have the object photos/2006/February/sample.jpg, specify the object key name as /photos/2006/February/sample.jpg. For a path-style request example, if you have the object photos/2006/February/sample.jpg in the bucket named examplebucket, specify the object key name as /examplebucket/photos/2006/February/sample.jpg. Directory buckets - Only virtual-hosted-style requests are supported. For a virtual hosted-style request example, if you have the object photos/2006/February/sample.jpg in the bucket named examplebucket--use1-az5--x-s3, specify the object key name as /photos/2006/February/sample.jpg. Also, when you make requests to this API operation, your requests are sent to the Zonal endpoint. These endpoints support virtual-hosted-style requests in the format https://bucket_name.s3express-az_id.region.amazonaws.com/key-name . Path-style requests are not supported.",
inputSchema={
"type": "object",
Expand Down Expand Up @@ -109,8 +109,8 @@ async def get_object(self, **kwargs) -> list[ImageContent] | list[TextContent]:

@tools.tool_meta(
types.Tool(
name="GetObjectURL", # https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
description="获取文件下载的 URL",
name="GetObjectURL",
description="Get the file download URL, and note that the Bucket where the file is located must be bound to a domain name. If using Qiniu's test domain, HTTPS access will not be available, and users need to make adjustments for this themselves.",
inputSchema={
"type": "object",
"properties": {
Expand All @@ -124,11 +124,11 @@ async def get_object(self, **kwargs) -> list[ImageContent] | list[TextContent]:
},
"disable_ssl": {
"type": "boolean",
"description": "是否禁用 SSL,默认不禁用使用 HTTP 协议,禁用后使用 HTTP 协议",
"description": "Whether to disable SSL. By default, it is not disabled (HTTP protocol is used). If disabled, the HTTP protocol will be used.",
},
"expires": {
"type": "integer",
"description": "下载链接中 Token 有效期,单位是秒;当空间是私有空间时,访问文件对象时需要对文件链接签名 Token,公有空间不签 Token",
"description": "Token expiration time (in seconds) for download links. When the bucket is private, a signed Token is required to access file objects. Public buckets do not require Token signing.",
},
},
"required": ["bucket", "key"],
Expand Down
9 changes: 9 additions & 0 deletions mcp_server/core/version/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .tools import register_tools
from ...config import config


def load(cfg: config.Config):
register_tools()


__all__ = ["load"]
31 changes: 31 additions & 0 deletions mcp_server/core/version/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

from mcp import types

from . import version
from ...tools import tools


class _ToolImpl:
def __init__(self):
pass

@tools.tool_meta(
types.Tool(
name="Version",
description="qiniu mcp server version info.",
inputSchema={
"type": "object",
"required": [],
}
)
)
def version(self, **kwargs) -> list[types.TextContent]:
return [types.TextContent(type="text", text=version.VERSION)]

def register_tools():
tool_impl = _ToolImpl()
tools.auto_register_tools(
[
tool_impl.version,
]
)
2 changes: 2 additions & 0 deletions mcp_server/core/version/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

VERSION = '0.1.0'
Loading