|
1 | 1 | import logging |
| 2 | + |
| 3 | +import qiniu |
2 | 4 | from mcp import types |
3 | 5 |
|
4 | 6 | from . import utils |
5 | 7 | from .processing import MediaProcessingService |
| 8 | +from ...config import config |
6 | 9 | from ...consts import consts |
7 | 10 | from ...tools import tools |
8 | 11 |
|
|
12 | 15 |
|
13 | 16 |
|
14 | 17 | class _ToolImpl: |
15 | | - def __init__(self, cli: MediaProcessingService): |
| 18 | + def __init__(self, cfg: config.Config, cli: MediaProcessingService): |
| 19 | + self.auth = qiniu.Auth(cfg.access_key, cfg.secret_key) |
16 | 20 | self.client = cli |
17 | 21 |
|
18 | 22 | @tools.tool_meta( |
@@ -55,8 +59,8 @@ def image_scale_by_percent( |
55 | 59 | types.TextContent(type="text", text="percent must be between 1 and 999") |
56 | 60 | ] |
57 | 61 |
|
58 | | - fop = f"imageMogr2/thumbnail/!{percent}p" |
59 | | - object_url = utils.url_add_processing_func(object_url, fop) |
| 62 | + func = f"imageMogr2/thumbnail/!{percent}p" |
| 63 | + object_url = utils.url_add_processing_func(auth=self.auth, url=object_url, func=func) |
60 | 64 | return [ |
61 | 65 | types.TextContent( |
62 | 66 | type="text", |
@@ -111,16 +115,16 @@ def image_scale_by_size( |
111 | 115 | if object_url is None or len(object_url) == 0: |
112 | 116 | return [types.TextContent(type="text", text="object_url is required")] |
113 | 117 |
|
114 | | - fop = f"{width}x{height}" |
115 | | - if len(fop) == 1: |
| 118 | + func = f"{width}x{height}" |
| 119 | + if len(func) == 1: |
116 | 120 | return [ |
117 | 121 | types.TextContent( |
118 | 122 | type="text", text="At least one width or height must be set" |
119 | 123 | ) |
120 | 124 | ] |
121 | 125 |
|
122 | | - fop = f"imageMogr2/thumbnail/{fop}" |
123 | | - object_url = utils.url_add_processing_func(object_url, fop) |
| 126 | + func = f"imageMogr2/thumbnail/{func}" |
| 127 | + object_url = utils.url_add_processing_func(auth=self.auth, url=object_url, func=func) |
124 | 128 | return [ |
125 | 129 | types.TextContent( |
126 | 130 | type="text", |
@@ -191,7 +195,7 @@ def image_round_corner(self, **kwargs) -> list[types.TextContent]: |
191 | 195 | radius_y = radius_x |
192 | 196 |
|
193 | 197 | func = f"roundPic/radiusx/{radius_x}/radiusy/{radius_y}" |
194 | | - object_url = utils.url_add_processing_func(object_url, func) |
| 198 | + object_url = utils.url_add_processing_func(auth=self.auth, url=object_url, func=func) |
195 | 199 | return [ |
196 | 200 | types.TextContent( |
197 | 201 | type="text", |
@@ -228,7 +232,7 @@ def image_info(self, **kwargs) -> list[types.TextContent]: |
228 | 232 | ] |
229 | 233 |
|
230 | 234 | func = "imageInfo" |
231 | | - object_url = utils.url_add_processing_func(object_url, func) |
| 235 | + object_url = utils.url_add_processing_func(auth=self.auth, url=object_url, func=func) |
232 | 236 | return [ |
233 | 237 | types.TextContent( |
234 | 238 | type="text", |
@@ -259,8 +263,8 @@ def get_fop_status(self, **kwargs) -> list[types.TextContent]: |
259 | 263 | return [types.TextContent(type="text", text=str(status))] |
260 | 264 |
|
261 | 265 |
|
262 | | -def register_tools(cli: MediaProcessingService): |
263 | | - tool_impl = _ToolImpl(cli) |
| 266 | +def register_tools(cfg: config.Config, cli: MediaProcessingService): |
| 267 | + tool_impl = _ToolImpl(cfg, cli) |
264 | 268 | tools.auto_register_tools( |
265 | 269 | [ |
266 | 270 | tool_impl.image_scale_by_percent, |
|
0 commit comments