gitcode-api 1.2.6__py3-none-any.whl → 1.2.8__py3-none-any.whl
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/cli.py +0 -1
- gitcode_api/llm/__init__.py +9 -1
- gitcode_api/llm/_tool.py +70 -10
- gitcode_api/llm/mcp.py +64 -9
- gitcode_api/run_mcp.py +6 -0
- gitcode_api/version.txt +1 -1
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/METADATA +20 -2
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/RECORD +12 -11
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/WHEEL +0 -0
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/entry_points.txt +0 -0
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/licenses/LICENSE +0 -0
- {gitcode_api-1.2.6.dist-info → gitcode_api-1.2.8.dist-info}/top_level.txt +0 -0
gitcode_api/cli.py
CHANGED
gitcode_api/llm/__init__.py
CHANGED
|
@@ -4,7 +4,13 @@ from importlib import import_module
|
|
|
4
4
|
from typing import TYPE_CHECKING, Any, Dict
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
|
-
from .mcp import
|
|
7
|
+
from .mcp import (
|
|
8
|
+
GitCodeMCP,
|
|
9
|
+
create_mcp_gitcode_api_tool,
|
|
10
|
+
create_mcp_server,
|
|
11
|
+
register_mcp_gitcode_api_tool,
|
|
12
|
+
register_mcp_help_resources,
|
|
13
|
+
)
|
|
8
14
|
from .openai import GitCodeOpenAITool
|
|
9
15
|
|
|
10
16
|
|
|
@@ -13,6 +19,7 @@ _IMPORT_MAP = {
|
|
|
13
19
|
"create_mcp_gitcode_api_tool": ".mcp",
|
|
14
20
|
"create_mcp_server": ".mcp",
|
|
15
21
|
"register_mcp_gitcode_api_tool": ".mcp",
|
|
22
|
+
"register_mcp_help_resources": ".mcp",
|
|
16
23
|
"GitCodeOpenAITool": ".openai",
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -46,4 +53,5 @@ __all__ = [
|
|
|
46
53
|
"create_mcp_gitcode_api_tool",
|
|
47
54
|
"create_mcp_server",
|
|
48
55
|
"register_mcp_gitcode_api_tool",
|
|
56
|
+
"register_mcp_help_resources",
|
|
49
57
|
]
|
gitcode_api/llm/_tool.py
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import base64
|
|
4
4
|
import inspect
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
6
7
|
from collections.abc import Mapping
|
|
7
8
|
from functools import lru_cache
|
|
8
|
-
import os
|
|
9
9
|
from typing import Any, Callable, Dict, Optional, Tuple
|
|
10
10
|
|
|
11
11
|
from gitcode_api import (
|
|
@@ -26,9 +26,27 @@ OP_TYPES = frozenset(
|
|
|
26
26
|
if inspect.isclass(annotation) and issubclass(annotation, SyncResource)
|
|
27
27
|
)
|
|
28
28
|
OP_TYPE_ENUM = sorted(OP_TYPES)
|
|
29
|
+
|
|
30
|
+
MCP_SERVER_INSTRUCTIONS = (
|
|
31
|
+
"This MCP server exposes the GitCode REST API through the gitcode-api package.\n\n"
|
|
32
|
+
"Use the single tool gitcode_api_tool with:\n"
|
|
33
|
+
"- op_type (required): client resource groups (same attribute names as on GitCode).\n"
|
|
34
|
+
"- action: the method on that resource (for example get, list).\n"
|
|
35
|
+
"- params: keyword arguments for that method as a JSON object; omit or null means {}.\n"
|
|
36
|
+
"- help: when true, returns formatted help (available methods or a method signature) instead of "
|
|
37
|
+
"calling the API where applicable.\n\n"
|
|
38
|
+
"Successful results are JSON-serializable. Raw bytes from endpoints such as contents.get_raw are "
|
|
39
|
+
'returned as {"encoding": "base64", "data": "<ascii>"}.\n'
|
|
40
|
+
'Failures are objects with "error": true and a "message" string.\n\n'
|
|
41
|
+
"Valid op_type values for this client version:\n- " + "\n- ".join(OP_TYPE_ENUM) + "\n\n"
|
|
42
|
+
"Optional MCP resources (read without calling the tool):\n"
|
|
43
|
+
"- gitcode-api://help — markdown index of help URIs\n"
|
|
44
|
+
"- gitcode-api://help/{op_type} — plain-text method list for that client resource\n"
|
|
45
|
+
)
|
|
46
|
+
|
|
29
47
|
TOOL_NAME = "gitcode_api_tool"
|
|
30
48
|
TOOL_DESCRIPTION = (
|
|
31
|
-
"Call the GitCode REST API through the gitcode-api
|
|
49
|
+
"Call the GitCode REST API through the gitcode-api client. Use op_type to choose a client resource group, "
|
|
32
50
|
"action as the resource method name, and params as the keyword arguments for that method. Set help=true to "
|
|
33
51
|
"inspect available resource methods or a target method signature without sending an API request."
|
|
34
52
|
)
|
|
@@ -38,7 +56,7 @@ TOOL_PARAMETERS = {
|
|
|
38
56
|
"op_type": {
|
|
39
57
|
"type": "string",
|
|
40
58
|
"enum": OP_TYPE_ENUM,
|
|
41
|
-
"description": "
|
|
59
|
+
"description": "Resource group matching client.<op_type>, such as repos, issues, or pulls.",
|
|
42
60
|
},
|
|
43
61
|
"action": {
|
|
44
62
|
"type": "string",
|
|
@@ -46,11 +64,11 @@ TOOL_PARAMETERS = {
|
|
|
46
64
|
},
|
|
47
65
|
"params": {
|
|
48
66
|
"type": "object",
|
|
49
|
-
"description": "Keyword arguments passed to the
|
|
67
|
+
"description": "Keyword arguments passed to the client method. Omitted or null is treated as {}.",
|
|
50
68
|
},
|
|
51
69
|
"help": {
|
|
52
70
|
"type": "boolean",
|
|
53
|
-
"description": "When true, return dynamic
|
|
71
|
+
"description": "When true, return dynamic client help instead of sending a request.",
|
|
54
72
|
"default": False,
|
|
55
73
|
},
|
|
56
74
|
},
|
|
@@ -73,7 +91,7 @@ def error_dict(message: str, **extra: Any) -> Dict[str, Any]:
|
|
|
73
91
|
|
|
74
92
|
|
|
75
93
|
def serialize(value: Any) -> Any:
|
|
76
|
-
"""Convert
|
|
94
|
+
"""Convert client responses into JSON-serializable values for tool clients."""
|
|
77
95
|
if value is None or isinstance(value, (bool, int, float, str)):
|
|
78
96
|
return value
|
|
79
97
|
if isinstance(value, bytes):
|
|
@@ -129,6 +147,44 @@ def _format_action_help(*, op_type: str, resource: Any, action: str) -> str:
|
|
|
129
147
|
return _format_help(op_type=op_type, resource=None, header=header)
|
|
130
148
|
|
|
131
149
|
|
|
150
|
+
def op_type_help_resource_body(op_type: str) -> str:
|
|
151
|
+
"""Return plain-text method list for one ``op_type``.
|
|
152
|
+
|
|
153
|
+
Content matches :meth:`GitCodeLLMTool.__async_call__` with ``help=true`` and an empty ``action``.
|
|
154
|
+
|
|
155
|
+
:param op_type: Resource attribute name on :class:`~gitcode_api.GitCode`.
|
|
156
|
+
:returns: Help body for MCP ``gitcode-api://help/{op_type}`` resources.
|
|
157
|
+
"""
|
|
158
|
+
if op_type not in OP_TYPES:
|
|
159
|
+
allowed = ", ".join(OP_TYPE_ENUM)
|
|
160
|
+
return f"Unknown op_type {op_type!r}. Allowed: {allowed}."
|
|
161
|
+
resource = resource_for_op_type(op_type)
|
|
162
|
+
header = "Specify non-empty action to invoke a method. Available methods:"
|
|
163
|
+
return _format_help(op_type=op_type, resource=resource, header=header)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def help_resource_index_body() -> str:
|
|
167
|
+
"""Return markdown listing ``gitcode-api://help/<op_type>`` URIs for MCP discovery.
|
|
168
|
+
|
|
169
|
+
:returns: Index body for MCP ``gitcode-api://help``.
|
|
170
|
+
"""
|
|
171
|
+
lines = [
|
|
172
|
+
"# GitCode API — MCP help resources",
|
|
173
|
+
"",
|
|
174
|
+
"Read any URI below for the method list for that `op_type` on `gitcode_api_tool`.",
|
|
175
|
+
"",
|
|
176
|
+
]
|
|
177
|
+
for name in OP_TYPE_ENUM:
|
|
178
|
+
lines.append(f"- gitcode-api://help/{name}")
|
|
179
|
+
lines.extend(
|
|
180
|
+
[
|
|
181
|
+
"",
|
|
182
|
+
"The same text is returned by `gitcode_api_tool` with `help: true` and an empty `action`.",
|
|
183
|
+
]
|
|
184
|
+
)
|
|
185
|
+
return "\n".join(lines)
|
|
186
|
+
|
|
187
|
+
|
|
132
188
|
def validate_call_kwargs(
|
|
133
189
|
fn: Callable[..., Any], params: Optional[Dict[str, Any]]
|
|
134
190
|
) -> Tuple[Optional[Dict[str, Any]], Optional[str]]:
|
|
@@ -191,8 +247,6 @@ class GitCodeLLMTool:
|
|
|
191
247
|
decrypt: Optional[Callable] = None,
|
|
192
248
|
) -> None:
|
|
193
249
|
"""Create a reusable tool with lazy sync and async clients."""
|
|
194
|
-
if not (api_key or os.getenv(DEFAULT_TOKEN_ENV)):
|
|
195
|
-
raise GitCodeConfigurationError("No API key provided. Pass api_key=... or set GITCODE_ACCESS_TOKEN.")
|
|
196
250
|
self._client = client
|
|
197
251
|
self._async_client = async_client
|
|
198
252
|
self._client_kwargs = {
|
|
@@ -204,10 +258,15 @@ class GitCodeLLMTool:
|
|
|
204
258
|
"decrypt": decrypt,
|
|
205
259
|
}
|
|
206
260
|
|
|
261
|
+
def _require_api_key_for_clients(self) -> None:
|
|
262
|
+
if not (self._client_kwargs.get("api_key") or os.getenv(DEFAULT_TOKEN_ENV)):
|
|
263
|
+
raise GitCodeConfigurationError("No API key provided. Pass api_key=... or set GITCODE_ACCESS_TOKEN.")
|
|
264
|
+
|
|
207
265
|
@property
|
|
208
266
|
def client(self) -> GitCode:
|
|
209
267
|
"""Return the synchronous client, creating it lazily when needed."""
|
|
210
268
|
if self._client is None:
|
|
269
|
+
self._require_api_key_for_clients()
|
|
211
270
|
self._client = GitCode(**self._client_kwargs) # type: ignore[arg-type]
|
|
212
271
|
return self._client
|
|
213
272
|
|
|
@@ -215,6 +274,7 @@ class GitCodeLLMTool:
|
|
|
215
274
|
def async_client(self) -> AsyncGitCode:
|
|
216
275
|
"""Return the asynchronous client, creating it lazily when needed."""
|
|
217
276
|
if self._async_client is None:
|
|
277
|
+
self._require_api_key_for_clients()
|
|
218
278
|
self._async_client = AsyncGitCode(**self._client_kwargs) # type: ignore[arg-type]
|
|
219
279
|
return self._async_client
|
|
220
280
|
|
|
@@ -226,7 +286,7 @@ class GitCodeLLMTool:
|
|
|
226
286
|
help: bool = False,
|
|
227
287
|
**kwargs,
|
|
228
288
|
) -> Any:
|
|
229
|
-
"""Invoke a synchronous GitCode
|
|
289
|
+
"""Invoke a synchronous GitCode client method through the tool contract."""
|
|
230
290
|
if kwargs:
|
|
231
291
|
return error_dict('Invalid tool invoke, API parameters should go into "params"')
|
|
232
292
|
return self._invoke(op_type=op_type, action=action, params=params, help=help)
|
|
@@ -239,7 +299,7 @@ class GitCodeLLMTool:
|
|
|
239
299
|
help: bool = False,
|
|
240
300
|
**kwargs,
|
|
241
301
|
) -> Any:
|
|
242
|
-
"""Invoke an asynchronous GitCode
|
|
302
|
+
"""Invoke an asynchronous GitCode client method through the tool contract."""
|
|
243
303
|
if kwargs:
|
|
244
304
|
return error_dict('Invalid tool invoke, API parameters should go into "params"')
|
|
245
305
|
return await self._ainvoke(op_type=op_type, action=action, params=params, help=help)
|
gitcode_api/llm/mcp.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
"""FastMCP integration for the GitCode
|
|
1
|
+
"""FastMCP integration for the GitCode LLM tool."""
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
|
|
4
4
|
|
|
5
|
-
from ._tool import
|
|
5
|
+
from ._tool import (
|
|
6
|
+
MCP_SERVER_INSTRUCTIONS,
|
|
7
|
+
TOOL_DESCRIPTION,
|
|
8
|
+
TOOL_NAME,
|
|
9
|
+
GitCodeLLMTool,
|
|
10
|
+
help_resource_index_body,
|
|
11
|
+
op_type_help_resource_body,
|
|
12
|
+
)
|
|
6
13
|
|
|
7
14
|
if TYPE_CHECKING:
|
|
8
15
|
from fastmcp import FastMCP
|
|
@@ -25,7 +32,7 @@ def _load_fastmcp() -> tuple["type[FastMCP]", Callable[..., "Tool"]]:
|
|
|
25
32
|
return FastMCP, fastmcp_tool # type: ignore[return-value]
|
|
26
33
|
|
|
27
34
|
|
|
28
|
-
def create_mcp_gitcode_api_tool(tool: Optional[GitCodeLLMTool] = None) ->
|
|
35
|
+
def create_mcp_gitcode_api_tool(tool: Optional[GitCodeLLMTool] = None) -> Callable:
|
|
29
36
|
"""Return the async callable that can be registered with an MCP server.
|
|
30
37
|
|
|
31
38
|
:param tool: Optional preconfigured shared GitCode LLM tool.
|
|
@@ -36,7 +43,7 @@ def create_mcp_gitcode_api_tool(tool: Optional[GitCodeLLMTool] = None) -> Any:
|
|
|
36
43
|
async def gitcode_api_tool(
|
|
37
44
|
op_type: str, action: str = "", params: Optional[dict[str, Any]] = None, help: bool = False
|
|
38
45
|
) -> Any:
|
|
39
|
-
"""Call GitCode
|
|
46
|
+
"""Call GitCode client resources using op_type, action, and params."""
|
|
40
47
|
return await wrapped.__async_call__(op_type=op_type, action=action, params=params, help=help)
|
|
41
48
|
|
|
42
49
|
gitcode_api_tool.__name__ = TOOL_NAME
|
|
@@ -44,7 +51,7 @@ def create_mcp_gitcode_api_tool(tool: Optional[GitCodeLLMTool] = None) -> Any:
|
|
|
44
51
|
return gitcode_api_tool
|
|
45
52
|
|
|
46
53
|
|
|
47
|
-
def register_mcp_gitcode_api_tool(mcp: Union["FastMCP", Any], tool: Optional[GitCodeLLMTool] = None) ->
|
|
54
|
+
def register_mcp_gitcode_api_tool(mcp: Union["FastMCP", Any], tool: Optional[GitCodeLLMTool] = None) -> "Tool":
|
|
48
55
|
"""Register the GitCode API tool with an existing FastMCP-compatible server.
|
|
49
56
|
|
|
50
57
|
:param mcp: FastMCP server instance.
|
|
@@ -64,27 +71,74 @@ def register_mcp_gitcode_api_tool(mcp: Union["FastMCP", Any], tool: Optional[Git
|
|
|
64
71
|
raise TypeError("mcp must provide a tool decorator or add_tool method")
|
|
65
72
|
|
|
66
73
|
|
|
74
|
+
def register_mcp_help_resources(mcp: Union["FastMCP", Any]) -> None:
|
|
75
|
+
"""Register optional MCP resources that mirror ``gitcode_api_tool`` help text.
|
|
76
|
+
|
|
77
|
+
Registers:
|
|
78
|
+
|
|
79
|
+
* ``gitcode-api://help`` — markdown index of per-``op_type`` URIs.
|
|
80
|
+
* ``gitcode-api://help/{op_type}`` — plain-text method list for one resource.
|
|
81
|
+
|
|
82
|
+
No-op when ``mcp`` does not expose FastMCP's ``resource`` decorator.
|
|
83
|
+
|
|
84
|
+
:param mcp: FastMCP server instance (or compatible object).
|
|
85
|
+
"""
|
|
86
|
+
if not hasattr(mcp, "resource"):
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
@mcp.resource(
|
|
90
|
+
"gitcode-api://help/{op_type}",
|
|
91
|
+
name="gitcode_api_op_type_help",
|
|
92
|
+
description=("Method list for one op_type (same as gitcode_api_tool with help=true and empty action)."),
|
|
93
|
+
mime_type="text/plain",
|
|
94
|
+
)
|
|
95
|
+
async def _op_type_help_resource(op_type: str) -> str:
|
|
96
|
+
return op_type_help_resource_body(op_type)
|
|
97
|
+
|
|
98
|
+
@mcp.resource(
|
|
99
|
+
"gitcode-api://help",
|
|
100
|
+
name="gitcode_api_help_index",
|
|
101
|
+
description="Markdown index of gitcode-api://help/{op_type} help resources.",
|
|
102
|
+
mime_type="text/markdown",
|
|
103
|
+
)
|
|
104
|
+
async def _help_index_resource() -> str:
|
|
105
|
+
return help_resource_index_body()
|
|
106
|
+
|
|
107
|
+
_ = (_op_type_help_resource, _help_index_resource)
|
|
108
|
+
|
|
109
|
+
|
|
67
110
|
class GitCodeMCP:
|
|
68
111
|
"""Small FastMCP server wrapper exposing the GitCode API tool.
|
|
69
112
|
|
|
70
113
|
:param name: MCP server name.
|
|
71
114
|
:param tool: Optional preconfigured shared GitCode LLM tool.
|
|
72
|
-
:param kwargs: Forwarded to ``fastmcp.FastMCP``.
|
|
115
|
+
:param kwargs: Forwarded to ``fastmcp.FastMCP``. If ``instructions`` is omitted, a default overview
|
|
116
|
+
of the tool (parameters, byte encoding, and valid ``op_type`` values) is supplied.
|
|
73
117
|
"""
|
|
74
118
|
|
|
75
|
-
def __init__(self, name: str = "GitCode API", tool: Optional[GitCodeLLMTool] = None, **kwargs) -> None:
|
|
119
|
+
def __init__(self, name: str = "GitCode API", tool: Optional[GitCodeLLMTool] = None, **kwargs: Any) -> None:
|
|
76
120
|
"""Create a FastMCP server and register the GitCode API tool."""
|
|
77
121
|
fastmcp, *_ = _load_fastmcp()
|
|
122
|
+
if "instructions" not in kwargs:
|
|
123
|
+
kwargs["instructions"] = MCP_SERVER_INSTRUCTIONS
|
|
78
124
|
self.mcp = fastmcp(name, **kwargs)
|
|
79
125
|
self.gitcode_api_tool = register_mcp_gitcode_api_tool(self.mcp, tool)
|
|
126
|
+
register_mcp_help_resources(self.mcp)
|
|
80
127
|
|
|
81
128
|
def __getattr__(self, name: str) -> Any:
|
|
82
129
|
"""Delegate unknown attributes to the wrapped FastMCP server."""
|
|
83
130
|
return getattr(self.mcp, name)
|
|
84
131
|
|
|
85
132
|
|
|
86
|
-
def create_mcp_server(name: str = "GitCode API", tool: Optional[GitCodeLLMTool] = None, **kwargs) -> "FastMCP":
|
|
87
|
-
"""Create a FastMCP server with the GitCode API tool already registered.
|
|
133
|
+
def create_mcp_server(name: str = "GitCode API", tool: Optional[GitCodeLLMTool] = None, **kwargs: Any) -> "FastMCP":
|
|
134
|
+
"""Create a FastMCP server with the GitCode API tool already registered.
|
|
135
|
+
|
|
136
|
+
:param name: MCP server display name.
|
|
137
|
+
:param tool: Optional preconfigured :class:`~gitcode_api.llm._tool.GitCodeLLMTool`.
|
|
138
|
+
:param kwargs: Forwarded to :class:`GitCodeMCP` and then to ``fastmcp.FastMCP`` (for example
|
|
139
|
+
``instructions=`` to override the default server instructions).
|
|
140
|
+
:returns: Configured ``FastMCP`` instance with ``gitcode_api_tool`` registered.
|
|
141
|
+
"""
|
|
88
142
|
return GitCodeMCP(name=name, tool=tool, **kwargs).mcp
|
|
89
143
|
|
|
90
144
|
|
|
@@ -93,4 +147,5 @@ __all__ = [
|
|
|
93
147
|
"create_mcp_gitcode_api_tool",
|
|
94
148
|
"create_mcp_server",
|
|
95
149
|
"register_mcp_gitcode_api_tool",
|
|
150
|
+
"register_mcp_help_resources",
|
|
96
151
|
]
|
gitcode_api/run_mcp.py
ADDED
gitcode_api/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.2.
|
|
1
|
+
1.2.8
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP and OpenAI tool) for agents. Community-maintained.
|
|
5
5
|
Author-email: Hugo Huang <hugo@hugohuang.com>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: changelog, https://gitcode-api.readthedocs.io/en/latest/changelog.html
|
|
8
|
+
Project-URL: issues, https://github.com/Trenza1ore/GitCode-API/issues
|
|
8
9
|
Project-URL: documentation, https://gitcode-api.readthedocs.io
|
|
9
10
|
Project-URL: gitcode, https://gitcode.com/SushiNinja/GitCode-API
|
|
10
11
|
Project-URL: github, https://github.com/Trenza1ore/GitCode-API
|
|
12
|
+
Project-URL: homepage, https://linktr.ee/Hugoooo
|
|
13
|
+
Project-URL: author, https://hugohuang.com
|
|
11
14
|
Keywords: gitcode,git,devops,api,sdk,python,httpx,client,mcp,agent,fastmcp,llm,mcp client,mcp server,model context protocol
|
|
12
15
|
Classifier: Development Status :: 4 - Beta
|
|
13
16
|
Classifier: Programming Language :: Python
|
|
@@ -34,7 +37,8 @@ Dynamic: license-file
|
|
|
34
37
|
|
|
35
38
|
# GitCode-API
|
|
36
39
|
|
|
37
|
-
[](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
|
+
[](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)
|
|
38
42
|
[](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API)
|
|
39
43
|
|
|
40
44
|
[](https://gitcode-api.readthedocs.io) [](README.zh.md)
|
|
@@ -48,6 +52,8 @@ Dynamic: license-file
|
|
|
48
52
|
- Resource groups such as `client.repos`, `client.pulls`, and `client.users`.
|
|
49
53
|
- Repository defaults via `owner=` and `repo=` on the client.
|
|
50
54
|
- Sphinx docs plus a mirrored GitCode REST API reference in `docs/`.
|
|
55
|
+
- Provides MCP server & OpenAI tool for LLM agent usage.
|
|
56
|
+
- Provide MCP service that directly installs to your IDE of choice, such as Cursor and VS Code!
|
|
51
57
|
|
|
52
58
|
## Installation
|
|
53
59
|
|
|
@@ -57,6 +63,16 @@ Install from PyPI:
|
|
|
57
63
|
pip install -U gitcode-api
|
|
58
64
|
```
|
|
59
65
|
|
|
66
|
+
Install the MCP server to your AI-powered IDE of choice:
|
|
67
|
+
[](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19)
|
|
68
|
+
[](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)
|
|
69
|
+
[](https://insiders.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&quality=insiders)
|
|
70
|
+
[](https://vs-open.link/mcp-install?%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)
|
|
71
|
+
[](https://block.github.io/goose/extension?cmd=uvx&arg=--from%2520gitcode-api%5Bmcp%5D%2520gitcode-api%2520serve&id=GitCode%20API&name=GitCode%20API&description=MCP%20Server%20for%20GitCode%20API)
|
|
72
|
+
[](https://lmstudio.ai/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19)
|
|
73
|
+
|
|
74
|
+
For detailed setup (including installing to services like Claude Code / Codex): see [install_mcp_server.md](install_mcp_server.md).
|
|
75
|
+
|
|
60
76
|
## Authentication
|
|
61
77
|
|
|
62
78
|
Pass `api_key=` directly, or set `GITCODE_ACCESS_TOKEN` in your environment:
|
|
@@ -299,6 +315,8 @@ The same server is available from the CLI as `gitcode-api serve` (see the [CLI](
|
|
|
299
315
|
|
|
300
316
|
To share auth or clients across tools, build `GitCodeLLMTool` once (`from gitcode_api.llm._tool import GitCodeLLMTool`) and pass it as `tool=` into `GitCodeMCP`, `create_mcp_server`, `register_mcp_gitcode_api_tool`, or `create_mcp_gitcode_api_tool`.
|
|
301
317
|
|
|
318
|
+
**Claude Desktop (MCPB):** published GitHub Releases include a `gitcode-<version>.mcpb` bundle for one-click installation as a Claude Desktop extension; see Anthropic’s guide, [Build a desktop extension with MCPB](https://claude.com/docs/connectors/building/mcpb). From a checkout you can run `make mcpb` (requires the [`@anthropic-ai/mcpb`](https://www.npmjs.com/package/@anthropic-ai/mcpb) CLI on your `PATH`).
|
|
319
|
+
|
|
302
320
|
## Examples
|
|
303
321
|
|
|
304
322
|
Runnable examples live in `examples/`:
|
|
@@ -6,12 +6,13 @@ gitcode_api/_cli_banner.py,sha256=3DsoJ2qZ-mWWB4yD-cnxDN_osXzrUKabrA5tbV6752M,97
|
|
|
6
6
|
gitcode_api/_client.py,sha256=bmZxBHdfshM5Kv_EurHUVu8rsEj0k3Up3ATSIPaFrvc,8258
|
|
7
7
|
gitcode_api/_exceptions.py,sha256=T5N8gBGmPSktDkLP5P_hxbzOHw3W378TzxN1xja40pA,1140
|
|
8
8
|
gitcode_api/_models.py,sha256=v-GZzCGAb3_frY6wFiQww9m271U5MigivpEHDHnoDcI,109030
|
|
9
|
-
gitcode_api/cli.py,sha256=
|
|
9
|
+
gitcode_api/cli.py,sha256=7LLDRCKJg7avaLgIwckZZC5LewSpMPWNQFFDRhAQkEs,16616
|
|
10
10
|
gitcode_api/py.typed,sha256=mDShSrm8qg9qjacQc2F-rI8ATllqP6EdgHuEYxuCXZ0,7
|
|
11
|
-
gitcode_api/
|
|
12
|
-
gitcode_api/
|
|
13
|
-
gitcode_api/llm/
|
|
14
|
-
gitcode_api/llm/
|
|
11
|
+
gitcode_api/run_mcp.py,sha256=a7zNrcAooGovzokJwTHQGj6iT4g7iltaUoD_E1KLvMg,130
|
|
12
|
+
gitcode_api/version.txt,sha256=0tMVNGQdoBgBUSo-x5O8jVcTLUzvoZpftQPomV85648,6
|
|
13
|
+
gitcode_api/llm/__init__.py,sha256=nCWs5jCnSxC9ILhiAh4vrNG0dVxkK3iqVz66c-0sE4I,1450
|
|
14
|
+
gitcode_api/llm/_tool.py,sha256=mBQPYzQ-SuSWgumapcjv3pjGQfcPYt-IxUXBT5un2Lk,16239
|
|
15
|
+
gitcode_api/llm/mcp.py,sha256=eeAuEETZ4THw31wbcnQaTlZQJ-9ZolvsejQY630OqHs,5702
|
|
15
16
|
gitcode_api/llm/openai.py,sha256=CcS3tFntzAuN2HMbbQDctb54AnasU3n3a1Jr9LWAHwM,1998
|
|
16
17
|
gitcode_api/resources/__init__.py,sha256=nsCKW0bFDZ5ombJZxLThmO82sOuF7o4OKUMRkAmwbwk,1725
|
|
17
18
|
gitcode_api/resources/_shared.py,sha256=7bCym8bIfs818SiYYrBGI7-ZtiYlxECSDG3RduInu10,5387
|
|
@@ -19,9 +20,9 @@ gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewt
|
|
|
19
20
|
gitcode_api/resources/collaboration.py,sha256=8lyk78GTjVXddiE9fieutsMGovRjteGfTJcAhwLoR0M,101607
|
|
20
21
|
gitcode_api/resources/misc.py,sha256=guDwh4cxbTVsSa7EivaYM3bKMJ8_Op4KucGbKEoayKE,22412
|
|
21
22
|
gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
|
|
22
|
-
gitcode_api-1.2.
|
|
23
|
-
gitcode_api-1.2.
|
|
24
|
-
gitcode_api-1.2.
|
|
25
|
-
gitcode_api-1.2.
|
|
26
|
-
gitcode_api-1.2.
|
|
27
|
-
gitcode_api-1.2.
|
|
23
|
+
gitcode_api-1.2.8.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
|
|
24
|
+
gitcode_api-1.2.8.dist-info/METADATA,sha256=xGX_RWA4_IiwVLLLGR1l58UVbiArZoocNxacHls7fU0,20698
|
|
25
|
+
gitcode_api-1.2.8.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
26
|
+
gitcode_api-1.2.8.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
|
|
27
|
+
gitcode_api-1.2.8.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
|
|
28
|
+
gitcode_api-1.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|