gitcode-api 1.2.10__tar.gz → 1.2.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/PKG-INFO +7 -5
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/README.md +5 -3
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/cli.py +72 -7
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/llm/__init__.py +4 -1
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/llm/jiuwen.py +28 -6
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/llm/openai.py +36 -5
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/run_mcp.py +1 -1
- gitcode_api-1.2.12/gitcode_api/version.txt +1 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/PKG-INFO +7 -5
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/pyproject.toml +2 -2
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_cli.py +2 -0
- gitcode_api-1.2.10/gitcode_api/version.txt +0 -1
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/LICENSE +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/__init__.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/__main__.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_base_client.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_base_resource.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_cli_banner.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_client.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_exceptions.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/_models.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/llm/_tool.py +4 -4
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/llm/mcp.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/py.typed +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/__init__.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/_shared.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/account.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/collaboration.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/misc.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api/resources/repositories.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/SOURCES.txt +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/dependency_links.txt +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/entry_points.txt +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/requires.txt +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/gitcode_api.egg-info/top_level.txt +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/setup.cfg +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_base_client.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_build_manifest.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_client.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_llm_tools.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_models.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_resources_account.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_resources_collaboration.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_resources_misc.py +0 -0
- {gitcode_api-1.2.10 → gitcode_api-1.2.12}/tests/test_resources_repositories.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.12
|
|
4
4
|
Summary: Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP, OpenAI tool, and openJiuwen tool) for agents. Community-maintained.
|
|
5
5
|
Author-email: Hugo Huang <hugo@hugohuang.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -9,7 +9,7 @@ Project-URL: issues, https://github.com/Trenza1ore/GitCode-API/issues
|
|
|
9
9
|
Project-URL: documentation, https://gitcode-api.readthedocs.io
|
|
10
10
|
Project-URL: gitcode, https://gitcode.com/SushiNinja/GitCode-API
|
|
11
11
|
Project-URL: github, https://github.com/Trenza1ore/GitCode-API
|
|
12
|
-
Project-URL: homepage, https://
|
|
12
|
+
Project-URL: homepage, https://hugohuang.com/gitcode-api
|
|
13
13
|
Project-URL: author, https://hugohuang.com
|
|
14
14
|
Keywords: gitcode,git,devops,api,sdk,python,httpx,client,mcp,agent,fastmcp,llm,openjiuwen,mcp client,mcp server,model context protocol
|
|
15
15
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -37,7 +37,7 @@ Dynamic: license-file
|
|
|
37
37
|
|
|
38
38
|
# GitCode-API
|
|
39
39
|
|
|
40
|
-
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
40
|
+
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
41
41
|
[](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19) [](https://vscode.dev/redirect/mcp/install?name=GitCode%20API&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22--from%22%2C%22gitcode-api%5Bmcp%5D%22%2C%22gitcode-api%22%2C%22serve%22%5D%2C%22env%22%3A%7B%22GITCODE_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitcode_access_token%7D%22%7D%2C%22inputs%22%3A%5B%7B%22id%22%3A%22gitcode_access_token%22%2C%22type%22%3A%22promptString%22%2C%22description%22%3A%22Enter%20GITCODE_ACCESS_TOKEN%22%2C%22password%22%3Atrue%7D%5D%7D)
|
|
42
42
|
[](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API)
|
|
43
43
|
|
|
@@ -111,12 +111,14 @@ With `gitcode-api[mcp]` installed (Python 3.10+), you can start the bundled Fast
|
|
|
111
111
|
gitcode-api serve --api-key "$GITCODE_ACCESS_TOKEN"
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, and
|
|
114
|
+
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, `--transport` (`stdio`, `http`, or `sse`), and other options.
|
|
115
115
|
|
|
116
116
|
Commands mirror the synchronous resource methods on `GitCode`, using the pattern
|
|
117
117
|
`gitcode-api <resource> <method> ...`. For methods that accept extra `**params`
|
|
118
118
|
or `**payload`, pass repeated `--set key=value` flags or `--set-json '{"key": "value"}'`.
|
|
119
119
|
|
|
120
|
+
When using string arguments with escape sequence (such as line break `\n`), pass `-e` / `--escape` with the sequences to un-escape, such as `-e '\n\t'`.
|
|
121
|
+
|
|
120
122
|
## Quick Start
|
|
121
123
|
|
|
122
124
|
### Sync client
|
|
@@ -231,7 +233,7 @@ Every resource group inherits a cached `methods` property from the shared resour
|
|
|
231
233
|
|
|
232
234
|
## LLM tools, MCP, and openJiuwen
|
|
233
235
|
|
|
234
|
-
The `gitcode_api.llm` module exposes a single
|
|
236
|
+
The `gitcode_api.llm` module exposes a single unified tool, **`gitcode_api_tool`**, that routes calls to respective sync or async SDK resource groups. Model-facing parameters match the JSON schema used by OpenAI-style function tools:
|
|
235
237
|
|
|
236
238
|
| Parameter | Role |
|
|
237
239
|
| --- | --- |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# GitCode-API
|
|
2
2
|
|
|
3
|
-
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
3
|
+
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
4
4
|
[](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19) [](https://vscode.dev/redirect/mcp/install?name=GitCode%20API&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22--from%22%2C%22gitcode-api%5Bmcp%5D%22%2C%22gitcode-api%22%2C%22serve%22%5D%2C%22env%22%3A%7B%22GITCODE_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitcode_access_token%7D%22%7D%2C%22inputs%22%3A%5B%7B%22id%22%3A%22gitcode_access_token%22%2C%22type%22%3A%22promptString%22%2C%22description%22%3A%22Enter%20GITCODE_ACCESS_TOKEN%22%2C%22password%22%3Atrue%7D%5D%7D)
|
|
5
5
|
[](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API)
|
|
6
6
|
|
|
@@ -74,12 +74,14 @@ With `gitcode-api[mcp]` installed (Python 3.10+), you can start the bundled Fast
|
|
|
74
74
|
gitcode-api serve --api-key "$GITCODE_ACCESS_TOKEN"
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, and
|
|
77
|
+
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, `--transport` (`stdio`, `http`, or `sse`), and other options.
|
|
78
78
|
|
|
79
79
|
Commands mirror the synchronous resource methods on `GitCode`, using the pattern
|
|
80
80
|
`gitcode-api <resource> <method> ...`. For methods that accept extra `**params`
|
|
81
81
|
or `**payload`, pass repeated `--set key=value` flags or `--set-json '{"key": "value"}'`.
|
|
82
82
|
|
|
83
|
+
When using string arguments with escape sequence (such as line break `\n`), pass `-e` / `--escape` with the sequences to un-escape, such as `-e '\n\t'`.
|
|
84
|
+
|
|
83
85
|
## Quick Start
|
|
84
86
|
|
|
85
87
|
### Sync client
|
|
@@ -194,7 +196,7 @@ Every resource group inherits a cached `methods` property from the shared resour
|
|
|
194
196
|
|
|
195
197
|
## LLM tools, MCP, and openJiuwen
|
|
196
198
|
|
|
197
|
-
The `gitcode_api.llm` module exposes a single
|
|
199
|
+
The `gitcode_api.llm` module exposes a single unified tool, **`gitcode_api_tool`**, that routes calls to respective sync or async SDK resource groups. Model-facing parameters match the JSON schema used by OpenAI-style function tools:
|
|
198
200
|
|
|
199
201
|
| Parameter | Role |
|
|
200
202
|
| --- | --- |
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Command-line interface for the GitCode SDK."""
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
+
import codecs
|
|
4
5
|
import inspect
|
|
5
6
|
import json
|
|
6
7
|
import re
|
|
@@ -8,7 +9,7 @@ import sys
|
|
|
8
9
|
import textwrap
|
|
9
10
|
from collections.abc import Mapping, Sequence
|
|
10
11
|
from pathlib import Path
|
|
11
|
-
from typing import Any, List, Optional, Union, get_args, get_origin
|
|
12
|
+
from typing import Any, Dict, List, Optional, Union, get_args, get_origin
|
|
12
13
|
|
|
13
14
|
import httpx
|
|
14
15
|
|
|
@@ -36,6 +37,40 @@ def _plain_cli_inline(text: str) -> str:
|
|
|
36
37
|
return t
|
|
37
38
|
|
|
38
39
|
|
|
40
|
+
_ESCAPE_PATTERN = re.compile(r"\\\w+")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _unescape_input(value: str, replacements: Dict[str, str]) -> str:
|
|
44
|
+
"""Unescape CLI input with provided escape sequences."""
|
|
45
|
+
for token, decoded in replacements.items():
|
|
46
|
+
value = value.replace(token, decoded)
|
|
47
|
+
return value
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _unescape_namespace(args: argparse.Namespace) -> None:
|
|
51
|
+
mapping = ((token, codecs.decode(token, "unicode-escape")) for token in _ESCAPE_PATTERN.findall(str(args.escape)))
|
|
52
|
+
replacements = {token: decoded for token, decoded in mapping if token and (token != decoded)}
|
|
53
|
+
if not replacements:
|
|
54
|
+
raise argparse.ArgumentTypeError("No valid escape sequence provided!")
|
|
55
|
+
for key, value in vars(args).items():
|
|
56
|
+
if key in {"escape", "base_url", "resource", "method", "api_key"}:
|
|
57
|
+
continue
|
|
58
|
+
if isinstance(value, str):
|
|
59
|
+
setattr(args, key, _unescape_input(value, replacements=replacements))
|
|
60
|
+
continue
|
|
61
|
+
if isinstance(value, list):
|
|
62
|
+
updated = []
|
|
63
|
+
changed = False
|
|
64
|
+
for item in value:
|
|
65
|
+
if isinstance(item, str):
|
|
66
|
+
updated.append(_unescape_input(item, replacements=replacements))
|
|
67
|
+
changed = True
|
|
68
|
+
else:
|
|
69
|
+
updated.append(item)
|
|
70
|
+
if changed:
|
|
71
|
+
setattr(args, key, updated)
|
|
72
|
+
|
|
73
|
+
|
|
39
74
|
def _unwrap_optional(annotation: Any) -> Any:
|
|
40
75
|
origin = get_origin(annotation)
|
|
41
76
|
if origin is Union:
|
|
@@ -179,12 +214,17 @@ def _invocation_parent_parser() -> argparse.ArgumentParser:
|
|
|
179
214
|
"""Parser with flags for real API calls (attached only to leaf METHOD parsers, not top-level usage)."""
|
|
180
215
|
parser = argparse.ArgumentParser(add_help=False)
|
|
181
216
|
parser.add_argument("--api-key", help=f"GitCode access token. Defaults to {DEFAULT_TOKEN_ENV}.")
|
|
182
|
-
parser.add_argument("--owner", help="Default repository owner.")
|
|
183
|
-
parser.add_argument("--repo", help="Default repository name.")
|
|
184
217
|
parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="Base URL for the REST API.")
|
|
185
218
|
parser.add_argument("--timeout", type=float, default=None, help="Request timeout in seconds.")
|
|
186
219
|
parser.add_argument("--output-file", help="Write the response to a file instead of stdout.")
|
|
187
220
|
parser.add_argument("--compact", action="store_true", help="Print JSON without indentation.")
|
|
221
|
+
parser.add_argument(
|
|
222
|
+
"-e",
|
|
223
|
+
"--escape",
|
|
224
|
+
default="",
|
|
225
|
+
metavar="SEQUENCES",
|
|
226
|
+
help='Unescape certain escape sequences (e.g. -e "\\n\\t") in arguments.',
|
|
227
|
+
)
|
|
188
228
|
return parser
|
|
189
229
|
|
|
190
230
|
|
|
@@ -192,6 +232,15 @@ def _root_banner() -> str:
|
|
|
192
232
|
return "Connection and defaults are documented on each method's help: %(prog)s RESOURCE METHOD -h."
|
|
193
233
|
|
|
194
234
|
|
|
235
|
+
def _parse_true_false(raw: str) -> bool:
|
|
236
|
+
value = raw.strip().lower()
|
|
237
|
+
if value == "true":
|
|
238
|
+
return True
|
|
239
|
+
if value == "false":
|
|
240
|
+
return False
|
|
241
|
+
raise argparse.ArgumentTypeError("Expected 'true' or 'false'.")
|
|
242
|
+
|
|
243
|
+
|
|
195
244
|
def _serve_parser() -> argparse.ArgumentParser:
|
|
196
245
|
"""Parser with options for starting the bundled MCP server."""
|
|
197
246
|
parser = argparse.ArgumentParser(add_help=False)
|
|
@@ -201,10 +250,25 @@ def _serve_parser() -> argparse.ArgumentParser:
|
|
|
201
250
|
parser.add_argument("--repo", help="Default repository name.")
|
|
202
251
|
parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="Base URL for the REST API.")
|
|
203
252
|
parser.add_argument("--timeout", type=float, default=None, help="Request timeout in seconds.")
|
|
204
|
-
parser.add_argument(
|
|
253
|
+
parser.add_argument(
|
|
254
|
+
"--transport",
|
|
255
|
+
default="stdio",
|
|
256
|
+
choices=("stdio", "http", "sse"),
|
|
257
|
+
metavar="{stdio,http,sse}",
|
|
258
|
+
help="FastMCP transport to run, such as stdio or http.",
|
|
259
|
+
)
|
|
205
260
|
parser.add_argument("--host", default=None, help="Host for HTTP-based transports.")
|
|
206
261
|
parser.add_argument("--port", type=int, default=None, help="Port for HTTP-based transports.")
|
|
207
262
|
parser.add_argument("--path", default=None, help="Path for HTTP-based transports.")
|
|
263
|
+
parser.add_argument(
|
|
264
|
+
"-b",
|
|
265
|
+
"--show-banner",
|
|
266
|
+
type=_parse_true_false,
|
|
267
|
+
choices=(True, False),
|
|
268
|
+
default=None,
|
|
269
|
+
metavar="{true,false}",
|
|
270
|
+
help="Show the FastMCP startup banner.",
|
|
271
|
+
)
|
|
208
272
|
return parser
|
|
209
273
|
|
|
210
274
|
|
|
@@ -356,7 +420,7 @@ def _run_mcp_server(args: argparse.Namespace) -> int:
|
|
|
356
420
|
if value is not None:
|
|
357
421
|
run_kwargs[key] = value
|
|
358
422
|
|
|
359
|
-
server.run(**run_kwargs)
|
|
423
|
+
server.run(show_banner=args.show_banner, **run_kwargs)
|
|
360
424
|
return 0
|
|
361
425
|
|
|
362
426
|
|
|
@@ -402,6 +466,9 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
402
466
|
parser.epilog = saved_epilog
|
|
403
467
|
return 0
|
|
404
468
|
args = parser.parse_args(effective)
|
|
469
|
+
escape_seq = getattr(args, "escape", None)
|
|
470
|
+
if escape_seq and isinstance(escape_seq, str):
|
|
471
|
+
_unescape_namespace(args)
|
|
405
472
|
|
|
406
473
|
try:
|
|
407
474
|
if getattr(args, "command", None) == "serve":
|
|
@@ -409,8 +476,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
409
476
|
|
|
410
477
|
with GitCode(
|
|
411
478
|
api_key=args.api_key,
|
|
412
|
-
owner=args.owner,
|
|
413
|
-
repo=args.repo,
|
|
414
479
|
base_url=args.base_url,
|
|
415
480
|
timeout=args.timeout,
|
|
416
481
|
) as client:
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from importlib import import_module
|
|
4
4
|
from typing import TYPE_CHECKING, Any, Dict
|
|
5
5
|
|
|
6
|
+
from ._tool import GitCodeLLMTool
|
|
7
|
+
|
|
6
8
|
if TYPE_CHECKING:
|
|
7
9
|
from .jiuwen import create_openjiuwen_gitcode_api_tool
|
|
8
10
|
from .mcp import (
|
|
@@ -25,7 +27,7 @@ _IMPORT_MAP = {
|
|
|
25
27
|
"create_openjiuwen_gitcode_api_tool": ".jiuwen",
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
_IMPORT_CACHE: Dict[str, Any] = {}
|
|
30
|
+
_IMPORT_CACHE: Dict[str, Any] = {"GitCodeLLMTool": GitCodeLLMTool}
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
def __getattr__(name: str) -> object:
|
|
@@ -50,6 +52,7 @@ def __dir__() -> list[str]:
|
|
|
50
52
|
|
|
51
53
|
|
|
52
54
|
__all__ = [
|
|
55
|
+
"GitCodeLLMTool",
|
|
53
56
|
"GitCodeOpenAITool",
|
|
54
57
|
"GitCodeMCP",
|
|
55
58
|
"create_mcp_gitcode_api_tool",
|
|
@@ -30,8 +30,30 @@ def _openjiuwen_tool_decorator() -> Callable[..., Any]:
|
|
|
30
30
|
class _GitCodeJiuwenTool(GitCodeLLMTool):
|
|
31
31
|
"""Build an openJiuwen ``LocalFunction`` bound to :class:`GitCodeLLMTool` (async invoke only)."""
|
|
32
32
|
|
|
33
|
-
def __init__(
|
|
34
|
-
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
*,
|
|
36
|
+
name: Optional[str] = None,
|
|
37
|
+
description: Optional[str] = None,
|
|
38
|
+
client: Optional[GitCode] = None,
|
|
39
|
+
async_client: Optional[AsyncGitCode] = None,
|
|
40
|
+
api_key: Optional[str] = None,
|
|
41
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
42
|
+
timeout: Optional[float] = None,
|
|
43
|
+
decrypt: Optional[Callable[..., Any]] = None,
|
|
44
|
+
owner: Optional[str] = None,
|
|
45
|
+
repo: Optional[str] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
super().__init__(
|
|
48
|
+
client=client,
|
|
49
|
+
async_client=async_client,
|
|
50
|
+
api_key=api_key,
|
|
51
|
+
owner=owner,
|
|
52
|
+
repo=repo,
|
|
53
|
+
base_url=base_url,
|
|
54
|
+
timeout=timeout,
|
|
55
|
+
decrypt=decrypt,
|
|
56
|
+
)
|
|
35
57
|
tool_name = name if name is not None else TOOL_NAME
|
|
36
58
|
tool_description = description if description is not None else TOOL_DESCRIPTION
|
|
37
59
|
oj_tool = _openjiuwen_tool_decorator()
|
|
@@ -60,11 +82,11 @@ def create_openjiuwen_gitcode_api_tool(
|
|
|
60
82
|
client: Optional[GitCode] = None,
|
|
61
83
|
async_client: Optional[AsyncGitCode] = None,
|
|
62
84
|
api_key: Optional[str] = None,
|
|
63
|
-
owner: Optional[str] = None,
|
|
64
|
-
repo: Optional[str] = None,
|
|
65
85
|
base_url: str = DEFAULT_BASE_URL,
|
|
66
86
|
timeout: Optional[float] = None,
|
|
67
87
|
decrypt: Optional[Callable[..., Any]] = None,
|
|
88
|
+
owner: Optional[str] = None,
|
|
89
|
+
repo: Optional[str] = None,
|
|
68
90
|
) -> "LocalFunction":
|
|
69
91
|
"""Create an openJiuwen ``LocalFunction`` for the GitCode API tool.
|
|
70
92
|
|
|
@@ -73,11 +95,11 @@ def create_openjiuwen_gitcode_api_tool(
|
|
|
73
95
|
:param client: Optional synchronous GitCode client.
|
|
74
96
|
:param async_client: Optional asynchronous GitCode client.
|
|
75
97
|
:param api_key: Personal access token when clients are not supplied.
|
|
76
|
-
:param owner: Default repository owner for generated clients.
|
|
77
|
-
:param repo: Default repository name for generated clients.
|
|
78
98
|
:param base_url: Base URL for generated clients.
|
|
79
99
|
:param timeout: Request timeout for generated clients.
|
|
80
100
|
:param decrypt: Optional decryption function for encrypted access tokens.
|
|
101
|
+
:param owner: Default repository owner for generated clients.
|
|
102
|
+
:param repo: Default repository name for generated clients.
|
|
81
103
|
:returns: openJiuwen ``LocalFunction`` with the standard parameter schema.
|
|
82
104
|
"""
|
|
83
105
|
adapter = _GitCodeJiuwenTool(
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
from functools import cached_property
|
|
5
|
-
from typing import Any, Coroutine, Dict, Union
|
|
5
|
+
from typing import Any, Callable, Coroutine, Dict, Optional, Union
|
|
6
|
+
|
|
7
|
+
from gitcode_api import AsyncGitCode, GitCode
|
|
8
|
+
from gitcode_api._base_client import DEFAULT_BASE_URL
|
|
6
9
|
|
|
7
10
|
from ._tool import TOOL_DESCRIPTION, TOOL_NAME, TOOL_PARAMETERS, GitCodeLLMTool
|
|
8
11
|
|
|
@@ -13,19 +16,47 @@ class GitCodeOpenAITool(GitCodeLLMTool):
|
|
|
13
16
|
:param async_mode: When true, calling the instance returns the async tool coroutine.
|
|
14
17
|
:param indent: ``indent`` argument passed to :func:`json.dumps` when serializing
|
|
15
18
|
invocation results (default ``2``).
|
|
16
|
-
:param
|
|
17
|
-
|
|
19
|
+
:param client: Optional synchronous GitCode client.
|
|
20
|
+
:param async_client: Optional asynchronous GitCode client.
|
|
21
|
+
:param api_key: Personal access token used when clients are not supplied.
|
|
22
|
+
:param base_url: Base URL for generated clients.
|
|
23
|
+
:param timeout: Request timeout for generated clients.
|
|
24
|
+
:param decrypt: Optional decryption function for encrypted access tokens.
|
|
25
|
+
:param owner: Default repository owner for generated clients.
|
|
26
|
+
:param repo: Default repository name for generated clients.
|
|
18
27
|
"""
|
|
19
28
|
|
|
20
29
|
name = TOOL_NAME
|
|
21
30
|
description = TOOL_DESCRIPTION
|
|
22
31
|
parameters = TOOL_PARAMETERS
|
|
23
32
|
|
|
24
|
-
def __init__(
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
async_mode: bool = False,
|
|
36
|
+
indent: int = 2,
|
|
37
|
+
*,
|
|
38
|
+
client: Optional[GitCode] = None,
|
|
39
|
+
async_client: Optional[AsyncGitCode] = None,
|
|
40
|
+
api_key: Optional[str] = None,
|
|
41
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
42
|
+
timeout: Optional[float] = None,
|
|
43
|
+
decrypt: Optional[Callable] = None,
|
|
44
|
+
owner: Optional[str] = None,
|
|
45
|
+
repo: Optional[str] = None,
|
|
46
|
+
) -> None:
|
|
25
47
|
"""Create an OpenAI tool wrapper."""
|
|
26
48
|
self.indent = indent
|
|
27
49
|
self.async_mode = bool(async_mode)
|
|
28
|
-
super().__init__(
|
|
50
|
+
super().__init__(
|
|
51
|
+
client=client,
|
|
52
|
+
async_client=async_client,
|
|
53
|
+
api_key=api_key,
|
|
54
|
+
owner=owner,
|
|
55
|
+
repo=repo,
|
|
56
|
+
base_url=base_url,
|
|
57
|
+
timeout=timeout,
|
|
58
|
+
decrypt=decrypt,
|
|
59
|
+
)
|
|
29
60
|
|
|
30
61
|
@cached_property
|
|
31
62
|
def tool(self) -> Dict[str, Any]:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.2.12
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.12
|
|
4
4
|
Summary: Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP, OpenAI tool, and openJiuwen tool) for agents. Community-maintained.
|
|
5
5
|
Author-email: Hugo Huang <hugo@hugohuang.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -9,7 +9,7 @@ Project-URL: issues, https://github.com/Trenza1ore/GitCode-API/issues
|
|
|
9
9
|
Project-URL: documentation, https://gitcode-api.readthedocs.io
|
|
10
10
|
Project-URL: gitcode, https://gitcode.com/SushiNinja/GitCode-API
|
|
11
11
|
Project-URL: github, https://github.com/Trenza1ore/GitCode-API
|
|
12
|
-
Project-URL: homepage, https://
|
|
12
|
+
Project-URL: homepage, https://hugohuang.com/gitcode-api
|
|
13
13
|
Project-URL: author, https://hugohuang.com
|
|
14
14
|
Keywords: gitcode,git,devops,api,sdk,python,httpx,client,mcp,agent,fastmcp,llm,openjiuwen,mcp client,mcp server,model context protocol
|
|
15
15
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -37,7 +37,7 @@ Dynamic: license-file
|
|
|
37
37
|
|
|
38
38
|
# GitCode-API
|
|
39
39
|
|
|
40
|
-
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
40
|
+
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
41
41
|
[](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19) [](https://vscode.dev/redirect/mcp/install?name=GitCode%20API&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22--from%22%2C%22gitcode-api%5Bmcp%5D%22%2C%22gitcode-api%22%2C%22serve%22%5D%2C%22env%22%3A%7B%22GITCODE_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitcode_access_token%7D%22%7D%2C%22inputs%22%3A%5B%7B%22id%22%3A%22gitcode_access_token%22%2C%22type%22%3A%22promptString%22%2C%22description%22%3A%22Enter%20GITCODE_ACCESS_TOKEN%22%2C%22password%22%3Atrue%7D%5D%7D)
|
|
42
42
|
[](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API)
|
|
43
43
|
|
|
@@ -111,12 +111,14 @@ With `gitcode-api[mcp]` installed (Python 3.10+), you can start the bundled Fast
|
|
|
111
111
|
gitcode-api serve --api-key "$GITCODE_ACCESS_TOKEN"
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, and
|
|
114
|
+
Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, `--transport` (`stdio`, `http`, or `sse`), and other options.
|
|
115
115
|
|
|
116
116
|
Commands mirror the synchronous resource methods on `GitCode`, using the pattern
|
|
117
117
|
`gitcode-api <resource> <method> ...`. For methods that accept extra `**params`
|
|
118
118
|
or `**payload`, pass repeated `--set key=value` flags or `--set-json '{"key": "value"}'`.
|
|
119
119
|
|
|
120
|
+
When using string arguments with escape sequence (such as line break `\n`), pass `-e` / `--escape` with the sequences to un-escape, such as `-e '\n\t'`.
|
|
121
|
+
|
|
120
122
|
## Quick Start
|
|
121
123
|
|
|
122
124
|
### Sync client
|
|
@@ -231,7 +233,7 @@ Every resource group inherits a cached `methods` property from the shared resour
|
|
|
231
233
|
|
|
232
234
|
## LLM tools, MCP, and openJiuwen
|
|
233
235
|
|
|
234
|
-
The `gitcode_api.llm` module exposes a single
|
|
236
|
+
The `gitcode_api.llm` module exposes a single unified tool, **`gitcode_api_tool`**, that routes calls to respective sync or async SDK resource groups. Model-facing parameters match the JSON schema used by OpenAI-style function tools:
|
|
235
237
|
|
|
236
238
|
| Parameter | Role |
|
|
237
239
|
| --- | --- |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "gitcode-api"
|
|
3
|
-
version = "1.2.
|
|
3
|
+
version = "1.2.12"
|
|
4
4
|
description = "Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP, OpenAI tool, and openJiuwen tool) for agents. Community-maintained."
|
|
5
5
|
keywords = [
|
|
6
6
|
"gitcode", "git", "devops", "api", "sdk", "python", "httpx", "client",
|
|
@@ -76,7 +76,7 @@ issues = "https://github.com/Trenza1ore/GitCode-API/issues"
|
|
|
76
76
|
documentation = "https://gitcode-api.readthedocs.io"
|
|
77
77
|
gitcode = "https://gitcode.com/SushiNinja/GitCode-API"
|
|
78
78
|
github = "https://github.com/Trenza1ore/GitCode-API"
|
|
79
|
-
homepage = "https://
|
|
79
|
+
homepage = "https://hugohuang.com/gitcode-api"
|
|
80
80
|
author = "https://hugohuang.com"
|
|
81
81
|
|
|
82
82
|
[project.scripts]
|
|
@@ -161,12 +161,14 @@ def test_run_mcp_server_passes_fastmcp_options(monkeypatch: Any) -> None:
|
|
|
161
161
|
host="127.0.0.1",
|
|
162
162
|
port=8000,
|
|
163
163
|
path="/mcp",
|
|
164
|
+
show_banner=None,
|
|
164
165
|
)
|
|
165
166
|
|
|
166
167
|
assert _run_mcp_server(args) == 0
|
|
167
168
|
assert captured["server_kwargs"]["name"] == "GitCode API"
|
|
168
169
|
assert captured["server_kwargs"]["tool"]._client_kwargs["api_key"] == "test-token"
|
|
169
170
|
assert captured["run_kwargs"] == {
|
|
171
|
+
"show_banner": None,
|
|
170
172
|
"transport": "http",
|
|
171
173
|
"host": "127.0.0.1",
|
|
172
174
|
"port": 8000,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.2.10
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -227,11 +227,11 @@ class GitCodeLLMTool:
|
|
|
227
227
|
:param client: Optional synchronous GitCode client.
|
|
228
228
|
:param async_client: Optional asynchronous GitCode client.
|
|
229
229
|
:param api_key: Personal access token used when clients are not supplied.
|
|
230
|
-
:param owner: Default repository owner for generated clients.
|
|
231
|
-
:param repo: Default repository name for generated clients.
|
|
232
230
|
:param base_url: Base URL for generated clients.
|
|
233
231
|
:param timeout: Request timeout for generated clients.
|
|
234
232
|
:param decrypt: Optional decryption function for encrypted access tokens.
|
|
233
|
+
:param owner: Default repository owner for generated clients.
|
|
234
|
+
:param repo: Default repository name for generated clients.
|
|
235
235
|
"""
|
|
236
236
|
|
|
237
237
|
def __init__(
|
|
@@ -240,11 +240,11 @@ class GitCodeLLMTool:
|
|
|
240
240
|
client: Optional[GitCode] = None,
|
|
241
241
|
async_client: Optional[AsyncGitCode] = None,
|
|
242
242
|
api_key: Optional[str] = None,
|
|
243
|
-
owner: Optional[str] = None,
|
|
244
|
-
repo: Optional[str] = None,
|
|
245
243
|
base_url: str = DEFAULT_BASE_URL,
|
|
246
244
|
timeout: Optional[float] = None,
|
|
247
245
|
decrypt: Optional[Callable] = None,
|
|
246
|
+
owner: Optional[str] = None,
|
|
247
|
+
repo: Optional[str] = None,
|
|
248
248
|
) -> None:
|
|
249
249
|
"""Create a reusable tool with lazy sync and async clients."""
|
|
250
250
|
self._client = client
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|