gitcode_api.llm

LLM tool adapters for the GitCode SDK.

class GitCodeLLMTool(*, client: GitCode | None = None, async_client: AsyncGitCode | None = None, api_key: str | None = None, base_url: str = 'https://api.gitcode.com/api/v5', timeout: float | None = None, decrypt: Callable | None = None, owner: str | None = None, repo: str | None = None)

Bases: object

Callable GitCode API tool shared by OpenAI and MCP adapters.

Parameters:
  • client – Optional synchronous GitCode client.

  • async_client – Optional asynchronous GitCode client.

  • api_key – Personal access token used when clients are not supplied.

  • base_url – Base URL for generated clients.

  • timeout – Request timeout for generated clients.

  • decrypt – Optional decryption function for encrypted access tokens.

  • owner – Default repository owner for generated clients.

  • repo – Default repository name for generated clients.

Create a reusable tool with lazy sync and async clients.

property client: GitCode

Return the synchronous client, creating it lazily when needed.

property async_client: AsyncGitCode

Return the asynchronous client, creating it lazily when needed.

class GitCodeOpenAITool(async_mode: bool = False, indent: int = 2, *, client: GitCode | None = None, async_client: AsyncGitCode | None = None, api_key: str | None = None, base_url: str = 'https://api.gitcode.com/api/v5', timeout: float | None = None, decrypt: Callable | None = None, owner: str | None = None, repo: str | None = None)

Bases: GitCodeLLMTool

OpenAI-compatible callable tool for invoking GitCode SDK resources.

Parameters:
  • async_mode – When true, calling the instance returns the async tool coroutine.

  • indentindent argument passed to json.dumps() when serializing invocation results (default 2).

  • client – Optional synchronous GitCode client.

  • async_client – Optional asynchronous GitCode client.

  • api_key – Personal access token used when clients are not supplied.

  • base_url – Base URL for generated clients.

  • timeout – Request timeout for generated clients.

  • decrypt – Optional decryption function for encrypted access tokens.

  • owner – Default repository owner for generated clients.

  • repo – Default repository name for generated clients.

Create an OpenAI tool wrapper.

property tool: Dict[str, Any]

Return this tool in OpenAI Chat Completions tool format.

to_dict() Dict[str, Any]

Return this tool in OpenAI Chat Completions tool format.

class GitCodeMCP(name: str = 'GitCode API', tool: GitCodeLLMTool | None = None, **kwargs: Any)

Bases: object

Small FastMCP server wrapper exposing the GitCode API tool.

Parameters:
  • name – MCP server name.

  • tool – Optional preconfigured shared GitCode LLM tool.

  • kwargs – Forwarded to fastmcp.FastMCP. If instructions is omitted, a default overview of the tool (parameters, byte encoding, and valid op_type values) is supplied.

Create a FastMCP server and register the GitCode API tool.

create_mcp_gitcode_api_tool(tool: GitCodeLLMTool | None = None) Callable

Return the async callable that can be registered with an MCP server.

Parameters:

tool – Optional preconfigured shared GitCode LLM tool.

Returns:

Async callable using the standard GitCode tool parameters.

create_mcp_server(name: str = 'GitCode API', tool: GitCodeLLMTool | None = None, **kwargs: Any) FastMCP

Create a FastMCP server with the GitCode API tool already registered.

Parameters:
  • name – MCP server display name.

  • tool – Optional preconfigured GitCodeLLMTool.

  • kwargs – Forwarded to GitCodeMCP and then to fastmcp.FastMCP (for example instructions= to override the default server instructions).

Returns:

Configured FastMCP instance with gitcode_api_tool registered.

register_mcp_gitcode_api_tool(mcp: FastMCP | Any, tool: GitCodeLLMTool | None = None) Tool

Register the GitCode API tool with an existing FastMCP-compatible server.

Parameters:
  • mcp – FastMCP server instance.

  • tool – Optional preconfigured shared GitCode LLM tool.

Returns:

The registered tool callable.

register_mcp_help_resources(mcp: FastMCP | Any) None

Register optional MCP resources that mirror gitcode_api_tool help text.

Registers:

  • gitcode-api://help — markdown index of per-op_type URIs.

  • gitcode-api://help/{op_type} — plain-text method list for one resource.

No-op when mcp does not expose FastMCP’s resource decorator.

Parameters:

mcp – FastMCP server instance (or compatible object).

create_openjiuwen_gitcode_api_tool(name: str | None = None, description: str | None = None, *, client: GitCode | None = None, async_client: AsyncGitCode | None = None, api_key: str | None = None, base_url: str = 'https://api.gitcode.com/api/v5', timeout: float | None = None, decrypt: Callable[[...], Any] | None = None, owner: str | None = None, repo: str | None = None) LocalFunction

Create an openJiuwen LocalFunction for the GitCode API tool.

Parameters:
  • name – Tool name on the LocalFunction card; defaults to gitcode_api_tool.

  • description – Tool description on the card; defaults to the shared GitCode tool description.

  • client – Optional synchronous GitCode client.

  • async_client – Optional asynchronous GitCode client.

  • api_key – Personal access token when clients are not supplied.

  • base_url – Base URL for generated clients.

  • timeout – Request timeout for generated clients.

  • decrypt – Optional decryption function for encrypted access tokens.

  • owner – Default repository owner for generated clients.

  • repo – Default repository name for generated clients.

Returns:

openJiuwen LocalFunction with the standard parameter schema.